ATLAS Offline Software
Loading...
Searching...
No Matches
LArConditionsContainerBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
14
16
17// Services/helpers
22
23// Gaudi/Athena
27#include <atomic>
28
36
44
45
48
49
50
51StatusCode
53{
54 //Get LArOnlineID....
55 ServiceHandle<StoreGateSvc> detStore("DetectorStore", "LArConditionsContainerBase");
56 CHECK( detStore.isValid() );
57
59 //Dealing with supercells, need supercell identifier helper
60 const LArOnline_SuperCellID* onlID = nullptr;
61 CHECK( detStore->retrieve(onlID,"LArOnline_SuperCellID") );
62 m_onlineHelper=onlID;//cast to base-class
63
64 const CaloCell_SuperCell_ID* oflID = nullptr;
65 CHECK( detStore->retrieve(oflID,"CaloCell_SuperCell_ID") );
66 m_offlineHelper=oflID; //cast to base-class
67 }
68 else {
69 //Regular readout
70 const LArOnlineID* onlID = nullptr;
71 CHECK( detStore->retrieve(onlID,"LArOnlineID") );
72 m_onlineHelper=onlID;//cast to base-class
73
74 const CaloCell_ID* oflID = nullptr;
75 CHECK( detStore->retrieve(oflID,"CaloCell_ID") );
76 m_offlineHelper=oflID; //cast to base-class
77 }
78
79 // initialize the grouping
81
82 // Set initialized to true
84
85 return (StatusCode::SUCCESS);
86}
87
88void
93
94
95StatusCode
96LArConditionsContainerBase::setGroupingType(const std::string& groupingStr, MsgStream& logStr)
97{
98 // Set grouping type - default is SubDet
99 if (groupingStr == "Single")
101 return StatusCode::SUCCESS;
102 }
103 else if (groupingStr == "SubDetector")
105 return StatusCode::SUCCESS;
106 }
107 else if (groupingStr == "ExtendedSubDetector")
109 return StatusCode::SUCCESS;
110 }
111 else if (groupingStr == "FeedThrough")
113 return StatusCode::SUCCESS;
114 }
115 else if (groupingStr == "ExtendedFeedThrough") {
117 return StatusCode::SUCCESS;
118 }
119 else if (groupingStr == "SuperCells") {
121 return StatusCode::SUCCESS;
122 }
123
124 logStr << MSG::ERROR << "Unknown COOL Channel Grouping '"<< groupingStr <<"'. Allowed values are:" << endmsg;
125 logStr << MSG::ERROR << "'Single','SubDetector', 'ExtendedSubDetector','FeedThrough','ExtendedFeedThrough'" << endmsg;
126 return StatusCode::FAILURE;
127}
128
129
130StatusCode
132{
133 MsgStream log(Athena::getMessageSvc(), "LArConditionsContainerBase");
134 log << MSG::DEBUG << "initGrouping "<< endmsg;
135
136 // We allow for different groupings
137
138 if (Unknown == m_groupType) {
139 log << MSG::ERROR << "Unknown grouping "<< endmsg;
140
141 // Not yet known
142 }
144
145 log << MSG::DEBUG << "Single group "<< endmsg;
146
147 // Only one group - add all feb ids to channel 0
148 std::vector<HWIdentifier>::const_iterator febIt = m_onlineHelper->feb_begin();
149 std::vector<HWIdentifier>::const_iterator febEnd = m_onlineHelper->feb_end();
151 for (; febIt != febEnd; ++febIt) {
152 febIds.push_back((*febIt).get_identifier32().get_compact());
153 }
154 // add for LArCondFEBIdChanMap
155 unsigned int nChanPerGain = 1;
156 unsigned int minGain = 0;
157 unsigned int nGains = 3;
158 m_febIdChanMap = LArCondFEBIdChanMap(nChanPerGain, minGain, nGains);
159 m_febIdChanMap.addFEBIdVector(0, febIds);
160 }
161 else if (SubDetectorGrouping == m_groupType) {
162
163 log << MSG::DEBUG << "Subdetector grouping "<< endmsg;
164
165 // Set up LArCondFEBIdChanMap for four groups: EM barrel, EMEM, HEC, FCal
166 std::vector<HWIdentifier>::const_iterator febIt = m_onlineHelper->feb_begin();
167 std::vector<HWIdentifier>::const_iterator febEnd = m_onlineHelper->feb_end();
168
173
174 for (; febIt != febEnd; ++febIt) {
175 unsigned int febId = (*febIt).get_identifier32().get_compact();
176 if (m_onlineHelper->isEMBchannel(*febIt)) {
177 emBarrel.push_back(febId);
178 }
179 else if (m_onlineHelper->isEMECchannel(*febIt)) {
180 emEndcap.push_back(febId);
181 }
182 else if (m_onlineHelper->isHECchannel(*febIt)) {
183 hec.push_back(febId);
184 }
185 else if (m_onlineHelper->isFCALchannel(*febIt)) {
186 fcal.push_back(febId);
187 }
188 else {
189 log << MSG::DEBUG << "Uassociated FEB id: "
190 << MSG::hex << (febId) << MSG::dec
191 << " isCalib " << m_onlineHelper->isCalibration(*febIt)
192 << " " << m_onlineHelper->show_to_string(*febIt)
193 << endmsg;
194 }
195 }
196 // add for LArCondFEBIdChanMap
197 unsigned int nChanPerGain = 4;
198 unsigned int minGain = 0;
199 unsigned int nGains = 3;
200 m_febIdChanMap = LArCondFEBIdChanMap(nChanPerGain, minGain, nGains);
201 m_febIdChanMap.addFEBIdVector(0, emBarrel);
202 m_febIdChanMap.addFEBIdVector(1, emEndcap);
203 m_febIdChanMap.addFEBIdVector(2, hec);
204 m_febIdChanMap.addFEBIdVector(3, fcal);
205
206// unsigned int coolChannel;
207// for (unsigned int gain = 0; gain < nGains; ++gain) {
208// for (unsigned int i = 0; i < emBarrel.size(); ++i) {
209// if (!m_febIdChanMap.getChannel(emBarrel[i], gain, coolChannel)) {
210// log << MSG::DEBUG << "Unable to get cool channel for em barrel - i = "
211// << i << endmsg;
212// return (StatusCode::FAILURE);
213// }
214// }
215// for (unsigned int i = 0; i < emEndcap.size(); ++i) {
216// if (!m_febIdChanMap.getChannel(emEndcap[i], gain, coolChannel)) {
217// log << MSG::DEBUG << "Unable to get cool channel for em endcap - i = "
218// << i << endmsg;
219// return (StatusCode::FAILURE);
220// }
221// }
222// for (unsigned int i = 0; i < hec.size(); ++i) {
223// if (!m_febIdChanMap.getChannel(hec[i], gain, coolChannel)) {
224// log << MSG::DEBUG << "Unable to get cool channel for hec - i = "
225// << i << endmsg;
226// return (StatusCode::FAILURE);
227// }
228// }
229// for (unsigned int i = 0; i < fcal.size(); ++i) {
230// if (!m_febIdChanMap.getChannel(fcal[i], gain, coolChannel)) {
231// log << MSG::DEBUG << "Unable to get cool channel for fcal - i = "
232// << i << endmsg;
233// return (StatusCode::FAILURE);
234// }
235// }
236// }
237 }
239 log << MSG::DEBUG << "Extended Subdetector grouping "<< endmsg;
240
241 // Set up LArCondFEBIdChanMap for four groups: EM barrel, EM barrel PS ,EMEC EMEC PS, HEC, FCal
242 std::vector<HWIdentifier>::const_iterator febIt = m_onlineHelper->feb_begin();
243 std::vector<HWIdentifier>::const_iterator febEnd = m_onlineHelper->feb_end();
244
245 LArCondFEBIdChanMap::FEBIdVector emBarrel[2] = {};
246 LArCondFEBIdChanMap::FEBIdVector emBarrelPS[2] = {};
247 LArCondFEBIdChanMap::FEBIdVector emEndcap[2] = {};
248 LArCondFEBIdChanMap::FEBIdVector emEndcapPS[2] = {};
251
252 for (; febIt != febEnd; ++febIt) {
253 int iside = m_onlineHelper->pos_neg(*febIt);
254 // Sanity check
255 if(iside <0 || iside > 1) {
256 log << MSG::ERROR << "Wrong side id: "<< iside <<" from: "
257 << MSG::hex << *febIt << MSG::dec << endmsg;
258 return (StatusCode::FAILURE);
259 }
260 unsigned int febId = (*febIt).get_identifier32().get_compact();
261 if (m_onlineHelper->isEMBPS(*febIt)) {
262 emBarrelPS[iside].push_back(febId);
263 }
264 else if (m_onlineHelper->isEMECPS(*febIt)) {
265 emEndcapPS[iside].push_back(febId);
266 }
267 else if (m_onlineHelper->isEMBchannel(*febIt)) {
268 emBarrel[iside].push_back(febId);
269 }
270 else if (m_onlineHelper->isEMECchannel(*febIt)) {
271 emEndcap[iside].push_back(febId);
272 }
273 else if (m_onlineHelper->isHECchannel(*febIt)) {
274 hec[iside].push_back(febId);
275 }
276 else if (m_onlineHelper->isFCALchannel(*febIt)) {
277 fcal[iside].push_back(febId);
278 }
279 else {
280 log << MSG::DEBUG << "Uassociated FEB id: "
281 << MSG::hex << (febId) << MSG::dec
282 << " isCalib " << m_onlineHelper->isCalibration(*febIt)
283 << " " << m_onlineHelper->show_to_string(*febIt)
284 << endmsg;
285 }
286 }
287 // add for LArCondFEBIdChanMap
288 unsigned int nChanPerGain = 12;
289 unsigned int minGain = 0;
290 unsigned int nGains = 3;
291 m_febIdChanMap = LArCondFEBIdChanMap(nChanPerGain, minGain, nGains);
292 for (int iside=0; iside<2; ++iside) {
293 m_febIdChanMap.addFEBIdVector(0+iside*6, emBarrel[iside]);
294 m_febIdChanMap.addFEBIdVector(1+iside*6, emBarrelPS[iside]);
295 m_febIdChanMap.addFEBIdVector(2+iside*6, emEndcap[iside]);
296 m_febIdChanMap.addFEBIdVector(3+iside*6, emEndcapPS[iside]);
297 m_febIdChanMap.addFEBIdVector(4+iside*6, hec[iside]);
298 m_febIdChanMap.addFEBIdVector(5+iside*6, fcal[iside]);
299 }
300
301 }
302 else if (FeedThroughGrouping == m_groupType) {
303 log << MSG::DEBUG << "FeedThrough grouping "<< endmsg;
304
305 // Set up LArCondFEBIdChanMap for four groups: EM barrel, EMEM, HEC, FCal
306 std::vector<HWIdentifier>::const_iterator febIt = m_onlineHelper->feb_begin();
307 std::vector<HWIdentifier>::const_iterator febEnd = m_onlineHelper->feb_end();
308
309 std::vector<LArCondFEBIdChanMap::FEBIdVector> ft(m_onlineHelper->feedthroughHashMax());
310
311
312 for (; febIt != febEnd; ++febIt) {
313 // Find the feedthru hash and add to vector
314 HWIdentifier febId = (*febIt);
315 int b_ec = m_onlineHelper->barrel_ec(febId);
316 int p_n = m_onlineHelper->pos_neg(febId);
317 int f_t = m_onlineHelper->feedthrough(febId);
318 HWIdentifier ftid = m_onlineHelper->feedthrough_Id(b_ec, p_n, f_t);
319 IdentifierHash fthash = m_onlineHelper->feedthrough_Hash(ftid);
320 if (fthash < ft.size()) {
321 ft[fthash].push_back(febId.get_identifier32().get_compact());
322 }
323 else {
324 log << MSG::ERROR << "Feedthru hash > channel map size: id, hash, size "
325 << MSG::hex << febId << MSG::dec << " "
326 << ftid << " " << ft.size()
327 << endmsg;
328 return (StatusCode::FAILURE);
329 }
330 }
331 // add for LArCondFEBIdChanMap
332 unsigned int nChanPerGain = ft.size();
333 unsigned int minGain = 0;
334 unsigned int nGains = 3;
335 m_febIdChanMap = LArCondFEBIdChanMap(nChanPerGain, minGain, nGains);
336 for (unsigned int i = 0; i < ft.size(); ++i) {
337 m_febIdChanMap.addFEBIdVector(i, ft[i]);
338 }
339 }
340 else if (ExtendedFTGrouping == m_groupType) {
341
342 log << MSG::DEBUG << "Extended FeedThrough grouping (PS goes seperatly, EMEC in HEC as well)"<< endmsg;
343
344 // Set up LArCondFEBIdChanMap for four groups: EM barrel, EMEM, HEC, FCal
345 std::vector<HWIdentifier>::const_iterator febIt = m_onlineHelper->feb_begin();
346 std::vector<HWIdentifier>::const_iterator febEnd = m_onlineHelper->feb_end();
347
348 //Vectors of groups
349 //Standard Febs (one group per FT)
350 std::vector<LArCondFEBIdChanMap::FEBIdVector> ft(m_onlineHelper->feedthroughHashMax());
351 //Presampler FEBs (one group per FT)
352 std::vector<LArCondFEBIdChanMap::FEBIdVector> ftPS(m_onlineHelper->feedthroughHashMax());
353 //EMEC channel in special crate:
354 std::vector<LArCondFEBIdChanMap::FEBIdVector> ftSpecial(8); //How many are there?
355
356 for (; febIt != febEnd; ++febIt) {
357 // Find the feedthru hash and add to vector
358 HWIdentifier febId = (*febIt);
359 int b_ec = m_onlineHelper->barrel_ec(febId);
360 int p_n = m_onlineHelper->pos_neg(febId);
361 int f_t = m_onlineHelper->feedthrough(febId);
362 HWIdentifier ftid = m_onlineHelper->feedthrough_Id(b_ec, p_n, f_t);
363 IdentifierHash fthash = m_onlineHelper->feedthrough_Hash(ftid);
364
365 //sanity check
366 if (fthash >= ft.size()) {
367 log << MSG::ERROR << "Feedthru hash > channel map size: id, hash, size "
368 << MSG::hex << febId << MSG::dec << " "
369 << ftid << " " << ft.size()
370 << endmsg;
371 return (StatusCode::FAILURE);
372 }
373
374 //Subdivide into specific cases:
375 if (!m_onlineHelper->isEMECinHECchannel(febId)) { //this is taken care of further down
376 if (m_onlineHelper->isPS(febId))
377 ftPS[fthash].push_back(febId.get_identifier32().get_compact()); //PS goes in separate channels
378 else
379 ft[fthash].push_back(febId.get_identifier32().get_compact());
380 }
381 }
382 //EMEC in HEC crate: Do 'by hand'
383 //FTs: 3,10,16,22 Slots: 1,2
384 //parameters: ec,pn,ft,slot
385 ftSpecial[0].push_back(m_onlineHelper->feb_Id(1,0,3,1).get_identifier32().get_compact());
386 ftSpecial[0].push_back(m_onlineHelper->feb_Id(1,0,3,2).get_identifier32().get_compact());
387
388 ftSpecial[1].push_back(m_onlineHelper->feb_Id(1,1,3,1).get_identifier32().get_compact());
389 ftSpecial[1].push_back(m_onlineHelper->feb_Id(1,1,3,2).get_identifier32().get_compact());
390
391 ftSpecial[2].push_back(m_onlineHelper->feb_Id(1,0,10,1).get_identifier32().get_compact());
392 ftSpecial[2].push_back(m_onlineHelper->feb_Id(1,0,10,2).get_identifier32().get_compact());
393
394 ftSpecial[3].push_back(m_onlineHelper->feb_Id(1,1,10,1).get_identifier32().get_compact());
395 ftSpecial[3].push_back(m_onlineHelper->feb_Id(1,1,10,2).get_identifier32().get_compact());
396
397 ftSpecial[4].push_back(m_onlineHelper->feb_Id(1,0,16,1).get_identifier32().get_compact());
398 ftSpecial[4].push_back(m_onlineHelper->feb_Id(1,0,16,2).get_identifier32().get_compact());
399
400 ftSpecial[5].push_back(m_onlineHelper->feb_Id(1,1,16,1).get_identifier32().get_compact());
401 ftSpecial[5].push_back(m_onlineHelper->feb_Id(1,1,16,2).get_identifier32().get_compact());
402
403 ftSpecial[6].push_back(m_onlineHelper->feb_Id(1,0,22,1).get_identifier32().get_compact());
404 ftSpecial[6].push_back(m_onlineHelper->feb_Id(1,0,22,2).get_identifier32().get_compact());
405
406 ftSpecial[7].push_back(m_onlineHelper->feb_Id(1,1,22,1).get_identifier32().get_compact());
407 ftSpecial[7].push_back(m_onlineHelper->feb_Id(1,1,22,2).get_identifier32().get_compact());
408
409
410 // add for LArCondFEBIdChanMap
411 unsigned int nChanPerGain = ft.size()+ftPS.size()+ftSpecial.size();
412 unsigned int minGain = 0;
413 unsigned int nGains = 3;
414 unsigned int iCoolChannel=0;
415 m_febIdChanMap = LArCondFEBIdChanMap(nChanPerGain, minGain, nGains);
416 for (unsigned int i = 0; i < ft.size(); ++i) {
417 m_febIdChanMap.addFEBIdVector(iCoolChannel++, ft[i]);
418 }
419 for (unsigned int i = 0; i < ftPS.size(); ++i) {
420 m_febIdChanMap.addFEBIdVector(iCoolChannel++, ftPS[i]);
421 }
422 for (unsigned int i = 0; i < ftSpecial.size(); ++i) {
423 m_febIdChanMap.addFEBIdVector(iCoolChannel++, ftSpecial[i]);
424 }
425 } else {
426 log << MSG::ERROR << "Unknown COOL Channel grouping " << m_groupType << endmsg;
427 return StatusCode::FAILURE;
428 }
429 // Resize the vector mapping the COOL channel to the
430 // DataVector.
431 m_channelToMultChanCollIndex = std::vector<unsigned int>(m_febIdChanMap.totalChannels(), 9999);
432
433 log << MSG::DEBUG << "Number of channels per gain "
434 << m_febIdChanMap.channelsPerGain()
435 << endmsg;
436
437 log << MSG::DEBUG << "Mininum gain value "
438 << m_febIdChanMap.minGain()
439 << endmsg;
440
441 log << MSG::DEBUG << "Number of gain values "
442 << m_febIdChanMap.nGains()
443 << endmsg;
444
445 log << MSG::DEBUG << "Number of offset channels "
446 << m_febIdChanMap.nOffsetChannels()
447 << endmsg;
448
449 log << MSG::DEBUG << "Total number of channels "
450 << m_febIdChanMap.totalChannels()
451 << endmsg;
452
453 return (StatusCode::SUCCESS);
454
455}
456
457std::string
459{
460 // Return grouping type in string form
461 switch (m_groupType){
462 case 0:
463 return ("Unknown");
464 case 1:
465 return ("SingleGroup");
466 case 2:
467 return ("SubDetectorGrouping");
468 case 3:
469 return ("FeedThroughGrouping");
470 case 4:
471 return ("ExtendedFTGrouping");
472 case 5:
473 return ("ExtendedSubDetGrouping");
474 case 6:
475 return ("SuperCells");
476 }
477 return ("Unknown");
478}
479
480const LArOnlineID_Base*
485
486const CaloCell_Base_ID*
491
492
495 unsigned int coolChannel) const
496{
497 return (m_febIdChanMap.febIdVector(gain, coolChannel));
498}
499
500void
502 unsigned int gain,
503 unsigned int& index,
504 unsigned int& coolChannel)
505{
506 MsgStream log(Athena::getMessageSvc(), "LArConditionsContainerBase");
507
508 index = 9999;
509 coolChannel = 0;
510 // First get cool channel number
511 if (!m_onlineHelper) {
512 log << MSG::ERROR << "correctionIndex> Could not get online id helper!" << endmsg;
513 return;
514 }
515
516 int p_n = m_onlineHelper->pos_neg(id);
517 if (m_onlineHelper->isEMBPS(id)) {
518 if (p_n) coolChannel = LArCondFEBIdChanMap::PSBA; // PS Barrel
519 else coolChannel = LArCondFEBIdChanMap::PSBC; // PS Barrel
520 }
521 else if (m_onlineHelper->isEMECPS(id)) {
522 if (p_n) coolChannel = LArCondFEBIdChanMap::PSECA; // PS Endcap
523 else coolChannel = LArCondFEBIdChanMap::PSECC; // PS Endcap
524 }
525 else if (m_onlineHelper->isEMBchannel(id)) {
526 if (p_n) coolChannel = LArCondFEBIdChanMap::EMBA; // EM Barrel
527 else coolChannel = LArCondFEBIdChanMap::EMBC; // EM Barrel
528 }
529 else if (m_onlineHelper->isEMECchannel(id)) {
530 if (p_n) coolChannel = LArCondFEBIdChanMap::EMECA; // EM Endcap
531 else coolChannel = LArCondFEBIdChanMap::EMECC; // EM Endcap
532 }
533 else if (m_onlineHelper->isHECchannel(id)) {
534 if (p_n) coolChannel = LArCondFEBIdChanMap::HECA; // HEC A
535 else coolChannel = LArCondFEBIdChanMap::HECC; // HEC C
536 }
537 else if (m_onlineHelper->isFCALchannel(id)) {
538 if (p_n) coolChannel = LArCondFEBIdChanMap::FCALA; // FCAL A
539 else coolChannel = LArCondFEBIdChanMap::FCALC; // FCAL C
540 }
541
542 if (!coolChannel) {
543 log << MSG::ERROR << "correctionIndex> coolChannel not found! Online ids: "
544 << " " << m_onlineHelper->show_to_string(id)
545 << endmsg;
546 return;
547 }
548
549 // add on offset for gain
550 unsigned int gainOffset = (gain - m_febIdChanMap.minGain())*LArCondFEBIdChanMap::NCORRTYPE;
551 coolChannel += gainOffset;
552
553 // look up the index in the table
554 if (coolChannel >= m_channelToMultChanCollIndex.size()) {
555 log << MSG::ERROR << "correctionIndex> coolChannel larger than lookup table: chan, size "
556 << coolChannel << " " << m_channelToMultChanCollIndex.size()
557 << endmsg;
558 }
559 else {
560 index = m_channelToMultChanCollIndex[coolChannel];
561 }
562}
563
564bool
566{
567 // If setFlag is true, change the value of static flag, otherwise
568 // return current value
569
570 // Default value is true
571 static std::atomic<bool> applyCorrs = true;
572
573 if (setFlag) applyCorrs = flag;
574
575 return (applyCorrs);
576}
577
#define endmsg
Helper class for offline supercell identifiers.
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
defines an "iterator" over instances of a given type in StoreGateSvc
This file contain an implementation base class for LArConditionsContainer.
Helper base class for offline cell identifiers.
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
Helper class for offline supercell identifiers.
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
This class maps FEB IDs to/from COOL channel ids.
std::vector< FEBId > FEBIdVector
static bool applyCorrectionsAtInit(bool setFlag=false, bool flag=true)
provide access to flag which determines corrections are applied at initialize, i.e.
const LArOnlineID_Base * m_onlineHelper
std::vector< unsigned int > m_channelToMultChanCollIndex
LArCondFEBIdChanMap::FEBIdVector FEBIdVector
const FEBIdVector & febIdVector(unsigned int gain, unsigned int coolChannel) const
Access to a FEB ID vector for a given gain and COOL channel.
void setGroupingType(GroupingType type)
allow group type to be set externally - need to (re)initialize after setting grouping type
void correctionIndexAndCoolChannel(HWIdentifier id, unsigned int gain, unsigned int &index, unsigned int &coolChannel)
const CaloCell_Base_ID * offlineHelper() const
provide access to offline id helper
const LArOnlineID_Base * onlineHelper() const
provide access to online id helper
const CaloCell_Base_ID * m_offlineHelper
LArConditionsContainerBase()
Default constructor.
Helper for the Liquid Argon Calorimeter cell identifiers.
IMessageSvc * getMessageSvc(bool quiet=false)
Definition index.py:1