ATLAS Offline Software
Loading...
Searching...
No Matches
TGCCablePPToSLB.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
12
13namespace MuonTGC_Cabling {
14
15// Constructor & Destructor
16TGCCablePPToSLB::TGCCablePPToSLB(const std::string& filename)
17 : TGCCable(TGCCable::PPToSLB), m_database{{{nullptr}}} {
18 m_database.at(+TGCId::RegionType::Endcap).at(+TGCId::ModuleType::WT) =
19 std::make_unique<TGCDatabasePPToSL>(filename, "PP EWT");
20 m_database.at(+TGCId::RegionType::Endcap).at(+TGCId::ModuleType::WD) =
21 std::make_unique<TGCDatabasePPToSL>(filename, "PP EWD");
22 m_database.at(+TGCId::RegionType::Endcap).at(+TGCId::ModuleType::ST) =
23 std::make_unique<TGCDatabasePPToSL>(filename, "PP EST");
24 m_database.at(+TGCId::RegionType::Endcap).at(+TGCId::ModuleType::SD) =
25 std::make_unique<TGCDatabasePPToSL>(filename, "PP ESD");
26 m_database.at(+TGCId::RegionType::Endcap).at(+TGCId::ModuleType::WI) =
27 std::make_unique<TGCDatabasePPToSL>(filename, "PP EWI");
28 m_database.at(+TGCId::RegionType::Endcap).at(+TGCId::ModuleType::SI) =
29 std::make_unique<TGCDatabasePPToSL>(filename, "PP ESI");
30 m_database.at(+TGCId::RegionType::Forward).at(+TGCId::ModuleType::WT) =
31 std::make_unique<TGCDatabasePPToSL>(filename, "PP FWT");
32 m_database.at(+TGCId::RegionType::Forward).at(+TGCId::ModuleType::WD) =
33 std::make_unique<TGCDatabasePPToSL>(filename, "PP FWD");
34 m_database.at(+TGCId::RegionType::Forward).at(+TGCId::ModuleType::ST) =
35 std::make_unique<TGCDatabasePPToSL>(filename, "PP FST");
36 m_database.at(+TGCId::RegionType::Forward).at(+TGCId::ModuleType::SD) =
37 std::make_unique<TGCDatabasePPToSL>(filename, "PP FSD");
38 m_database.at(+TGCId::RegionType::Forward).at(+TGCId::ModuleType::WI) =
39 std::make_unique<TGCDatabasePPToSL>(filename, "PP FWI");
40 m_database.at(+TGCId::RegionType::Forward).at(+TGCId::ModuleType::SI) =
41 std::make_unique<TGCDatabasePPToSL>(filename, "PP FSI");
42}
43
44TGCCablePPToSLB::~TGCCablePPToSLB() = default;
45
46std::unique_ptr<TGCChannelId> TGCCablePPToSLB::getChannel(
47 const TGCChannelId& channelId, bool orChannel) const {
48 if (channelId.getChannelIdType() == TGCChannelId::ChannelIdType::PPOut) {
49 return getChannelOut(channelId, orChannel);
50 }
51 if (channelId.getChannelIdType() == TGCChannelId::ChannelIdType::SLBIn) {
52 return getChannelIn(channelId, orChannel);
53 }
54
55 return nullptr;
56}
57
59 if (moduleId.getModuleIdType() == TGCModuleId::PP) {
60 return getModuleOut(moduleId);
61 }
62 if (moduleId.getModuleIdType() == TGCModuleId::SLB) {
63 return getModuleIn(moduleId);
64 }
65 return TGCModuleMap{};
66}
67
68std::unique_ptr<TGCChannelId> TGCCablePPToSLB::getChannelIn(
69 const TGCChannelId& slbin, bool orChannel) const {
70 if (orChannel || slbin.isValid() == false) {
71 return nullptr;
72 }
73
74 // SLB channel
75 const TGCChannelSLBIn* slbIn = nullptr;
77 slbIn = dynamic_cast<const TGCChannelSLBIn*>(&slbin);
78 }
79 if (!slbIn) {
80 return nullptr;
81 }
82
83 // SLB module
84 std::unique_ptr<TGCModuleId> slb = slbIn->getModule();
85 if (!slb) {
86 return nullptr;
87 }
88
89 // SLB -> PP module connection
90 TGCModuleMap mapId = getModule(*slb);
91 if (!mapId.size()) {
92 return nullptr;
93 }
94
95 // PP module
96 int port = mapId.begin()->first;
97 auto pp = mapId.popModule(port);
98 if (!pp) {
99 return nullptr;
100 }
101
102 // SLB ->PP channel connection
103 int block = -1;
104 int channel = -1;
105 TGCChannelSLBIn::CellType cellType = slbIn->getCellType();
106 if (cellType == TGCChannelSLBIn::NoCellType) {
107 return nullptr;
108 }
109
110 if (cellType == TGCChannelSLBIn::CellA) {
111 block = 1 + 2 * port;
112 int lengthOfSLB = TGCChannelSLBIn::getLengthOfSLB(
114 channel = lengthOfSLB + slbIn->getChannelInSLB();
115 }
116 if (cellType == TGCChannelSLBIn::CellB) {
117 block = 1 + 2 * port;
118 channel = slbIn->getChannelInSLB();
119 }
120 if (cellType == TGCChannelSLBIn::CellC) {
121 block = 0 + 2 * port;
122 int lengthOfSLB = TGCChannelSLBIn::getLengthOfSLB(
124 channel = lengthOfSLB + slbIn->getChannelInSLB();
125 }
126 if (cellType == TGCChannelSLBIn::CellD) {
127 block = 0 + 2 * port;
128 channel = slbIn->getChannelInSLB();
129 }
130 return std::make_unique<TGCChannelPPOut>(
131 pp->getSideType(), pp->getStation(),
132 pp->getModuleType(), pp->getRegionType(),
133 pp->getSector(), pp->getId(), block, channel);
134}
135
136std::unique_ptr<TGCChannelId> TGCCablePPToSLB::getChannelOut(
137 const TGCChannelId& ppout, bool orChannel) const {
138 if (orChannel || ppout.isValid() == false) {
139 return nullptr;
140 }
141
142 const int ppoutBlock = ppout.getBlock();
143
144 // PP module
145 std::unique_ptr<TGCModuleId> pp{ppout.getModule()};
146 if (!pp) {
147 return nullptr;
148 }
149
150 // PP -> SLB module connection
151 TGCModuleMap mapId = getModule(*pp);
152 if (!mapId.size()) {
153 return nullptr;
154 }
155
156 // SLB module
157 auto slb = mapId.popModule(ppoutBlock / 2);
158
159 if (!slb) {
160 return nullptr;
161 }
162
163 // PP ->SLB channel connection
165 int channelInSLB = -1;
166 if (ppoutBlock % 2 == 0) { // D,C
167 int lengthOfSLB = TGCChannelSLBIn::getLengthOfSLB(
168 slb->getModuleType(), TGCChannelSLBIn::CellD);
169 if (ppout.getChannel() < lengthOfSLB) {
170 cellType = TGCChannelSLBIn::CellD;
171 channelInSLB = ppout.getChannel();
172 } else {
173 cellType = TGCChannelSLBIn::CellC;
174 channelInSLB = ppout.getChannel() - lengthOfSLB;
175 }
176 } else { // B,A
177 int lengthOfSLB = TGCChannelSLBIn::getLengthOfSLB(
178 slb->getModuleType(), TGCChannelSLBIn::CellB);
179 if (ppout.getChannel() < lengthOfSLB) {
180 cellType = TGCChannelSLBIn::CellB;
181 channelInSLB = ppout.getChannel();
182 } else {
183 cellType = TGCChannelSLBIn::CellA;
184 channelInSLB = ppout.getChannel() - lengthOfSLB;
185 }
186 }
187
188 int channel = TGCChannelSLBIn::convertChannel(slb->getModuleType(),
189 cellType, channelInSLB);
190 return std::make_unique<TGCChannelSLBIn>(
191 slb->getSideType(), slb->getModuleType(), slb->getRegionType(),
192 slb->getSector(), slb->getId(), channel);
193}
194
196 if (slb.isValid() == false) {
197 return TGCModuleMap{};
198 }
199
200 const int slbId = slb.getId();
201
202 TGCDatabase* databaseP =
203 m_database.at(+slb.getRegionType()).at(+slb.getModuleType()).get();
204 TGCModuleMap mapId{};
205 const int MaxEntry = databaseP->getMaxEntry();
206 for (int i = 0; i < MaxEntry; i++) {
207 if (databaseP->getEntry(i, 1) == slbId) {
208 int id = databaseP->getEntry(i, 0);
209 auto pp = std::make_unique<TGCModulePP>(
210 slb.getSideType(), slb.getStation(),
211 slb.getModuleType(), slb.getRegionType(),
212 slb.getSector(), id);
213
214 mapId.insert(0, std::move(pp));
215 break;
216 }
217 if (databaseP->getEntry(i, 2) == slbId) {
218 int id = databaseP->getEntry(i, 0);
219 auto pp = std::make_unique<TGCModulePP>(
220 slb.getSideType(), slb.getStation(),
221 slb.getModuleType(), slb.getRegionType(),
222 slb.getSector(), id);
223
224 mapId.insert(1, std::move(pp));
225 break;
226 }
227 }
228
229 return mapId;
230}
231
233 if (pp.isValid() == false) {
234 return TGCModuleMap{};
235 }
236
237 const int ppId = pp.getId();
238
239 TGCDatabase* databaseP =
240 m_database.at(+pp.getRegionType()).at(+pp.getModuleType()).get();
241 TGCModuleMap mapId{};
242 const int MaxEntry = databaseP->getMaxEntry();
243 for (int i = 0; i < MaxEntry; i++) {
244 if (databaseP->getEntry(i, 0) == ppId) {
245 int id = -1;
246
247 id = databaseP->getEntry(i, 1);
248 if (id != -1) {
249 auto slb = std::make_unique<TGCModuleSLB>(
250 pp.getSideType(), pp.getModuleType(), pp.getRegionType(),
251 pp.getSector(), id);
252
253 mapId.insert(0, std::move(slb));
254 }
255
256 id = databaseP->getEntry(i, 2);
257 if (id != -1) {
258 auto slb = std::make_unique<TGCModuleSLB>(
259 pp.getSideType(), pp.getModuleType(), pp.getRegionType(),
260 pp.getSector(), id);
261
262 mapId.insert(1, std::move(slb));
263 }
264 break;
265 }
266 }
267
268 return mapId;
269}
270
271} // namespace MuonTGC_Cabling
bool getModule(std::istream &s, RegSelModule &m)
TGCModuleMap getModuleIn(const TGCModuleId &slb) const
std::unique_ptr< TGCChannelId > getChannel(const TGCChannelId &channelId, bool orChannel=false) const
TGCModuleMap getModule(const TGCModuleId &moduleId) const
std::unique_ptr< TGCChannelId > getChannelOut(const TGCChannelId &ppout, bool orChannel=false) const
TGCModuleMap getModuleOut(const TGCModuleId &pp) const
std::array< std::array< std::unique_ptr< TGCDatabase >,+TGCId::ModuleType::MaxModuleType >,+TGCId::RegionType::MaxRegionType > m_database
std::unique_ptr< TGCChannelId > getChannelIn(const TGCChannelId &slbin, bool orChannel=false) const
TGCCable(CableType type=NoCableType)
Definition TGCCable.h:31
virtual std::unique_ptr< TGCModuleId > getModule() const
ChannelIdType getChannelIdType() const
virtual bool isValid() const
virtual CellType getCellType() const
virtual std::unique_ptr< TGCModuleId > getModule() const override
static int convertChannel(TGCId::ModuleType moduleType, CellType cellType, int channelInSLB)
static int getLengthOfSLB(TGCId::ModuleType moduleType, CellType cellType)
virtual int getMaxEntry() const
virtual int getEntry(int entry, int column) const
StationType getStation() const
Definition TGCId.h:128
ModuleType getModuleType() const
Definition TGCId.h:131
RegionType getRegionType() const
Definition TGCId.h:137
virtual int getSector() const
Definition TGCId.h:144
SideType getSideType() const
Definition TGCId.h:125
int getId() const
Definition TGCId.h:150
ModuleIdType getModuleIdType() const
Definition TGCModuleId.h:32
virtual bool isValid() const
Definition TGCModuleId.h:36
Store_t::const_iterator begin() const
Returns the begin iterator of the underlying map.
void insert(int connector, std::unique_ptr< TGCModuleId > moduleId)
std::unique_ptr< TGCModuleId > popModule(const int connector)
Return a certain module and remove it from the map.