ATLAS Offline Software
Loading...
Searching...
No Matches
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
11namespace MuonCalib{
12
20
22inline std::optional<unsigned int> MdtCalibDataContainer::containerIndex(const Identifier& measId, MsgStream& msg) const {
23 IdentifierHash hash{0};
24
25 if (m_granularity == RegionGranularity::OnePerMultiLayer &&
26 (m_idHelper.get_detectorElement_hash(measId, hash) ||
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;
31 } else if (m_granularity == RegionGranularity::OnePerChamber &&
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
41bool 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
46const 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}
57bool 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}
82bool 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}
107bool 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;
130 if (m_granularity == RegionGranularity::OneRt ||
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}
#define endmsg
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
This is a "hash" representation of an Identifier.
std::optional< unsigned int > containerIndex(const Identifier &measId, MsgStream &msg) const
bool storeData(const Identifier &mlID, CorrectionPtr corrFuncSet, MsgStream &msg)
std::vector< MdtFullCalibData > m_dataCache
MdtFullCalibData::TubeContainerPtr TubeContainerPtr
MdtCalibDataContainer(const Muon::IMuonIdHelperSvc *idHelprSvc, const RegionGranularity granularity)
MdtFullCalibData::CorrectionPtr CorrectionPtr
const Muon::IMuonIdHelperSvc * m_idHelperSvc
MdtFullCalibData::RtRelationPtr RtRelationPtr
bool hasDataForChannel(const Identifier &measId, MsgStream &msg) const
Checks whether a calibration data object is already present.
void setInversePropSpeed(const float speed)
const MdtFullCalibData * getCalibData(const Identifier &measId, MsgStream &msg) const
Returns the calibration data associated with this station.
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition index.py:1
class which holds the full set of calibration constants for a given tube
MsgStream & msg
Definition testRead.cxx:32