ATLAS Offline Software
Loading...
Searching...
No Matches
MuonABLineJsonDumpAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
6#include "nlohmann/json.hpp"
7#include <fstream>
8
9MuonABLineJsonDumpAlg::MuonABLineJsonDumpAlg(const std::string& name, ISvcLocator* pSvcLocator):
10 AthAlgorithm{name, pSvcLocator} {}
11
13 ATH_CHECK(m_readALineKey.initialize());
14 ATH_CHECK(m_readBLineKey.initialize());
15 ATH_CHECK(m_idHelperSvc.retrieve());
16 return StatusCode::SUCCESS;
17 }
18StatusCode MuonABLineJsonDumpAlg::execute(const EventContext& ctx){
20 if (!aLineContainer.isValid()){
21 ATH_MSG_FATAL("Failed to load ALine container "<<m_readALineKey.fullKey());
22 return StatusCode::FAILURE;
23 }
25 if (!aLineContainer.isValid()){
26 ATH_MSG_FATAL("Failed to load BLine container "<<m_readBLineKey.fullKey());
27 return StatusCode::FAILURE;
28 }
29
30 std::ofstream ostr{m_jsonFile};
31 if (!ostr.good()) {
32 ATH_MSG_FATAL("Failed to create output file "<<m_jsonFile);
33 return StatusCode::FAILURE;
34 }
35 ostr<<"[\n";
36 unsigned int nLines{0};
37 for (const ALinePar& aLine : **aLineContainer) {
38 ++nLines;
39 ostr<<" {\n";
41 ostr<<" \"typ\": \""<<aLine.AmdbStation()<<"\",\n";
42 ostr<<" \"jzz\": "<<aLine.AmdbEta()<<", \n";
43 ostr<<" \"jff\": "<<aLine.AmdbPhi()<<", \n";
44 ostr<<" \"job\": "<<aLine.AmdbJob()<<", \n";
46 using APar = ALinePar::Parameter;
47 ostr<<" \"svalue\": "<<aLine.getParameter(APar::transS)<<", \n";
48 ostr<<" \"zvalue\": "<<aLine.getParameter(APar::transZ)<<", \n";
49 ostr<<" \"tvalue\": "<<aLine.getParameter(APar::transT)<<", \n";
50 ostr<<" \"tsv\": "<<aLine.getParameter(APar::rotS)<<", \n";
51 ostr<<" \"tzv\": "<<aLine.getParameter(APar::rotZ)<<", \n";
52 ostr<<" \"ttv\": "<<aLine.getParameter(APar::rotT);
54 BLineContainer::const_iterator itr = bLineContainer->find(aLine.identify());
55 if (itr == bLineContainer->end()) {
57 ostr<<"\n }"<< (nLines != aLineContainer->size() ? "," : "")<<"\n";
58 continue;
59 }
60 ostr<<",\n";
61 using BPar = BLinePar::Parameter;
62 const BLinePar& bLine = (*itr);
63 ostr<<" \"bz\": "<<bLine.getParameter(BPar::bz)<<",\n";
64 ostr<<" \"bp\": "<<bLine.getParameter(BPar::bp)<<",\n";
65 ostr<<" \"bn\": "<<bLine.getParameter(BPar::bn)<<",\n";
66 ostr<<" \"sp\": "<<bLine.getParameter(BPar::sp)<<",\n";
67 ostr<<" \"sn\": "<<bLine.getParameter(BPar::sn)<<",\n";
68 ostr<<" \"tw\": "<<bLine.getParameter(BPar::tw)<<",\n";
69 ostr<<" \"pg\": "<<bLine.getParameter(BPar::pg)<<",\n";
70 ostr<<" \"tr\": "<<bLine.getParameter(BPar::tr)<<",\n";
71 ostr<<" \"eg\": "<<bLine.getParameter(BPar::eg)<<",\n";
72 ostr<<" \"ep\": "<<bLine.getParameter(BPar::ep)<<",\n";
73 ostr<<" \"en\": "<<bLine.getParameter(BPar::en)<<",\n";
75 ostr<<" \"xAtlas\": 0 ,\n";
76 ostr<<" \"yAtlas\": 0 ,\n";
77 ostr<<" \"hwElement\": \"";
78 ostr<<m_idHelperSvc->stationNameString(bLine.identify());
79 const int stEta = m_idHelperSvc->stationEta(bLine.identify());
80 ostr<<std::abs(stEta)<<(stEta > 0 ? "A" : "C");
81 ostr<<m_idHelperSvc->stationPhi(bLine.identify());
82 ostr<<"\"\n";
83 ostr<<" }"<< (nLines != aLineContainer->size() ? "," : "")<<"\n";
84 }
85 ostr<<"]"<<std::endl;
86 ostr.close();
87
88
89 return StatusCode::SUCCESS;
90}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
Parameter
amdb frame (s, z, t) = chamber frame (y, z, x)
Definition ALinePar.h:23
virtual StatusCode execute()
Execute method without EventContext (deprecated).
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
float getParameter(const Parameter p) const
Returns a given parameter.
Definition BLinePar.h:40
MuonABLineJsonDumpAlg(const std::string &name, ISvcLocator *pSvcLocator)
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< std::string > m_jsonFile
SG::ReadCondHandleKey< BLineContainer > m_readBLineKey
virtual StatusCode initialize() override
SG::ReadCondHandleKey< ALineContainer > m_readALineKey
const Identifier & identify() const