ATLAS Offline Software
Loading...
Searching...
No Matches
TGCCabling.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
22
23namespace MuonTGC_Cabling {
24
25// Constructor & Destructor
27 : m_cableInASD{std::make_unique<TGCCableInASD>(cfg.fileNameASDtoPP)},
29 cfg.fileNameASDtoPP, cfg.fileNameASDtoPPdiff)},
30 m_cableInPP{std::make_unique<TGCCableInPP>(cfg.fileNameInPP)},
31 m_cablePPToSLB{std::make_unique<TGCCablePPToSLB>(cfg.fileNamePPtoSL)},
32 m_cableInSLB{std::make_unique<TGCCableInSLB>()},
33 m_cableSLBToHPB{std::make_unique<TGCCableSLBToHPB>(cfg.fileNamePPtoSL)},
34 m_cableHPBToSL{std::make_unique<TGCCableHPBToSL>(cfg.fileNamePPtoSL)},
35 m_cableSLBToSSW{std::make_unique<TGCCableSLBToSSW>(cfg.fileNameSLBtoROD)},
37 std::make_unique<TGCCableSSWToROD>(cfg.fileNameSLBtoROD)} {}
38
39TGCCabling::~TGCCabling() = default;
40// slbIn --> AsdOut
41std::unique_ptr<TGCChannelId> TGCCabling::getASDOutChannel(
42 const TGCChannelId& in) const {
44 in.getRegionType(), in.getSector(), in.getId(),
45 in.getChannel());
47}
48
49// readout ID -> SLB Module
51 int rodId, int sswId,
52 int sbLoc) const {
53 std::scoped_lock lock(m_mutex);
54
55 int indexFromReadoutWithoutChannel =
56 getIndexFromReadoutWithoutChannel(side, rodId, sswId, sbLoc);
57 const auto it = m_slbModuleIdMap.find(indexFromReadoutWithoutChannel);
58 if (it != m_slbModuleIdMap.end()) {
59 // Already seen this ReadoutID without channel.
60 // Stored pointer is returned.
61 return it->second.get();
62 }
63
64 // ROD Module
65 int readoutSector = rodId - 1; // rodID = 1..12
66 TGCModuleROD rod(side, readoutSector);
67
68 // SSW Module
70 if (sswMap.empty()) {
71 m_slbModuleIdMap.insert(
72 std::make_pair(indexFromReadoutWithoutChannel, nullptr));
73 return nullptr;
74 }
75
76 std::unique_ptr<TGCModuleId> ssw = sswMap.popModule(sswId);
77 if (!ssw) {
78 m_slbModuleIdMap.insert(
79 std::make_pair(indexFromReadoutWithoutChannel, nullptr));
80 return nullptr; // Do not need to delete ssw here.
81 // We can delete ssw but nothing will be done.
82 }
83
84 // SLB Module
86
87 if (slbMap.empty()) {
88 m_slbModuleIdMap.insert(
89 std::make_pair(indexFromReadoutWithoutChannel, nullptr));
90 return nullptr;
91 }
92
93 std::unique_ptr<TGCModuleId> slb{};
94 for (auto& [id, module] : slbMap) {
95 const auto* SLB = dynamic_cast<TGCModuleSLB*>(module.get());
96 if (SLB && SLB->getSBLoc() == sbLoc) {
97 slb = std::move(module);
98 break;
99 }
100 }
101
102 if (!slb) {
103 m_slbModuleIdMap.insert(
104 std::make_pair(indexFromReadoutWithoutChannel, nullptr));
105 return nullptr; // Do not delete slb here.
106 }
107
108 return m_slbModuleIdMap
109 .insert(std::make_pair(indexFromReadoutWithoutChannel, std::move(slb)))
110 .first->second.get();
111}
112
113// SSW ID/Rx ID -> SLB Module
114std::unique_ptr<TGCModuleId> TGCCabling::getSLBFromRxId(TGCId::SideType side,
115 int rodId, int sswId,
116 int rxId) const {
117
118 // ROD Module
119 int readoutSector = rodId - 1; // rodID = 1..12
120 TGCModuleROD rod(side, readoutSector);
121
122 // SSW Module
124 if (sswMap.empty()) {
125 return nullptr;
126 }
127
128 std::unique_ptr<TGCModuleId> ssw = sswMap.popModule(sswId);
129
130 if (!ssw) {
131 return nullptr; // Do not need to delete ssw here.
132 // We can delete ssw but nothing will be done.
133 }
134
135 // SLB Module
137 if (slbMap.empty()) {
138 return nullptr;
139 }
140
141 return slbMap.popModule(rxId);
142}
143
144// SLB Module -> readout ID
146 TGCId::SideType& side, int& rodId,
147 int& sswId, int& sbLoc) const {
148 // initialize
149 side = TGCId::NoSideType;
150 rodId = -1;
151 sswId = -1;
152 sbLoc = -1;
153
154 // Fill side
155 side = slb.getSideType();
156
158
159 if (sswMap.empty()) {
160 return false;
161 }
162
163 // SSW Module
164 std::unique_ptr<TGCModuleId>& ssw = sswMap.begin()->second;
165 if (!ssw) {
166 return false;
167 }
168
169 // Fill SSW ID
170 sswId = ssw->getId();
171
172 // Fill SBLoc
173 sbLoc = slb.getSBLoc();
174
175 if (sbLoc < 0) {
177 if (slbMap.empty()) {
178 return false;
179 }
180
181 TGCModuleSLB* pSlb = nullptr;
182
183 for (auto& [id, module] : slbMap) {
184 pSlb = dynamic_cast<TGCModuleSLB*>(module.get());
185
186 if (pSlb && slb.getRegionType() == pSlb->getRegionType() &&
187 slb.getSector() == pSlb->getSector() &&
188 slb.getId() == pSlb->getId()) {
189 if (slb.getModuleType() == pSlb->getModuleType()) {
190 sbLoc = pSlb->getSBLoc();
191 break;
192 }
193 // SI is connected to the SLB corrsponding WI
194 if (slb.getModuleType() == TGCId::SI &&
195 pSlb->getModuleType() == TGCId::WI) {
196 sbLoc = pSlb->getSBLoc();
197
198 break;
199 }
200 }
201 }
202 if (sbLoc < 0) {
203 return false;
204 }
205 }
206
208 if (rodMap.empty()) {
209 return false;
210 }
211
212 // ROD Module
213 std::unique_ptr<TGCModuleId>& rod = rodMap.begin()->second;
214
215 // Fill ROD ID
216 rodId = rod->getId();
217 return true;
218}
219
220// coincidence channel -> readout channel
222 TGCId::SideType side, int rodId, int& sswId, int& sbLoc, int& channel,
223 TGCId::SignalType signal, TGCId::RegionType region, int sectorInReadout,
224 int hpbId, int block, int hitId, int pos, TGCId::ModuleType moduleType,
225 bool orChannel) const {
226 // initialize
227 sswId = -1;
228 sbLoc = -1;
229 channel = -1;
230
231 // get sector number
232
233 int readoutSector = (rodId - 1);
234 int sector = sectorInReadout;
235 if (rodId < 13) {
236 if (region == TGCId::Forward) {
237 sector +=
238 readoutSector * (TGCId::NUM_FORWARD_SECTOR / TGCId::N_RODS);
239 } else {
240 sector +=
241 readoutSector * (TGCId::NUM_ENDCAP_SECTOR / TGCId::N_RODS);
242 }
243 } else if (rodId < 20) {
244 readoutSector -= 16;
245 if (region == TGCId::Forward) {
246 sector += readoutSector * (TGCId::NUM_FORWARD_SECTOR /
248 } else {
249 sector += readoutSector * (TGCId::NUM_ENDCAP_SECTOR /
251 }
252 }
253
254 TGCChannelHPBIn hpbin(side, signal, region, sector, hpbId, block,
255 hitId * 2 + pos);
256 if (!hpbin.isValid()) {
257 return false;
258 }
259
260 std::unique_ptr<TGCChannelId> slbout =
261 m_cableSLBToHPB->getChannelInforHPB(hpbin, moduleType, false);
262 if (!slbout || !slbout->isValid()) {
263 return 0;
264 }
265 std::unique_ptr<TGCChannelId> slbin =
266 m_cableInSLB->getChannel(*slbout, orChannel);
267
268 if (!slbin) {
269 return false;
270 }
271 channel = slbin->getChannel();
272
273 auto slb = slbin->getModule();
274 if (!slb) {
275 return false;
276 }
277
278 // SLB Module -> readout ID
279 TGCId::SideType sideType;
280 int rodid; // dummy
281 bool status = getReadoutFromSLB(*dynamic_cast<TGCModuleSLB*>(slb.get()),
282 sideType, rodid, sswId, sbLoc);
283
284 return status;
285}
286
287// readout channel -> coincidence channel
289 TGCId::SideType side, int rodId, int sswId, int sbLoc, int channel,
290 TGCId::SignalType& signal, TGCId::RegionType& region, int& sectorInReadout,
291 int& hpbId, int& block, int& hitId, int& pos) const {
292 signal = TGCId::NoSignalType;
293 region = TGCId::NoRegionType;
294 sectorInReadout = -1;
295 hpbId = -1;
296 block = -1;
297 hitId = -1;
298 pos = -1;
299
300 const TGCModuleId* slb = getSLBFromReadout(side, rodId, sswId, sbLoc);
301 if (!slb) {
302 return 0;
303 }
304
305 TGCChannelSLBIn slbin(slb->getSideType(), slb->getModuleType(),
306 slb->getRegionType(), slb->getSector(), slb->getId(),
307 channel);
308
309 std::unique_ptr<TGCChannelId> hpbin =
311 if (!hpbin || !hpbin->isValid()) {
312 return false;
313 }
314 signal = hpbin->getSignalType();
315 region = hpbin->getRegionType();
316 sectorInReadout = hpbin->getSectorInReadout();
317 hpbId = hpbin->getId();
318 block = hpbin->getBlock();
319 pos = hpbin->getChannel() % 2;
320 hitId = (hpbin->getChannel() - pos) / 2;
321
322 return true;
323}
324
325// coincidence channel -> readout channel
327 int sswId, int sbLoc,
328 int& channel, int block,
329 int pos, bool flag) const {
330 bool orChannel = flag;
331
332 const TGCModuleId* slb = getSLBFromReadout(side, rodId, sswId, sbLoc);
333 if (!slb) {
334 return 0;
335 }
336
337 TGCChannelSLBOut slbout(slb->getSideType(), slb->getModuleType(),
338 slb->getRegionType(), slb->getSector(),
339 slb->getId(), block, pos);
340
341 std::unique_ptr<TGCChannelId> slbin =
343
344 if (!slbin) {
345 return false;
346 }
347
348 channel = slbin->getChannel();
349
350 return true;
351}
352
353// readout channel -> chamber channel
354std::unique_ptr<TGCChannelId> TGCCabling::getASDOutFromReadout(
355 TGCId::SideType side, int rodId, int sswId, int sbLoc, int channel,
356 bool orChannel) const {
357 const TGCModuleId* slb = getSLBFromReadout(side, rodId, sswId, sbLoc);
358 if (!slb) {
359 return nullptr;
360 }
361
362 TGCChannelSLBIn slbin(slb->getSideType(), slb->getModuleType(),
363 slb->getRegionType(), slb->getSector(), slb->getId(),
364 channel);
365 if (!slbin.isValid()) {
366 return nullptr;
367 }
368
369 return getChannel(slbin, TGCChannelId::ChannelIdType::ASDOut, orChannel);
370}
371
372// chamber channel -> readout channel
374 TGCId::SideType& side, int& rodId,
375 int& sswId, int& sbLoc, int& channel,
376 bool orChannel) const {
377 // initialize
378 side = TGCId::NoSideType;
379 rodId = -1;
380 sswId = -1;
381 sbLoc = -1;
382 channel = -1;
383
384 // SLBIn channel
385 std::unique_ptr<TGCChannelId> slbin{
387
388 if (!slbin) {
389 return false;
390 }
391 channel = slbin->getChannel();
392
393 auto slb = slbin->getModule();
394 if (!slb) {
395 return false;
396 }
397
398 // SLB Module -> readout ID
399 return getReadoutFromSLB(*static_cast<TGCModuleSLB*>(slb.get()), side,
400 rodId, sswId, sbLoc);
401}
402
403std::unique_ptr<TGCChannelId> TGCCabling::getChannel(
405 bool orChannel) const {
406 switch (channelId.getChannelIdType()) {
409 return m_cableInASD->getChannel(channelId, orChannel);
410 }
412 std::unique_ptr<TGCChannelId> asdout =
413 m_cableInASD->getChannel(channelId, false);
414 if (!asdout || !asdout->isValid()) {
415
416 return nullptr;
417 }
418 std::unique_ptr<TGCChannelId> ppin =
419 m_cableASDToPP->getChannel(*asdout, false);
420 if (!ppin || !ppin->isValid()) {
421 return nullptr;
422 }
423 std::unique_ptr<TGCChannelId> ppout =
424 m_cableInPP->getChannel(*ppin, orChannel);
425 if (!ppout || !ppout->isValid()) {
426
427 return nullptr;
428 }
429 return m_cablePPToSLB->getChannel(*ppout, false);
430 }
431 break;
434 return m_cableInASD->getChannel(channelId, orChannel);
435 }
437 return m_cableASDToPP->getChannel(channelId, orChannel);
438 }
440 std::unique_ptr<TGCChannelId> ppin =
441 m_cableASDToPP->getChannel(channelId, false);
442 if (!ppin || !ppin->isValid()) {
443
444 return nullptr;
445 }
446 std::unique_ptr<TGCChannelId> ppout =
447 m_cableInPP->getChannel(*ppin, orChannel);
448 if (!ppout || !ppout->isValid()) {
449
450 return nullptr;
451 }
452 return m_cablePPToSLB->getChannel(*ppout, false);
453 }
454 break;
457 return m_cableASDToPP->getChannel(channelId, orChannel);
458 }
460 return m_cableInPP->getChannel(channelId, orChannel);
461 }
462 break;
465 return m_cableInPP->getChannel(channelId, orChannel);
466 }
468 return m_cablePPToSLB->getChannel(channelId, orChannel);
469 }
470 break;
473 return m_cableInSLB->getChannel(channelId, orChannel);
474 }
476 std::unique_ptr<TGCChannelId> slbout =
477 m_cableInSLB->getChannel(channelId, orChannel);
478 if (!slbout || !slbout->isValid()) {
479
480 return nullptr;
481 }
482 return m_cableSLBToHPB->getChannel(*slbout, false);
483 }
485 return m_cablePPToSLB->getChannel(channelId, orChannel);
486 }
488 std::unique_ptr<TGCChannelId> ppout =
489 m_cablePPToSLB->getChannel(channelId, false);
490 if (!ppout || !ppout->isValid()) {
491
492 return nullptr;
493 }
494 std::unique_ptr<TGCChannelId> ppin =
495 m_cableInPP->getChannel(*ppout, orChannel);
496 if (!ppin || !ppin->isValid()) {
497 return nullptr;
498 }
499 return m_cableASDToPP->getChannel(*ppin, false);
500 }
502 std::unique_ptr<TGCChannelId> ppout =
503 m_cablePPToSLB->getChannel(channelId, false);
504 if (!ppout || !ppout->isValid()) {
505 return nullptr;
506 }
507 std::unique_ptr<TGCChannelId> ppin =
508 m_cableInPP->getChannel(*ppout, orChannel);
509 if (!ppin || !ppin->isValid()) {
510 return nullptr;
511 }
512 std::unique_ptr<TGCChannelId> asdout =
513 m_cableASDToPP->getChannel(*ppin, false);
514 if (!asdout || !asdout->isValid()) {
515 return nullptr;
516 }
517 return m_cableInASD->getChannel(*asdout, false);
518 }
519 break;
522 return m_cableInSLB->getChannel(channelId, orChannel);
523 }
525 return m_cableSLBToHPB->getChannel(channelId, orChannel);
526 }
527 break;
530 std::unique_ptr<TGCChannelId> slbout =
531 m_cableSLBToHPB->getChannel(channelId, false);
532 if (!slbout || !slbout->isValid()) {
533 return nullptr;
534 }
535 return m_cableInSLB->getChannel(*slbout, orChannel);
536 }
538 return m_cableSLBToHPB->getChannel(channelId, orChannel);
539 }
540 break;
541 default:
542 break;
543 }
544 return nullptr;
545}
546
549 switch (moduleId.getModuleIdType()) {
550 case TGCModuleId::PP:
551 if (type == TGCModuleId::SLB) {
552 return m_cablePPToSLB->getModule(moduleId);
553 }
554 break;
555 case TGCModuleId::SLB:
556 if (type == TGCModuleId::PP) {
557 return m_cablePPToSLB->getModule(moduleId);
558 }
559 if (type == TGCModuleId::HPB) {
560 return m_cableSLBToHPB->getModule(moduleId);
561 }
562 if (type == TGCModuleId::SSW) {
563 return m_cableSLBToSSW->getModule(moduleId);
564 }
565 break;
566 case TGCModuleId::HPB:
567 if (type == TGCModuleId::SLB) {
568 return m_cableSLBToHPB->getModule(moduleId);
569 }
570 if (type == TGCModuleId::SL) {
571 return m_cableHPBToSL->getModule(moduleId);
572 }
573 break;
574 case TGCModuleId::SL:
575 if (type == TGCModuleId::HPB) {
576 return m_cableHPBToSL->getModule(moduleId);
577 }
578 break;
579 case TGCModuleId::SSW:
580 if (type == TGCModuleId::SLB) {
581 return m_cableSLBToSSW->getModule(moduleId);
582 }
583 if (type == TGCModuleId::ROD) {
584 return m_cableSSWToROD->getModule(moduleId);
585 }
586 break;
587 case TGCModuleId::ROD:
588 if (type == TGCModuleId::SSW) {
589 return m_cableSSWToROD->getModule(moduleId);
590 }
591 break;
592 default:
593 break;
594 }
595 return TGCModuleMap{};
596}
597
599 const int rodId,
600 const int sswId,
601 const int sbLoc) const {
602 return ((((side - TGCId::Aside) * (MAXRODID - MINRODID + 1) + rodId -
603 MINRODID) *
604 (MAXSSWID - MINSSWID + 1) +
605 sswId - MINSSWID) *
606 (MAXSBLOC - MINSBLOC + 1) +
607 sbLoc - MINSBLOC);
608}
609
610} // namespace MuonTGC_Cabling
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
bool getModule(std::istream &s, RegSelModule &m)
if(pathvar)
bool getReadoutFromLowPtCoincidence(TGCId::SideType side, int rodId, int sswId, int sbLoc, int &channel, int block, int pos, bool middle=false) const
bool getReadoutFromSLB(const TGCModuleSLB &slb, TGCId::SideType &side, int &rodId, int &sswId, int &sbLoc) const
std::unique_ptr< TGCCableInPP > m_cableInPP
Definition TGCCabling.h:126
bool getHighPtIDFromReadout(TGCId::SideType side, int rodId, int sswId, int sbLoc, int channel, TGCId::SignalType &signal, TGCId::RegionType &region, int &sectorInReadout, int &hpbId, int &block, int &hitId, int &pos) const
std::unique_ptr< TGCChannelId > getASDOutFromReadout(TGCId::SideType side, int rodId, int sswId, int sbLoc, int channel, bool orChannel=false) const
TGCCabling(const TGCCabling &)=delete
std::unique_ptr< TGCCableSSWToROD > m_cableSSWToROD
Definition TGCCabling.h:132
bool getReadoutFromASDOut(const TGCChannelASDOut &asdout, TGCId::SideType &side, int &rodId, int &sswId, int &sbLoc, int &channel, bool orChannel=false) const
std::unique_ptr< TGCCablePPToSLB > m_cablePPToSLB
Definition TGCCabling.h:127
std::unique_ptr< TGCCableSLBToSSW > m_cableSLBToSSW
Definition TGCCabling.h:131
std::unique_ptr< TGCModuleId > getSLBFromRxId(TGCId::SideType side, int rodId, int sswId, int rxId) const
std::unique_ptr< TGCCableSLBToHPB > m_cableSLBToHPB
Definition TGCCabling.h:129
int getIndexFromReadoutWithoutChannel(const TGCId::SideType side, const int rodId, const int sswId, const int sbLoc) const
std::unique_ptr< TGCChannelId > getChannel(const TGCChannelId &channelId, TGCChannelId::ChannelIdType type, bool orChannel=false) const
TGCModuleMap getModule(const TGCModuleId &moduleId, TGCModuleId::ModuleIdType type) const
std::unique_ptr< TGCCableInSLB > m_cableInSLB
Definition TGCCabling.h:128
std::unique_ptr< TGCCableInASD > m_cableInASD
Definition TGCCabling.h:124
std::unique_ptr< TGCCableHPBToSL > m_cableHPBToSL
Definition TGCCabling.h:130
std::unique_ptr< TGCChannelId > getASDOutChannel(const TGCChannelId &slb_in) const
bool getReadoutFromHighPtID(TGCId::SideType side, int rodId, int &sswId, int &sbLoc, int &channel, TGCId::SignalType signal, TGCId::RegionType region, int sectorInReadout, int hpbId, int block, int hitId, int pos, TGCId::ModuleType moduleType, bool orChannel) const
const TGCModuleId * getSLBFromReadout(TGCId::SideType side, int rodId, int sswId, int sbLoc) const
std::unique_ptr< TGCCableASDToPP > m_cableASDToPP
Definition TGCCabling.h:125
virtual bool isValid() const override
virtual bool isValid() const override
ModuleType getModuleType() const
Definition TGCId.h:141
static constexpr int NUM_ENDCAP_SECTOR
Definition TGCId.h:41
RegionType getRegionType() const
Definition TGCId.h:150
static constexpr int N_RODS
Definition TGCId.h:44
virtual int getSector() const
Definition TGCId.h:157
SideType getSideType() const
Definition TGCId.h:135
int getId() const
Definition TGCId.h:163
static constexpr int NUM_FORWARD_SECTOR
Definition TGCId.h:42
ModuleIdType getModuleIdType() const
Definition TGCModuleId.h:32
Store_t::const_iterator begin() const
Returns the begin iterator of the underlying map.
std::unique_ptr< TGCModuleId > popModule(const int connector)
Return a certain module and remove it from the map.
STL namespace.