ATLAS Offline Software
RpcCablingMap.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
6 
9 #include <cmath>
10 #include <ranges>
11 #include <format>
12 
13 namespace Muon {
15  m_rpcIdHelper{idHelperSvc->rpcIdHelper()}{}
16 
18 
19  bool RpcCablingMap::convert(const RpcCablingData& translator, Identifier& id, bool check_valid) const {
20  bool valid{!check_valid};
21  id = check_valid
22  ? m_rpcIdHelper.channelID(translator.stationIndex, translator.eta, translator.phi,
23  translator.doubletR, translator.doubletZ,
24  translator.doubletPhi, translator.gasGap,
25  translator.measuresPhi(), translator.strip, valid)
26  : m_rpcIdHelper.channelID(translator.stationIndex, translator.eta, translator.phi,
27  translator.doubletR, translator.doubletZ,
28  translator.doubletPhi, translator.gasGap,
29  translator.measuresPhi(), translator.strip);
30  return valid;
31  }
32 
33  bool RpcCablingMap::convert(const Identifier& channelId, RpcCablingData& translator, bool setSideBit) const {
35  return false;
36  }
38  translator.eta = m_rpcIdHelper.stationEta(channelId);
39  translator.phi = m_rpcIdHelper.stationPhi(channelId);
43  translator.gasGap = m_rpcIdHelper.gasGap(channelId);
44  translator.setMeasPhiAndSide(m_rpcIdHelper.measuresPhi(channelId), setSideBit);
45  translator.strip = m_rpcIdHelper.strip(channelId);
46  return true;
47  }
48 
50  bool RpcCablingMap::getOnlineId(RpcCablingData& translatorCache, MsgStream& log) const {
51  if (log.level()<= MSG::DEBUG) {
52  log<<MSG::DEBUG<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<": test "<<translatorCache<<endmsg;
53  }
54  const RpcCablingOfflineID& offId{translatorCache};
55  OfflToOnlMap::const_iterator itr = m_offToOnline.find(offId);
56  if (itr == m_offToOnline.end()) {
57  log << MSG::ERROR<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<": The offline identifier "
58  << offId << " is unknown " << endmsg;
59  return false;
60  }
61  const AllTdcsPerGasGap& tdcs{itr->second};
63  if (log.level() <= MSG::DEBUG) {
64  log<<MSG::DEBUG<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<": Chamber "<<offId<<" has "
65  <<tdcs.size()<<" cards "<<endmsg;
66  }
67 
68  const AllTdcsPerGasGap::const_iterator onlineCardItr =
69  std::ranges::find_if(tdcs, [&translatorCache](const GasGapToTdcAssociation& tdc){
70  return tdc.firstStrip + RpcFlatCableTranslator::readStrips > translatorCache.strip
71  && tdc.firstStrip <= translatorCache.strip;
72  });
73  if (onlineCardItr != itr->second.end()) {
74  const GasGapToTdcAssociation& onlineCard = (*onlineCardItr);
76  std::optional<uint8_t> tdcChannel = onlineCard.flatCable->tdcChannel(translatorCache.strip, log);
77  if (tdcChannel) {
78  static_cast<RpcCablingOnlineID&>(translatorCache) = onlineCard.tdcID;
79  translatorCache.channelId = (*tdcChannel);
80  if (log.level() <= MSG::DEBUG) {
81  log <<MSG::DEBUG<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<": Mapped to card "
82  <<onlineCard.tdcID<<", channel: "<<static_cast<int>(translatorCache.channelId)<<endmsg;
83  }
84  return true;
85  } else if (log.level() <= MSG::DEBUG) {
86  log <<MSG::DEBUG<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<":\n"<<(*onlineCard.flatCable)<<endmsg;
87  }
88  }
89  log << MSG::ERROR<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<": No tdc channel could be found for the object "
90  << static_cast<const RpcCablingOfflineID&>(translatorCache)<< " strip: " << static_cast<int>(translatorCache.strip) << endmsg;
91  return false;
92  }
93  bool RpcCablingMap::getOfflineId(RpcCablingData& translatorCache, MsgStream& log) const {
94  OnlToOfflMap::const_iterator itr = m_onToOffline.find(translatorCache);
95  if (itr == m_onToOffline.end()) {
96  log << MSG::ERROR <<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<": The tdc chip "
97  << static_cast<const RpcCablingOnlineID&>(translatorCache) << " is unknown " << endmsg;
98  return false;
99  }
100  for (const TdcToGasGapAssociation& connectChamb: itr->second) {
101  const std::optional<uint8_t> stripCh = connectChamb.flatCable->stripChannel(translatorCache.channelId, log);
103  if (!stripCh) {
104  continue;
105  }
107  static_cast<RpcCablingOfflineID&>(translatorCache) = connectChamb.gasGapID;
108  translatorCache.strip = (*stripCh) + connectChamb.firstStrip;
109  if (log.level() <= MSG::DEBUG) {
110  log <<MSG::DEBUG<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<": -- Card "
111  <<connectChamb.gasGapID<<", strip: "<<static_cast<int>(translatorCache.strip)<<endmsg;
112  }
113  return true;
114  }
115  log << MSG::ERROR<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<": No tdc channel could be found for the object "
116  << static_cast<const RpcCablingOnlineID&>(translatorCache)
117  << " tdc: " << static_cast<int>(translatorCache.channelId) << endmsg;
118 
119  return false;
120  }
121 
123  RpcCablingOfflineID offCh{entry};
124  RpcCablingOnlineID onlCh{entry};
125  GasGapToTdcAssociation offToOnl{};
126  offToOnl.tdcID = onlCh;
127  offToOnl.flatCable = entry.flatCable;
128  offToOnl.firstStrip = entry.firstStrip;
129 
130  m_offToOnline[offCh].emplace_back(std::move(offToOnl));
131  std::ranges::sort(m_offToOnline[offCh],
133  return a.firstStrip < b.firstStrip;
134  });
135 
136  TdcToGasGapAssociation onlToOff{};
137  onlToOff.gasGapID = offCh;
138  onlToOff.firstStrip = entry.firstStrip - RpcFlatCableTranslator::firstStrip;
139  onlToOff.flatCable = entry.flatCable;
140  m_onToOffline[onlCh].push_back(std::move(onlToOff));
141  std::ranges::sort(m_onToOffline[onlCh],
143  return a.firstStrip < b.firstStrip;
144  });
145 
146  if (log.level()<= MSG::DEBUG) {
147  log<<MSG::DEBUG<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__<<": Add new cabling channel "
148  <<offCh<<std::format("firstStrip: {:2d}", entry.firstStrip)<<" - "<<onlCh
149  <<std::format("flatCable: {:2d}", entry.flatCable->id())<<endmsg;
150  }
151  return true;
152  }
153  bool RpcCablingMap::finalize(MsgStream& log) {
154  if (m_offToOnline.empty()) {
155  log << MSG::ERROR <<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__
156  <<": finalize() -- No data has been loaded " << endmsg;
157  return false;
158  }
160  RpcCablingData RobOffId{};
161  RobOffId.strip = 1;
162  for (const auto& [card, chambers] : m_onToOffline) {
163  for (const TdcToGasGapAssociation& chamber : chambers) {
164  static_cast<RpcCablingOfflineID&>(RobOffId) = chamber.gasGapID;
165  Identifier chId{0};
166  if (!convert(RobOffId, chId, true)) {
167  log << MSG::ERROR<<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__
168  << ": Could not construct an offline identifier from " << chamber.gasGapID << endmsg;
169  return false;
170  }
171  IdentifierHash hash{0};
172  if (m_rpcIdHelper.get_module_hash(chId, hash)) {
173  log << MSG::ERROR <<"RpcCablingMap::"<<__func__<<"() - "<<__LINE__
174  << ": Failed to generate a hash for " << chamber.gasGapID << endmsg;
175  return false;
176  }
177  uint32_t hardId = (card.subDetector << 16) | card.tdcSector;
178  m_chambROBs[hash] = hardId;
179  std::vector<IdentifierHash>& robHashes = m_ROBHashes[hardId];
180  if (std::ranges::find(robHashes, hash) == robHashes.end()){
181  robHashes.push_back(hash);
182  }
183  }
184  }
185  return true;
186  }
187  uint32_t RpcCablingMap::getROBId(const IdentifierHash& stationCode, MsgStream& log) const {
188  ChamberToROBMap::const_iterator it = m_chambROBs.find(stationCode);
189  if (it != m_chambROBs.end()) {
190  return it->second;
191  }
192  if (log.level() <= MSG::WARNING) {
193  log << MSG::WARNING << "Station code " << stationCode << " not found !! "<< endmsg;
194  }
195  return 0;
196  }
197 
198  RpcCablingMap::ListOfROB RpcCablingMap::getROBId(const std::vector<IdentifierHash>& rpcHashVector, MsgStream& log) const {
199  ListOfROB toRet{};
200  toRet.reserve(rpcHashVector.size());
201  for (const IdentifierHash& hash : rpcHashVector) {
202  toRet.push_back(getROBId(hash, log));
203  }
204  return toRet;
205  }
206  const std::vector<IdentifierHash>& RpcCablingMap::getChamberHashVec(const uint32_t ROBI, MsgStream& log) const {
207  ROBToChamberMap::const_iterator itr = m_ROBHashes.find(ROBI);
208  if (itr != m_ROBHashes.end()){
209  return itr->second;
210  }
211  if (log.level() <= MSG::WARNING) {
212  log << MSG::WARNING << "ROB ID " << ROBI << " not found ! " << endmsg;
213  }
214  static const std::vector<IdentifierHash> dummy;
215  return dummy;
216  }
217  std::vector<IdentifierHash> RpcCablingMap::getChamberHashVec(const ListOfROB& ROBs, MsgStream& log) const {
218  std::unordered_set<IdentifierHash> hashSet{};
219  for (const uint32_t rob : ROBs) {
220  const std::vector<IdentifierHash>& hashFromROB = getChamberHashVec(rob, log);
221  hashSet.insert(hashFromROB.begin(), hashFromROB.end());
222  }
223  std::vector<IdentifierHash> hashVec{};
224  hashVec.insert(hashVec.end(), hashSet.begin(), hashSet.end());
225  return hashVec;
226  }
227 
228  const RpcCablingMap::ListOfROB& RpcCablingMap::getAllROBId() const {
229  return m_listOfROB;
230  }
231  std::set<RpcCablingMap::FlatCablePtr> RpcCablingMap::flatCables() const {
232  std::set<FlatCablePtr> cables{};
233  for (const auto &[offId, gapToTdcs] : m_offToOnline) {
234  for (const GasGapToTdcAssociation& assoc : gapToTdcs){
235  cables.insert(assoc.flatCable);
236  }
237  }
238  return cables;
239  }
240 }
Muon::RpcFlatCableTranslator::readStrips
static constexpr uint8_t readStrips
Number of channels covered by one chip.
Definition: RpcFlatCableTranslator.h:21
Muon::RpcCablingMap::~RpcCablingMap
~RpcCablingMap()
Muon::RpcCablingOfflineID::doubletZ
int8_t & doubletZ
doublet Phi -> 1,2
Definition: RpcCablingData.h:48
MuonIdHelper::is_rpc
bool is_rpc(const Identifier &id) const
Definition: MuonIdHelper.cxx:788
Muon::RpcCablingMap::RpcCablingMap
RpcCablingMap(const IMuonIdHelperSvc *idHelperSvc)
Constructor taking the IdHelperSvc.
Definition: RpcCablingMap.cxx:14
Muon::RpcCablingOfflineID::stationIndex
int8_t & stationIndex
Definition: RpcCablingData.h:42
vtune_athena.format
format
Definition: vtune_athena.py:14
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
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:1061
Muon::RpcCablingMap::m_onToOffline
OnlToOfflMap m_onToOffline
Map storing the connection from online -> offline channels.
Definition: RpcCablingMap.h:121
Muon::RpcCablingData::channelId
uint8_t channelId
Online tdc channel number.
Definition: RpcCablingData.h:100
Muon::RpcCablingMap::AllTdcsPerGasGap
std::vector< GasGapToTdcAssociation > AllTdcsPerGasGap
Definition: RpcCablingMap.h:115
RpcCablingMap.h
Muon::RpcCablingOfflineID::measuresPhi
bool measuresPhi() const
: Does the channel measure phi
Definition: RpcCablingData.h:58
skel.it
it
Definition: skel.GENtoEVGEN.py:396
RpcIdHelper::measuresPhi
bool measuresPhi(const Identifier &id) const override
Definition: RpcIdHelper.cxx:1067
Muon::RpcCablingOfflineID::setMeasPhiAndSide
void setMeasPhiAndSide(bool measPhi, bool stripSide)
Sets the measuresPhi & stripSide fields of the cabling data object.
Definition: RpcCablingData.h:62
Muon::RpcCablingOfflineID
Struct to represent the offline identifier of the Rpc measurement decomposed into the particular fiel...
Definition: RpcCablingData.h:39
MuonIdHelper::stationName
int stationName(const Identifier &id) const
Definition: MuonIdHelper.cxx:800
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:939
Muon::RpcCablingMap::TdcToGasGapAssociation
Helper struct to associate all Tdcs to their corresponding strips in the gasGap.
Definition: RpcCablingMap.h:50
Muon::RpcCablingMap::GasGapToTdcAssociation::flatCable
FlatCablePtr flatCable
Pointer to the flat cable card.
Definition: RpcCablingMap.h:41
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
Muon::RpcCablingMap::getOnlineId
bool getOnlineId(RpcCablingData &cabling_data, MsgStream &log) const
return the online id given the offline id
Definition: RpcCablingMap.cxx:50
Muon::RpcCablingMap::finalize
bool finalize(MsgStream &log)
Performs consistency checks for the cabling data (I.e.
Definition: RpcCablingMap.cxx:153
RpcIdHelper.h
Muon::RpcCablingMap::m_offToOnline
OfflToOnlMap m_offToOnline
Map to cache the offline -> online conversions *‍/.
Definition: RpcCablingMap.h:123
RpcIdHelper::gasGap
int gasGap(const Identifier &id) const override
get the hashes
Definition: RpcIdHelper.cxx:1065
Muon::RpcCablingMap::insertChannels
bool insertChannels(CoolDBEntry &&dbEntry, MsgStream &log)
Inserts a new dbEntry into the map.
Definition: RpcCablingMap.cxx:122
calibdata.valid
list valid
Definition: calibdata.py:45
Muon::RpcCablingOfflineID::eta
int8_t & eta
Station of the chamber (i.e, BIL,BIS,etc.)
Definition: RpcCablingData.h:43
RpcIdHelper::doubletR
int doubletR(const Identifier &id) const
Definition: RpcIdHelper.cxx:1059
Muon::RpcCablingMap::GasGapToTdcAssociation
Helper struct to associate all strips in an eta/phi gasGap to the corresponding Tdc.
Definition: RpcCablingMap.h:37
Muon::RpcFlatCableTranslator::tdcChannel
std::optional< uint8_t > tdcChannel(uint8_t strip, MsgStream &log) const
Returns the connected tdc channel connected to a strip.
Definition: RpcFlatCableTranslator.cxx:38
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Muon::RpcCablingMap::TdcToGasGapAssociation::gasGapID
RpcCablingOfflineID gasGapID
Associated tdc chip.
Definition: RpcCablingMap.h:54
jobOptions.card
card
Definition: jobOptions.GenevaPy8_Zmumu.py:11
Muon::RpcCablingOfflineID::gasGap
int8_t & gasGap
doublet Z -> 1,2
Definition: RpcCablingData.h:49
RpcIdHelper::strip
int strip(const Identifier &id) const
Definition: RpcIdHelper.cxx:1069
python.xAODType.dummy
dummy
Definition: xAODType.py:4
Muon::RpcCablingMap::convert
bool convert(const RpcCablingData &translationCache, Identifier &id, bool checkValid=true) const
Converts the translation cache back to an Identifier.
Definition: RpcCablingMap.cxx:19
Muon::RpcCablingMap::m_rpcIdHelper
const RpcIdHelper & m_rpcIdHelper
Pointer to the RpcIdHelper.
Definition: RpcCablingMap.h:114
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
Muon::RpcCablingMap::m_chambROBs
ChamberToROBMap m_chambROBs
Definition: RpcCablingMap.h:125
Muon::RpcCablingMap::m_ROBHashes
ROBToChamberMap m_ROBHashes
Definition: RpcCablingMap.h:126
MuonIdHelper::stationPhi
int stationPhi(const Identifier &id) const
Definition: MuonIdHelper.cxx:810
Muon::RpcCablingOfflineID::doubletR
int8_t & doubletR
Station phi of the RPC station.
Definition: RpcCablingData.h:45
Muon::RpcCablingData::strip
uint8_t strip
Offline strip number.
Definition: RpcCablingData.h:98
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
Muon::RpcCablingData
Helper struct that is parsed to the cabling map to translate between the offline & online Identifiers...
Definition: RpcCablingData.h:94
Muon::RpcCablingMap::CoolDBEntry
Helper struct to ship all information from the Database
Definition: RpcCablingMap.h:59
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Muon::RpcCablingOnlineID
In an analogous way to the RpcCablingOfflineID, the RpcCablingOnlineID, holds all information needed ...
Definition: RpcCablingData.h:77
Muon::RpcCablingOfflineID::doubletPhi
int8_t & doubletPhi
doublet R -> 1,2
Definition: RpcCablingData.h:47
MuonIdHelper::stationEta
int stationEta(const Identifier &id) const
Definition: MuonIdHelper.cxx:805
Muon::RpcCablingMap::TdcToGasGapAssociation::firstStrip
uint8_t firstStrip
first strip
Definition: RpcCablingMap.h:56
Muon::RpcCablingMap::getOfflineId
bool getOfflineId(RpcCablingData &cabling_data, MsgStream &log) const
return the offline id given the online id
Definition: RpcCablingMap.cxx:93
a
TList * a
Definition: liststreamerinfos.cxx:10
RpcFlatCableTranslator.h
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
Muon::RpcFlatCableTranslator::firstStrip
static constexpr uint8_t firstStrip
Convention of the lowest strip number.
Definition: RpcFlatCableTranslator.h:25
Muon::RpcCablingMap::GasGapToTdcAssociation::tdcID
RpcCablingOnlineID tdcID
Associated tdc chip.
Definition: RpcCablingMap.h:43
DEBUG
#define DEBUG
Definition: page_access.h:11
Muon::RpcCablingMap::TdcToGasGapAssociation::flatCable
FlatCablePtr flatCable
Pointer to the flat cable card.
Definition: RpcCablingMap.h:52
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:27
Muon::RpcCablingMap::ListOfROB
std::vector< uint32_t > ListOfROB
Definition: RpcCablingMap.h:33
TrigPartialEventBuildingConfig.ROBs
ROBs
Definition: TrigPartialEventBuildingConfig.py:122
Muon::RpcFlatCableTranslator::stripChannel
std::optional< uint8_t > stripChannel(uint8_t tdcChannel, MsgStream &log) const
Returns the strip channel connected to a strip.
Definition: RpcFlatCableTranslator.cxx:53
Muon::RpcCablingMap::GasGapToTdcAssociation::firstStrip
uint8_t firstStrip
Lowest strip number covered by the cable.
Definition: RpcCablingMap.h:39
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
Muon::RpcCablingOfflineID::phi
int8_t & phi
Eta index of the RPC station.
Definition: RpcCablingData.h:44
IMuonIdHelperSvc.h
Muon::IMuonIdHelperSvc::rpcIdHelper
virtual const RpcIdHelper & rpcIdHelper() const =0
access to RpcIdHelper
RpcIdHelper::doubletPhi
int doubletPhi(const Identifier &id) const
Definition: RpcIdHelper.cxx:1063
RpcIdHelper::get_module_hash
virtual int get_module_hash(const Identifier &id, IdentifierHash &hash_id) const override
Definition: RpcIdHelper.cxx:289
Identifier
Definition: IdentifierFieldParser.cxx:14