ATLAS Offline Software
RpcToyCablingJsonDumpAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 
9 #include "nlohmann/json.hpp"
10 #include <fstream>
11 
12 
13 
14 RpcToyCablingJsonDumpAlg::RpcToyCablingJsonDumpAlg(const std::string& name, ISvcLocator* pSvcLocator):
15  AthAlgorithm{name, pSvcLocator} {}
16 
18  ATH_CHECK(m_idHelperSvc.retrieve());
20  if (!m_idHelperSvc->hasRPC()) {
21  ATH_MSG_FATAL("You can't write rpc cablings without rpc detectors? ");
22  return StatusCode::FAILURE;
23  }
24 
25  m_BIL_stIdx = m_idHelperSvc->rpcIdHelper().stationNameIndex("BIL");
26  return StatusCode::SUCCESS;
27 }
29  std::ofstream outStream{m_cablingJSON};
30  if (!outStream.good()) {
31  ATH_MSG_FATAL("Failed to create JSON file "<<m_cablingJSON);
32  return StatusCode::FAILURE;
33  }
34 
35  std::vector<const MuonGMR4::RpcReadoutElement*> reEles{m_detMgr->getAllRpcReadoutElements()};
36 
38  constexpr int subDetA = 0x65;
39  constexpr int subDetB = 0x66;
40  constexpr unsigned int nStripsPerTdc = 64;
41 
42  unsigned int tdcSecA{0}, tdcSecC{0};
43 
44  nlohmann::json overallMap{};
45 
46  constexpr int16_t measPhiBit = NrpcCablingData::measPhiBit;
47  constexpr int16_t stripSideBit = NrpcCablingData::stripSideBit;
48  for (const MuonGMR4::RpcReadoutElement* reEle : reEles) {
49  const unsigned int subDet = reEle->stationEta() > 0 ? subDetA : subDetB;
50  const unsigned int tdcSec = reEle->stationEta() > 0 ? (++tdcSecA) : (++tdcSecC);
51  unsigned int tdc{1};
52  for (unsigned int gasGap =1 ; gasGap <= reEle->nGasGaps(); ++gasGap){
53  for (int doubletPhi = reEle->doubletPhi(); doubletPhi <= reEle->doubletPhiMax(); ++doubletPhi) {
54  for (bool measPhi: {false, true}) {
55  const unsigned int nStrips = (measPhi ? reEle->nPhiStrips() : reEle->nEtaStrips())+1;
56  const unsigned int nTdcStrips = (nStrips % nStripsPerTdc ? 1 : 0) +
57  (nStrips - (nStrips % nStripsPerTdc)) / nStripsPerTdc;
58  for (bool side : {false, true}) {
59  if (side && reEle->stationName() != m_BIL_stIdx) {
61  continue;
62  }
63  unsigned int measPhiSide = (side * stripSideBit) | (measPhi * measPhiBit);
64  for (unsigned int strip = 0; strip < nTdcStrips; ++strip) {
65  nlohmann::json cablingChannel{};
66  cablingChannel["station"] = m_idHelperSvc->stationNameString(reEle->identify());
67  cablingChannel["eta"] = reEle->stationEta();
68  cablingChannel["phi"] = reEle->stationPhi();
69  cablingChannel["doubletR"] = reEle->doubletR();
70  cablingChannel["doubletZ"] = reEle->doubletZ();
71  cablingChannel["doubletPhi"] = doubletPhi;
72  cablingChannel["gasGap"] = gasGap;
73  cablingChannel["measPhi"] = measPhiSide;
74 
75  cablingChannel["subDetector"] = subDet;
76  cablingChannel["tdcSector"] = tdcSec;
77  cablingChannel["firstStrip"] = (1 + nStripsPerTdc*strip);
78  cablingChannel["lastStrip"] = nStripsPerTdc*(strip +1);
79  cablingChannel["firstTdcChan"] = 1;
80  cablingChannel["lastTdcChan"] = nStripsPerTdc;
81  cablingChannel["tdc"] = (++tdc);
82 
83  overallMap.push_back(cablingChannel);
84  }
85  }
86  }
87  }
88  }
89  }
90  outStream<<overallMap.dump(2)<<std::endl;
91  return StatusCode::SUCCESS;
92 }
93 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
RpcToyCablingJsonDumpAlg::RpcToyCablingJsonDumpAlg
RpcToyCablingJsonDumpAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: RpcToyCablingJsonDumpAlg.cxx:14
RpcToyCablingJsonDumpAlg.h
RpcToyCablingJsonDumpAlg::m_detMgr
const MuonGMR4::MuonDetectorManager * m_detMgr
Definition: RpcToyCablingJsonDumpAlg.h:34
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SiliconTech::strip
@ strip
json
nlohmann::json json
Definition: HistogramDef.cxx:9
RpcToyCablingJsonDumpAlg::m_cablingJSON
Gaudi::Property< std::string > m_cablingJSON
Definition: RpcToyCablingJsonDumpAlg.h:36
MuonGMR4::RpcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/RpcReadoutElement.h:18
xAOD::int16_t
setScaleOne setStatusOne setSaturated int16_t
Definition: gFexGlobalRoI_v1.cxx:55
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TRT::Hit::side
@ side
Definition: HitInfo.h:83
NrpcCablingOfflineID::measPhiBit
static constexpr int8_t measPhiBit
gas gap -> 1-3
Definition: NrpcCablingData.h:50
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
RpcToyCablingJsonDumpAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: RpcToyCablingJsonDumpAlg.h:32
RpcToyCablingJsonDumpAlg::execute
virtual StatusCode execute() override
Definition: RpcToyCablingJsonDumpAlg.cxx:28
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
NrpcCablingData.h
AthAlgorithm
Definition: AthAlgorithm.h:47
MuonGM::nStrips
int nStrips(const MuonGM::TgcReadoutElement &readoutEle, int layer)
Definition: MuonDetDescr/MuonGeoModelTest/src/GeoModelTgcTest.cxx:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
NrpcCablingOfflineID::stripSideBit
static constexpr int8_t stripSideBit
Definition: NrpcCablingData.h:51
RpcToyCablingJsonDumpAlg::initialize
virtual StatusCode initialize() override
Definition: RpcToyCablingJsonDumpAlg.cxx:17
createCablingJSON.doubletPhi
int doubletPhi
Definition: createCablingJSON.py:11
RpcToyCablingJsonDumpAlg::m_BIL_stIdx
int m_BIL_stIdx
Definition: RpcToyCablingJsonDumpAlg.h:38