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}
21 const EventContext& ctx{Gaudi::Hive::currentContext()};
23 if (!readCondHandle.isValid()) {
24 ATH_MSG_FATAL("Failed to open chamber load conditions "<<m_readKey.fullKey());
25 return StatusCode::FAILURE;
26 }
28 {
29 std::ofstream deadChannels{m_deadChannelJSON};
30 if (!deadChannels.good()) {
31 ATH_MSG_ERROR("Failed to write "<<m_deadChannelJSON);
32 return StatusCode::FAILURE;
33 }
34 deadChannels<<"{"<<std::endl;
35 deadChannels<<" \"Chambers\": ";
36 dumpDeadChannels(readCondHandle->getDeadChambersId(), deadChannels);
37 deadChannels<<","<<std::endl;
38 deadChannels<<" \"MultiLayers\": ";
39 dumpDeadChannels(readCondHandle->getDeadMultilayersId(), deadChannels, true);
40 deadChannels<<","<<std::endl;
41 deadChannels<<" \"TubeLayers:\": ";
42 dumpDeadChannels(readCondHandle->getDeadLayersId(), deadChannels, true, true);
43 deadChannels<<","<<std::endl;
44 deadChannels<<" \"Tubes:\": ";
45 dumpDeadChannels(readCondHandle->getDeadTubesId(), deadChannels, true, true, true);
46 deadChannels<<std::endl<<"}"<<std::endl;
47 }
49 if (readCondHandle->getAllHvStates().empty() || m_dcsJSON.value().empty()){
50 return StatusCode::SUCCESS;
51 }
52 std::ofstream dcsStates{m_dcsJSON};
53 if (!dcsStates.good()) {
54 ATH_MSG_ERROR("Failed to write "<<m_dcsJSON);
55 return StatusCode::FAILURE;
56 }
57
58
59 dcsStates<<"["<<std::endl;
60
61
62 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
65
66 for (MuonIdHelper::const_id_iterator itr = begin; itr != end; ++itr) {
67 const Identifier& detElId{*itr};
68 const MuonCond::DcsConstants& dcs{readCondHandle->getHvState(detElId)};
69 dcsStates<<" {"<<std::endl;
70 dumpIdentifier(detElId, dcsStates, true, false, false, true);
71 dcsStates<<" \"state\": \""<<MuonCond::getFsmStateStrg(dcs.fsmState)<<"\","<<std::endl;
72 dcsStates<<" \"standByVolt\": "<<dcs.standbyVolt<<", "<<std::endl;
73 dcsStates<<" \"readyVolt\": "<<dcs.readyVolt<<std::endl;
74 dcsStates<<" }";
75 if ((itr +1 ) != end) dcsStates<<",";
76 dcsStates<<std::endl;
77 }
78 dcsStates<<"]"<<std::endl;
79
80
81 return StatusCode::SUCCESS;
82}
83
85 std::ostream& ostr,
86 bool dumpMultiLayer,
87 bool dumpLayer,
88 bool dumpTube,
89 bool trailingComma) const {
90 ostr<<" \"station\": \""<<m_idHelperSvc->stationNameString(id)<<"\","<<std::endl;
91 ostr<<" \"eta\": "<<m_idHelperSvc->stationEta(id)<<","<<std::endl;
92 ostr<<" \"phi\": "<<m_idHelperSvc->stationPhi(id);
93 if (!dumpMultiLayer) {
94 ostr<<(trailingComma ? "," : "")<<std::endl;
95 return;
96 }
97 ostr<<","<<std::endl;
98 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
99 ostr<<" \"ml\": "<<idHelper.multilayer(id);
100 if (!dumpLayer) {
101 ostr<<(trailingComma ? "," : "")<<std::endl;
102 return;
103 }
104 ostr<<","<<std::endl;
105 ostr<<" \"layer\": "<<idHelper.tubeLayer(id);
106 if (!dumpTube) {
107 ostr<<(trailingComma ? "," : "")<<std::endl;
108 return;
109 }
110 ostr<<" \"tube:\": \""<<idHelper.tube(id);
111 ostr<<(trailingComma ? "," : "")<<std::endl;
112}
113void MdtCondJsonDumpAlg::dumpDeadChannels(const std::set<Identifier>& channels,
114 std::ostream& ostr,
115 bool dumpMultiLayer,
116 bool dumpLayer, bool dumpTube) const {
117 unsigned int processed{0};
118 ostr<<"["<<std::endl;
119 for (const Identifier& id : channels) {
120 ostr<<" {"<<std::endl;
121 dumpIdentifier(id, ostr, dumpMultiLayer, dumpLayer, dumpTube, false);
122 ostr<<" }";
123 ++processed;
124 if(processed != channels.size()) ostr<<",";
125 ostr<<std::endl;
126 }
127 ostr<<"]";
128}
#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 with parameters:
Gaudi::Property< std::string > m_dcsJSON
void dumpDeadChannels(const std::set< Identifier > &channels, std::ostream &ostr, bool dumpMultiLayer=false, bool dumpLayer=false, bool dumpTube=false) const
Dumps all channels into a JSON format.
virtual StatusCode execute() override
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
Gaudi::Property< std::string > m_deadChannelJSON
MdtCondJsonDumpAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
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.