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// readout ID -> RxID
114int TGCCabling::getRxIdFromReadout(TGCId::SideType side, int rodId, int sswId,
115 int sbLoc) const {
116 int rxId = -1;
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 rxId;
126 }
127
128 std::unique_ptr<TGCModuleId> ssw = sswMap.popModule(sswId);
129 if (!ssw) {
130 return rxId; // Do not need to delete ssw here.
131 // We can delete ssw but nothing will be done.
132 }
133
134 // SLB Module
136
137 if (slbMap.empty()) {
138 return rxId;
139 }
140
141 for (auto& [id, module] : slbMap) {
142 auto slb = dynamic_cast<TGCModuleSLB*>(module.get());
143 if (slb && slb->getSBLoc() == sbLoc) {
144 rxId = id;
145 break;
146 }
147 }
148 return rxId;
149}
150
151// SSW ID/Rx ID -> SLB Module
152std::unique_ptr<TGCModuleId> TGCCabling::getSLBFromRxId(TGCId::SideType side,
153 int rodId, int sswId,
154 int rxId) const {
155
156 // ROD Module
157 int readoutSector = rodId - 1; // rodID = 1..12
158 TGCModuleROD rod(side, readoutSector);
159
160 // SSW Module
162 if (sswMap.empty()) {
163 return nullptr;
164 }
165
166 std::unique_ptr<TGCModuleId> ssw = sswMap.popModule(sswId);
167
168 if (!ssw) {
169 return nullptr; // Do not need to delete ssw here.
170 // We can delete ssw but nothing will be done.
171 }
172
173 // SLB Module
175 if (slbMap.empty()) {
176 return nullptr;
177 }
178
179 return slbMap.popModule(rxId);
180}
181
182// SLB Module -> readout ID
184 TGCId::SideType& side, int& rodId,
185 int& sswId, int& sbLoc) const {
186 // initialize
187 side = TGCId::NoSideType;
188 rodId = -1;
189 sswId = -1;
190 sbLoc = -1;
191
192 // Fill side
193 side = slb.getSideType();
194
196
197 if (sswMap.empty()) {
198 return false;
199 }
200
201 // SSW Module
202 std::unique_ptr<TGCModuleId>& ssw = sswMap.begin()->second;
203 if (!ssw) {
204 return false;
205 }
206
207 // Fill SSW ID
208 sswId = ssw->getId();
209
210 // Fill SBLoc
211 sbLoc = slb.getSBLoc();
212
213 if (sbLoc < 0) {
215 if (slbMap.empty()) {
216 return false;
217 }
218
219 TGCModuleSLB* pSlb = nullptr;
220
221 for (auto& [id, module] : slbMap) {
222 pSlb = dynamic_cast<TGCModuleSLB*>(module.get());
223
224 if (pSlb && slb.getRegionType() == pSlb->getRegionType() &&
225 slb.getSector() == pSlb->getSector() &&
226 slb.getId() == pSlb->getId()) {
227 if (slb.getModuleType() == pSlb->getModuleType()) {
228 sbLoc = pSlb->getSBLoc();
229 break;
230 }
231 // SI is connected to the SLB corrsponding WI
232 if (slb.getModuleType() == TGCId::SI &&
233 pSlb->getModuleType() == TGCId::WI) {
234 sbLoc = pSlb->getSBLoc();
235
236 break;
237 }
238 }
239 }
240 if (sbLoc < 0) {
241 return false;
242 }
243 }
244
246 if (rodMap.empty()) {
247 return false;
248 }
249
250 // ROD Module
251 std::unique_ptr<TGCModuleId>& rod = rodMap.begin()->second;
252
253 // Fill ROD ID
254 rodId = rod->getId();
255 return true;
256}
257
258// coincidence channel -> readout channel
260 TGCId::SideType side, int rodId, int& sswId, int& sbLoc, int& channel,
261 TGCId::SignalType signal, TGCId::RegionType region, int sectorInReadout,
262 int hpbId, int block, int hitId, int pos, TGCId::ModuleType moduleType,
263 bool orChannel) const {
264 // initialize
265 sswId = -1;
266 sbLoc = -1;
267 channel = -1;
268
269 // get sector number
270
271 int readoutSector = (rodId - 1);
272 int sector = sectorInReadout;
273 if (rodId < 13) {
274 if (region == TGCId::Forward) {
275 sector +=
276 readoutSector * (TGCId::NUM_FORWARD_SECTOR / TGCId::N_RODS);
277 } else {
278 sector +=
279 readoutSector * (TGCId::NUM_ENDCAP_SECTOR / TGCId::N_RODS);
280 }
281 } else if (rodId < 20) {
282 readoutSector -= 16;
283 if (region == TGCId::Forward) {
284 sector += readoutSector * (TGCId::NUM_FORWARD_SECTOR /
286 } else {
287 sector += readoutSector * (TGCId::NUM_ENDCAP_SECTOR /
289 }
290 }
291
292 TGCChannelHPBIn hpbin(side, signal, region, sector, hpbId, block,
293 hitId * 2 + pos);
294 if (!hpbin.isValid()) {
295 return false;
296 }
297
298 std::unique_ptr<TGCChannelId> slbout =
299 m_cableSLBToHPB->getChannelInforHPB(hpbin, moduleType, false);
300 if (!slbout || !slbout->isValid()) {
301 return 0;
302 }
303 std::unique_ptr<TGCChannelId> slbin =
304 m_cableInSLB->getChannel(*slbout, orChannel);
305
306 if (!slbin) {
307 return false;
308 }
309 channel = slbin->getChannel();
310
311 auto slb = slbin->getModule();
312 if (!slb) {
313 return false;
314 }
315
316 // SLB Module -> readout ID
317 TGCId::SideType sideType;
318 int rodid; // dummy
319 bool status = getReadoutFromSLB(*dynamic_cast<TGCModuleSLB*>(slb.get()),
320 sideType, rodid, sswId, sbLoc);
321
322 return status;
323}
324
325// readout channel -> coincidence channel
327 TGCId::SideType side, int rodId, int sswId, int sbLoc, int channel,
328 TGCId::SignalType& signal, TGCId::RegionType& region, int& sectorInReadout,
329 int& hpbId, int& block, int& hitId, int& pos) const {
330 signal = TGCId::NoSignalType;
331 region = TGCId::NoRegionType;
332 sectorInReadout = -1;
333 hpbId = -1;
334 block = -1;
335 hitId = -1;
336 pos = -1;
337
338 const TGCModuleId* slb = getSLBFromReadout(side, rodId, sswId, sbLoc);
339 if (!slb) {
340 return 0;
341 }
342
343 TGCChannelSLBIn slbin(slb->getSideType(), slb->getModuleType(),
344 slb->getRegionType(), slb->getSector(), slb->getId(),
345 channel);
346
347 std::unique_ptr<TGCChannelId> hpbin =
349 if (!hpbin || !hpbin->isValid()) {
350 return false;
351 }
352 signal = hpbin->getSignalType();
353 region = hpbin->getRegionType();
354 sectorInReadout = hpbin->getSectorInReadout();
355 hpbId = hpbin->getId();
356 block = hpbin->getBlock();
357 pos = hpbin->getChannel() % 2;
358 hitId = (hpbin->getChannel() - pos) / 2;
359
360 return true;
361}
362
363// coincidence channel -> readout channel
365 int sswId, int sbLoc,
366 int& channel, int block,
367 int pos, bool flag) const {
368 bool orChannel = flag;
369
370 const TGCModuleId* slb = getSLBFromReadout(side, rodId, sswId, sbLoc);
371 if (!slb) {
372 return 0;
373 }
374
375 TGCChannelSLBOut slbout(slb->getSideType(), slb->getModuleType(),
376 slb->getRegionType(), slb->getSector(),
377 slb->getId(), block, pos);
378
379 std::unique_ptr<TGCChannelId> slbin =
381
382 if (!slbin) {
383 return false;
384 }
385
386 channel = slbin->getChannel();
387
388 return true;
389}
390
391// readout channel -> coincidence channel
393 int sswId, int sbLoc,
394 int channel, int& block,
395 int& pos, bool middle) const {
396
397 const TGCModuleId* slb = getSLBFromReadout(side, rodId, sswId, sbLoc);
398 if (!slb) {
399 return 0;
400 }
401
402 TGCChannelSLBIn slbin(slb->getSideType(), slb->getModuleType(),
403 slb->getRegionType(), slb->getSector(), slb->getId(),
404 channel);
405 if (!slbin.isValid()) {
406 return false;
407 }
408
409 std::unique_ptr<TGCChannelId> slbout =
411 if (!slbout) {
412 return false;
413 }
414
415 block = slbout->getBlock();
416 pos = slbout->getChannel();
417
418 return true;
419}
420
421// readout channel -> chamber channel
422std::unique_ptr<TGCChannelId> TGCCabling::getASDOutFromReadout(
423 TGCId::SideType side, int rodId, int sswId, int sbLoc, int channel,
424 bool orChannel) const {
425 const TGCModuleId* slb = getSLBFromReadout(side, rodId, sswId, sbLoc);
426 if (!slb) {
427 return nullptr;
428 }
429
430 TGCChannelSLBIn slbin(slb->getSideType(), slb->getModuleType(),
431 slb->getRegionType(), slb->getSector(), slb->getId(),
432 channel);
433 if (!slbin.isValid()) {
434 return nullptr;
435 }
436
437 return getChannel(slbin, TGCChannelId::ChannelIdType::ASDOut, orChannel);
438}
439
440// chamber channel -> readout channel
442 TGCId::SideType& side, int& rodId,
443 int& sswId, int& sbLoc, int& channel,
444 bool orChannel) const {
445 // initialize
446 side = TGCId::NoSideType;
447 rodId = -1;
448 sswId = -1;
449 sbLoc = -1;
450 channel = -1;
451
452 // SLBIn channel
453 std::unique_ptr<TGCChannelId> slbin{
455
456 if (!slbin) {
457 return false;
458 }
459 channel = slbin->getChannel();
460
461 auto slb = slbin->getModule();
462 if (!slb) {
463 return false;
464 }
465
466 // SLB Module -> readout ID
467 return getReadoutFromSLB(*static_cast<TGCModuleSLB*>(slb.get()), side,
468 rodId, sswId, sbLoc);
469}
470
471std::unique_ptr<TGCChannelId> TGCCabling::getChannel(
473 bool orChannel) const {
474 switch (channelId.getChannelIdType()) {
477 return m_cableInASD->getChannel(channelId, orChannel);
478 }
480 std::unique_ptr<TGCChannelId> asdout =
481 m_cableInASD->getChannel(channelId, false);
482 if (!asdout || !asdout->isValid()) {
483
484 return nullptr;
485 }
486 std::unique_ptr<TGCChannelId> ppin =
487 m_cableASDToPP->getChannel(*asdout, false);
488 if (!ppin || !ppin->isValid()) {
489 return nullptr;
490 }
491 std::unique_ptr<TGCChannelId> ppout =
492 m_cableInPP->getChannel(*ppin, orChannel);
493 if (!ppout || !ppout->isValid()) {
494
495 return nullptr;
496 }
497 return m_cablePPToSLB->getChannel(*ppout, false);
498 }
499 break;
502 return m_cableInASD->getChannel(channelId, orChannel);
503 }
505 return m_cableASDToPP->getChannel(channelId, orChannel);
506 }
508 std::unique_ptr<TGCChannelId> ppin =
509 m_cableASDToPP->getChannel(channelId, false);
510 if (!ppin || !ppin->isValid()) {
511
512 return nullptr;
513 }
514 std::unique_ptr<TGCChannelId> ppout =
515 m_cableInPP->getChannel(*ppin, orChannel);
516 if (!ppout || !ppout->isValid()) {
517
518 return nullptr;
519 }
520 return m_cablePPToSLB->getChannel(*ppout, false);
521 }
522 break;
525 return m_cableASDToPP->getChannel(channelId, orChannel);
526 }
528 return m_cableInPP->getChannel(channelId, orChannel);
529 }
530 break;
533 return m_cableInPP->getChannel(channelId, orChannel);
534 }
536 return m_cablePPToSLB->getChannel(channelId, orChannel);
537 }
538 break;
541 return m_cableInSLB->getChannel(channelId, orChannel);
542 }
544 std::unique_ptr<TGCChannelId> slbout =
545 m_cableInSLB->getChannel(channelId, orChannel);
546 if (!slbout || !slbout->isValid()) {
547
548 return nullptr;
549 }
550 return m_cableSLBToHPB->getChannel(*slbout, false);
551 }
553 return m_cablePPToSLB->getChannel(channelId, orChannel);
554 }
556 std::unique_ptr<TGCChannelId> ppout =
557 m_cablePPToSLB->getChannel(channelId, false);
558 if (!ppout || !ppout->isValid()) {
559
560 return nullptr;
561 }
562 std::unique_ptr<TGCChannelId> ppin =
563 m_cableInPP->getChannel(*ppout, orChannel);
564 if (!ppin || !ppin->isValid()) {
565 return nullptr;
566 }
567 return m_cableASDToPP->getChannel(*ppin, false);
568 }
570 std::unique_ptr<TGCChannelId> ppout =
571 m_cablePPToSLB->getChannel(channelId, false);
572 if (!ppout || !ppout->isValid()) {
573 return nullptr;
574 }
575 std::unique_ptr<TGCChannelId> ppin =
576 m_cableInPP->getChannel(*ppout, orChannel);
577 if (!ppin || !ppin->isValid()) {
578 return nullptr;
579 }
580 std::unique_ptr<TGCChannelId> asdout =
581 m_cableASDToPP->getChannel(*ppin, false);
582 if (!asdout || !asdout->isValid()) {
583 return nullptr;
584 }
585 return m_cableInASD->getChannel(*asdout, false);
586 }
587 break;
590 return m_cableInSLB->getChannel(channelId, orChannel);
591 }
593 return m_cableSLBToHPB->getChannel(channelId, orChannel);
594 }
595 break;
598 std::unique_ptr<TGCChannelId> slbout =
599 m_cableSLBToHPB->getChannel(channelId, false);
600 if (!slbout || !slbout->isValid()) {
601 return nullptr;
602 }
603 return m_cableInSLB->getChannel(*slbout, orChannel);
604 }
606 return m_cableSLBToHPB->getChannel(channelId, orChannel);
607 }
608 break;
609 default:
610 break;
611 }
612 return nullptr;
613}
614
617 switch (moduleId.getModuleIdType()) {
618 case TGCModuleId::PP:
619 if (type == TGCModuleId::SLB) {
620 return m_cablePPToSLB->getModule(moduleId);
621 }
622 break;
623 case TGCModuleId::SLB:
624 if (type == TGCModuleId::PP) {
625 return m_cablePPToSLB->getModule(moduleId);
626 }
627 if (type == TGCModuleId::HPB) {
628 return m_cableSLBToHPB->getModule(moduleId);
629 }
630 if (type == TGCModuleId::SSW) {
631 return m_cableSLBToSSW->getModule(moduleId);
632 }
633 break;
634 case TGCModuleId::HPB:
635 if (type == TGCModuleId::SLB) {
636 return m_cableSLBToHPB->getModule(moduleId);
637 }
638 if (type == TGCModuleId::SL) {
639 return m_cableHPBToSL->getModule(moduleId);
640 }
641 break;
642 case TGCModuleId::SL:
643 if (type == TGCModuleId::HPB) {
644 return m_cableHPBToSL->getModule(moduleId);
645 }
646 break;
647 case TGCModuleId::SSW:
648 if (type == TGCModuleId::SLB) {
649 return m_cableSLBToSSW->getModule(moduleId);
650 }
651 if (type == TGCModuleId::ROD) {
652 return m_cableSSWToROD->getModule(moduleId);
653 }
654 break;
655 case TGCModuleId::ROD:
656 if (type == TGCModuleId::SSW) {
657 return m_cableSSWToROD->getModule(moduleId);
658 }
659 break;
660 default:
661 break;
662 }
663 return TGCModuleMap{};
664}
665
667 const int rodId,
668 const int sswId,
669 const int sbLoc) const {
670 return ((((side - TGCId::Aside) * (MAXRODID - MINRODID + 1) + rodId -
671 MINRODID) *
672 (MAXSSWID - MINSSWID + 1) +
673 sswId - MINSSWID) *
674 (MAXSBLOC - MINSBLOC + 1) +
675 sbLoc - MINSBLOC);
676}
677
678} // namespace MuonTGC_Cabling
if(febId1==febId2)
bool getModule(std::istream &s, RegSelModule &m)
bool getReadoutFromLowPtCoincidence(TGCId::SideType side, int rodId, int sswId, int sbLoc, int &channel, int block, int pos, bool middle=false) const
bool getLowPtCoincidenceFromReadout(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
int getRxIdFromReadout(TGCId::SideType side, int rodId, int sswId, int sbLoc) const
std::unique_ptr< TGCCableInPP > m_cableInPP
Definition TGCCabling.h:136
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:142
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:137
std::unique_ptr< TGCCableSLBToSSW > m_cableSLBToSSW
Definition TGCCabling.h:141
std::unique_ptr< TGCModuleId > getSLBFromRxId(TGCId::SideType side, int rodId, int sswId, int rxId) const
std::unique_ptr< TGCCableSLBToHPB > m_cableSLBToHPB
Definition TGCCabling.h:139
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:138
std::unique_ptr< TGCCableInASD > m_cableInASD
Definition TGCCabling.h:134
std::unique_ptr< TGCCableHPBToSL > m_cableHPBToSL
Definition TGCCabling.h:140
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:135
virtual bool isValid() const override
virtual bool isValid() const override
ModuleType getModuleType() const
Definition TGCId.h:137
static constexpr int NUM_ENDCAP_SECTOR
Definition TGCId.h:41
RegionType getRegionType() const
Definition TGCId.h:146
static constexpr int N_RODS
Definition TGCId.h:44
virtual int getSector() const
Definition TGCId.h:156
SideType getSideType() const
Definition TGCId.h:134
int getId() const
Definition TGCId.h:162
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.