ATLAS Offline Software
Loading...
Searching...
No Matches
MdtAsBuiltJsonDumpAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
6#include "nlohmann/json.hpp"
7#include <fstream>
8#include <format>
9#include <string_view>
10
11MdtAsBuiltJsonDumpAlg::MdtAsBuiltJsonDumpAlg(const std::string& name, ISvcLocator* pSvcLocator):
12 AthAlgorithm{name, pSvcLocator} {}
13
15 ATH_CHECK(m_readKey.initialize());
16 ATH_CHECK(m_idHelperSvc.retrieve());
17 return StatusCode::SUCCESS;
18 }
19StatusCode MdtAsBuiltJsonDumpAlg::execute(const EventContext& ctx){
21 if (!asBuiltContainer.isValid()){
22 ATH_MSG_FATAL("Failed to load ALine container "<<m_readKey.fullKey());
23 return StatusCode::FAILURE;
24 }
25 std::ofstream ostr{m_jsonFile};
26 if (!ostr.good()) {
27 ATH_MSG_FATAL("Failed to create output file "<<m_jsonFile);
28 return StatusCode::FAILURE;
29 }
30 ostr<<"["<<std::endl;
31 unsigned int nLines{0};
32 using multilayer_t = MdtAsBuiltPar::multilayer_t;
33 using tubeSide_t = MdtAsBuiltPar::tubeSide_t;
34 for (const MdtAsBuiltPar& asBuilt : **asBuiltContainer) {
35 ++nLines;
36 ostr<<" {"<<std::endl;
38 ostr<<" \"typ\": \""<<asBuilt.AmdbStation()<<"\","<<std::endl;
39 ostr<<" \"jzz\": "<<asBuilt.AmdbEta()<<", "<<std::endl;
40 ostr<<" \"jff\": "<<asBuilt.AmdbPhi()<<", "<<std::endl;
41 for (const multilayer_t ml : {multilayer_t::ML1, multilayer_t::ML2}){
42 for (const tubeSide_t side: {tubeSide_t::POS, tubeSide_t::NEG}){
43 const std::string prefix = std::format("Ml{}{}TubeSide",
44 static_cast<unsigned>(ml) + 1,
45 side == tubeSide_t::POS ? "Pos" : "Neg");
46
47 const auto dumpValue = [&ostr, &prefix](std::string_view field,
48 float val,
49 bool last = false) {
50 ostr << " \"" << prefix << field << "\": "
51 << val << (last ? "" : ", ") << '\n';
52 };
53
54 dumpValue("y0", asBuilt.y0(ml, side));
55 dumpValue("z0", asBuilt.z0(ml, side));
56 dumpValue("alpha", asBuilt.alpha(ml, side));
57 dumpValue("ypitch", asBuilt.ypitch(ml, side));
58 dumpValue("zpitch", asBuilt.zpitch(ml, side));
59 dumpValue("stagg", asBuilt.stagg(ml, side),
60 ml == multilayer_t::ML2 && side == tubeSide_t::NEG);
61 }
62 }
63 ostr<<" }"<< (nLines != asBuiltContainer->size() ? "," : "")<<std::endl;
64 }
65 ostr<<"]"<<std::endl;
66 ostr.close();
67
68
69 return StatusCode::SUCCESS;
70}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Gaudi::Property< std::string > m_jsonFile
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
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.