ATLAS Offline Software
MuonNRPC_CablingMap.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cmath>
8 
9 #include "GaudiKernel/ISvcLocator.h"
11 #include "StoreGate/StoreGateSvc.h"
12 
14  // initialize the message service
15 
16  // retrieve the RpcIdHelper
17  ISvcLocator* svcLocator = Gaudi::svcLocator();
18  StoreGateSvc* detStore = nullptr;
19  StatusCode sc = svcLocator->service("DetectorStore", detStore);
20  if (sc != StatusCode::SUCCESS) {
21  throw std::runtime_error("Could not find the detctor store");
22  }
23  sc = detStore->retrieve(m_rpcIdHelper, "RPCIDHELPER");
24  if (sc != StatusCode::SUCCESS) {
25  throw std::runtime_error("Could not retrieve the RpcIdHelper");
26  }
27 }
28 
30 
32  Identifier& id, bool check_valid) const {
33  bool valid{!check_valid};
34  id =
35  check_valid
37  cabling_data.stationIndex, cabling_data.eta, cabling_data.phi,
38  cabling_data.doubletR, cabling_data.doubletZ,
39  cabling_data.doubletPhi, cabling_data.gasGap,
40  cabling_data.measuresPhi(), cabling_data.strip, valid)
42  cabling_data.stationIndex, cabling_data.eta, cabling_data.phi,
43  cabling_data.doubletR, cabling_data.doubletZ,
44  cabling_data.doubletPhi, cabling_data.gasGap,
45  cabling_data.measuresPhi(), cabling_data.strip);
46  return valid;
47 }
48 
51  bool setSideBit) const {
52  if (!m_rpcIdHelper->is_rpc(module_id))
53  return false;
54  cabling_data.stationIndex = m_rpcIdHelper->stationName(module_id);
55  cabling_data.eta = m_rpcIdHelper->stationEta(module_id);
56  cabling_data.phi = m_rpcIdHelper->stationPhi(module_id);
57  cabling_data.doubletR = m_rpcIdHelper->doubletR(module_id);
58  cabling_data.doubletPhi = m_rpcIdHelper->doubletPhi(module_id);
59  cabling_data.doubletZ = m_rpcIdHelper->doubletZ(module_id);
60  cabling_data.gasGap = m_rpcIdHelper->gasGap(module_id);
61  cabling_data.setMeasPhiAndSide(m_rpcIdHelper->measuresPhi(module_id), setSideBit);
62  cabling_data.strip = m_rpcIdHelper->strip(module_id);
63  return true;
64 }
65 
67  MsgStream& log) const {
68  // Identify the chamber
69  OnlToOfflMap::const_iterator itr = m_onToOffline.find(cabling_map);
70  if (itr == m_onToOffline.end()) {
71  log << MSG::ERROR << "getOfflineId() -- The detector "
72  << static_cast<const NrpcCablingOnlineID&>(cabling_map) << " is unknown"
73  << endmsg;
74  return false;
75  }
76  cabling_map.NrpcCablingOfflineID::operator=(itr->second);
77  cabling_map.strip = itr->first.firstStrip + cabling_map.channelId - itr->first.firstChannel;
78  if (log.level() <= MSG::DEBUG) {
79  log << MSG::ALWAYS << " getOfflineId() -- Successfully converted " << cabling_map << endmsg;
80  }
81  return true;
82 }
83 
86  MsgStream& log) const {
87  if (log.level()<= MSG::DEBUG) {
88  log<<MSG::ALWAYS<<__FILE__<<":"<<__LINE__<<" getOnlineId() - Test: "<<cabling_map<<endmsg;
89  }
90  const NrpcCablingOfflineID& offId{cabling_map};
91  OfflToOnlMap::const_iterator itr = m_offToOnline.find(offId);
92  if (itr == m_offToOnline.end()) {
93  log << MSG::ERROR <<__FILE__<<":"<<__LINE__<< " getOnlineId() -- The offline identifier "
94  << offId << " is unknown " << endmsg;
95  return false;
96  }
97  const NrpcCablOnDataByStripSet::const_iterator onlineCardItr = itr->second.find(cabling_map);
98  if (onlineCardItr != itr->second.end()) {
99  const NrpcCablOnDataByStrip& onlineCard = (*onlineCardItr);
101  static_cast<NrpcCablingOnlineID&>(cabling_map) = onlineCard;
102  cabling_map.channelId = (cabling_map.strip - onlineCard.firstStrip) + onlineCard.firstChannel;
103  if (log.level() <= MSG::DEBUG) {
104  log <<MSG::ALWAYS<<__FILE__<<":"<<__LINE__
105  <<" getOnlineId() -- Card "<<onlineCard<<" matches... Deduced channel "
106  <<static_cast<int>(cabling_map.channelId)<<endmsg;
107  }
108 
109  return true;
110  }
111  log << MSG::ERROR <<__FILE__<<":"<<__LINE__
112  << " getOnlineId() -- No tdc channel could be found for the object "
113  << static_cast<const NrpcCablingOfflineID&>(cabling_map)
114  << " strip: " << static_cast<int>(cabling_map.strip) << endmsg;
115  return false;
116 }
117 
119  MsgStream& log) {
120  // Check that the channel is not overwritten
121  if (log.level() <= MSG::DEBUG) {
122  log << MSG::ALWAYS << "insertChannels() -- Insert new channel "
123  << cabling_data << endmsg;
124  }
126  log << MSG::ERROR
127  << "insertChannels() -- Failed to fill the offline -> online map "
128  << endmsg;
129  log << MSG::ERROR
130  << " --- Old: " << (*m_offToOnline[cabling_data].find(cabling_data))
131  << endmsg;
132  log << MSG::ERROR << " --- New: "
133  << static_cast<const NrpcCablingOnlineID&>(cabling_data) << endmsg;
134  return false;
135  }
136  if (!m_onToOffline[cabling_data]) {
138  } else {
139  log << MSG::ERROR
140  << "insertChannels() -- The online to offline map is already "
141  "booked for identifier "
142  << static_cast<const NrpcCablingOnlineID&>(cabling_data) << endmsg;
143  log << MSG::ERROR << " -- Old: " << m_onToOffline[cabling_data]
144  << endmsg;
145  log << MSG::ERROR << " -- New: "
146  << static_cast<const NrpcCablingOfflineID&>(cabling_data) << endmsg;
147  return false;
148  }
149 
150  int sub = cabling_data.subDetector;
151  int rod = cabling_data.tdcSector;
152 
153  uint32_t hardId = (sub << 16) | rod;
154 
155  const bool robInitialized = std::find(m_listOfROB.begin(), m_listOfROB.end(), hardId) != m_listOfROB.end();
156  if (!robInitialized) {
157  m_listOfROB.push_back(hardId);
158  }
159 
160  return true;
161 }
163  if (m_offToOnline.empty()) {
164  log << MSG::ERROR << "finalize() -- No data has been loaded " << endmsg;
165  return false;
166  }
168  NrpcCablingData RobOffId{};
169  RobOffId.strip = 1;
170  for (const auto& [card, chamber] : m_onToOffline) {
171  static_cast<NrpcCablingOfflineID&>(RobOffId) = chamber;
172  Identifier chId{0};
173  if (!convert(RobOffId, chId, true)) {
174  log << MSG::ERROR
175  << "Could not construct an offline identifier from " << chamber
176  << endmsg;
177  return false;
178  }
179  IdentifierHash hash{0};
180  if (m_rpcIdHelper->get_module_hash(chId, hash)) {
181  log << MSG::ERROR << " Failed to generate a hash for " << chamber
182  << endmsg;
183  return false;
184  }
185  uint32_t hardId = (card.subDetector << 16) | card.tdcSector;
186  m_chambROBs[hash] = hardId;
187  std::vector<IdentifierHash>& robHashes = m_ROBHashes[hardId];
188  if (std::find(robHashes.begin(), robHashes.end(), hash) ==
189  robHashes.end())
190  robHashes.push_back(hash);
191  }
192  return true;
193 }
195  MsgStream& log) const {
196  ChamberToROBMap::const_iterator it = m_chambROBs.find(stationCode);
197  if (it != m_chambROBs.end()) {
198  return it->second;
199  }
200  log << MSG::WARNING << "Station code " << stationCode << " not found !"
201  << endmsg;
202  return 0;
203 }
204 
206  const std::vector<IdentifierHash>& rpcHashVector, MsgStream& log) const {
207  ListOfROB to_ret{};
208  to_ret.reserve(rpcHashVector.size());
209  for (const IdentifierHash& hash : rpcHashVector)
210  to_ret.push_back(getROBId(hash, log));
211  return to_ret;
212 }
213 const std::vector<IdentifierHash>& MuonNRPC_CablingMap::getChamberHashVec(
214  const uint32_t ROBI, MsgStream& log) const {
215  ROBToChamberMap::const_iterator itr = m_ROBHashes.find(ROBI);
216  if (itr != m_ROBHashes.end())
217  return itr->second;
218  log << MSG::WARNING << "ROB ID " << ROBI << " not found ! " << endmsg;
219  static const std::vector<IdentifierHash> dummy;
220  return dummy;
221 }
223  return m_listOfROB;
224 }
NrpcTdcStripRange::firstStrip
uint8_t firstStrip
First strip covered by the Tdc chip.
Definition: NrpcCablingData.h:98
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
MuonNRPC_CablingMap::getChamberHashVec
const std::vector< IdentifierHash > & getChamberHashVec(const uint32_t ROBI, MsgStream &log) const
return a HashId list for a given ROD
Definition: MuonNRPC_CablingMap.cxx:213
MuonNRPC_CablingMap::finalize
bool finalize(MsgStream &log)
Performs consistency checks for the cabling data (I.e.
Definition: MuonNRPC_CablingMap.cxx:162
NrpcCablingOfflineID
Representation of the offline Identifier in a more tangible format.
Definition: NrpcCablingData.h:34
MuonIdHelper::is_rpc
bool is_rpc(const Identifier &id) const
Definition: MuonIdHelper.cxx:792
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
MuonNRPC_CablingMap::m_offToOnline
OfflToOnlMap m_offToOnline
Map to cache the offline -> online conversions.
Definition: MuonNRPC_CablingMap.h:71
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
calibdata.chamber
chamber
Definition: calibdata.py:32
RpcIdHelper::doubletZ
int doubletZ(const Identifier &id) const
Definition: RpcIdHelper.cxx:1062
NrpcCablingCoolData
Struct to represent all cabling information coming from the cabling database per channel.
Definition: NrpcCablingData.h:140
MuonNRPC_CablingMap.h
MuonNRPC_CablingMap::m_chambROBs
ChamberToROBMap m_chambROBs
Definition: MuonNRPC_CablingMap.h:73
skel.it
it
Definition: skel.GENtoEVGEN.py:423
RpcIdHelper::measuresPhi
bool measuresPhi(const Identifier &id) const override
Definition: RpcIdHelper.cxx:1068
MuonNRPC_CablingMap::m_listOfROB
ListOfROB m_listOfROB
full list of ROBs
Definition: MuonNRPC_CablingMap.h:80
createCablingJSON.cabling_data
dictionary cabling_data
Definition: createCablingJSON.py:18
MuonIdHelper::stationName
int stationName(const Identifier &id) const
Definition: MuonIdHelper.cxx:804
RpcIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int doubletR, int doubletZ, int doubletPhi, int gasGap, int measuresPhi, int strip) const
Definition: RpcIdHelper.cxx:940
MuonNRPC_CablingMap::insertChannels
bool insertChannels(const NrpcCablingCoolData &cabling_data, MsgStream &log)
Inserts a cabling object into the map.
Definition: MuonNRPC_CablingMap.cxx:118
MuonNRPC_CablingMap::getOnlineId
bool getOnlineId(NrpcCablingData &cabling_data, MsgStream &log) const
return the online id given the offline id
Definition: MuonNRPC_CablingMap.cxx:85
RpcIdHelper.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MuonNRPC_CablingMap::MuonNRPC_CablingMap
MuonNRPC_CablingMap()
Definition: MuonNRPC_CablingMap.cxx:13
RpcIdHelper::gasGap
int gasGap(const Identifier &id) const override
get the hashes
Definition: RpcIdHelper.cxx:1066
calibdata.valid
list valid
Definition: calibdata.py:45
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
MuonNRPC_CablingMap::getAllROBId
const ListOfROB & getAllROBId() const
return the full list of ROD id
Definition: MuonNRPC_CablingMap.cxx:222
RpcIdHelper::doubletR
int doubletR(const Identifier &id) const
Definition: RpcIdHelper.cxx:1060
TrigConf::MSGTC::ALWAYS
@ ALWAYS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:29
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
NrpcCablingData
Cabling information shipped around the Digi <-> Rdo conversions.
Definition: NrpcCablingData.h:121
MuonNRPC_CablingMap::getROBId
uint32_t getROBId(const IdentifierHash &stationCode, MsgStream &log) const
return the ROD id of a given chamber, given the hash id
Definition: MuonNRPC_CablingMap.cxx:194
MuonNRPC_CablingMap::~MuonNRPC_CablingMap
~MuonNRPC_CablingMap()
RpcIdHelper::strip
int strip(const Identifier &id) const
Definition: RpcIdHelper.cxx:1070
python.xAODType.dummy
dummy
Definition: xAODType.py:4
RunTileMonitoring.rod
rod
Definition: RunTileMonitoring.py:134
MuonIdHelper::stationPhi
int stationPhi(const Identifier &id) const
Definition: MuonIdHelper.cxx:814
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
NrpcTdcChannelRange::firstChannel
uint8_t firstChannel
First tdc channel.
Definition: NrpcCablingData.h:111
NrpcCablingData::channelId
uint8_t channelId
Definition: NrpcCablingData.h:124
MuonIdHelper::stationEta
int stationEta(const Identifier &id) const
Definition: MuonIdHelper.cxx:809
MuonNRPC_CablingMap::m_onToOffline
OnlToOfflMap m_onToOffline
Map to cache the online -> offline conversions.
Definition: MuonNRPC_CablingMap.h:69
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
MuonNRPC_CablingMap::m_ROBHashes
ROBToChamberMap m_ROBHashes
Definition: MuonNRPC_CablingMap.h:74
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonNRPC_CablingMap::getOfflineId
bool getOfflineId(NrpcCablingData &cabling_data, MsgStream &log) const
return the offline id given the online id
Definition: MuonNRPC_CablingMap.cxx:66
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
NrpcCablOnDataByStrip
Struct to build the offline -> online map.
Definition: NrpcCablingData.h:146
MuonNRPC_CablingMap::ListOfROB
std::vector< uint32_t > ListOfROB
Definition: MuonNRPC_CablingMap.h:27
MuonNRPC_CablingMap::m_rpcIdHelper
const RpcIdHelper * m_rpcIdHelper
Pointer to the RpcIdHelper.
Definition: MuonNRPC_CablingMap.h:77
NrpcCablingOnlineID
Struct summarizing all the Identifier fields to uniquely Identify a Nrpc TDC chip.
Definition: NrpcCablingData.h:74
IdentifierHash
Definition: IdentifierHash.h:38
StoreGateSvc.h
MuonNRPC_CablingMap::convert
bool convert(const NrpcCablingData &cabling_data, Identifier &id, bool check_valid=true) const
converts the cabling data into an identifier.
Definition: MuonNRPC_CablingMap.cxx:31
NrpcCablingData::strip
uint8_t strip
Definition: NrpcCablingData.h:123
RpcIdHelper::doubletPhi
int doubletPhi(const Identifier &id) const
Definition: RpcIdHelper.cxx:1064
RpcIdHelper::get_module_hash
virtual int get_module_hash(const Identifier &id, IdentifierHash &hash_id) const override
Definition: RpcIdHelper.cxx:288