ATLAS Offline Software
Loading...
Searching...
No Matches
TGCTriggerDbAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9TGCTriggerDbAlg::TGCTriggerDbAlg(const std::string& name, ISvcLocator* pSvcLocator) :
10 AthCondAlgorithm(name, pSvcLocator)
11{}
12
14
15 ATH_MSG_INFO( "initialize " << name() );
16
17 ATH_CHECK(m_readKey_bw.initialize());
18 ATH_CHECK(m_readKey_eifi.initialize());
19 ATH_CHECK(m_readKey_tile.initialize());
20
21 ATH_CHECK(m_writeKey.initialize());
22
23 return StatusCode::SUCCESS;
24}
25
26StatusCode TGCTriggerDbAlg::execute(const EventContext& ctx) const
27{
29 if (writeHandle.isValid()) {
30 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
31 << ". In theory this should not be called, but may happen"
32 << " if multiple concurrent events are being processed out of order.");
33 return StatusCode::SUCCESS;
34 }
35
36 auto writeCdo = std::make_unique<TGCTriggerData>();
37
38 // Big wheel
40 const CondAttrListCollection* readCdo_bw(*readHandle_bw);
41
42 if (readCdo_bw == nullptr) {
43 ATH_MSG_ERROR("Null pointer to the read conditions object");
44 return StatusCode::FAILURE;
45 }
46
47 ATH_MSG_INFO("Size of CondAttrListCollection" << readHandle_bw.fullKey() << " = " << readCdo_bw->size());
48
49 EventIDRange rangeW_bw;
50 if ( !readHandle_bw.range(rangeW_bw) ) {
51 ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle_bw.key());
52 return StatusCode::FAILURE;
53 }
54 ATH_MSG_INFO("Range of input is " << rangeW_bw);
55
56 fillReadMapBw(writeCdo.get(), readCdo_bw);
57
58 // EIFI
60 const CondAttrListCollection* readCdo_eifi(*readHandle_eifi);
61
62 if (readCdo_eifi == nullptr) {
63 ATH_MSG_ERROR("Null pointer to the read conditions object");
64 return StatusCode::FAILURE;
65 }
66
67 ATH_MSG_INFO("Size of CondAttrListCollection" << readHandle_eifi.fullKey() << " = " << readCdo_eifi->size());
68
69 EventIDRange rangeW_eifi;
70 if ( !readHandle_eifi.range(rangeW_eifi) ) {
71 ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle_eifi.key());
72 return StatusCode::FAILURE;
73 }
74 ATH_MSG_INFO("Range of input is " << rangeW_eifi);
75
76 fillTrigBitEifi(writeCdo.get(), readCdo_eifi);
77
78 // Tile
80 const CondAttrListCollection* readCdo_tile = *readHandle_tile;
81 if (readCdo_tile == nullptr) {
82 ATH_MSG_ERROR("Null pointer to the read conditions object");
83 return StatusCode::FAILURE;
84 }
85 ATH_MSG_INFO("Size of CondAttrListCollection" << readHandle_tile.fullKey() << " = " << readCdo_tile->size());
86
87 EventIDRange rangeW_tile;
88 if ( !readHandle_tile.range(rangeW_tile) ) {
89 ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle_tile.key());
90 return StatusCode::FAILURE;
91 }
92 ATH_MSG_INFO("Range of input is " << rangeW_tile);
93
94 fillTrigBitTile(writeCdo.get(), readCdo_tile);
95
96 // write condition object
97 EventIDRange rangeIntersection = EventIDRange::intersect(rangeW_bw,rangeW_eifi,rangeW_tile);
98 if(rangeIntersection.start()>rangeIntersection.stop()) {
99 ATH_MSG_ERROR("Invalid intersection range: " << rangeIntersection);
100 return StatusCode::FAILURE;
101 }
102
103 if (writeHandle.record(rangeIntersection, std::move(writeCdo)).isFailure()) {
104 ATH_MSG_FATAL("Could not record TGCTriggerData " << writeHandle.key()
105 << " with EventRange " << rangeIntersection
106 << " into Conditions Store");
107 return StatusCode::FAILURE;
108 }
109 ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << rangeIntersection << " into Conditions Store");
110
111 return StatusCode::SUCCESS;
112}
113
114
116
117 ATH_MSG_INFO( "finalize " << name() );
118 return StatusCode::SUCCESS;
119}
120
121
123 const CondAttrListCollection* readCdo) const
124{
125 const uint8_t kNMODULETYPE = 12;
126 const uint8_t modulenumber[kNMODULETYPE] = {0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8};
127 const std::string modulename[kNMODULETYPE] = {"0","1","2a","2b","3","4","5a","5b","6","7","8a","8b"};
128 const std::string sidename[TGCTriggerData::N_SIDE] = {"A","C"};
129
130 bool first = true;
131
132 for(auto& attrmap : *readCdo) {
133 const coral::AttributeList& atr = attrmap.second;
134 writeCdo->m_active[TGCTriggerData::CW_BW] = atr["active"].data<bool>();
135 writeCdo->m_type[TGCTriggerData::CW_BW] = atr["type"].data<std::string>();
136
137 std::string version = *(static_cast<const std::string*>((atr["version"]).addressOfData()));
138 std::string file = *(static_cast<const std::string*>((atr["file"]).addressOfData()));
139 ATH_MSG_DEBUG("channel: " << attrmap.first << ", file: " << file);
140 if ( first ) {
141 ATH_MSG_INFO("type: " << writeCdo->m_type[TGCTriggerData::CW_BW]
142 << " active: " << writeCdo->m_active[TGCTriggerData::CW_BW] << " version: " << version);
143 first = false;
144 }
145 else {
146 ATH_MSG_DEBUG("type: " << writeCdo->m_type[TGCTriggerData::CW_BW]
147 << " active: " << writeCdo->m_active[TGCTriggerData::CW_BW] << " version: " << version);
148 }
149
150 if (!writeCdo->m_active[TGCTriggerData::CW_BW]) continue;
151
152 bool fullCW = (writeCdo->m_type[TGCTriggerData::CW_BW] == "full");
153
154 uint8_t sideId = 0; // if the file is not fullCW, sideId should be zero.
155 if(fullCW) {
156 std::string side = file.substr(strlen("RPhiCoincidenceMap."), 1);
157 for(int id=0; id<TGCTriggerData::N_SIDE; id++) {
158 if(sidename[id] == side) {
159 sideId = id;
160 break;
161 }
162 }
163 }
164
165 uint16_t octantId = 0; // if the file is not fullCW, octantId should be zero.
166 if(fullCW) {
167 octantId = std::stoi(file.substr(strlen("RPhiCoincidenceMap.X"), 1));
168 }
169
170 uint32_t octaddr = ((sideId & TGCTriggerData::SIDE_MASK)<<TGCTriggerData::SIDE_SHIFT) +
172
173 uint16_t moduleId = 0;
174 for(size_t iModule = 0; iModule < kNMODULETYPE; iModule++) {
175 std::ostringstream dbname;
176 dbname << "RPhiCoincidenceMap.";
177 if (fullCW) dbname << sidename[sideId] << octantId << ".";
178 dbname << "mod" << modulename[iModule] + "." + version +"._12.db";
179 if(dbname.str() == file) {
180 moduleId = iModule;
181 break;
182 }
183 }
184
185 std::string data = *(static_cast<const std::string*>((atr["data"]).addressOfData()));
186 std::istringstream stream(data);
187
188 char delimiter = '\n';
189 std::string field, tag;
190 uint32_t phimod2 = modulename[moduleId].find('b') != std::string::npos ? 1 : 0;
191 uint32_t modaddr = ((modulenumber[moduleId] & TGCTriggerData::MODULE_MASK)<<TGCTriggerData::MODULE_SHIFT) +
193
194 while (std::getline(stream, field, delimiter)) {
195
196 std::istringstream header(field);
197 header >> tag;
198
199 if (tag == "#") { // read header part.
200 uint16_t ptLevel, roi, mod;
201 int16_t lDR, hDR, lDPhi, hDPhi;
202 header >> ptLevel >> roi >> mod >> lDR >> hDR >> lDPhi >> hDPhi;
203
204 int16_t type = writeCdo->getTYPE( lDR, hDR, lDPhi, hDPhi );
205
206 // check moduleNumber and ptLevel
207 if( mod != modulenumber[moduleId] ||
208 ptLevel > TGCTriggerData::N_PT_THRESH || type < 0 ) {
209 ATH_MSG_WARNING("Invalid configuration of DB file! - Nothing to load this DB file");
210 break;
211 }
212
213 uint32_t cwaddr = ((uint8_t(type) & TGCTriggerData::TYPE_MASK)<<TGCTriggerData::TYPE_SHIFT) +
215
216 // get window data
217 std::getline(stream, field, delimiter);
218 std::istringstream cont(field);
219
220 for (uint8_t ir = 0; ir < 31; ir++) { // ir=0, 15 and 30 point to -15, 0 and +15 of dR, respectively.
222
223 uint32_t bit;
224 cont >> bit;
225 if (bit == 0) continue; // none of window is opened in this dR
226
227 for(uint8_t iphi=0; iphi<15; iphi++) { // iphi=0, 7 and 14 point to -7, 0 and +7 of dPhi, respectively.
228 if(bit>>iphi & 0x1) {
229 uint32_t theaddr = octaddr + modaddr + cwaddr + draddr + iphi;
230 writeCdo->m_ptmap_bw[theaddr] = (uint8_t)(ptLevel & TGCTriggerData::PT_MASK);
231 }
232 }
233 }
234
235 } // end of if(tag)...
236 } // end of while(getline...)
237
238 } // end of for(attrmap)
239
240 ATH_MSG_DEBUG("BW-CW LUT size: " << writeCdo->m_ptmap_bw.size());
241}
242
244 const CondAttrListCollection* readCdo) const
245{
246 const std::string sidename[TGCTriggerData::N_SIDE] = {"A","C"};
247
248 bool first = true;
249
250 for(auto& attrmap : *readCdo) {
251 const coral::AttributeList& atr = attrmap.second;
252 writeCdo->m_active[TGCTriggerData::CW_EIFI] = atr["active"].data<bool>();
253 writeCdo->m_type[TGCTriggerData::CW_EIFI] = atr["type"].data<std::string>();
254
255 std::string version = *(static_cast<const std::string*>((atr["version"]).addressOfData()));
256 std::string file = *(static_cast<const std::string*>((atr["file"]).addressOfData()));
257 ATH_MSG_DEBUG("channel: " << attrmap.first << ", file: " << file);
258
262 if ( first ) {
263 ATH_MSG_INFO("type: " << writeCdo->m_type[TGCTriggerData::CW_EIFI]
264 << " active: " << writeCdo->m_active[TGCTriggerData::CW_EIFI] << " version: " << version);
265 first = false;
266 }
267 else {
268 ATH_MSG_DEBUG("type: " << writeCdo->m_type[TGCTriggerData::CW_EIFI]
269 << " active: " << writeCdo->m_active[TGCTriggerData::CW_EIFI] << " version: " << version);
270 }
271
272 if (!writeCdo->m_active[TGCTriggerData::CW_EIFI]) continue;
273
274 bool fullCW = (writeCdo->m_type[TGCTriggerData::CW_EIFI] == "full");
275
276 uint8_t sideId = 0; // if the file is not fullCW, sideId should be zero.
277 if(fullCW) {
278 std::string side = file.substr(strlen("InnerCoincidenceMap."), 1);
279 for(int id=0; id<TGCTriggerData::N_SIDE; id++) {
280 if(sidename[id] == side) {
281 sideId = id;
282 break;
283 }
284 }
285 }
286
287 std::string dbname="";
288 if (!fullCW) {
289 dbname = "InnerCoincidenceMap." + version + "._12.db";
290 } else {
291 dbname = "InnerCoincidenceMap." + sidename[sideId]
292 + "." + version + "._12.db";
293 }
294 if(file != dbname) {
295 ATH_MSG_WARNING("The file name is different. Skip to load.");
296 continue;
297 }
298
299 std::istringstream stream(*(static_cast<const std::string*>((atr["data"]).addressOfData())));
300
301 char delimiter = '\n';
302 std::string field;
303 std::string tag;
304
305 while (std::getline(stream, field, delimiter)) {
306 int sectorId = -1;
307 int sscId = -1;
308
309 std::istringstream header(field);
310 header >> tag;
311 if(tag=="#"){ // read header part.
312 header >> sectorId >> sscId;
313 }
314
315 if (sectorId < 0 || sectorId >= TGCTriggerData::N_ENDCAP_SECTOR ||
316 sscId < 0 || sscId >= TGCTriggerData::N_ENDCAP_SSC ) {
317 ATH_MSG_WARNING("Invalid configuration of DB file.");
318 return;
319 }
320
321 uint16_t addr = ((uint16_t(sideId) & TGCTriggerData::SIDE_MASK)<<TGCTriggerData::ADDR_SIDE_SHIFT) +
323 (uint16_t(sscId) & TGCTriggerData::SSC_MASK);
324
325 uint8_t flag_pt = 0x0;
326 for (size_t pt = 0; pt < TGCTriggerData::N_PT_THRESH; pt++){
327 uint8_t use;
328 header >> use;
329 flag_pt |= (use&0x1)<<pt;
330 }
331 writeCdo->m_flagpt_eifi[addr] = flag_pt;
332
333 uint8_t flag_roi = 0x0;
334 for (size_t pos = 0; pos < TGCTriggerData::N_ROI_IN_SSC; pos++){
335 uint8_t use;
336 header >> use;
337 flag_roi |= (use&0x1)<<pos;
338 }
339 writeCdo->m_flagroi_eifi[addr] = flag_roi;
340
341 std::getline(stream, field, delimiter);
342 std::istringstream cont(field);
343 for(size_t pos=0; pos < TGCTriggerData::N_EIFI_INPUT; pos++){
344 unsigned int word;
345 cont >> word;
346 uint16_t inputaddr = (addr<<TGCTriggerData::EIFI_TRIGBIT_SHIFT) + pos;
347 writeCdo->m_trigbit_eifi[inputaddr] = word;
348 }
349 } // end of while(std::geline(...))
350
351 if (!fullCW) break;
352
353 } // end of for(attrmap)
354
355 ATH_MSG_DEBUG("EIFI-CW LUT size: " << writeCdo->m_flagpt_eifi.size() + writeCdo->m_flagroi_eifi.size() + writeCdo->m_trigbit_eifi.size());
356}
357
359 const CondAttrListCollection* readCdo) const
360{
361
362 bool first = true;
363
364 for(auto& attrmap : *readCdo) {
365 const coral::AttributeList& atr = attrmap.second;
366 writeCdo->m_active[TGCTriggerData::CW_TILE] = atr["active"].data<bool>();
367 writeCdo->m_type[TGCTriggerData::CW_TILE] = atr["type"].data<std::string>();
368
369 ATH_MSG_DEBUG("channel: " << attrmap.first << ", file: " << atr["file"].data<std::string>());
370
371 if ( first ) {
372 ATH_MSG_INFO("type: " << writeCdo->m_type[TGCTriggerData::CW_TILE]
373 << " active: " << writeCdo->m_active[TGCTriggerData::CW_TILE]
374 << " version: " << atr["version"].data<std::string>());
375 first = false;
376 }
377 else {
378 ATH_MSG_DEBUG("type: " << writeCdo->m_type[TGCTriggerData::CW_TILE]
379 << " active: " << writeCdo->m_active[TGCTriggerData::CW_TILE]
380 << " version: " << atr["version"].data<std::string>());
381 }
382
383 if(!writeCdo->m_active[TGCTriggerData::CW_TILE]) continue;
384
385 std::istringstream stream(*(static_cast<const std::string*>((atr["data"]).addressOfData())));
386
387 char delimiter = '\n';
388 std::string field;
389
390 while (std::getline(stream, field, delimiter)) {
391
392 int16_t sideId = -1;
393 int16_t sectorId = -1;
394 int16_t sscId = -1;
395
396 std::istringstream header(field);
397 std::string tag;
398 header >> tag;
399 if (tag=="#"){ // read header part.
400 header >> sideId >> sectorId >> sscId;
401 }
402
403 if(sideId < 0 || sideId >= TGCTriggerData::N_SIDE ||
404 sectorId < 0 || sectorId >= TGCTriggerData::N_ENDCAP_SECTOR ||
405 sscId < 0 || sscId >= TGCTriggerData::N_ENDCAP_SSC ) {
406 ATH_MSG_WARNING("Invalid configuration of DB file.");
407 return;
408 }
409 uint16_t addr = ((uint16_t(sideId) & TGCTriggerData::SIDE_MASK)<<TGCTriggerData::ADDR_SIDE_SHIFT) +
411 (uint16_t(sscId) & TGCTriggerData::SSC_MASK);
412
413 uint8_t flagpt = 0;
414 for (size_t pt = 0; pt < TGCTriggerData::N_PT_THRESH; pt++){
415 uint8_t use;
416 header >> use;
417 flagpt |= (use&0x1)<<pt;
418 }
419 writeCdo->m_flagpt_tile[addr] = flagpt;
420
421 uint8_t roi = 0;
422 for (size_t pos=0; pos< TGCTriggerData::N_ROI_IN_SSC; pos++){
423 uint8_t use;
424 header >> use;
425 roi |= (use&0x1)<<pos;
426 }
427 writeCdo->m_flagroi_tile[addr] = roi;
428
429 std::getline(stream, field, delimiter);
430 std::istringstream cont(field);
431 uint16_t trigbit = 0x0;
432 for(size_t pos=0; pos < TGCTriggerData::N_TILE_INPUT; pos++){
433 uint16_t word;
434 cont >> word;
435 trigbit |= (word & 0xf)<<(pos*4);
436 }
437 writeCdo->m_trigbit_tile[addr] = trigbit;
438 }
439 }
440
441 ATH_MSG_DEBUG("Tile-CW LUT size: " << writeCdo->m_flagpt_tile.size() + writeCdo->m_flagroi_tile.size() + writeCdo->m_trigbit_tile.size());
442}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Base class for conditions algorithms.
This class is a collection of AttributeLists where each one is associated with a channel number.
size_type size() const
number of Chan/AttributeList pairs
bool range(EventIDRange &r)
const std::string & key() const
const DataObjID & fullKey() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
static constexpr uint8_t TYPE_SHIFT
Bit position of the octant bits in the GLOBALADDR.
std::unordered_map< uint16_t, uint8_t > m_flagroi_eifi
static constexpr uint8_t SECTOR_MASK
Mask for trigger sector for the (EIFI/TILE) ADDR.
static constexpr uint8_t TYPE_MASK
Mask for extracting the octant from the GLOBALADDR.
static constexpr uint8_t EIFI_TRIGBIT_SHIFT
Special bit shift for the EIFI Trigger bit.
bool m_active[CW_NUM]
static constexpr uint8_t MODULE_SHIFT
Bit position of the module number bits in the GLOBALADDR.
static constexpr uint8_t PT_MASK
Mask for pT value for Run-2.
static constexpr uint8_t SIDE_MASK
Mask for extracting the side from the GLOBALADDR.
static constexpr uint8_t SIDE_SHIFT
Bit position of the side bit in the GLOBALADDR.
static constexpr uint8_t PHIMOD2_MASK
Mask for extracting the phi(F or B) from the GLOBALADDR.
std::unordered_map< uint32_t, uint8_t > m_ptmap_bw
Run-2 BW-CW LUT map.
std::unordered_map< uint16_t, uint16_t > m_trigbit_eifi
std::unordered_map< uint16_t, uint8_t > m_flagroi_tile
static constexpr uint8_t ROI_SHIFT
Bit position of the module number bits in the GLOBALADDR.
static constexpr uint8_t MODULE_MASK
Mask for extracting the module number from the GLOBALADDR.
static constexpr uint8_t DR_MASK
Mask for extracting the deltaR from the GLOBALADDR.
static constexpr uint8_t OCTANT_SHIFT
Bit position of the octant bits in the GLOBALADDR.
std::unordered_map< uint16_t, uint8_t > m_flagpt_eifi
static constexpr uint8_t OCTANT_MASK
Mask for extracting the octant from the GLOBALADDR.
std::unordered_map< uint16_t, uint16_t > m_trigbit_tile
static constexpr uint8_t DR_SHIFT
Bit position of the deltaR bits in the GLOBALADDR.
std::unordered_map< uint16_t, uint8_t > m_flagpt_tile
static constexpr uint8_t PHIMOD2_SHIFT
Bit position of the module number bits in the GLOBALADDR.
static constexpr uint8_t ADDR_SIDE_SHIFT
Bit position of the side bit in the (EIFI/TILE) ADDR.
static constexpr uint8_t SSC_MASK
Mask for SSC for the (EIFI/TILE) ADDR.
int8_t getTYPE(const int16_t lDR, const int16_t hDR, const int16_t lDPhi, const int16_t hDPhi) const
static constexpr uint8_t ROI_MASK
Mask for extracting the module number from the GLOBALADDR.
std::string m_type[CW_NUM]
static constexpr uint8_t ADDR_SECTOR_SHIFT
Bit position of the trigger sector bit in the (EIFI/TILE) ADDR.
void fillTrigBitTile(TGCTriggerData *writeCdo, const CondAttrListCollection *readKey) const
TGCTriggerDbAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &ctx) const override
void fillTrigBitEifi(TGCTriggerData *writeCdo, const CondAttrListCollection *readKey) const
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_bw
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_eifi
SG::WriteCondHandleKey< TGCTriggerData > m_writeKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_tile
virtual StatusCode finalize() override
void fillReadMapBw(TGCTriggerData *writeCdo, const CondAttrListCollection *readKey) const
virtual StatusCode initialize() override
int ir
counter of the current depth
Definition fastadd.cxx:49
TFile * file