ATLAS Offline Software
Loading...
Searching...
No Matches
MdtCondJsonDumpAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8#include <fstream>
9
10
11
12MdtCondJsonDumpAlg::MdtCondJsonDumpAlg(const std::string& name, ISvcLocator* pSvcLocator):
13 AthAlgorithm{name, pSvcLocator} {}
14
16 ATH_CHECK(m_idHelperSvc.retrieve());
17 ATH_CHECK(m_readKey.initialize());
18 return StatusCode::SUCCESS;
19}
20StatusCode MdtCondJsonDumpAlg::execute(const EventContext& ctx) {
22 if (!readCondHandle.isValid()) {
23 ATH_MSG_FATAL("Failed to open chamber load conditions "<<m_readKey.fullKey());
24 return StatusCode::FAILURE;
25 }
27 {
28 std::ofstream deadChannels{m_deadChannelJSON};
29 if (!deadChannels.good()) {
30 ATH_MSG_ERROR("Failed to write "<<m_deadChannelJSON);
31 return StatusCode::FAILURE;
32 }
33 deadChannels<<"{"<<std::endl;
34 deadChannels<<" \"Chambers\": ";
35 dumpDeadChannels(readCondHandle->getDeadChambersId(), deadChannels);
36 deadChannels<<","<<std::endl;
37 deadChannels<<" \"MultiLayers\": ";
38 dumpDeadChannels(readCondHandle->getDeadMultilayersId(), deadChannels, true);
39 deadChannels<<","<<std::endl;
40 deadChannels<<" \"TubeLayers:\": ";
41 dumpDeadChannels(readCondHandle->getDeadLayersId(), deadChannels, true, true);
42 deadChannels<<","<<std::endl;
43 deadChannels<<" \"Tubes:\": ";
44 dumpDeadChannels(readCondHandle->getDeadTubesId(), deadChannels, true, true, true);
45 deadChannels<<std::endl<<"}"<<std::endl;
46 }
48 if (readCondHandle->getAllHvStates().empty() || m_dcsJSON.value().empty()){
49 return StatusCode::SUCCESS;
50 }
51 std::ofstream dcsStates{m_dcsJSON};
52 if (!dcsStates.good()) {
53 ATH_MSG_ERROR("Failed to write "<<m_dcsJSON);
54 return StatusCode::FAILURE;
55 }
56
57
58 dcsStates<<"["<<std::endl;
59
60
61 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
64
65 for (MuonIdHelper::const_id_iterator itr = begin; itr != end; ++itr) {
66 const Identifier& detElId{*itr};
67 const MuonCond::DcsConstants& dcs{readCondHandle->getHvState(detElId)};
68 dcsStates<<" {"<<std::endl;
69 dumpIdentifier(detElId, dcsStates, true, false, false, true);
70 dcsStates<<" \"state\": \""<<MuonCond::getFsmStateStrg(dcs.fsmState)<<"\","<<std::endl;
71 dcsStates<<" \"standByVolt\": "<<dcs.standbyVolt<<", "<<std::endl;
72 dcsStates<<" \"readyVolt\": "<<dcs.readyVolt<<std::endl;
73 dcsStates<<" }";
74 if ((itr +1 ) != end) dcsStates<<",";
75 dcsStates<<std::endl;
76 }
77 dcsStates<<"]"<<std::endl;
78
79
80 return StatusCode::SUCCESS;
81}
82
84 std::ostream& ostr,
85 bool dumpMultiLayer,
86 bool dumpLayer,
87 bool dumpTube,
88 bool trailingComma) const {
89 ostr<<" \"station\": \""<<m_idHelperSvc->stationNameString(id)<<"\","<<std::endl;
90 ostr<<" \"eta\": "<<m_idHelperSvc->stationEta(id)<<","<<std::endl;
91 ostr<<" \"phi\": "<<m_idHelperSvc->stationPhi(id);
92 if (!dumpMultiLayer) {
93 ostr<<(trailingComma ? "," : "")<<std::endl;
94 return;
95 }
96 ostr<<","<<std::endl;
97 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
98 ostr<<" \"ml\": "<<idHelper.multilayer(id);
99 if (!dumpLayer) {
100 ostr<<(trailingComma ? "," : "")<<std::endl;
101 return;
102 }
103 ostr<<","<<std::endl;
104 ostr<<" \"layer\": "<<idHelper.tubeLayer(id);
105 if (!dumpTube) {
106 ostr<<(trailingComma ? "," : "")<<std::endl;
107 return;
108 }
109 ostr<<" \"tube:\": \""<<idHelper.tube(id);
110 ostr<<(trailingComma ? "," : "")<<std::endl;
111}
112void MdtCondJsonDumpAlg::dumpDeadChannels(const std::unordered_set<Identifier>& channels,
113 std::ostream& ostr,
114 bool dumpMultiLayer,
115 bool dumpLayer, bool dumpTube) const {
116 unsigned int processed{0};
117 ostr<<"["<<std::endl;
118 for (const Identifier& id : channels) {
119 ostr<<" {"<<std::endl;
120 dumpIdentifier(id, ostr, dumpMultiLayer, dumpLayer, dumpTube, false);
121 ostr<<" }";
122 ++processed;
123 if(processed != channels.size()) ostr<<",";
124 ostr<<std::endl;
125 }
126 ostr<<"]";
127}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Gaudi::Property< std::string > m_dcsJSON
void dumpIdentifier(const Identifier &id, std::ostream &ostr, bool dumpMultiLayer, bool dumpLayer, bool dumpTube, bool trailingComma) const
Dumps the Identifier into a json format.
SG::ReadCondHandleKey< MdtCondDbData > m_readKey
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Gaudi::Property< std::string > m_deadChannelJSON
MdtCondJsonDumpAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
void dumpDeadChannels(const std::unordered_set< Identifier > &channels, std::ostream &ostr, bool dumpMultiLayer=false, bool dumpLayer=false, bool dumpTube=false) const
Dumps all channels into a JSON format.
int multilayer(const Identifier &id) const
Access to components of the ID.
int tube(const Identifier &id) const
int tubeLayer(const Identifier &id) const
std::vector< Identifier >::const_iterator const_id_iterator
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
const_id_iterator detectorElement_end() const
std::string getFsmStateStrg(DcsFsmState fsmState)
Definition Defs.cxx:22
Helper struct to cache all dcs constants in a common place of the memory.