ATLAS Offline Software
Loading...
Searching...
No Matches
MdtAsBuiltJsonDumpAlg.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
9MdtAsBuiltJsonDumpAlg::MdtAsBuiltJsonDumpAlg(const std::string& name, ISvcLocator* pSvcLocator):
10 AthAlgorithm{name, pSvcLocator} {}
11
13 ATH_CHECK(m_readKey.initialize());
14 ATH_CHECK(m_idHelperSvc.retrieve());
15 return StatusCode::SUCCESS;
16 }
18 const EventContext& ctx = Gaudi::Hive::currentContext();
20 if (!asBuiltContainer.isValid()){
21 ATH_MSG_FATAL("Failed to load ALine container "<<m_readKey.fullKey());
22 return StatusCode::FAILURE;
23 }
24 std::ofstream ostr{m_jsonFile};
25 if (!ostr.good()) {
26 ATH_MSG_FATAL("Failed to create output file "<<m_jsonFile);
27 return StatusCode::FAILURE;
28 }
29 ostr<<"["<<std::endl;
30 unsigned int nLines{0};
31 using multilayer_t = MdtAsBuiltPar::multilayer_t;
32 using tubeSide_t = MdtAsBuiltPar::tubeSide_t;
33 for (const MdtAsBuiltPar& asBuilt : **asBuiltContainer) {
34 ++nLines;
35 ostr<<" {"<<std::endl;
37 ostr<<" \"typ\": \""<<asBuilt.AmdbStation()<<"\","<<std::endl;
38 ostr<<" \"jzz\": "<<asBuilt.AmdbEta()<<", "<<std::endl;
39 ostr<<" \"jff\": "<<asBuilt.AmdbPhi()<<", "<<std::endl;
40 for (const multilayer_t ml : {multilayer_t::ML1, multilayer_t::ML2}){
41 for (const tubeSide_t side: {tubeSide_t::POS, tubeSide_t::NEG}){
42 std::stringstream prefix{};
43 prefix<<"Ml"<<(static_cast<unsigned>(ml) + 1);
44 prefix<<(side == tubeSide_t::POS? "Pos" : "Neg")<<"TubeSide";
45
46 auto dumpValue = [&prefix,&ostr](const std::string& field,
47 const float val,
48 bool last = false) {
49 ostr<<" \""<<prefix.str()<<field<<"\": ";
50 ostr<<val<<(last ? "":", ")<<std::endl;
51 };
52 dumpValue("y0", asBuilt.y0(ml, side));
53 dumpValue("z0", asBuilt.z0(ml, side));
54 dumpValue("alpha", asBuilt.alpha(ml, side));
55 dumpValue("ypitch", asBuilt.ypitch(ml, side));
56 dumpValue("zpitch", asBuilt.zpitch(ml, side));
57 dumpValue("stagg", asBuilt.stagg(ml, side),
58 ml == multilayer_t::ML2 && side == tubeSide_t::NEG);
59 }
60 }
61 ostr<<" }"<< (nLines != asBuiltContainer->size() ? "," : "")<<std::endl;
62 }
63 ostr<<"]"<<std::endl;
64 ostr.close();
65
66
67 return StatusCode::SUCCESS;
68}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Property< std::string > m_jsonFile
virtual StatusCode execute() override
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::ReadCondHandleKey< MdtAsBuiltContainer > m_readKey
MdtAsBuiltJsonDumpAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
Container classifier the MDT as-built parameters See parameter description in http://atlas-muon-align...
multilayer_t
MDT multi-layer index.
tubeSide_t
MDT tube side.