ATLAS Offline Software
Loading...
Searching...
No Matches
CscCondDbData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "GaudiKernel/MsgStream.h"
9#include <atomic>
10
11
12// loadParameters
13void
15
16 // prepare contexts
17 m_moduleContext = idHelper->module_context();
19
20
21 for(int stationName = 0; stationName < 2; stationName++){
22 for(int stationEta =0; stationEta <2; stationEta++){
23 for(int stationPhi = 0; stationPhi <8; stationPhi++){
24 for(int wireLayer = 0; wireLayer <4; wireLayer++){
25 for(int measuresPhi = 0; measuresPhi <2; measuresPhi++){
26 Identifier id = idHelper->channelID(
27 stationName+1,
28 (stationEta? 1:-1),
29 stationPhi+1,
30 2,//only installed chamber layer
31 wireLayer+1,
32 measuresPhi,
33 1 //channel doesn't matter. We'll just use first
34 );
35 unsigned int onlineId;
36 if(!offlineToOnlineId(idHelper, id, onlineId).isSuccess()) {
37 MsgStream log(Athena::getMessageSvc(),"CscCondDbData");
38 log << MSG::WARNING << "Failed at geting online id!" << endmsg;
39 }
40 else {
41 m_onlineChannelIdsFromLayerHash.push_back(onlineId);
42 }
43 }
44 }
45 }
46 }
47 }
48}
49
50
51// set Parameters
52void
53CscCondDbData::setParameters(bool onlineOfflinePhiFlip){
54 m_onlineOfflinePhiFlip = onlineOfflinePhiFlip;
55}
56
57// --- writing identifiers -------
58
59
60// setChannelF001
61void
63 m_cachedChannelsF001[(unsigned int) hash] = f001;
64}
65
66// setChannelNoise
67void
69 m_cachedChannelsNoise[(unsigned int) hash] = noise;
70}
71
72// setChannelPed
73void
75 m_cachedChannelsPed[(unsigned int) hash] = ped;
76}
77
78// setChannelPSlope
79void
81 m_cachedChannelsPSlope[(unsigned int) hash] = pslope;
82}
83
84// setChannelRMS
85void
87 m_cachedChannelsRMS[(unsigned int) hash] = rms;
88}
89
90// setChannelStatus
91void
93 m_cachedChannelsStatus[(unsigned int) hash] = status;
94 if((status & 0x1) || ((status >> 1) & 0x1)) setDeadChannelHash(hash);
95}
96
97// setChannelT0Base
98void
100 m_cachedChannelsT0Base[(unsigned int) hash] = t0base;
101}
102
103// setChannelT0Phase
104void
106 m_cachedChannelsT0Phase[(unsigned int) hash] = t0phase;
107}
108
109
110
111// --- writing dead channels -----
112
113// setDeadChannelHash
114void
116 if(std::find(m_cachedDeadChannelsHash.begin(), m_cachedDeadChannelsHash.end(), (unsigned int) hash) != m_cachedDeadChannelsHash.end()) return;
117 m_cachedDeadChannelsHash.push_back((unsigned int) hash);
118}
119
120// setDeadLayer
121void
122CscCondDbData::setDeadLayer(std::string_view name, Identifier Id){
123 if(std::find(m_cachedDeadLayersId.begin(), m_cachedDeadLayersId.end(), Id)!=m_cachedDeadLayersId.end()) return;
124 m_cachedDeadLayers .push_back(std::string(name));
125 m_cachedDeadLayersId.push_back(Id );
126}
127
128// setDeadStation
129void
130CscCondDbData::setDeadStation(std::string_view name, Identifier Id){
131 if(std::find(m_cachedDeadStationsId.begin(), m_cachedDeadStationsId.end(), Id)!=m_cachedDeadStationsId.end()) return;
132 m_cachedDeadStations .push_back(std::string(name));
133 m_cachedDeadStationsId.push_back(Id );
134}
135
136
137
138
139
140// --- reading identifiers -------
141
142// getDeadLayers
143const
144std::vector<std::string>& CscCondDbData::getDeadLayers() const{
145 if(m_cachedDeadLayers.size()!=0) return m_cachedDeadLayers;
146 return m_emptyNames;
147}
148
149// getDeadStations
150const
151std::vector<std::string>& CscCondDbData::getDeadStations() const{
152 if(m_cachedDeadStations.size()!=0) return m_cachedDeadStations;
153 return m_emptyNames;
154}
155
156
157
158// getDeadLayersId
159const
160std::vector<Identifier>& CscCondDbData::getDeadLayersId() const{
161 if(m_cachedDeadLayersId.size()!=0) return m_cachedDeadLayersId;
162 return m_emptyIds;
163}
164
165// getDeadStationsId
166const
167std::vector<Identifier>& CscCondDbData::getDeadStationsId() const{
169 return m_emptyIds;
170}
171
172
173
174// getDeadChannelsHashs
175const
176std::vector<unsigned int>& CscCondDbData::getDeadChannelsHash() const{
178 return m_emptyHashs;
179}
180
181
182
183// --- stored info for all -------
184
185// hasChannelT0Phase
187 if(m_cachedChannelsT0Phase.find((unsigned int) hash)==m_cachedChannelsT0Phase.end()) return false;
188 return true;
189}
190
191// getChannelF001
192const
194 if(m_cachedChannelsF001.find((unsigned int) hash)==m_cachedChannelsF001.end()) return m_nillfloat;
195 return m_cachedChannelsF001.find((unsigned int) hash)->second;
196}
197
198// getChannelNoise
199const
201 if(m_cachedChannelsNoise.find((unsigned int) hash)==m_cachedChannelsNoise.end()) return m_nillfloat;
202 return m_cachedChannelsNoise.find((unsigned int) hash)->second;
203}
204
205// getChannelPed
206const
208 if(m_cachedChannelsPed.find((unsigned int) hash)==m_cachedChannelsPed.end()) return m_nillfloat;
209 return m_cachedChannelsPed.find((unsigned int) hash)->second;
210}
211
212// getChannelPSlope
213const
215 if(m_cachedChannelsPSlope.find((unsigned int) hash)==m_cachedChannelsPSlope.end()) return m_nillfloat;
216 return m_cachedChannelsPSlope.find((unsigned int) hash)->second;
217}
218
219// getChannelRMS
220const
222 if(m_cachedChannelsRMS.find((unsigned int) hash)==m_cachedChannelsRMS.end()) return m_nillfloat;
223 return m_cachedChannelsRMS.find((unsigned int) hash)->second;
224}
225
226// getChannelStatus
227const
229 if(m_cachedChannelsStatus.find((unsigned int) hash)==m_cachedChannelsStatus.end()) return m_nillint;
230 return m_cachedChannelsStatus.find((unsigned int) hash)->second;
231}
232
233// getChannelT0Base
234const
236 if(m_cachedChannelsT0Base.find((unsigned int) hash)==m_cachedChannelsT0Base.end()) return m_nillfloat;
237 return m_cachedChannelsT0Base.find((unsigned int) hash)->second;
238}
239
240// getChannelT0Phase
241const
243 if(m_cachedChannelsT0Phase.find((unsigned int) hash)==m_cachedChannelsT0Phase.end()) return m_nillbool;
244 return m_cachedChannelsT0Phase.find((unsigned int) hash)->second;
245}
246
247// readChannelF001
248StatusCode CscCondDbData::readChannelF001(IdentifierHash hash, float& val) const{
249 val = getChannelF001(hash);
250 if(val==-1) return StatusCode::FAILURE;
251 return StatusCode::SUCCESS;
252}
253
254// readChannelNoise
255StatusCode CscCondDbData::readChannelNoise(IdentifierHash hash, float& val) const{
256 val = getChannelNoise(hash);
257 if(val==-1) return StatusCode::FAILURE;
258 return StatusCode::SUCCESS;
259}
260
261// readChannelPed
262StatusCode CscCondDbData::readChannelPed(IdentifierHash hash, float& val) const{
263 val = getChannelPed(hash);
264 if(val==-1) return StatusCode::FAILURE;
265 return StatusCode::SUCCESS;
266}
267
268// readChannelPSlope
269StatusCode CscCondDbData::readChannelPSlope(IdentifierHash hash, float& val) const{
270 val = getChannelPSlope(hash);
271 if(val==-1) return StatusCode::FAILURE;
272 return StatusCode::SUCCESS;
273}
274
275// readChannelRMS
276StatusCode CscCondDbData::readChannelRMS(IdentifierHash hash, float& val) const{
277 val = getChannelRMS(hash);
278 if(val==-1) return StatusCode::FAILURE;
279 return StatusCode::SUCCESS;
280}
281
282// readChannelStatus
283StatusCode CscCondDbData::readChannelStatus(IdentifierHash hash, int& val) const{
284 val = getChannelStatus(hash);
285 if(val==-1) return StatusCode::FAILURE;
286 return StatusCode::SUCCESS;
287}
288
289// readChannelT0Base
290StatusCode CscCondDbData::readChannelT0Base(IdentifierHash hash, float& val) const{
291 val = getChannelT0Base(hash);
292 if(val==-1) return StatusCode::FAILURE;
293 return StatusCode::SUCCESS;
294}
295
296// readChannelT0Phase
297StatusCode CscCondDbData::readChannelT0Phase(IdentifierHash hash, bool& val) const{
298 if(!hasChannelT0Phase(hash)) return StatusCode::FAILURE;
299 val = getChannelT0Phase(hash);
300 return StatusCode::SUCCESS;
301}
302
303
304
305// --- probing identifiers -------
306
307// isGood
308bool
310 // probing id in all lists
311 if(not isGoodLayer (Id)) return false;
312 if(not isGoodStation (Id)) return false;
313 return true;
314}
315
316// isGoodChannelHash
317bool
319 if(m_cachedDeadChannelsHash.size()==0) return true;
320 bool found = std::find(m_cachedDeadChannelsHash.begin(), m_cachedDeadChannelsHash.end(), (unsigned int) hash) != m_cachedDeadChannelsHash.end();
321 return !found;
322}
323
324// isGoodLayer
325bool
327 if(m_cachedDeadLayersId.size()==0) return true;
328 bool found = std::find(m_cachedDeadLayersId.begin(), m_cachedDeadLayersId.end(), Id)!=m_cachedDeadLayersId.end();
329 return !found;
330}
331
332// isGoodStation
333bool
335 if(m_cachedDeadStationsId.size()==0) return true;
336 bool found = std::find(m_cachedDeadStationsId.begin(), m_cachedDeadStationsId.end(), Id)!=m_cachedDeadStationsId.end();
337 return !found;
338}
339
340
341
342// ID HELPER FUNCTIONS BELOW ------------------------------
343
344
345// indexToStringId
346StatusCode
347CscCondDbData::indexToStringId(const CscIdHelper* idHelper, const unsigned int & index, const std::string & cat, std::string & idString) const {
348 // copy-paste from CscCoolStrSvc
349
350 //There is no string id for the CSC category.
351 if(cat == "CSC") {
352 idString = "";
353 return StatusCode::SUCCESS;
354 }
355 if(cat == "ENDCAP") {
356 if(index == 0)
357 idString = "-1";
358 if(index == 1)
359 idString = "1";
360 else {
361 MsgStream log(Athena::getMessageSvc(),"CscCondDbData");
362 log << MSG::INFO << "Requested index " << index << " can't be converted to a string Id for the category " << cat << endmsg;
363 return StatusCode::RECOVERABLE;
364 }
365 }
366
367 //remaining categories need online identifiers
368 unsigned int onlineId = 0;
369 std::stringstream ss;
370 if(cat == "CHAMBER"){
371 Identifier chamberId;
372 idHelper->get_id(IdentifierHash(index), chamberId, &m_moduleContext);
373 if(!offlineElementToOnlineId(idHelper, chamberId, onlineId).isSuccess()) {
374 MsgStream log(Athena::getMessageSvc(),"CscCondDbData");
375 log << MSG::INFO << "Failed converting chamber identifier to online id during stringId gen." << endmsg;
376 return StatusCode::RECOVERABLE;
377 }
378 }
379 else if(cat == "LAYER"){
380 unsigned int onlineId;
381 if(!layerHashToOnlineId(index, onlineId)){
382 MsgStream log(Athena::getMessageSvc(),"CscCondDbData");
383 log << MSG::INFO << "Failed at getting online id from layer hash during stringId gen." << endmsg;
384 }
385 }
386 else if(cat == "CHANNEL"){
387 Identifier channelId;
388 idHelper->get_id(IdentifierHash(index), channelId, &m_channelContext);
389 if(!offlineToOnlineId(idHelper, channelId, onlineId).isSuccess()) {
390 MsgStream log(Athena::getMessageSvc(),"CscCondDbData");
391 log << MSG::INFO << "Failed converting chamber identifier to online id during stringId gen." << endmsg;
392 return StatusCode::RECOVERABLE;
393 }
394 }
395
396 ss << std::hex << std::setfill('0') << std::setw(5) << onlineId << std::dec;
397 idString = ss.str();
398 return StatusCode::SUCCESS;
399}
400
401
402// layerHashToOnlineId
403StatusCode
404CscCondDbData::layerHashToOnlineId(const unsigned int & layerHash, unsigned int & onlineId) const {
405 // copy-paste from CscCoolStrSvc
406
407 if(layerHash >= m_onlineChannelIdsFromLayerHash.size()) {
408 MsgStream log(Athena::getMessageSvc(),"CscCondDbData");
409 log << MSG::INFO << "Tried to lookup online id from layer hash " << layerHash <<". Max is " << m_onlineChannelIdsFromLayerHash.size() << endmsg;
410 return StatusCode::SUCCESS;
411 }
412 onlineId = m_onlineChannelIdsFromLayerHash[layerHash];
413 return StatusCode::SUCCESS;
414}
415
416
417// offlineElementToOnlineId
418StatusCode
419CscCondDbData::offlineElementToOnlineId(const CscIdHelper* idHelper, const Identifier & id, unsigned int &onlineId) const {
420 // copy-paste from CscCoolStrSvc
421
422 onlineId = 0;
423 //Phi,wireLayer,and strip all are offset by one between the two schemes.
424 //Also, station name is 50 or 51 in Identifiers, but only 0 or 1 in
425 //the online id.
426 int stationName ((idHelper->stationName(id) -50)&0x1 ); // 0001 0000 0000 0000 0000
427 int phi = (idHelper->stationPhi(id) - 1)&0x7 ; // 0000 1110 0000 0000 0000
428 int eta = ((idHelper->stationEta(id) == 1) ? 1:0) &0x1; // 0000 0001 0000 0000 0000
429 int chamLay = 1; // 0000 0000 1000 0000 0000
430 int wireLay = 0; // 0000 0000 0110 0000 0000
431 int measuresPhi = 0; // 0000 0000 0001 0000 0000
432 int strip = 0; // 0000 0000 0000 1111 1111
433
434 onlineId += (stationName << 16); // 0001 0000 0000 0000 0000
435 onlineId += (phi << 13) ; // 0000 1110 0000 0000 0000
436 onlineId += (eta <<12); // 0000 0001 0000 0000 0000
437 onlineId += (chamLay <<11); // 0000 0000 1000 0000 0000
438 onlineId += (wireLay << 9); // 0000 0000 0110 0000 0000
439 onlineId += (measuresPhi << 8); // 0000 0000 0001 0000 0000
440 onlineId += strip ; // 0000 0000 0000 1111 1111
441 return StatusCode::SUCCESS;
442}
443
444
445// offlineToOnlineId
446StatusCode
447CscCondDbData::offlineToOnlineId(const CscIdHelper* idHelper, const Identifier & id, unsigned int &onlineId) const {
448 // copy-paste from CscCoolStrSvc
449
450 onlineId = 0;
451 //Phi,wireLayer,and strip all are offset by one between the two schemes.
452 //Also, station name is 50 or 51 in Identifiers, but only 0 or 1 in
453 //the online id.
454 int stationName ((idHelper->stationName(id) -50)&0x1 ); // 0001 0000 0000 0000 0000
455 int phi = (idHelper->stationPhi(id) - 1)&0x7 ; // 0000 1110 0000 0000 0000
456 int eta = ((idHelper->stationEta(id) == 1) ? 1:0) &0x1; // 0000 0001 0000 0000 0000
457 int chamLay = (idHelper->chamberLayer(id)-1) &0x1; // 0000 0000 1000 0000 0000
458 int wireLay = (idHelper->wireLayer(id)-1) &0x3; // 0000 0000 0110 0000 0000
459 int measuresPhi = (idHelper->measuresPhi(id) &0x1); // 0000 0000 0001 0000 0000
460 int strip; // 0000 0000 0000 1111 1111
461
462 //Online and offline phi ids are flipped on A wheel
463 if(m_onlineOfflinePhiFlip && measuresPhi && eta == 1){
464 strip = (48 - (idHelper->strip(id))) & 0xff;
465 }
466 else {
467 strip = (idHelper->strip(id)-1) & 0xff;
468 }
469
470
471 onlineId += (stationName << 16); // 0001 0000 0000 0000 0000
472 onlineId += (phi << 13) ; // 0000 1110 0000 0000 0000
473 onlineId += (eta <<12); // 0000 0001 0000 0000 0000
474 onlineId += (chamLay <<11); // 0000 0000 1000 0000 0000
475 onlineId += (wireLay << 9); // 0000 0000 0110 0000 0000
476 onlineId += (measuresPhi << 8); // 0000 0000 0001 0000 0000
477 onlineId += strip ; // 0000 0000 0000 1111 1111
478 return StatusCode::SUCCESS;
479}
480
481// onlineToOfflineIds
482StatusCode
483CscCondDbData::onlineToOfflineIds(const CscIdHelper* idHelper, const unsigned int & onlineId, Identifier &elementId, Identifier &channelId) const {
484 // copy-paste from CscCoolStrSvc
485
486 int stationName = ((onlineId >> 16)&0x1) + 50;
487 int phi = ((onlineId >> 13)&0x7)+1;
488 int eta = ((((onlineId >> 12)&0x1) == 1) ? 1:-1);
489 int chamLay = ((onlineId>>11)&0x1) +1;
490 int wireLay = ((onlineId>>9)&0x3) +1;
491 int measuresPhi = ((onlineId >> 8)&0x1);
492 int strip;
493
494 //Online and offline phi ids are flipped on A wheel
495 if(m_onlineOfflinePhiFlip && measuresPhi && eta == 1){
496 strip = 48 - ((onlineId)&0xff) ; //equivalent: 49 -( onlineId&0xff +1)
497 }
498 else {
499 strip = ((onlineId)&0xff) +1;
500 }
501
502 elementId = idHelper->elementID(stationName,eta,phi);
503
504 // The following call of channelID with check=true ensures that the identifier is checked to be physically valid.
505 // This is currently required to be checked when running with layouts which do not contain all CSCs anymore, since the
506 // CSCCool database contains still all CSCs. A clean fix would be to have a dedicated database for every layout.
507 bool isValid = true;
508 channelId = idHelper->channelID(stationName,eta,phi,chamLay,wireLay,measuresPhi,strip,isValid);
509 static std::atomic<bool> conversionFailPrinted = false;
510 if (!isValid) {
511 if (!conversionFailPrinted) {
512 MsgStream log(Athena::getMessageSvc(),"CscCondDbData");
513 log << MSG::WARNING << "Failed to retrieve offline Identifier from online Identifier " << onlineId
514 << " (station " << stationName << ", eta=" << eta << ", phi=" << phi << "). "
515 << "This is likely due to the fact that the CSCCool database contains "
516 << "more entries than the detector layout." << endmsg;
517 conversionFailPrinted = true;
518 }
519 return StatusCode::FAILURE;
520 }
521
522 return StatusCode::SUCCESS;
523}
524
525
526
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define endmsg
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
static Double_t ss
void setParameters(bool)
std::vector< std::string > m_cachedDeadLayers
bool isGood(const Identifier &) const
StatusCode onlineToOfflineIds(const CscIdHelper *, const unsigned int &, Identifier &, Identifier &) const
StatusCode indexToStringId(const CscIdHelper *, const unsigned int &, const std::string &, std::string &) const
StatusCode offlineToOnlineId(const CscIdHelper *, const Identifier &, unsigned int &) const
std::map< unsigned int, float > m_cachedChannelsRMS
const bool & getChannelT0Phase(IdentifierHash) const
const std::vector< std::string > & getDeadStations() const
std::map< unsigned int, bool > m_cachedChannelsT0Phase
bool isGoodStation(const Identifier &) const
StatusCode readChannelPed(IdentifierHash, float &) const
StatusCode readChannelT0Base(IdentifierHash, float &) const
void setChannelStatus(IdentifierHash, int)
const std::vector< unsigned int > & getDeadChannelsHash() const
const bool m_nillbool
void setDeadLayer(std::string_view, Identifier)
void setChannelT0Phase(IdentifierHash, bool)
void setChannelRMS(IdentifierHash, float)
const int m_nillint
std::vector< unsigned int > m_onlineChannelIdsFromLayerHash
void setDeadStation(std::string_view, Identifier)
StatusCode offlineElementToOnlineId(const CscIdHelper *, const Identifier &, unsigned int &) const
std::vector< std::string > m_cachedDeadStations
bool isGoodLayer(const Identifier &) const
StatusCode readChannelT0Phase(IdentifierHash, bool &) const
const std::vector< Identifier > & getDeadLayersId() const
const float m_nillfloat
StatusCode readChannelRMS(IdentifierHash, float &) const
const float & getChannelPed(IdentifierHash) const
const float & getChannelPSlope(IdentifierHash) const
StatusCode readChannelStatus(IdentifierHash, int &) const
const int & getChannelStatus(IdentifierHash) const
void loadParameters(const CscIdHelper *)
std::vector< unsigned int > m_emptyHashs
std::vector< std::string > m_emptyNames
void setChannelNoise(IdentifierHash, float)
void setChannelPSlope(IdentifierHash, float)
const float & getChannelF001(IdentifierHash) const
bool isGoodChannelHash(const IdentifierHash &) const
IdContext m_channelContext
const float & getChannelRMS(IdentifierHash) const
std::map< unsigned int, float > m_cachedChannelsF001
std::vector< Identifier > m_emptyIds
std::map< unsigned int, float > m_cachedChannelsNoise
const std::vector< Identifier > & getDeadStationsId() const
void setChannelF001(IdentifierHash, float)
void setChannelT0Base(IdentifierHash, float)
StatusCode readChannelPSlope(IdentifierHash, float &) const
void setChannelPed(IdentifierHash, float)
const float & getChannelNoise(IdentifierHash) const
bool hasChannelT0Phase(IdentifierHash) const
StatusCode readChannelNoise(IdentifierHash, float &) const
std::vector< Identifier > m_cachedDeadStationsId
const float & getChannelT0Base(IdentifierHash) const
std::map< unsigned int, float > m_cachedChannelsT0Base
StatusCode layerHashToOnlineId(const unsigned int &, unsigned int &) const
bool m_onlineOfflinePhiFlip
std::vector< Identifier > m_cachedDeadLayersId
std::vector< unsigned int > m_cachedDeadChannelsHash
std::map< unsigned int, int > m_cachedChannelsStatus
IdContext m_moduleContext
StatusCode readChannelF001(IdentifierHash, float &) const
void setDeadChannelHash(IdentifierHash)
const std::vector< std::string > & getDeadLayers() const
std::map< unsigned int, float > m_cachedChannelsPSlope
std::map< unsigned int, float > m_cachedChannelsPed
Identifier channelID(int stationName, int stationEta, int stationPhi, int chamberLayer, int wireLayer, int measuresPhi, int strip) const
Identifier elementID(int stationName, int stationEta, int stationPhi) const
int wireLayer(const Identifier &id) const
int chamberLayer(const Identifier &id) const
int strip(const Identifier &id) const
bool measuresPhi(const Identifier &id) const override
This is a "hash" representation of an Identifier.
int stationEta(const Identifier &id) const
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const override
Create compact id from hash id (return == 0 for OK)
IdContext module_context() const
id for module
int stationPhi(const Identifier &id) const
int stationName(const Identifier &id) const
IdContext channel_context() const
id for channel
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
Definition index.py:1