ATLAS Offline Software
Loading...
Searching...
No Matches
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 <chrono>
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
22NswDcsTestAlg::NswDcsTestAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
23
24// destructor
26
27// initialize
29 ATH_MSG_INFO("Calling initialize");
30 ATH_CHECK(m_readKey.initialize());
31 ATH_CHECK(m_idHelperSvc.retrieve());
32 return StatusCode::SUCCESS;
33}
34
35// execute
36StatusCode 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
74StatusCode 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());
80 auto start1 = std::chrono::high_resolution_clock::now();
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
128 auto end1 = std::chrono::high_resolution_clock::now();
129 timer += end1 - start1;
130 ATH_MSG_INFO("Ending at " << timestamp());
131 return StatusCode::SUCCESS;
132}
133
134std::string NswDcsTestAlg::timestamp() const {
135 auto now = std::chrono::system_clock::now();
136 std::time_t time_now = std::chrono::system_clock::to_time_t(now);
137 std::tm local_tm;
138 localtime_r(&time_now, &local_tm);
139 auto duration_since_epoch = now.time_since_epoch();
140 auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(duration_since_epoch) % 1000;
141 std::ostringstream oss;
142 oss << std::put_time(&local_tm, "%H:%M:%S") << '.' << std::setw(3) << std::setfill('0') << milliseconds.count();
143 return oss.str();
144}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_ALWAYS(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
An algorithm that can be simultaneously executed in multiple threads.
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
MuonCond::DcsConstants DcsConstants
const DcsConstants * getDataForChannelHv(const DcsTechType tech, const Identifier &channelId, bool issTgcQ1OuterHv) const
Retrieves the calibration constant for a particular readout channel.
bool isGood(const EventContext &ctx, const Identifier &channelId, bool issTgcQ1OuterHv=false) const
Returns whether the channel is alive, i.e. DCS state on, etc...
std::vector< Identifier > getChannelIdsHv(const DcsTechType tech, const std::string &side) const
bool isGoodTDaq(const EventContext &ctx, const Identifier &channelId, bool &permanentlyDisabled) const
StatusCode retrieveData(const EventContext &ctx, const DcsDataType data, const DcsTechType tech, const std::string &side, std::chrono::duration< double > &timer) const
SG::ReadCondHandleKey< NswDcsDbData > m_readKey
virtual ~NswDcsTestAlg() override
NswDcsTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
NswDcsDbData::DcsTechType DcsTechType
std::string timestamp() const
virtual StatusCode execute(const EventContext &) const override
NswDcsDbData::DcsDataType DcsDataType
virtual StatusCode initialize() override
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Gaudi::Property< std::string > m_logName
bool range(EventIDRange &r)
const std::string & key() const
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146