|
| 1 | +/** |
| 2 | + * @class |
| 3 | + * @brief The header information in an ACE file |
| 4 | + * |
| 5 | + * There are multiple version of the header. |
| 6 | + * |
| 7 | + * The 1.0.0 (or legacy header) contains the following information: |
| 8 | + * - line 1: ZAID, AW (atomic mass ratio), TZ (temperature in MeV), date |
| 9 | + * - line 2: description (70 characters), material identifier (10 characters) |
| 10 | + * |
| 11 | + * The 2.0.0 and 2.0.1 header contains the following information: |
| 12 | + * - line 1: VERS (header version), SZAID, SRC (evaluation source) |
| 13 | + * - line 2: AW (atomic mass ratio), TZ (temperature in MeV), date, N (comments) |
| 14 | + * - line 3 to N+2: comment lines (this is often 2 lines for the 1.0.0 |
| 15 | + * header but that is not guaranteed) |
| 16 | + * |
| 17 | + * Some ACE files with 2.0.x headers also seem to have some formatting issues |
| 18 | + * where the data is shifted by a column. |
| 19 | + */ |
1 | 20 | class Header { |
2 | | -public: |
3 | | - #include "ACEtk/Table/Header/String.hpp" |
4 | 21 |
|
5 | | - /* convenience typedefs */ |
6 | | - using Comment = String<70>; |
7 | | - using SZAID = String<24, true>; |
8 | | - |
9 | 22 | /* fields */ |
10 | | - year_month_day processDate; |
11 | | - Quantity< Mega<ElectronVolts> > processTemperature; |
12 | | - double atomicWeightRatio; |
13 | | - SZAID szaid; |
14 | | - std::vector< Comment > comments; |
15 | | - |
16 | | -protected: |
17 | | - using MAT = String<10, true>; |
18 | | - using Source = String<24>; |
19 | | - |
20 | | - template< int... values > |
21 | | - using Version = std::integer_sequence< int, values... > ; |
22 | | - |
23 | | - std::optional< MAT > mat; |
24 | | - std::optional< Source > source; |
| 23 | + std::string zaid_; |
| 24 | + double temp_; |
| 25 | + double awr_; |
| 26 | + std::string date_; |
| 27 | + std::vector< std::string > comments_; |
| 28 | + |
| 29 | + /* auxiliary functions */ |
| 30 | + static std::string strip( const std::string& string ) { |
| 31 | + |
| 32 | + std::string result = string; |
| 33 | + auto notspace = [] ( char c ) { return !std::isspace( c ); }; |
| 34 | + |
| 35 | + auto front = std::find_if( result.begin(), result.end(), notspace ); |
| 36 | + result.erase( result.begin(), front ); |
| 37 | + auto back = std::find_if( result.rbegin(), result.rend(), notspace ); |
| 38 | + result.erase( back.base(), result.end() ); |
| 39 | + return result; |
| 40 | + } |
| 41 | + |
| 42 | + static std::string left( const std::string& string, std::size_t length ) { |
| 43 | + |
| 44 | + std::string result = string; |
| 45 | + result.resize( length, ' ' ); |
| 46 | + return result; |
| 47 | + } |
| 48 | + |
| 49 | + static std::string right( const std::string& string, std::size_t length ) { |
| 50 | + |
| 51 | + std::string result = string; |
| 52 | + const auto pivot = result.size(); |
| 53 | + left( result, length ); |
| 54 | + std::rotate( result.begin(), |
| 55 | + std::next( result.begin(), pivot ), |
| 56 | + result.end() ); |
| 57 | + return result; |
| 58 | + } |
25 | 59 |
|
26 | 60 | public: |
27 | | - Header( year_month_day processDate, |
28 | | - Quantity< Mega<ElectronVolts> > processTemperature, |
29 | | - double atomicWeightRatio, |
30 | | - SZAID&& szaid, |
31 | | - std::vector< Comment >&& comments ) : |
32 | | - processDate( processDate ), |
33 | | - processTemperature( processTemperature ), |
34 | | - atomicWeightRatio( atomicWeightRatio ), |
35 | | - szaid( std::move(szaid) ), |
36 | | - comments( std::move(comments) ){} |
37 | | - |
38 | | - /* static methods */ |
39 | | - #include "ACEtk/Table/Header/src/parse.hpp" |
| 61 | + |
| 62 | + Header( const Header& ) = default; |
| 63 | + Header( Header&& ) = default; |
| 64 | + |
| 65 | + Header( const std::string& zaid, double awr, double temperature, |
| 66 | + const std::string& date, const std::string& title, |
| 67 | + const std::string& material ) : |
| 68 | + zaid_( strip( zaid ) ), awr_( awr ), temp_( temperature ), |
| 69 | + date_( strip( date ) ), |
| 70 | + comments_( { left( title, 70 ) + right( material, 10 ) } ) {} |
| 71 | + |
| 72 | + /** |
| 73 | + * @brief Constructor (from a buffer) |
| 74 | + * |
| 75 | + * @tparam Iterator a buffer iterator |
| 76 | + * |
| 77 | + * @param[in] state the buffer state |
| 78 | + */ |
| 79 | + template< typename Iterator > |
| 80 | + Header( State< Iterator >& state ) |
| 81 | + try : Header( parse( state ) ) {} |
| 82 | + catch( std::exception& e ) { |
| 83 | + |
| 84 | + Log::info("Error while constructing ACE Table Header"); |
| 85 | + throw e; |
| 86 | + } |
| 87 | + |
| 88 | + /* static methods */ |
40 | 89 | #include "ACEtk/Table/Header/src/print.hpp" |
| 90 | + |
| 91 | +private: |
| 92 | + |
| 93 | + #include "ACEtk/Table/Header/src/parse.hpp" |
41 | 94 | }; |
0 commit comments