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 }
20 const EventContext& ctx = Gaudi::Hive::currentContext();
22 if (!asBuiltContainer.isValid()){
23 ATH_MSG_FATAL("Failed to load ALine container "<<m_readKey.fullKey());
24 return StatusCode::FAILURE;
25 }
26 std::ofstream ostr{m_jsonFile};
27 if (!ostr.good()) {
28 ATH_MSG_FATAL("Failed to create output file "<<m_jsonFile);
29 return StatusCode::FAILURE;
30 }
31 ostr<<"["<<std::endl;
32 unsigned int nLines{0};
33 using multilayer_t = MdtAsBuiltPar::multilayer_t;
34 using tubeSide_t = MdtAsBuiltPar::tubeSide_t;
35 for (const MdtAsBuiltPar& asBuilt : **asBuiltContainer) {
36 ++nLines;
37 ostr<<" {"<<std::endl;
39 ostr<<" \"typ\": \""<<asBuilt.AmdbStation()<<"\","<<std::endl;
40 ostr<<" \"jzz\": "<<asBuilt.AmdbEta()<<", "<<std::endl;
41 ostr<<" \"jff\": "<<asBuilt.AmdbPhi()<<", "<<std::endl;
42 for (const multilayer_t ml : {multilayer_t::ML1, multilayer_t::ML2}){
43 for (const tubeSide_t side: {tubeSide_t::POS, tubeSide_t::NEG}){
44 const std::string prefix = std::format("Ml{}{}TubeSide",
45 static_cast<unsigned>(ml) + 1,
46 side == tubeSide_t::POS ? "Pos" : "Neg");
47
48 const auto dumpValue = [&ostr, &prefix](std::string_view field,
49 float val,
50 bool last = false) {
51 ostr << " \"" << prefix << field << "\": "
52 << val << (last ? "" : ", ") << '\n';
53 };
54
55 dumpValue("y0", asBuilt.y0(ml, side));
56 dumpValue("z0", asBuilt.z0(ml, side));
57 dumpValue("alpha", asBuilt.alpha(ml, side));
58 dumpValue("ypitch", asBuilt.ypitch(ml, side));
59 dumpValue("zpitch", asBuilt.zpitch(ml, side));
60 dumpValue("stagg", asBuilt.stagg(ml, side),
61 ml == multilayer_t::ML2 && side == tubeSide_t::NEG);
62 }
63 }
64 ostr<<" }"<< (nLines != asBuiltContainer->size() ? "," : "")<<std::endl;
65 }
66 ostr<<"]"<<std::endl;
67 ostr.close();
68
69
70 return StatusCode::SUCCESS;
71}
#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.