ATLAS Offline Software
MdtCalibDataContainer.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 #include "Identifier/Identifier.h"
9 
10 
11 namespace MuonCalib{
12 
14  const RegionGranularity granularity):
15  m_idHelperSvc{idHelperSvc},
16  m_granularity{granularity} {
17 }
20 
22 inline std::optional<unsigned int> MdtCalibDataContainer::containerIndex(const Identifier& measId, MsgStream& msg) const {
24 
27  m_idHelper.detectorElement_hash_max() < static_cast<unsigned int>(hash))) {
28  msg<<MSG::ERROR <<__FILE__<<":"<<__LINE__<<" Failed to look up a proper detector element hash for "
29  <<m_idHelperSvc->toString(measId)<<endmsg;
30  return std::nullopt;
32  (m_idHelper.get_module_hash(measId, hash) ||
33  m_idHelper.module_hash_max() < static_cast<unsigned int>(hash))) {
34  msg<<MSG::ERROR <<__FILE__<<":"<<__LINE__<<" Failed to look up a proper detector element hash for "
35  <<m_idHelperSvc->toString(measId)<<endmsg;
36  return std::nullopt;
37  }
38  return std::make_optional<unsigned int>(static_cast<unsigned int>(hash));
39 }
40 
41 bool MdtCalibDataContainer::hasDataForChannel(const Identifier& measId, MsgStream& msg) const {
42  std::optional<unsigned int > index = containerIndex(measId, msg);
43  return !(!index || (*index) >= m_dataCache.size() || !m_dataCache[*index]);
44 }
45 
46 const MdtFullCalibData* MdtCalibDataContainer::getCalibData(const Identifier& measId, MsgStream& msg) const {
47  std::optional<unsigned int> index = containerIndex(measId, msg);
48  if (!index) return nullptr;
49  if ((*index ) < m_dataCache.size()) {
51  if (data) {return &data;}
52  }
53  msg<<MSG::WARNING<<__FILE__<<":"<<__LINE__<<" No Mdt calibration data is stored for "
54  <<m_idHelperSvc->toString(measId)<<endmsg;
55  return nullptr;
56 }
57 bool MdtCalibDataContainer::storeData(const Identifier& mlID, CorrectionPtr corrFuncSet, MsgStream& msg) {
59  std::optional<unsigned int> index = containerIndex(mlID, msg);
60  if (!index) return false;
61  if (!corrFuncSet) {
62  msg << MSG::ERROR<<__FILE__<<":"<<__LINE__<<" No correction functional set parsed for multilayer "
63  <<m_idHelperSvc->toString(mlID) << endmsg;
64  return false;
65  }
67  if (m_dataCache.size() <= (*index)) m_dataCache.resize(*index + 1);
69  if (cache.corrections && cache.corrections != corrFuncSet) {
70  msg << MSG::ERROR<<__FILE__<<":"<<__LINE__<<" There already exist a rt relation object for multilayer "
71  <<m_idHelperSvc->toString(mlID) << endmsg;
72  return false;
73  }
74  cache.corrections = std::move(corrFuncSet);
75 
76  if (msg.level() <= MSG::DEBUG) {
77  msg << MSG::DEBUG<<__FILE__<<":"<<__LINE__<<" Added successfully the rt corrections for "
78  << m_idHelperSvc->toString(mlID)<<endmsg;
79  }
80  return true;
81 }
82 bool MdtCalibDataContainer::storeData(const Identifier& mlID, RtRelationPtr rtRelation, MsgStream& msg) {
84  std::optional<unsigned int> index = containerIndex(mlID, msg);
85  if (!index) return false;
86  if (!rtRelation) {
87  msg << MSG::ERROR<<__FILE__<<":"<<__LINE__<<" No rt relation parsed for multilayer "
88  <<m_idHelperSvc->toString(mlID) << endmsg;
89  return false;
90  }
92  if (m_dataCache.size() <= (*index)) m_dataCache.resize(*index + 1);
94  if (cache.rtRelation && cache.rtRelation != rtRelation) {
95  msg << MSG::ERROR<<__FILE__<<":"<<__LINE__<<" There already exist a rt relation object for multilayer "
96  <<m_idHelperSvc->toString(mlID) << endmsg;
97  return false;
98  }
99  cache.rtRelation = std::move(rtRelation);
100 
101  if (msg.level() <= MSG::DEBUG) {
102  msg << MSG::DEBUG<<__FILE__<<":"<<__LINE__<<" Added successfully the rt relations for "
103  << m_idHelperSvc->toString(mlID)<<endmsg;
104  }
105  return true;
106 }
107 bool MdtCalibDataContainer::storeData(const Identifier& mlID, TubeContainerPtr tubeContainer, MsgStream& msg){
109  std::optional<unsigned int> index = containerIndex(mlID, msg);
110  if (!index) return false;
111  if (!tubeContainer) {
112  msg << MSG::ERROR<<__FILE__<<":"<<__LINE__<<" No tube ontainer parsed for multilayer "
113  <<m_idHelperSvc->toString(mlID) << endmsg;
114  return false;
115  }
116 
118  if (m_dataCache.size() <= (*index)) m_dataCache.resize(*index + 1);
120  if (cache.tubeCalib && cache.tubeCalib != tubeContainer) {
121  msg << MSG::ERROR<<__FILE__<<":"<<__LINE__<<" There already exist a tube calibration container for multilayer "
122  <<m_idHelperSvc->toString(mlID) << endmsg;
123  return false;
124  }
125  if (msg.level() <= MSG::DEBUG) {
126  msg << MSG::DEBUG<<__FILE__<<":"<<__LINE__<<" Added successfully the tube calibrations for "
127  << m_idHelperSvc->toString(mlID)<<endmsg;
128  }
129  cache.tubeCalib = tubeContainer;
131  m_idHelper.multilayer(mlID) == 2 ||
132  m_idHelper.numberOfMultilayers(mlID) == 1) return true;
133  return storeData(m_idHelper.multilayerID(mlID, 2), std::move(tubeContainer), msg);
134 }
135 
136 
137 
138 }
MdtIdHelper::multilayer
int multilayer(const Identifier &id) const
Access to components of the ID.
Definition: MdtIdHelper.cxx:727
MuonCalib::MdtCalibDataContainer::m_granularity
const RegionGranularity m_granularity
Definition: MdtCalibDataContainer.h:58
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
GeoModel::TransientConstSharedPtr< MdtCorFuncSet >
MuonCalib::MdtCalibDataContainer::setInversePropSpeed
void setInversePropSpeed(const float speed)
Definition: MdtCalibDataContainer.cxx:18
MdtIdHelper::numberOfMultilayers
int numberOfMultilayers(const Identifier &id) const
Definition: MdtIdHelper.cxx:501
MuonCalib::MdtCalibDataContainer::RegionGranularity
RegionGranularity
Definition: MdtCalibDataContainer.h:33
index
Definition: index.py:1
MuonCalib::MdtCalibDataContainer::storeData
bool storeData(const Identifier &mlID, CorrectionPtr corrFuncSet, MsgStream &msg)
Definition: MdtCalibDataContainer.cxx:57
MuonIdHelper::detectorElement_hash_max
size_type detectorElement_hash_max() const
Definition: MuonIdHelper.h:183
MdtCalibDataContainer.h
MuonCalib::MdtFullCalibData::rtRelation
RtRelationPtr rtRelation
Definition: MdtFullCalibData.h:21
MuonCalib::MdtCalibDataContainer::m_dataCache
std::vector< MdtFullCalibData > m_dataCache
Definition: MdtCalibDataContainer.h:60
MuonCalib::MdtFullCalibData
class which holds the full set of calibration constants for a given tube
Definition: MdtFullCalibData.h:15
MuonCalib::MdtFullCalibData::corrections
CorrectionPtr corrections
Definition: MdtFullCalibData.h:20
MuonCalib::MdtCalibDataContainer::m_idHelperSvc
const Muon::IMuonIdHelperSvc * m_idHelperSvc
Definition: MdtCalibDataContainer.h:57
MuonCalib::MdtFullCalibData::tubeCalib
TubeContainerPtr tubeCalib
Definition: MdtFullCalibData.h:22
MuonCalib::MdtCalibDataContainer::granularity
RegionGranularity granularity() const
Definition: MdtCalibDataContainer.cxx:21
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib::MdtCalibDataContainer::RegionGranularity::OnePerChamber
@ OnePerChamber
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::MdtCalibDataContainer::m_invPropSpeed
float m_invPropSpeed
Definition: MdtCalibDataContainer.h:61
MuonCalib::MdtCalibDataContainer::RegionGranularity::OnePerMultiLayer
@ OnePerMultiLayer
IdentifierHash.h
MuonCalib::MdtCalibDataContainer::getCalibData
const MdtFullCalibData * getCalibData(const Identifier &measId, MsgStream &msg) const
Returns the calibration data associated with this station
Definition: MdtCalibDataContainer.cxx:46
MuonIdHelper::module_hash_max
size_type module_hash_max() const
the maximum hash value
Definition: MuonIdHelper.cxx:758
DeMoScan.index
string index
Definition: DeMoScan.py:362
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:108
Muon::IMuonIdHelperSvc::toString
virtual std::string toString(const Identifier &id) const =0
print all fields to string
MdtIdHelper::get_detectorElement_hash
virtual int get_detectorElement_hash(const Identifier &id, IdentifierHash &hash_id) const override
Definition: MdtIdHelper.cxx:331
MuonCalib::MdtCalibDataContainer::RegionGranularity::OneRt
@ OneRt
DEBUG
#define DEBUG
Definition: page_access.h:11
MuonCalib::MdtCalibDataContainer::containerIndex
std::optional< unsigned int > containerIndex(const Identifier &measId, MsgStream &msg) const
Definition: MdtCalibDataContainer.cxx:22
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:27
MdtIdHelper::multilayerID
Identifier multilayerID(const Identifier &channeldID) const
Definition: MdtIdHelper.cxx:338
MuonCalib::MdtCalibDataContainer::hasDataForChannel
bool hasDataForChannel(const Identifier &measId, MsgStream &msg) const
Checks whether a calibration data object is already present.
Definition: MdtCalibDataContainer.cxx:41
MdtIdHelper::get_module_hash
virtual int get_module_hash(const Identifier &id, IdentifierHash &hash_id) const override
Definition: MdtIdHelper.cxx:324
MuonCalib::MdtCalibDataContainer::m_idHelper
const MdtIdHelper & m_idHelper
Definition: MdtCalibDataContainer.h:59
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
MuonCalib::MdtCalibDataContainer::inversePropSpeed
float inversePropSpeed() const
Definition: MdtCalibDataContainer.cxx:19
MuonCalib::MdtCalibDataContainer::MdtCalibDataContainer
MdtCalibDataContainer(const Muon::IMuonIdHelperSvc *idHelprSvc, const RegionGranularity granularity)
Definition: MdtCalibDataContainer.cxx:13
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
IMuonIdHelperSvc.h
Identifier
Definition: IdentifierFieldParser.cxx:14