ATLAS Offline Software
NswDcsTestAlg.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 "NswDcsTestAlg.h"
6 
7 // STL
8 #include <stdio.h>
9 
10 #include <boost/date_time/posix_time/posix_time.hpp>
11 #include <ctime>
12 #include <iostream>
13 #include <sstream>
14 #include <fstream>
15 
16 // Gaudi and Athena
18 #include "GaudiKernel/StatusCode.h"
19 #include "Identifier/Identifier.h"
20 
21 // constructor
22 NswDcsTestAlg::NswDcsTestAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
23 
24 // destructor
26 
27 // initialize
29  ATH_MSG_INFO("Calling initialize");
31  ATH_CHECK(m_idHelperSvc.retrieve());
32  return StatusCode::SUCCESS;
33 }
34 
35 // execute
36 StatusCode NswDcsTestAlg::execute(const EventContext& ctx) const {
37  ATH_MSG_INFO("Calling execute");
38 
39  // setup parameters
40  std::chrono::duration<double> retrieving_MMG_HV_A{};
41  std::chrono::duration<double> retrieving_MMG_HV_C{};
42  std::chrono::duration<double> retrieving_MMD_HV_A{};
43  std::chrono::duration<double> retrieving_MMD_HV_C{};
44  std::chrono::duration<double> retrieving_STG_HV_A{};
45  std::chrono::duration<double> retrieving_STG_HV_C{};
46 
47  // retrieve all folders
48  if (!retrieveData(ctx, DcsDataType::HV, DcsTechType::MMG, "A", retrieving_MMG_HV_A).isSuccess()) return StatusCode::FAILURE;
49  if (!retrieveData(ctx, DcsDataType::HV, DcsTechType::MMG, "C", retrieving_MMG_HV_A).isSuccess()) return StatusCode::FAILURE;
50  if (!retrieveData(ctx, DcsDataType::HV, DcsTechType::MMD, "A", retrieving_MMD_HV_A).isSuccess()) return StatusCode::FAILURE;
51  if (!retrieveData(ctx, DcsDataType::HV, DcsTechType::MMD, "C", retrieving_MMD_HV_A).isSuccess()) return StatusCode::FAILURE;
52  if (!retrieveData(ctx, DcsDataType::HV, DcsTechType::STG, "A", retrieving_STG_HV_A).isSuccess()) return StatusCode::FAILURE;
53  if (!retrieveData(ctx, DcsDataType::HV, DcsTechType::STG, "C", retrieving_STG_HV_A).isSuccess()) return StatusCode::FAILURE;
54 
55  // postprocess
56  ATH_MSG_INFO("Retrieving time for (MMG, HV, Side A) = "
57  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MMG_HV_A).count() * 0.001) << "s ");
58  ATH_MSG_INFO("Retrieving time for (MMG, HV, Side C) = "
59  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MMG_HV_C).count() * 0.001) << "s ");
60  ATH_MSG_INFO("Retrieving time for (MMD, HV, Side A) = "
61  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MMD_HV_A).count() * 0.001) << "s ");
62  ATH_MSG_INFO("Retrieving time for (MMD, HV, Side C) = "
63  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MMD_HV_C).count() * 0.001) << "s ");
64  ATH_MSG_INFO("Retrieving time for (STG, HV, Side A) = "
65  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_STG_HV_A).count() * 0.001) << "s ");
66  ATH_MSG_INFO("Retrieving time for (STG, HV, Side C) = "
67  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_STG_HV_C).count() * 0.001) << "s ");
68 
69  ATH_MSG_INFO("MADE IT TO THE END!!");
70  return StatusCode::SUCCESS;
71 }
72 
73 // retrieveTdoPdo
74 StatusCode NswDcsTestAlg::retrieveData(const EventContext& ctx, const DcsDataType data, const DcsTechType tech,
75  const std::string& side, std::chrono::duration<double>& timer) const {
76 
77  std::string sdata = data == DcsDataType::HV ? "HV" : "LV"; // for now we will only look at HV, LV not implemented yet
78  std::string stech = tech == DcsTechType::MMG ? "MMG" : (tech == DcsTechType::MMD ? "MMD" : "STG");
79  ATH_MSG_INFO("Starting with " << sdata << " data for " << stech << " and " << side << " at " << timestamp());
81 
82  // Start with an infinte range and narrow it down as needed
83  EventIDRange rangeW = IOVInfiniteRange::infiniteMixed();
84 
85  // Retrieve Data Object
87  const NswDcsDbData* readCdo{*readHandle};
88  if (!readCdo) {
89  ATH_MSG_ERROR("Null pointer to the read conditions object");
90  return StatusCode::FAILURE;
91  }
92 
93  EventIDRange range;
94  if (!readHandle.range(range)) {
95  ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle.key());
96  return StatusCode::FAILURE;
97  }
98 
99  // Intersect validity range of this obj with the validity of already-loaded objs
100  rangeW = EventIDRange::intersect(range, rangeW);
101 
102  // retrieve all channels
103  std::vector<Identifier> channelIds = readCdo->getChannelIdsHv(tech, side);
104  ATH_MSG_INFO("Found data for " << channelIds.size() << " channels!");
105 
106  // retrieve data for the first channel
107  std::stringstream sstr{};
108  if (!channelIds.empty()) {
109  const Identifier& channel = channelIds[0];
110  const NswDcsDbData::DcsConstants& dcs_data = *readCdo->getDataForChannelHv(tech, channel, false);
111  ATH_MSG_INFO("Checking channel 0 (Id = " << channel.get_compact() << ") "<<dcs_data);
112  if (!m_logName.empty()){
113  for (const Identifier& chan_id : channelIds) {
114  const NswDcsDbData::DcsConstants& thedata = *readCdo->getDataForChannelHv(tech, chan_id, false);
115  bool permanentlyDisabled{false};
116  sstr<<m_idHelperSvc->toString(chan_id)<<" "<<thedata<<" "<<readCdo->isGood(ctx, chan_id)<< " " << readCdo->isGoodTDaq(ctx,chan_id, permanentlyDisabled) <<std::endl;
117  }
118  }
119  }
120 
121  if (!m_logName.empty()){
122  std::ofstream ostr{m_logName+"_"+sdata+"_"+stech+"_"+side+".txt"};
123  ostr<<sstr.str()<<std::endl;
124  }
125 
126  ATH_MSG_ALWAYS(sstr.str());
127 
129  timer += end1 - start1;
130  ATH_MSG_INFO("Ending at " << timestamp());
131  return StatusCode::SUCCESS;
132 }
133 
134 std::string NswDcsTestAlg::timestamp() const {
135  const boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
136  const boost::posix_time::time_duration td = now.time_of_day();
137  const long hours = td.hours();
138  const long minutes = td.minutes();
139  const long seconds = td.seconds();
140  const long milliseconds = td.total_milliseconds() - ((hours * 3600 + minutes * 60 + seconds) * 1000);
141  char buf[40];
142  sprintf(buf, "%02ld:%02ld:%02ld.%03ld", hours, minutes, seconds, milliseconds);
143  return buf;
144 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
NswDcsDbData::DcsTechType
DcsTechType
Definition: NswDcsDbData.h:22
NswDcsDbData::DcsTechType::STG
@ STG
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
NswDcsTestAlg::m_readKey
SG::ReadCondHandleKey< NswDcsDbData > m_readKey
Definition: NswDcsTestAlg.h:38
IOVInfiniteRange::infiniteMixed
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Definition: IOVInfiniteRange.h:55
NswDcsTestAlg::NswDcsTestAlg
NswDcsTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: NswDcsTestAlg.cxx:22
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TRT::Hit::side
@ side
Definition: HitInfo.h:83
python.handimod.now
now
Definition: handimod.py:675
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
NswDcsTestAlg::initialize
virtual StatusCode initialize() override
Definition: NswDcsTestAlg.cxx:28
NswDcsDbData::DcsTechType::MMD
@ MMD
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
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_MSG_ALWAYS
#define ATH_MSG_ALWAYS(x)
Definition: AthMsgStreamMacros.h:35
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
NswDcsTestAlg.h
python.LArCalib_HVCorrConfig.seconds
seconds
Definition: LArCalib_HVCorrConfig.py:86
NswDcsDbData::DcsTechType::MMG
@ MMG
IOVInfiniteRange.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MuonCond::DcsDataType
DcsDataType
Definition: MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/MuonCondData/Defs.h:11
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
NswDcsDbData
Definition: NswDcsDbData.h:19
taskman.hours
hours
Definition: taskman.py:650
NswDcsTestAlg::~NswDcsTestAlg
virtual ~NswDcsTestAlg() override
Amg::intersect
std::optional< double > intersect(const AmgVector(N)&posA, const AmgVector(N)&dirA, const AmgVector(N)&posB, const AmgVector(N)&dirB)
Calculates the point of closest approach of two lines.
Definition: GeoPrimitivesHelpers.h:325
NswDcsTestAlg::retrieveData
StatusCode retrieveData(const EventContext &ctx, const DcsDataType data, const DcsTechType tech, const std::string &side, std::chrono::duration< double > &timer) const
Definition: NswDcsTestAlg.cxx:74
NswDcsTestAlg::m_logName
Gaudi::Property< std::string > m_logName
Definition: NswDcsTestAlg.h:44
NswDcsTestAlg::timestamp
std::string timestamp() const
Definition: NswDcsTestAlg.cxx:134
NswDcsTestAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: NswDcsTestAlg.cxx:36
NswDcsTestAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: NswDcsTestAlg.h:42
Identifier
Definition: IdentifierFieldParser.cxx:14