Subdetector identifiers (0x65 for chambers on the posivie side and 0x66 for chambers on the other side
26 {
28 if (!outStream.good()) {
30 return StatusCode::FAILURE;
31 }
32
33 std::vector<const MuonGMR4::RpcReadoutElement *> reEles{
m_detMgr->getAllRpcReadoutElements()};
34
36 constexpr int subDetA{0x65}, subDetB{0x66};
38
39 unsigned int boardSecA{0}, boardSecC{0};
40
41 nlohmann::json chamberJSON{}, flatCableJSON{};
42 std::vector<std::unique_ptr<RpcFlatCableTranslator>> flatTranslators{};
43
44 auto connectFlatCable = [&flatCableJSON, &flatTranslators, this](const unsigned coveredStrips) -> unsigned{
45 for (std::unique_ptr<RpcFlatCableTranslator>& translator : flatTranslators){
46 if (static_cast<unsigned>(translator->connectedChannels()) == coveredStrips){
47 return translator->id();
48 }
49 }
50 auto& translator = flatTranslators.emplace_back(std::make_unique<RpcFlatCableTranslator>(flatTranslators.size()));
54 }
55 }
56 nlohmann::json chipJSON{};
57 chipJSON["flatCableId"] = translator->id();
58 std::vector<std::pair<unsigned,unsigned>> pins{};
61 }
62 chipJSON["pinAssignment"] = pins;
63
64 flatCableJSON.push_back(chipJSON);
65 return translator->id();
66 };
67
70 for (const MuonGMR4::RpcReadoutElement *reEle : reEles) {
71 const unsigned int subDet = reEle->stationEta() > 0 ? subDetA : subDetB;
72 const unsigned int boardSec = reEle->stationEta() > 0 ? (++boardSecA) : (++boardSecC);
73 unsigned int board{1};
74 for (
unsigned int gasGap = 1;
gasGap <= reEle->nGasGaps(); ++
gasGap) {
75 for (
int doubletPhi = reEle->doubletPhi(); doubletPhi <= reEle->doubletPhiMax(); ++
doubletPhi) {
76 for (bool measPhi : {false, true}) {
77 const IdentifierHash layHash = reEle->createHash(1, gasGap, doubletPhi, measPhi);
78 if (!reEle->nStrips(layHash))
79 continue;
80 const unsigned int nStrips = reEle->nStrips(layHash);
81 const unsigned int nBoardChips = (
nStrips % nStripsPerBoard > 0) +
82 (nStrips - (nStrips % nStripsPerBoard)) / nStripsPerBoard;
83
84 for (bool side : {false, true}) {
85 bool run4_BIS = ((reEle->stationName() ==
m_BIS_stIdx) && (std::abs(reEle->stationEta()) < 7));
86 if (side && reEle->stationName() !=
m_BIL_stIdx && !(run4_BIS)) {
88 continue;
89 }
90 unsigned int measPhiSide = (
side * stripSideBit) | (measPhi * measPhiBit);
91 for (unsigned int chip = 0; chip < nBoardChips; ++chip) {
94 nlohmann::json cablingChannel{};
95 cablingChannel[
"station"] =
m_idHelperSvc->stationNameString(reEle->identify());
96 cablingChannel["eta"] = reEle->stationEta();
97 cablingChannel["phi"] = reEle->stationPhi();
98 cablingChannel["doubletR"] = reEle->doubletR();
99 cablingChannel["doubletZ"] = reEle->doubletZ();
101 cablingChannel[
"gasGap"] =
gasGap;
102 cablingChannel["measPhi"] = measPhiSide;
103
104 cablingChannel["subDetector"] = subDet;
105 cablingChannel["boardSector"] = boardSec;
107 cablingChannel["board"] = (++board);
108 cablingChannel["flatCableId"] = connectFlatCable(coveredStrips);
110 <<"nStrips: "<<nStrips<<", stripsPerBoard "
111 <<nStripsPerBoard<<", nChips: "<<nBoardChips<<", covered: "<<coveredStrips);
112 chamberJSON.push_back(cablingChannel);
113 }
114 }
115 }
116 }
117 }
118 }
119 nlohmann::json finalJSON{};
120 finalJSON["chamberMap"] = chamberJSON;
121 finalJSON["readoutCards"] = flatCableJSON;
122 outStream << finalJSON.dump(2) << std::endl;
123 return StatusCode::SUCCESS;
124 }
#define ATH_MSG_VERBOSE(x)
static constexpr uint8_t firstStrip
Convention of the lowest strip number.
static constexpr uint8_t readStrips
Number of channels covered by one chip.
static constexpr uint8_t notSet
Default value indicating that the channel is not set.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< std::string > m_cablingJSON
const MuonGMR4::MuonDetectorManager * m_detMgr
int nStrips(const MuonGM::TgcReadoutElement &readoutEle, int layer)
setScaleOne setStatusOne setSaturated int16_t
static constexpr int8_t measPhiBit
gas gap -> 1-3
static constexpr int8_t stripSideBit
#define THROW_EXCEPTION(MESSAGE)