Execute method.
The staggering of the hedgehog cards does not coincide with the multi-layer staggering i.e. tubeZero is 2,3,4,5 or 2,3,4,5,6,7.
45 {
46 ATH_MSG_INFO(
"Dump cabling & mezzanines into JSON file");
47
48 const MuonGM::MuonDetectorManager* detectorMgr{nullptr};
50
51 const MuonMDT_CablingMap*
cabling{
nullptr};
53
55
56 std::vector<MdtMezzanineCard> cached_cards{};
57 std::set<MdtCablingData> cached_chnls{};
61 if (!readEle) {
63 continue;
64 }
69 << " since it will be inserted manually");
70 continue;
71 }
72
74 MdtMezzanineCard dummy_card(Mapping{}, readEle->
getNLayers(), -1);
75 std::map<TdcIdentifier, Mapping> chamber_mezz{};
79
80 for (
int layer = 1 ;
layer <= nLayers; ++
layer){
81 for (int tubeInLayer = 1 ; tubeInLayer <= nTubes; ++tubeInLayer) {
82 bool is_valid{false};
84 layer, tubeInLayer, is_valid);
85 if (!is_valid) {
87 continue;
88 }
91 cabling->convert(tube_id,cabling_data);
93 if (!
cabling->getOnlineId(cabling_data, msgStream())) {
95 continue;
96 }
98 chamber_mezz.try_emplace(tdc_id,unsetArray);
99 chamber_mezz[tdc_id][
cabling_data.channelId] = dummy_card.tubeNumber(layer, tubeInLayer);
100 }
101 }
103 for (auto&[tdc, mezz_mapping] : chamber_mezz) {
104 MdtCablingData mezzCablingId{};
105
107 static_cast<MdtCablingOnData&>(mezzCablingId) = tdc;
108 mezzCablingId.
tdcId = tdc.tdcId;
109
110 MdtTdcOnlSorter chipInCab =
cabling->getOnlineConvMap().at(tdc).all_modules.at(tdc.tdcId);
112 static_cast<MdtCablingOffData&
>(mezzCablingId) = chipInCab->
offId();
115
116 const uint8_t tubeOffSet = (mezzCablingId.
tube-1)%dummy_card.numTubesPerLayer();
119 if (tubeOffSet) {
120 MdtMezzanineCard
remap{mezz_mapping, dummy_card.numTubeLayers(), 0};
121 for (
size_t chan = 0 ;
chan < mezz_mapping.size(); ++
chan) {
122 const OfflineCh tube_lay =
remap.offlineTube(chan, msgStream());
123 if (!tube_lay.isValid) continue;
124 uint8_t tubeNumber = tube_lay.tube + tubeOffSet + 1;
125 mezz_mapping[
chan] =
remap.tubeNumber(tube_lay.layer, tubeNumber);
126 }
127 }
129 Mapping& mtmp = mezz_mapping;
130 std::vector<MdtMezzanineCard>::const_iterator itr = std::find_if(cached_cards.begin(), cached_cards.end(),
131 [&dummy_card, &mtmp](const MdtMezzanineCard& card ){
132 if (dummy_card.numTubeLayers() != card.numTubeLayers()) return false;
133 for (size_t ch =0; ch < mtmp.size(); ++ch) {
134 if (mtmp[ch] != card.tdcToTubeMap()[ch]) return false;
135 }
136 return true;
137 });
138 if (itr != cached_cards.end()) {
140 } else {
141 cached_cards.emplace_back(mezz_mapping, dummy_card.numTubeLayers(), cached_cards.size() + 10);
142 if (!cached_cards.back().checkConsistency(msgStream())) {
144 return StatusCode::FAILURE;
145 }
147 }
148 cached_chnls.insert(std::move(mezzCablingId));
149 }
150 }
151
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 constexpr std::array<uint8_t,24> mezzanineType6InvertedMap{23, 17, 11, 5,
181 22, 16, 10, 4,
182 21, 15, 9, 3,
183 20, 14, 8, 2,
184 19, 13, 7, 1,
185 18, 12, 6, 0};
186
187 constexpr std::array<uint8_t,24> mezzanineType6bInvertedMap{250, 250, 250,250,
188 22, 16, 10, 4,
189 21, 15, 9, 3,
190 20, 14, 8, 2,
191 19, 13, 7, 1,
192 18, 12, 6, 0};
193 constexpr std::array<uint8_t,24> mezzanineType6b2InvertedMap{250, 250, 250, 250,
194 23, 17, 11, 5,
195 22, 16, 10, 4,
196 21, 15, 9, 3,
197 20, 14, 8, 2,
198 19, 13, 7, 1};
199
200 constexpr std::array<uint8_t,24> mezzanineType7Map{12, 18, 0, 6,
201 13, 19, 1, 7,
202 14, 20, 2, 8,
203 15, 21, 3, 9,
204 16, 22, 4, 10,
205 17, 23, 5, 11};
206
207 constexpr std::array<uint8_t,24> mezzanineType7bMap{12, 18, 0, 6,
208 13, 19, 1, 7,
209 14, 20, 2, 8,
210 15, 21, 3, 9,
211 16, 22, 4, 10,
212 250, 250, 250, 250};
213
214 constexpr std::array<uint8_t,24> mezzanineType7b2Map{ 13, 19, 1, 7,
215 14, 20, 2, 8,
216 15, 21, 3, 9,
217 16, 22, 4, 10,
218 17, 23, 5, 11,
219 250, 250, 250, 250};
220
221
222
223
224 std::map<std::string, MdtMezzanineCard> mezzTypes{};
225 mezzTypes.emplace(std::make_pair("mezzanineType6", MdtMezzanineCard(mezzanineType6InvertedMap, 4, 0)));
226 mezzTypes.emplace(std::make_pair("mezzanineType6b", MdtMezzanineCard(mezzanineType6bInvertedMap, 4, 0)));
227 mezzTypes.emplace(std::make_pair("mezzanineType6b2", MdtMezzanineCard(mezzanineType6b2InvertedMap, 4, 0)));
228 mezzTypes.emplace(std::make_pair("mezzanineType7", MdtMezzanineCard(mezzanineType7Map, 4, 0)));
229 mezzTypes.emplace(std::make_pair("mezzanineType7b", MdtMezzanineCard(mezzanineType7bMap, 4, 0)));
230 mezzTypes.emplace(std::make_pair("mezzanineType7b2", MdtMezzanineCard(mezzanineType7b2Map, 4, 0)));
231 std::map<std::string, int> mezzTypeIds{};
232 for(auto& [type,card] : mezzTypes){
233 auto itr = std::ranges::find_if(cached_cards,
234 [&card](const MdtMezzanineCard& cachedCard){
236 return false;
237 }
238 for(
size_t ch = 0;
ch < card.tdcToTubeMap().
size(); ++
ch){
239 if(cachedCard.
tdcToTubeMap()[ch] != card.tdcToTubeMap()[ch]) {
240 return false;
241 }
242 }
243 return true;
244 });
245 if(itr != cached_cards.end()){
246 mezzTypeIds[
type] = itr->id();
247 } else {
248 cached_cards.emplace_back(card.tdcToTubeMap(), card.numTubeLayers(), cached_cards.size() + 10);
249 mezzTypeIds[
type] = cached_cards.back().id();
250 }
251 }
252
253 for(auto& [type,card] : mezzTypes){
254 ATH_MSG_VERBOSE(
"mezzz type" << type <<
" has id " << mezzTypeIds[type]);
255 }
256
257
258
259 std::map<uint8_t, uint8_t> mrodMap, csmMap;
260 mrodMap[97] = 55; csmMap[97] = 0;
261 mrodMap[98] = 55; csmMap[98] = 0;
262
265 if (!readEle) {
267 continue;
268 }
269
271 continue;
272 }
275 continue;
276 }
277
281
283
289 subdetectorId = 97;
290 } else{
291 subdetectorId = 98;
292 }
293 for(int tubeInLayer = 1 ; tubeInLayer <= nTubes;
294 tubeInLayer += mezzTypes.at("mezzanineType6").numTubesPerLayer()){
295
296 if(tubeInLayer==1 && std::abs(readEle->
getStationEta()) !=7){tubeInLayer -=1;}
297 MdtCablingData mezzCablingId_ml1{};
298 if(tubeInLayer <= tubesPerLayer_ml1){
304 mezzCablingId_ml1.
csm = csmMap[subdetectorId];
305 mezzCablingId_ml1.
mrod = mrodMap[subdetectorId];
306 mezzCablingId_ml1.
tdcId = tdcId;
307 mezzCablingId_ml1.
tube = tubeInLayer;
308 }
309
310
311 MdtCablingData mezzCablingId_ml2{};
317 mezzCablingId_ml2.
csm = csmMap[subdetectorId];
318 mezzCablingId_ml2.
mrod = mrodMap[subdetectorId];
319 mezzCablingId_ml2.
tdcId = tdcId +1;
320 mezzCablingId_ml2.
tube = tubeInLayer;
321
322
323
324 std::string mezzEndString = "";
325
326 if(std::abs(readEle->
getStationEta()) !=7 && tubeInLayer + 6 > nTubes) { mezzEndString =
"b"; }
327 if(std::abs(readEle->
getStationEta()) !=7 && tubeInLayer==0 ) { mezzEndString =
"b2"; }
328 ATH_MSG_VERBOSE(
"For station "<<
m_idHelperSvc->toString(station_id) <<
" tube " << tubeInLayer<<
" assigning mezzanine types for tubeInLayer "<<tubeInLayer <<
" mezzEndString "<<mezzEndString);
330
332 if(tubeInLayer <= tubesPerLayer_ml1) {
333 mezzCablingId_ml1.
mezzanine_type = mezzTypeIds[
"mezzanineType7"+mezzEndString];
334 }
335 mezzCablingId_ml2.
mezzanine_type = mezzTypeIds[
"mezzanineType7"+mezzEndString];
336 } else {
337 if(tubeInLayer <= tubesPerLayer_ml1) {
338 mezzCablingId_ml1.
mezzanine_type = mezzTypeIds[
"mezzanineType6"+mezzEndString];
339 }
340 mezzCablingId_ml2.
mezzanine_type = mezzTypeIds[
"mezzanineType6"+mezzEndString];
341 }
342 } else {
343
345 if(tubeInLayer <= tubesPerLayer_ml1){
346 mezzCablingId_ml1.
mezzanine_type = mezzTypeIds[
"mezzanineType6"+mezzEndString];
347 }
348 mezzCablingId_ml2.
mezzanine_type = mezzTypeIds[
"mezzanineType6"+mezzEndString];
349 } else {
350 if(tubeInLayer <= tubesPerLayer_ml1){
351 mezzCablingId_ml1.
mezzanine_type = mezzTypeIds[
"mezzanineType7"+mezzEndString];
352 }
353 mezzCablingId_ml2.
mezzanine_type = mezzTypeIds[
"mezzanineType7"+mezzEndString];
354 }
355 }
356 if(tubeInLayer <= tubesPerLayer_ml1) {
357 cached_chnls.insert(std::move(mezzCablingId_ml1));
358 }
359 cached_chnls.insert(std::move(mezzCablingId_ml2));
360
361 tdcId+=2;
362
363 if((std::abs(readEle->
getStationEta()) == 1 && tdcId >=12) ||
365
366 tdcId = 0;
367 csmMap[subdetectorId] +=1;
368 if(csmMap[subdetectorId]>5){
369 csmMap[subdetectorId]=0;
370 mrodMap[subdetectorId]+=1;
371 }
372 }
373 }
374
375 csmMap[subdetectorId] +=1;
376 if(csmMap[subdetectorId]>5){
377 csmMap[subdetectorId]=0;
378 mrodMap[subdetectorId]+=1;
379 }
380 }
381 }
383 {
387 return StatusCode::FAILURE;
388 }
389 summary<<
"Extracted "<<cached_cards.size()<<
" mezzanine card layouts and "
390 <<cached_chnls.size()<<" chamber channels. \n\n\n";
391 for (const MdtMezzanineCard& card : cached_cards) {
393 MdtCablingOffData chamb{};
394 for (const MdtCablingData& cabling : cached_chnls) {
395 if (
cabling.mezzanine_type != card.id())
continue;
396 if (chamb != cabling) {
399 summary<<static_cast<int>(std::abs(chamb.
eta));
401 summary<<static_cast<int>(chamb.
phi);
404 }
405 summary<<static_cast<int>(
cabling.tdcId)<<
", ";
406 }
408 <<"##############################################################\n";
409 }
410 }
412 {
414 if (!mezz_json.good()) {
416 return StatusCode::FAILURE;
417 }
418 mezz_json<<"["<<std::endl;
419 for (
size_t i = 0;
i < cached_cards.size() ; ++
i) {
420 const MdtMezzanineCard& card = cached_cards[
i];
421 mezz_json<<" {\n";
422 mezz_json<<
" \"mezzId\": "<<
static_cast<int>(card.
id())<<
",\n";
423 mezz_json<<
" \"nTubeLayer\": "<<
static_cast<int>(card.
numTubeLayers())<<
",\n";
424 mezz_json<<" \"tdcToTubeMap\": [";
427 if (ch + 1 != card.
tdcToTubeMap().size())mezz_json<<
",";
428 }
429 mezz_json<<"]\n";
430 mezz_json<<" }";
431 if (i +1 != cached_cards.size()) mezz_json<<",";
432 mezz_json<<"\n";
433 }
434 mezz_json<<"]";
435 }
436 {
438 if (!chamb_json.good()) {
440 return StatusCode::FAILURE;
441 }
442 chamb_json<<"[\n";
444 for (const MdtCablingData& chamb : cached_chnls){
445 chamb_json<<" {\n";
447 chamb_json<<
" \"eta\": "<<
static_cast<int>(chamb.
eta)<<
",\n";
448 chamb_json<<
" \"phi\": "<<
static_cast<int>(chamb.
phi)<<
",\n";
449 chamb_json<<
" \"ml\": "<<
static_cast<int>(chamb.
multilayer)<<
",\n";
450 chamb_json<<" \"subDet\": "<<static_cast<int>(chamb.subdetectorId)<<",\n";
451 chamb_json<<" \"csm\": "<<static_cast<int>(chamb.csm)<<",\n";
452 chamb_json<<" \"mrod\": "<<static_cast<int>(chamb.mrod)<<",\n";
453 chamb_json<<" \"tdcId\": "<<static_cast<int>(chamb.tdcId)<<",\n";
454 chamb_json<<" \"mezzId\": "<<static_cast<int>(chamb.mezzanine_type)<<",\n";
455 chamb_json<<" \"tubeZero\": "<<static_cast<int>(chamb.tube)<<"\n";
456 chamb_json<<" }";
457 if (i +1 != cached_chnls.size()) chamb_json<<",";
458 chamb_json<<"\n";
460 }
461 chamb_json<<"]"<<std::endl;
462 }
463
464
465 return StatusCode::SUCCESS;
466}
constexpr std::array< T, N > make_array(const T &def_val)
Helper function to initialize in-place arrays with non-zero values.
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
size_t size() const
Number of registered mappings.
Gaudi::Property< std::string > m_summaryTxt
Gaudi::Property< std::string > m_mezzJSON
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_cablingKey
Gaudi::Property< std::string > m_cablingJSON
Gaudi::Property< bool > m_insertBISCabling
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Identifier multilayerID(const Identifier &channeldID) const
Identifier elementID(int stationName, int stationEta, int stationPhi) const
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const
static constexpr uint8_t NOTSET
const Mapping & tdcToTubeMap() const
Returns the underlying TDC -> Tube conversion map.
uint8_t id() const
returns mezzanine database identifier
uint8_t numTubeLayers() const
returns the number of layers
const MdtCablingOffData & offId() const
get the offline identifier
int getNLayers() const
Returns the number of tube layers inside the multilayer.
int getMultilayer() const
Returns the multilayer represented by the readout element.
int getNtubesperlayer() const
Returns the number of tubes in each tube layer.
const MdtReadoutElement * getMdtReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
int getStationPhi() const
int getStationEta() const
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
const std::string & stationNameString(const Identifier &id) const
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
const_id_iterator detectorElement_end() const
std::map< std::string, std::string > remap
list of directories to be explicitly remapped
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
uint8_t tdcId
Mezzanine type.
uint8_t mezzanine_type
Tube number in the layer.
int tube
Layer inside the multilayer.
int8_t & multilayer
Phi sector of the MDT station.
int8_t & eta
Station of the chamber (i.e, BIL,BIS,etc.).
int8_t & phi
Eta of the MDT station.
uint8_t & subdetectorId
CSM number.
uint8_t & csm
MROD number.