ATLAS Offline Software
MuonABLineJsonDumpAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
6 #include "nlohmann/json.hpp"
7 #include <fstream>
8 
9 MuonABLineJsonDumpAlg::MuonABLineJsonDumpAlg(const std::string& name, ISvcLocator* pSvcLocator):
10  AthAlgorithm{name, pSvcLocator} {}
11 
15  ATH_CHECK(m_idHelperSvc.retrieve());
16  return StatusCode::SUCCESS;
17  }
19  const EventContext& ctx = Gaudi::Hive::currentContext();
21  if (!aLineContainer.isValid()){
22  ATH_MSG_FATAL("Failed to load ALine container "<<m_readALineKey.fullKey());
23  return StatusCode::FAILURE;
24  }
26  if (!aLineContainer.isValid()){
27  ATH_MSG_FATAL("Failed to load BLine container "<<m_readBLineKey.fullKey());
28  return StatusCode::FAILURE;
29  }
30 
31  std::ofstream ostr{m_jsonFile};
32  if (!ostr.good()) {
33  ATH_MSG_FATAL("Failed to create output file "<<m_jsonFile);
34  return StatusCode::FAILURE;
35  }
36  ostr<<"["<<std::endl;
37  unsigned int nLines{0};
38  for (const ALinePar& aLine : **aLineContainer) {
39  ++nLines;
40  ostr<<" {"<<std::endl;
42  ostr<<" \"typ\": \""<<aLine.AmdbStation()<<"\","<<std::endl;
43  ostr<<" \"jzz\": "<<aLine.AmdbEta()<<", "<<std::endl;
44  ostr<<" \"jff\": "<<aLine.AmdbPhi()<<", "<<std::endl;
45  ostr<<" \"job\": "<<aLine.AmdbJob()<<", "<<std::endl;
47  using APar = ALinePar::Parameter;
48  ostr<<" \"svalue\": "<<aLine.getParameter(APar::transS)<<", "<<std::endl;
49  ostr<<" \"zvalue\": "<<aLine.getParameter(APar::transZ)<<", "<<std::endl;
50  ostr<<" \"tvalue\": "<<aLine.getParameter(APar::transT)<<", "<<std::endl;
51  ostr<<" \"tsv\": "<<aLine.getParameter(APar::rotS)<<", "<<std::endl;
52  ostr<<" \"tzv\": "<<aLine.getParameter(APar::rotZ)<<", "<<std::endl;
53  ostr<<" \"ttv\": "<<aLine.getParameter(APar::rotT);
55  BLineContainer::const_iterator itr = bLineContainer->find(aLine.identify());
56  if (itr == bLineContainer->end()) {
58  ostr<<std::endl<<" }"<< (nLines != aLineContainer->size() ? "," : "")<<std::endl;
59  continue;
60  }
61  ostr<<","<<std::endl;
62  using BPar = BLinePar::Parameter;
63  const BLinePar& bLine = (*itr);
64  ostr<<" \"bz\": "<<bLine.getParameter(BPar::bz)<<","<<std::endl;
65  ostr<<" \"bp\": "<<bLine.getParameter(BPar::bp)<<","<<std::endl;
66  ostr<<" \"bn\": "<<bLine.getParameter(BPar::bn)<<","<<std::endl;
67  ostr<<" \"sp\": "<<bLine.getParameter(BPar::sp)<<","<<std::endl;
68  ostr<<" \"sn\": "<<bLine.getParameter(BPar::sn)<<","<<std::endl;
69  ostr<<" \"tw\": "<<bLine.getParameter(BPar::tw)<<","<<std::endl;
70  ostr<<" \"pg\": "<<bLine.getParameter(BPar::pg)<<","<<std::endl;
71  ostr<<" \"tr\": "<<bLine.getParameter(BPar::tr)<<","<<std::endl;
72  ostr<<" \"eg\": "<<bLine.getParameter(BPar::eg)<<","<<std::endl;
73  ostr<<" \"ep\": "<<bLine.getParameter(BPar::ep)<<","<<std::endl;
74  ostr<<" \"en\": "<<bLine.getParameter(BPar::en)<<","<<std::endl;
76  ostr<<" \"xAtlas\": 0 ,"<<std::endl;
77  ostr<<" \"yAtlas\": 0 ,"<<std::endl;
78  ostr<<" \"hwElement\": \"";
79  ostr<<m_idHelperSvc->stationNameString(bLine.identify());
80  const int stEta = m_idHelperSvc->stationEta(bLine.identify());
81  ostr<<std::abs(stEta)<<(stEta > 0 ? "A" : "C");
82  ostr<<m_idHelperSvc->stationPhi(bLine.identify());
83  ostr<<"\""<<std::endl;
84  ostr<<" }"<< (nLines != aLineContainer->size() ? "," : "")<<std::endl;
85  }
86  ostr<<"]"<<std::endl;
87  ostr.close();
88 
89 
90  return StatusCode::SUCCESS;
91 }
python.changerun.bn
bn
Definition: changerun.py:79
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ParticleTest.eg
eg
Definition: ParticleTest.py:29
ALinePar
Definition: ALinePar.h:15
MuonABLineJsonDumpAlg::m_readBLineKey
SG::ReadCondHandleKey< BLineContainer > m_readBLineKey
Definition: MuonABLineJsonDumpAlg.h:27
MuonABLineJsonDumpAlg::m_jsonFile
Gaudi::Property< std::string > m_jsonFile
Definition: MuonABLineJsonDumpAlg.h:32
BLinePar::getParameter
float getParameter(const Parameter p) const
Returns a given parameter.
Definition: BLinePar.h:39
ReadCondHandle.h
fitman.bz
bz
Definition: fitman.py:412
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonABLineJsonDumpAlg::initialize
virtual StatusCode initialize() override
Definition: MuonABLineJsonDumpAlg.cxx:12
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonABLineJsonDumpAlg.h
BLinePar
Definition: BLinePar.h:14
AthAlgorithm
Definition: AthAlgorithm.h:47
ParticleGun_EoverP_Config.pg
pg
Definition: ParticleGun_EoverP_Config.py:61
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
PlotCalibFromCool.en
en
Definition: PlotCalibFromCool.py:399
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
MuonABLineJsonDumpAlg::execute
virtual StatusCode execute() override
Definition: MuonABLineJsonDumpAlg.cxx:18
MuonAlignmentPar::identify
const Identifier & identify() const
Definition: MuonAlignmentPar.cxx:11
BLinePar::Parameter
Parameter
Definition: BLinePar.h:21
MuonABLineJsonDumpAlg::m_readALineKey
SG::ReadCondHandleKey< ALineContainer > m_readALineKey
Definition: MuonABLineJsonDumpAlg.h:26
MuonABLineJsonDumpAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonABLineJsonDumpAlg.h:29
ALinePar::Parameter
Parameter
amdb frame (s, z, t) = chamber frame (y, z, x)
Definition: ALinePar.h:23
MuonABLineJsonDumpAlg::MuonABLineJsonDumpAlg
MuonABLineJsonDumpAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonABLineJsonDumpAlg.cxx:9