GCC Code Coverage Report


Directory: ./
File: src/detID/chips.cc
Date: 2025-09-01 06:19:01
Exec Total Coverage
Lines: 25 39 64.1%
Functions: 3 5 60.0%
Branches: 18 24 75.0%

Line Branch Exec Source
1 #include "na64detID/chips.hh"
2 #include "na64detID/TBNameErrors.hh"
3 #include "na64util/str-fmt.hh"
4
5 #include <log4cpp/Category.hh>
6
7 namespace na64dp {
8 namespace nameutils {
9
10 DetChip_t
11 63 ChipFeaturesTable::chip_id( const std::string & chipName ) const {
12 assert(!_chipIDs.empty()); // LCOV_EXCL_LINE
13
1/1
✓ Branch 1 taken 63 times.
63 auto it = _chipIDs.find(chipName);
14
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 62 times.
63 if( _chipIDs.end() == it ) {
15 throw errors::NoEntryForKey<std::string>(
16 2 util::format( "Chip \"%s\" is not defined."
17 3 , chipName.c_str() ).c_str(), chipName);
18 }
19 124 return it->second;
20 }
21
22 const ChipFeaturesTable::Features &
23 26 ChipFeaturesTable::chip_features(DetChip_t chipID) const {
24
1/1
✓ Branch 1 taken 26 times.
26 auto it = _chipFeatures.find(chipID);
25
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 26 times.
26 if( _chipFeatures.end() == it ) {
26 // TODO: exception UnknownChipID
27 NA64DP_RUNTIME_ERROR( "Chip ID %#x is not defined.", chipID );
28 }
29 52 return it->second;
30 }
31
32 const ChipFeaturesTable::Features &
33 ChipFeaturesTable::chip_features(const std::string & chipName) const {
34 DetChip_t chipID = chip_id(chipName);
35 auto it = _chipFeatures.find(chipID);
36 assert( _chipFeatures.end() != it ); // maps are not synchronized
37 return it->second;
38 }
39
40 ChipFeaturesTable::Features &
41 24 ChipFeaturesTable::chip_add( const std::string & chipName
42 , DetChip_t chipID
43 , const std::string & chipDescription
44 , const std::string & histsTPath
45 ) {
46
2/2
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
24 auto & L = log4cpp::Category::getInstance("detID");
47
3/4
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
24 if( chipID > aux::gChipIDMax || 0 == chipID ) {
48 1 L.error( "Provided detector ID %#x (> %#x) or =0 is out of range."
49 , chipID
50 , aux::gChipIDMax
51 );
52 throw errors::IDIsOutOfRange( "ChipID is out of range."
53 1 , chipID, aux::gChipIDMax );
54 }
55
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
23 if( chipName.empty() ) {
56 NA64DP_RUNTIME_ERROR( "Empty chip name provided for id %d."
57 , (int) chipID );
58 }
59
60
1/1
✓ Branch 1 taken 23 times.
23 auto irName = _chipIDs.emplace(chipName, chipID);
61
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if( !irName.second ) {
63 NA64DP_RUNTIME_ERROR( "Chip name \"%s\" is already defined"
64 " (existing ID=%d, this ID=%d)."
65 , chipName.c_str()
66 , (int) irName.first->second
67 , (int) chipID );
68 }
69
70
2/2
✓ Branch 1 taken 23 times.
✓ Branch 4 taken 23 times.
23 auto ir = _chipFeatures.emplace( chipID, Features(chipName) );
71
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 if( ! ir.second ) {
73 L.error( "Duplicating chip ID %#x.", chipID );
74 _chipIDs.erase( irName.first );
75 throw errors::IDIsNotUniq( "Non-unique chip ID.", chipID );
76 }
77 23 L.debug( "Registered new chip \"%s\" with ID %#x."
78 , chipName.c_str(), chipID );
79 23 Features & ft = ir.first->second;
80
1/1
✓ Branch 1 taken 23 times.
23 ft.description = chipDescription;
81
1/1
✓ Branch 1 taken 23 times.
23 ft.pathFormat = histsTPath;
82 23 return ft;
83 }
84
85 void
86 ChipFeaturesTable::clear() {
87 _chipFeatures.clear();
88 _chipIDs.clear();
89 }
90
91 }
92 }
93
94