| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "na64detID/kins.hh" | ||
| 2 | #include "na64util/str-fmt.hh" | ||
| 3 | #include "na64detID/TBNameErrors.hh" | ||
| 4 | |||
| 5 | #include <log4cpp/Category.hh> | ||
| 6 | |||
| 7 | #include <utility> | ||
| 8 | |||
| 9 | namespace na64dp { | ||
| 10 | namespace nameutils { | ||
| 11 | |||
| 12 | KinFeaturesTable::KinID | ||
| 13 | 34 | KinFeaturesTable::kin_id( const std::string & name ) const { | |
| 14 |
1/1✓ Branch 1 taken 34 times.
|
34 | auto it = _kinIDs.find(name); |
| 15 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
|
34 | if( _kinIDs.end() == it ) { |
| 16 | ✗ | NA64DP_RUNTIME_ERROR( "Unknown detector kin \"%s\"" | |
| 17 | , name.c_str() ); | ||
| 18 | } | ||
| 19 | 68 | return it->second; | |
| 20 | } | ||
| 21 | |||
| 22 | const KinFeaturesTable::Features & | ||
| 23 | 16 | KinFeaturesTable::kin_features( KinID kid ) const { | |
| 24 |
1/1✓ Branch 1 taken 16 times.
|
16 | auto it = _kinTraits.find( kid ); |
| 25 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
|
16 | if( _kinTraits.end() == it ) { |
| 26 | ✗ | NA64DP_RUNTIME_ERROR( "Unknown chip(=%#x)+kin(=%#x) IDs pair." | |
| 27 | , kid.first | ||
| 28 | , kid.second ); | ||
| 29 | } | ||
| 30 | 32 | return it->second; | |
| 31 | } | ||
| 32 | |||
| 33 | const KinFeaturesTable::Features & | ||
| 34 | ✗ | KinFeaturesTable::kin_features( const std::string & name ) const { | |
| 35 | ✗ | auto kid = kin_id( name ); | |
| 36 | ✗ | return kin_features( kid ); | |
| 37 | } | ||
| 38 | |||
| 39 | KinFeaturesTable::Features & | ||
| 40 | 58 | KinFeaturesTable::define_kin( const std::string & kinName | |
| 41 | , DetKin_t kinID_ | ||
| 42 | , DetChip_t chipID | ||
| 43 | , const std::string & nameFormat | ||
| 44 | , const std::string & kinDescription | ||
| 45 | , const std::string & histsTPath | ||
| 46 | ) { | ||
| 47 |
2/2✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
|
58 | auto & L = log4cpp::Category::getInstance("detID"); |
| 48 |
4/4✓ Branch 0 taken 57 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 56 times.
|
58 | if( kinID_ > aux::gKinIDMax || 0 == kinID_ ) { |
| 49 | 2 | L.error( "Provided kin ID %#x (> %#x) or =0 for \"%s\" is out of range." | |
| 50 | , kinID_, aux::gKinIDMax, kinName.c_str() ); | ||
| 51 | throw errors::IDIsOutOfRange( "KinID is out of range." | ||
| 52 | 2 | , kinID_, aux::gKinIDMax ); | |
| 53 | } | ||
| 54 |
1/1✓ Branch 1 taken 56 times.
|
56 | KinID kinID = std::make_pair(chipID, kinID_); |
| 55 |
1/1✓ Branch 1 taken 56 times.
|
56 | auto nameIR = _kinIDs.emplace(kinName, kinID); |
| 56 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 55 times.
|
56 | if( !nameIR.second ) { |
| 57 | 1 | L.error( "Duplicating kin name \"%s\"." | |
| 58 | , kinName.c_str() ); | ||
| 59 | throw errors::NameIsNotUniq( "Kin name is not unique." | ||
| 60 | 1 | , kinName.c_str() ); | |
| 61 | } | ||
| 62 |
1/1✓ Branch 1 taken 55 times.
|
55 | auto kinIR = _kinTraits.emplace( kinID |
| 63 |
1/1✓ Branch 1 taken 55 times.
|
110 | , Features(kinName) ); |
| 64 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
|
55 | if( !kinIR.second ) { |
| 65 | ✗ | _kinIDs.erase( nameIR.first ); | |
| 66 | ✗ | throw errors::IDIsNotUniq( "Non-unique kin ID.", kinID_ ); | |
| 67 | } | ||
| 68 | 55 | Features & fts = kinIR.first->second; | |
| 69 |
1/1✓ Branch 1 taken 55 times.
|
55 | fts.description = kinDescription; |
| 70 |
1/1✓ Branch 1 taken 55 times.
|
55 | fts.nameFormat = nameFormat; |
| 71 |
1/1✓ Branch 1 taken 55 times.
|
55 | fts.pathFormat = histsTPath; |
| 72 | |||
| 73 | 55 | L.debug( "New detector kin \"%s\" on chip (%#x) is defined" | |
| 74 | " with ID %#x." | ||
| 75 | , kinName.c_str(), chipID, kinID_ ); | ||
| 76 | 55 | return fts; | |
| 77 | } | ||
| 78 | |||
| 79 | void | ||
| 80 | ✗ | KinFeaturesTable::clear() { | |
| 81 | ✗ | _kinTraits.clear(); | |
| 82 | ✗ | _kinIDs.clear(); | |
| 83 | } | ||
| 84 | |||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 |