ATLAS Offline Software
Loading...
Searching...
No Matches
NswDcsDbData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "Identifier/Identifier.h"
9
12
13
16
17#include "GeoModelKernel/throwExcept.h"
18
19
20
21
22// general functions ---------------------------------
23
25 m_idHelperSvc(idHelperSvc),
26 m_muonGeoMgr(muonGeoMgr){}
27
28std::ostream& operator<<(std::ostream& ostr, const NswDcsDbData::TDaqConstants& obj) {
29 ostr << " timeSince " << obj.timeSince << " timeUntil " << obj.timeUntil << " elink " << obj.elink;
30 return ostr;
31}
32
33unsigned int NswDcsDbData::identToModuleIdx(const Identifier& chan_id) const{
34 const IdentifierHash hash = m_idHelperSvc->detElementHash(chan_id);
35 if (m_idHelperSvc->isMM(chan_id)) {
36 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
37 return static_cast<unsigned int>(hash)*(idHelper.gasGapMax()) + (idHelper.gasGap(chan_id) -1);
38 } else if (m_idHelperSvc->issTgc(chan_id)) {
39 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
40 return static_cast<unsigned int>(hash)*(idHelper.gasGapMax()) + (idHelper.gasGap(chan_id) -1);
41 }
42 THROW_EXCEPTION("NswDcsDbData() - No NSW identifier");
43 return -1;
44 }
45
46// setting functions ---------------------------------
47
48// setDataHv
49void
51 if((tech == DcsTechType::MMG || tech == DcsTechType::MMD) ) {
52 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
54 const unsigned int array_idx = identToModuleIdx(chnlId);
55 if (array_idx >= dcsMap.size()) dcsMap.resize(array_idx + 1);
56 DcsModule& dcs_mod = dcsMap[array_idx];
57 const unsigned int channel = idHelper.channel(chnlId)-1;
58 if(dcs_mod.channels.empty())
59 dcs_mod.layer_id = m_idHelperSvc->gasGapId(chnlId);
60 if(dcs_mod.channels.size() <= channel) dcs_mod.channels.resize(channel +1);
61 if(dcs_mod.channels[channel]) {
62 THROW_EXCEPTION("NswDcsDbData::setData() -- Cannot overwrite channel");
63 return;
64 }
65 dcs_mod.channels[channel] = std::make_unique<DcsConstants>(std::move(constants));
66 } else if(tech == DcsTechType::STG) {
67 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
69 const unsigned int array_idx = identToModuleIdx(chnlId);
70 if (array_idx >= dcsMap.size()) dcsMap.resize(array_idx + 1);
71 DcsModule& dcs_mod = dcsMap.at(array_idx);
72 const unsigned int channel = idHelper.channel(chnlId)-1;
73 if(dcs_mod.channels.empty()) {
74 dcs_mod.layer_id = m_idHelperSvc->layerId(chnlId);
75 }
76 if(dcs_mod.channels.size() <= channel) dcs_mod.channels.resize(channel +1);
77 if(dcs_mod.channels[channel]) {
78 THROW_EXCEPTION("setData() -- Cannot overwrite channel");
79 return;
80 }
81 dcs_mod.channels[channel] = std::make_unique<DcsConstants>(std::move(constants));
82 }
83}
84
85// setDataTDaq
86void
87NswDcsDbData::setDataTDaq(const DcsTechType tech, const Identifier& chnlId, uint64_t timeSince, uint64_t timeUntil, unsigned int elink, bool permanentlyDisabled) {
89 const unsigned int array_idx = identToModuleIdx(chnlId);
90 if (array_idx >= data.size()) data.resize(array_idx + 1);
92 x.timeSince = timeSince;
93 x.timeUntil = timeUntil;
94 x.elink = elink;
95 x.permanentlyDisabled = permanentlyDisabled;
96 data[array_idx][chnlId].insert(x);
97}
98
99void
100NswDcsDbData::setDataEltx(const DcsTechType tech, const Identifier& channelId) {
102 const uint array_idx = identToModuleIdx(channelId);
103 if (array_idx >= data.size()) data.resize(array_idx + 1);
104 data[array_idx].insert(channelId);
105}
106
107
108
109// retrieval functions -------------------------------
110
111// getChannelIds
112std::vector<Identifier>
113NswDcsDbData::getChannelIdsHv(const DcsTechType tech, const std::string& side) const {
114 std::vector<Identifier> chnls;
115 if(tech == DcsTechType::MMG || tech == DcsTechType::MMD){
116 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
117 const ChannelDcsMap& dcsMap = tech == DcsTechType::MMG ? m_data_hv_mmg : m_data_hv_mmd;
118 chnls.reserve(dcsMap.size());
119 for(const DcsModule& module : dcsMap) {
120 if(module.channels.empty()) continue;
121 if(side == "A" && idHelper.stationEta(module.layer_id) < 0) continue;
122 if(side == "C" && idHelper.stationEta(module.layer_id) > 0) continue;
123 for(unsigned int chn = 1 ; chn <= module.channels.size() ; ++chn) {
124 if(!module.channels[chn -1]) continue;
125 chnls.push_back(idHelper.channelID(module.layer_id, idHelper.multilayer(module.layer_id), idHelper.gasGap(module.layer_id), chn ));
126 }
127 }
128 } else if(tech == DcsTechType::STG){
129 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
130 const ChannelDcsMap& dcsMap = m_data_hv_stg;
131 chnls.reserve(dcsMap.size());
132 for(const DcsModule& module : dcsMap) {
133 if(module.channels.empty()) continue;
134 if(side == "A" && idHelper.stationEta(module.layer_id) < 0) continue;
135 if(side == "C" && idHelper.stationEta(module.layer_id) > 0) continue;
136 for(unsigned int chn = 1 ; chn <= module.channels.size() ; ++chn) {
137 if(!module.channels[chn -1]) continue;
138 chnls.push_back(idHelper.channelID(module.layer_id, idHelper.multilayer(module.layer_id),
139 idHelper.gasGap(module.layer_id), idHelper.channelType(module.layer_id), chn ));
140 }
141 }
142 }
143 return chnls;
144}
145
147NswDcsDbData::getDataForChannelHv(const DcsTechType tech, const Identifier& channelId, bool issTgcQ1OuterHv) const {
148 if(tech == DcsTechType::MMG){
149 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
150 if(!idHelper.is_mm(channelId)) return nullptr;
151 Identifier dcsChannelIdStripHv = idHelper.pcbID(channelId);
152 const ChannelDcsMap& dcsMap = m_data_hv_mmg; // later add something like: type == DcsDataType::HV ? m_data_hv : m_data_lv;
153 const unsigned int array_idx = identToModuleIdx(dcsChannelIdStripHv);
154 const unsigned int channel = idHelper.channel(dcsChannelIdStripHv) -1;
155 if (dcsMap.size() > array_idx && dcsMap.at(array_idx).channels.size() > channel && dcsMap[array_idx].channels[channel]) return dcsMap[array_idx].channels[channel].get();
156 } else if (tech == DcsTechType::MMD) {
157 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
158 if(!idHelper.is_mm(channelId)) return nullptr;
159 Identifier dcsChannelIdDriftHv = idHelper.multilayerID(channelId);
160 const ChannelDcsMap& dcsMap = m_data_hv_mmd;
161 const unsigned int array_idx = identToModuleIdx(dcsChannelIdDriftHv);
162 const unsigned int channel = idHelper.channel(dcsChannelIdDriftHv) -1;
163 if (dcsMap.size() > array_idx && dcsMap.at(array_idx).channels.size() > channel && dcsMap[array_idx].channels[channel]) return dcsMap[array_idx].channels[channel].get();
164 } else if(tech == DcsTechType::STG){
165 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
166 if(!idHelper.is_stgc(channelId)) return nullptr;
167
168 // the parameter issTgcQ1OuterHv is only relevant for the Q1s of the stgcs. So set it to false if we are not in Q1, just in case
169 if(std::abs(idHelper.stationEta(channelId))!= 1) {issTgcQ1OuterHv=false;}
170 Identifier dcsChannelId = idHelper.hvID(channelId, !issTgcQ1OuterHv /* the function takes isInnerQ1 therefore invert the isOuterQ1 variable*/);
171 const ChannelDcsMap& dcsMap = m_data_hv_stg;
172 const unsigned int array_idx = identToModuleIdx(dcsChannelId);
173 const unsigned int channel = idHelper.channel(dcsChannelId) -1;
174 if (dcsMap.size() > array_idx && dcsMap.at(array_idx).channels.size() > channel && dcsMap[array_idx].channels[channel]) return dcsMap[array_idx].channels[channel].get();
175 }
176 return nullptr;
177}
178
179
180bool NswDcsDbData::isGood(const EventContext& ctx, const Identifier& channelId, bool issTgcQ1OuterHv) const {
181 // here we will check the different DCS components that need to be good to declare a detector region as good
182 // for now we only we only have the HV data
183 if(!isGoodHv(channelId, issTgcQ1OuterHv)) return false;
184 //isGoodEltx and isGoodTdaq are still under validation, but since they are switched off in the NswDcsAlg their data will be empty so they do not reject hits for now.
185 bool permanentlyDisabled{false};
186 if(!isGoodTDaq(ctx, channelId, permanentlyDisabled)) return false;
187 if(!isGoodEltx(channelId)) return false;
188 if(!isConnectedChannel(channelId)) return false;
189 return true;
190
191}
192
193
194bool NswDcsDbData::isGoodHv(const Identifier& channelId, bool issTgcQ1OuterHv) const {
195 if (m_idHelperSvc->issTgc(channelId)){
196 const NswDcsDbData::DcsConstants* dcs = getDataForChannelHv(DcsTechType::STG, channelId, issTgcQ1OuterHv);
198 return !dcs || dcs->fsmState == DcsFsmState::ON;
199 } else if (m_idHelperSvc->isMM(channelId)){
200 const NswDcsDbData::DcsConstants* dcsDrift = getDataForChannelHv(DcsTechType::MMD, channelId, issTgcQ1OuterHv);
201 bool driftHvIsGood = (!dcsDrift || dcsDrift->fsmState == DcsFsmState::ON);
202
203 const NswDcsDbData::DcsConstants* dcsStrips = getDataForChannelHv(DcsTechType::MMG, channelId, issTgcQ1OuterHv);
204 bool stripHvIsGood = (!dcsStrips || dcsStrips->fsmState == DcsFsmState::ON);
205
206 return driftHvIsGood && stripHvIsGood;
207 }
208 return false;
209}
210
211bool NswDcsDbData::isGoodTDaq(const EventContext& ctx, const Identifier& channelId, bool &permanentlyDisabled) const {
212 const ChannelTDaqMap & data = m_idHelperSvc->isMM(channelId) ? m_data_tdaq_mmg : m_data_tdaq_stg;
213 const unsigned int array_idx = identToModuleIdx(channelId);
214 if(data.size()<=array_idx || data[array_idx].empty()) return true; // for this ro element no bad elink have been recorded
215 const std::map<Identifier, std::set<TDaqConstants>>& dataInRoElement = data[array_idx];
216 Identifier mapIdentifier{0};
217 uint elink{0};
218
219 if(m_idHelperSvc->issTgc(channelId)){
220 const sTgcIdHelper& idHelper{m_idHelperSvc->stgcIdHelper()};
221 mapIdentifier = idHelper.febID(channelId);
222 auto mapper = Muon::nsw::MapperSTG();
223 mapper.elink_info(idHelper.channelType(channelId), !idHelper.isSmall(channelId), std::abs(idHelper.stationEta(channelId))-1, 4*(idHelper.multilayer(channelId)-1) + idHelper.gasGap(channelId) -1, idHelper.channel(channelId), elink);
224 } else {
225 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
226 mapIdentifier = idHelper.febID(channelId);
227 auto mapper = Muon::nsw::MapperMMG();
228 mapper.elink_info(std::abs(idHelper.stationEta(channelId))-1, idHelper.channel(channelId), elink);
229 }
230
231 auto elm = dataInRoElement.find(mapIdentifier);
232 if(elm == dataInRoElement.end()) return true; // channel in question was not deactivated at all
234 uint64_t evtTime = ctx.eventID().time_stamp()*1e9; // go from seconds to nanoseconds
235 evtTime += ctx.eventID().time_stamp_ns_offset();
236 x.timeSince = evtTime;
237 x.timeUntil = evtTime;
238 x.elink = elink;
239
240 auto disabledLink = elm->second.find(x);
241 if(disabledLink != elm->second.end()){// elink was deactivated for this time period
242 permanentlyDisabled = disabledLink->permanentlyDisabled;
243 return false;
244 }
245 return true; // checked the channel in question, not deactivated for given run and lumi block combination, all good
246}
247
248bool NswDcsDbData::isGoodEltx(const Identifier& channelId) const{
249 const ChannelTDaqMap & data = m_idHelperSvc->isMM(channelId) ? m_data_tdaq_mmg : m_data_tdaq_stg;
250 const unsigned int array_idx = identToModuleIdx(channelId);
251 if(data.size()<=array_idx || data[array_idx].empty()) return true; // for this ro element no bad elink have been recorded
252 if(data[array_idx].find(channelId) != data[array_idx].end()) return false;
253 return true;
254}
255
256
257bool NswDcsDbData::isConnectedChannel(const Identifier& channelId) const {
258 // for stgc we do not have unconnected channels
259 if(m_idHelperSvc->issTgc(channelId)) return true;
260
261 if(!m_idHelperSvc->isMM(channelId)) THROW_EXCEPTION("the check for unconnected channels was called with an identifier that is in MM and not sTGC");
262
263 const MmIdHelper& idHelper{m_idHelperSvc->mmIdHelper()};
264
265 const MuonGM::MMReadoutElement* detectorReadoutElement = m_muonGeoMgr->getMMReadoutElement(channelId);
266 if(!detectorReadoutElement) {
267 THROW_EXCEPTION("failed to retrieve MMReadoutElement");
268 }
269 const MuonGM::MuonChannelDesign* channelDesign = detectorReadoutElement->getDesign(channelId);
270 if(!channelDesign) {
271 THROW_EXCEPTION("failed to retrieve MuonChannelDesign");
272 }
273
274 int channel_number = idHelper.channel(channelId);
275 if(idHelper.isStereo(channelId)){
276 if(channel_number <= channelDesign->nMissedBottomStereo || channel_number >= channelDesign->totalStrips - channelDesign->nMissedTopStereo) {
277 return false;
278 }
279 } else {
280 if(channel_number <= channelDesign->nMissedBottomEta || channel_number >= channelDesign->totalStrips - channelDesign->nMissedTopEta) {
281 return false;
282 }
283 }
284 return true;
285
286}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
unsigned int uint
std::ostream & operator<<(std::ostream &ostr, const NswDcsDbData::TDaqConstants &obj)
#define x
This is a "hash" representation of an Identifier.
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channel) const
static int gasGapMax()
Identifier pcbID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int pcb) const
Identifier multilayerID(const Identifier &channeldID) const
bool isStereo(const Identifier &id) const
Identifier febID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int radius) const
int channel(const Identifier &id) const override
int gasGap(const Identifier &id) const override
get the hashes
int multilayer(const Identifier &id) const
An MMReadoutElement corresponds to a single STGC module; therefore typicaly a barrel muon station con...
const MuonChannelDesign * getDesign(const Identifier &id) const
returns the MuonChannelDesign class for the given identifier
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
int stationEta(const Identifier &id) const
bool is_stgc(const Identifier &id) const
bool isSmall(const Identifier &id) const
bool is_mm(const Identifier &id) const
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
MuonCond::DcsConstants DcsConstants
std::vector< DcsModule > ChannelDcsMap
ChannelDcsMap m_data_hv_stg
void setDataHv(const DcsTechType tech, const Identifier &chnlId, DcsConstants constants)
ChannelDcsMap m_data_hv_mmd
bool isGoodEltx(const Identifier &channelId) const
ChannelEltxMap m_data_eltx_stg
const DcsConstants * getDataForChannelHv(const DcsTechType tech, const Identifier &channelId, bool issTgcQ1OuterHv) const
Retrieves the calibration constant for a particular readout channel.
ChannelDcsMap m_data_hv_mmg
bool isGood(const EventContext &ctx, const Identifier &channelId, bool issTgcQ1OuterHv=false) const
Returns whether the channel is alive, i.e. DCS state on, etc...
ChannelTDaqMap m_data_tdaq_mmg
ChannelTDaqMap m_data_tdaq_stg
NswDcsDbData(const Muon::IMuonIdHelperSvc *idHelperSvc, const MuonGM::MuonDetectorManager *muonGeoMgr)
unsigned int identToModuleIdx(const Identifier &chan_id) const
const Muon::IMuonIdHelperSvc * m_idHelperSvc
ChannelEltxMap m_data_eltx_mmg
std::vector< std::set< Identifier > > ChannelEltxMap
bool isConnectedChannel(const Identifier &channelId) const
bool isGoodHv(const Identifier &channelId, bool issTgcQ1OuterHv=false) const
const MuonGM::MuonDetectorManager * m_muonGeoMgr
std::vector< std::map< Identifier, std::set< TDaqConstants > > > ChannelTDaqMap
std::vector< Identifier > getChannelIdsHv(const DcsTechType tech, const std::string &side) const
void setDataTDaq(const DcsTechType tech, const Identifier &chnlId, uint64_t timeSince, uint64_t timeUntil, unsigned int elink, bool permanentlyDisabled)
bool isGoodTDaq(const EventContext &ctx, const Identifier &channelId, bool &permanentlyDisabled) const
void setDataEltx(const DcsTechType tech, const Identifier &chnlId)
int multilayer(const Identifier &id) const
Identifier hvID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, bool isInnerQ1) const
int channelType(const Identifier &id) const
static int gasGapMax()
Identifier febID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channelType) const
int channel(const Identifier &id) const override
int gasGap(const Identifier &id) const override
get the hashes
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channelType, int channel) const
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
std::vector< std::unique_ptr< DcsConstants > > channels
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10