ATLAS Offline Software
MdtCondJsonDumpAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MdtCondJsonDumpAlg.h"
6 
8 #include <fstream>
9 
10 
11 
12 MdtCondJsonDumpAlg::MdtCondJsonDumpAlg(const std::string& name, ISvcLocator* pSvcLocator):
13  AthAlgorithm{name, pSvcLocator} {}
14 
16  ATH_CHECK(m_idHelperSvc.retrieve());
18  return StatusCode::SUCCESS;
19 }
21  const EventContext& ctx{Gaudi::Hive::currentContext()};
22  SG::ReadCondHandle<MdtCondDbData> readCondHandle{m_readKey, ctx};
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()};
63  const MuonIdHelper::const_id_iterator begin = idHelper.detectorElement_begin();
64  const MuonIdHelper::const_id_iterator end = idHelper.detectorElement_end();
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 }
113 void 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 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
MuonCond::getFsmStateStrg
std::string getFsmStateStrg(DcsFsmState fsmState)
Definition: Defs.cxx:22
MdtCondJsonDumpAlg::initialize
virtual StatusCode initialize() override
Definition: MdtCondJsonDumpAlg.cxx:15
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
MdtCondJsonDumpAlg::m_dcsJSON
Gaudi::Property< std::string > m_dcsJSON
Definition: MdtCondJsonDumpAlg.h:47
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
MdtCondJsonDumpAlg::dumpIdentifier
void dumpIdentifier(const Identifier &id, std::ostream &ostr, bool dumpMultiLayer, bool dumpLayer, bool dumpTube, bool trailingComma) const
Dumps the Identifier into a json format.
Definition: MdtCondJsonDumpAlg.cxx:84
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonCond::DcsConstants
Helper struct to cache all dcs constants in a common place of the memory.
Definition: MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/Defs.h:31
MdtIdHelper
Definition: MdtIdHelper.h:61
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MdtCondJsonDumpAlg::dumpDeadChannels
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.
Definition: MdtCondJsonDumpAlg.cxx:113
AthAlgorithm
Definition: AthAlgorithm.h:47
ReadCondHandleKey.h
MdtCondJsonDumpAlg.h
MdtCondJsonDumpAlg::m_readKey
SG::ReadCondHandleKey< MdtCondDbData > m_readKey
Definition: MdtCondJsonDumpAlg.h:44
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
MdtCondJsonDumpAlg::execute
virtual StatusCode execute() override
Definition: MdtCondJsonDumpAlg.cxx:20
MdtCondJsonDumpAlg::m_deadChannelJSON
Gaudi::Property< std::string > m_deadChannelJSON
Definition: MdtCondJsonDumpAlg.h:46
MuonIdHelper::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: MuonIdHelper.h:143
MdtCondJsonDumpAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MdtCondJsonDumpAlg.h:42
MdtCondJsonDumpAlg::MdtCondJsonDumpAlg
MdtCondJsonDumpAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MdtCondJsonDumpAlg.cxx:12