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  m_BIS_stIdx = m_idHelperSvc->rpcIdHelper().stationNameIndex("BIS");
27  return StatusCode::SUCCESS;
28 }
30  std::ofstream outStream{m_cablingJSON};
31  if (!outStream.good()) {
32  ATH_MSG_FATAL("Failed to create JSON file "<<m_cablingJSON);
33  return StatusCode::FAILURE;
34  }
35 
36  std::vector<const MuonGMR4::RpcReadoutElement*> reEles{m_detMgr->getAllRpcReadoutElements()};
37 
39  constexpr int subDetA = 0x65;
40  constexpr int subDetB = 0x66;
41  constexpr unsigned int nStripsPerTdc = 64;
42 
43  unsigned int tdcSecA{0}, tdcSecC{0};
44 
45  nlohmann::json overallMap{};
46 
47  constexpr int16_t measPhiBit = NrpcCablingData::measPhiBit;
48  constexpr int16_t stripSideBit = NrpcCablingData::stripSideBit;
49  for (const MuonGMR4::RpcReadoutElement* reEle : reEles) {
50  const unsigned int subDet = reEle->stationEta() > 0 ? subDetA : subDetB;
51  const unsigned int tdcSec = reEle->stationEta() > 0 ? (++tdcSecA) : (++tdcSecC);
52  unsigned int tdc{1};
53  for (unsigned int gasGap =1 ; gasGap <= reEle->nGasGaps(); ++gasGap){
54  for (int doubletPhi = reEle->doubletPhi(); doubletPhi <= reEle->doubletPhiMax(); ++doubletPhi) {
55  for (bool measPhi: {false, true}) {
56  const IdentifierHash layHash = reEle->createHash(1,gasGap,doubletPhi,measPhi);
57  if (!reEle->nStrips(layHash)) continue;
58  const unsigned int nStrips = reEle->nStrips(layHash)+1;
59  const unsigned int nTdcStrips = (nStrips % nStripsPerTdc ? 1 : 0) +
60  (nStrips - (nStrips % nStripsPerTdc)) / nStripsPerTdc;
61  for (bool side : {false, true}) {
62  bool run4_BIS = ((reEle->stationName() == m_BIS_stIdx) && (abs(reEle->stationEta()) < 7));
63  if (side && reEle->stationName() != m_BIL_stIdx && !(run4_BIS)) {
65  continue;
66  }
67  unsigned int measPhiSide = (side * stripSideBit) | (measPhi * measPhiBit);
68  for (unsigned int strip = 0; strip < nTdcStrips; ++strip) {
69  nlohmann::json cablingChannel{};
70  cablingChannel["station"] = m_idHelperSvc->stationNameString(reEle->identify());
71  cablingChannel["eta"] = reEle->stationEta();
72  cablingChannel["phi"] = reEle->stationPhi();
73  cablingChannel["doubletR"] = reEle->doubletR();
74  cablingChannel["doubletZ"] = reEle->doubletZ();
75  cablingChannel["doubletPhi"] = doubletPhi;
76  cablingChannel["gasGap"] = gasGap;
77  cablingChannel["measPhi"] = measPhiSide;
78 
79  cablingChannel["subDetector"] = subDet;
80  cablingChannel["tdcSector"] = tdcSec;
81  cablingChannel["firstStrip"] = (1 + nStripsPerTdc*strip);
82  cablingChannel["lastStrip"] = nStripsPerTdc*(strip +1);
83  cablingChannel["firstTdcChan"] = 1;
84  cablingChannel["lastTdcChan"] = nStripsPerTdc;
85  cablingChannel["tdc"] = (++tdc);
86 
87  overallMap.push_back(cablingChannel);
88  }
89  }
90  }
91  }
92  }
93  }
94  outStream<<overallMap.dump(2)<<std::endl;
95  return StatusCode::SUCCESS;
96 }
97 
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
RpcToyCablingJsonDumpAlg::m_BIS_stIdx
int m_BIS_stIdx
Definition: RpcToyCablingJsonDumpAlg.h:39
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:17
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:29
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:221
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
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
RpcToyCablingJsonDumpAlg::m_BIL_stIdx
int m_BIL_stIdx
Definition: RpcToyCablingJsonDumpAlg.h:38