ATLAS Offline Software
NswCondTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "NswCondTestAlg.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 
17 
18 // Gaudi and Athena
20 #include "CoralBase/Blob.h"
22 #include "GaudiKernel/StatusCode.h"
23 #include "Identifier/Identifier.h"
24 
25 // constructor
26 NswCondTestAlg::NswCondTestAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
27 
28 // destructor
30 
31 // initialize
33  ATH_MSG_INFO("Calling initialize");
37  ATH_CHECK(m_idHelperSvc.retrieve());
38  return StatusCode::SUCCESS;
39 }
40 
41 // execute
42 StatusCode NswCondTestAlg::execute(const EventContext& ctx) const {
43  ATH_MSG_INFO("Calling execute");
44 
45  // setup parameters
46  std::chrono::duration<double> retrieving_MM_TDO_A{};
47  std::chrono::duration<double> retrieving_MM_TDO_C{};
48  std::chrono::duration<double> retrieving_MM_PDO_A{};
49  std::chrono::duration<double> retrieving_MM_PDO_C{};
50  std::chrono::duration<double> retrieving_MM_VMM_A{};
51  std::chrono::duration<double> retrieving_MM_VMM_C{};
52  std::chrono::duration<double> retrieving_STGC_TDO_A{};
53  std::chrono::duration<double> retrieving_STGC_TDO_C{};
54  std::chrono::duration<double> retrieving_STGC_PDO_A{};
55  std::chrono::duration<double> retrieving_STGC_PDO_C{};
56  std::chrono::duration<double> retrieving_STGC_VMM_A{};
57  std::chrono::duration<double> retrieving_STGC_VMM_C{};
58  std::chrono::duration<double> retrieving_T0{};
59 
60  // retrieve all folders
61  ATH_CHECK(retrieveTdoPdo(ctx, TimeChargeType::PDO, "MM", "A", retrieving_MM_PDO_A));
62  ATH_CHECK(retrieveTdoPdo(ctx, TimeChargeType::PDO, "MM", "C", retrieving_MM_PDO_C));
63  ATH_CHECK(retrieveTdoPdo(ctx, TimeChargeType::TDO, "MM", "A", retrieving_MM_TDO_A));
64  ATH_CHECK(retrieveTdoPdo(ctx, TimeChargeType::TDO, "MM", "C", retrieving_MM_TDO_C));
65  if(m_isMC) ATH_CHECK(retrieveVmm(ctx, "MM", "A", retrieving_MM_VMM_A));
66  if(m_isMC) ATH_CHECK(retrieveVmm(ctx, "MM", "C", retrieving_MM_VMM_C));
67  ATH_CHECK(retrieveTdoPdo(ctx, TimeChargeType::TDO, "STGC", "A", retrieving_STGC_TDO_A));
68  ATH_CHECK(retrieveTdoPdo(ctx, TimeChargeType::TDO, "STGC", "C", retrieving_STGC_TDO_C));
69  ATH_CHECK(retrieveTdoPdo(ctx, TimeChargeType::PDO, "STGC", "A", retrieving_STGC_PDO_A));
70  ATH_CHECK(retrieveTdoPdo(ctx, TimeChargeType::PDO, "STGC", "C", retrieving_STGC_PDO_C));
71  if(m_isMC) ATH_CHECK(retrieveVmm(ctx, "STGC", "A", retrieving_STGC_VMM_A));
72  if(m_isMC) ATH_CHECK(retrieveVmm(ctx, "STGC", "C", retrieving_STGC_VMM_C));
73  if(!m_isMC) ATH_CHECK(retrieveT0(ctx,retrieving_T0));
74 
75  // postprocess
76  ATH_MSG_INFO("Retrieving time for (MM , TDO, Side A) = "
77  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MM_TDO_A).count() * 1.0) << "s ");
78  ATH_MSG_INFO("Retrieving time for (MM , TDO, Side C) = "
79  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MM_TDO_C).count() * 1.0) << "s ");
80  ATH_MSG_INFO("Retrieving time for (MM , PDO, Side A) = "
81  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MM_PDO_A).count() * 1.0) << "s ");
82  ATH_MSG_INFO("Retrieving time for (MM , PDO, Side C) = "
83  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MM_PDO_C).count() * 1.0) << "s ");
84  if(m_isMC){
85  ATH_MSG_INFO("Retrieving time for (MM , VMM, Side A) = "
86  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MM_VMM_A).count() * 1.0) << "s ");
87  ATH_MSG_INFO("Retrieving time for (MM , VMM, Side C) = "
88  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_MM_VMM_C).count() * 1.0) << "s ");
89  }
90 
91  ATH_MSG_INFO("Retrieving time for (STGC, TDO, Side A) = "
92  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_STGC_TDO_A).count() * 1.0) << "s ");
93  ATH_MSG_INFO("Retrieving time for (STGC, TDO, Side C) = "
94  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_STGC_TDO_C).count() * 1.0) << "s ");
95  ATH_MSG_INFO("Retrieving time for (STGC, PDO, Side A) = "
96  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_STGC_PDO_A).count() * 1.0) << "s ");
97  ATH_MSG_INFO("Retrieving time for (STGC, PDO, Side C) = "
98  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_STGC_PDO_C).count() * 1.0) << "s ");
99  if(m_isMC) {
100  ATH_MSG_INFO("Retrieving time for (STGC, VMM, Side A) = "
101  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_STGC_VMM_A).count() * 1.0) << "s ");
102  ATH_MSG_INFO("Retrieving time for (STGC, VMM, Side C) = "
103  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_STGC_VMM_C).count() * 1.0) << "s ");
104  }
105 
106  if(!m_isMC){
107  ATH_MSG_INFO("retrieving time for T0 for NSW = "
108  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_T0).count() * 1.0) << "s ");
109  }
110 
111  ATH_MSG_INFO("MADE IT TO THE END!!");
112  return StatusCode::SUCCESS;
113 }
114 
115 // retrieveTdoPdo
116 StatusCode NswCondTestAlg::retrieveTdoPdo(const EventContext& ctx, TimeChargeType data, const std::string& tech,
117  const std::string& side, std::chrono::duration<double>& timer) const {
118  ATH_MSG_INFO("Starting with " << " data for " << tech << " and " << side << " at " << timestamp());
120 
121  // Start with an infinte range and narrow it down as needed
122  EventIDRange rangeW = IOVInfiniteRange::infiniteMixed();
123 
124  // Retrieve Data Object
126  const NswCalibDbTimeChargeData* readCdo{*readHandle};
127  if (!readCdo) {
128  ATH_MSG_ERROR("Null pointer to the read conditions object");
129  return StatusCode::FAILURE;
130  }
131 
132  EventIDRange range;
133  if (!readHandle.range(range)) {
134  ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle.key());
135  return StatusCode::FAILURE;
136  }
137 
138  // Intersect validity range of this obj with the validity of already-loaded objs
139  rangeW = EventIDRange::intersect(range, rangeW);
140 
141  // retrieve all channels
142  std::vector<Identifier> channelIds = readCdo->getChannelIds(data, tech, side);
143  ATH_MSG_INFO("Found data for " << channelIds.size() << " channels!");
144 
145  // retrieve data for the first channel
146  std::stringstream sstr{};
147  if (!channelIds.empty()) {
148  const Identifier& channel = channelIds[0];
149 
150  const NswCalibDbTimeChargeData::CalibConstants& calib_data = *readCdo->getCalibForChannel(data, channel);
151  ATH_MSG_INFO("Checking channel 0 (Id = " << channel.get_compact() << ") "<<calib_data);
152  if (!m_logName.empty()){
153  for (const Identifier& chan_id : channelIds) {
154  const NswCalibDbTimeChargeData::CalibConstants& calib_data = *readCdo->getCalibForChannel(data, chan_id);
155  sstr<<m_idHelperSvc->toString(chan_id)<<" "<<calib_data<<std::endl;
156  }
157  }
158  } else if (!m_logName.empty()) {
159  const NswCalibDbTimeChargeData::CalibConstants& calib_data = *readCdo->getZeroCalibChannel(data, tech == "MM" ? TimeTech::MM : TimeTech::STGC);
160  sstr<<"Dummy calib channel "<<calib_data<<std::endl;
161  }
162 
163  if (!m_logName.empty()){
164  std::ofstream ostr{m_logName+"_"+ (data == TimeChargeType::TDO ? "TDO" : "PDO") + "_"+tech+side+".txt"};
165  ostr<<sstr.str()<<std::endl;
166  }
167 
168  ATH_MSG_ALWAYS(sstr.str());
169 
171  timer += end1 - start1;
172  ATH_MSG_INFO("Ending at " << timestamp());
173  return StatusCode::SUCCESS;
174 }
175 
176 // retrieveVmm
177 StatusCode NswCondTestAlg::retrieveVmm(const EventContext& ctx, const std::string& tech, const std::string& side,
178  std::chrono::duration<double>& timer) const {
179  ATH_MSG_INFO("Starting with VMM data for " << tech << " and " << side << " at " << timestamp());
181 
182  // Start with an infinte range and narrow it down as needed
183  EventIDRange rangeW = IOVInfiniteRange::infiniteMixed();
184 
185  // Retrieve Data Object
187  const NswCalibDbThresholdData* readCdo{*readHandle};
188  if (!readCdo) {
189  ATH_MSG_ERROR("Null pointer to the read conditions object");
190  return StatusCode::FAILURE;
191  }
192 
193  EventIDRange range;
194  if (!readHandle.range(range)) {
195  ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle.key());
196  return StatusCode::FAILURE;
197  }
198 
199  // Intersect validity range of this obj with the validity of already-loaded objs
200  rangeW = EventIDRange::intersect(range, rangeW);
201 
202  // retrieve all channels
203  std::vector<Identifier> channelIds = readCdo->getChannelIds(tech, side);
204  ATH_MSG_INFO("Found data for " << channelIds.size() << " channels!");
205 
206  // retrieve data for the first channel
207  std::stringstream sstr {};
208  if (!channelIds.empty()) {
209  const Identifier& channel = channelIds[0];
210  float threshold{0.};
211  readCdo->getThreshold(channel, threshold);
212  ATH_MSG_INFO("Checking channel 0 (Id = " << m_idHelperSvc->toString(channel)<< ") threshold "<< threshold);
213  if (!m_logName.empty()){
214  for (const Identifier& id : channelIds){
215  sstr<<m_idHelperSvc->toString(id)<<" threshold "<<threshold<<std::endl;
216  }
217  }
218  }
219  if (!m_logName.empty()){
220  std::ofstream ostr{m_logName+"_THRESH_"+tech+side+".txt"};
221  ostr<<sstr.str()<<std::endl;
222  }
223 
225  timer += end1 - start1;
226  ATH_MSG_INFO("Ending at " << timestamp());
227  return StatusCode::SUCCESS;
228 }
229 
230 // retrieve T0
231 StatusCode NswCondTestAlg::retrieveT0(const EventContext& ctx,
232  std::chrono::duration<double>& timer) const {
233  ATH_MSG_INFO("Starting to retrieve T0 values at " << timestamp());
235 
236  // Start with an infinte range and narrow it down as needed
237  EventIDRange rangeW = IOVInfiniteRange::infiniteMixed();
238 
239  // Retrieve Data Object
241  const NswT0Data* readCdo{*readHandle};
242  if (!readCdo) {
243  ATH_MSG_ERROR("Null pointer to the read conditions object");
244  return StatusCode::FAILURE;
245  }
246 
247  EventIDRange range;
248  if (!readHandle.range(range)) {
249  ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle.key());
250  return StatusCode::FAILURE;
251  }
252 
253  // Intersect validity range of this obj with the validity of already-loaded objs
254  rangeW = EventIDRange::intersect(range, rangeW);
255 
256  std::stringstream sstr {};
257  const MmIdHelper& id_helper = m_idHelperSvc->mmIdHelper();
258  auto it = id_helper.detectorElement_begin();
259  for(; it!= id_helper.detectorElement_end(); it++){
260  for(int i_layer=id_helper.gasGapMin(*it); i_layer <= id_helper.gasGapMax(*it); i_layer++){
261  Identifier layerId = id_helper.channelID(*it,id_helper.multilayer(*it), i_layer,1);
262  for(int i_channel=id_helper.channelMin(layerId); i_channel < id_helper.channelMax(layerId); i_channel++){
263  Identifier channelId = id_helper.channelID(layerId,id_helper.multilayer(*it), i_layer, i_channel);
264  float t0{0};
265  if(!readCdo->getT0(channelId, t0)){
266  ATH_MSG_ERROR("Failed to retrieve t0 calibration for channel"<< m_idHelperSvc->toString(channelId));
267  return StatusCode::FAILURE;
268  }
269  if (!m_logName.empty()){
270  sstr<<m_idHelperSvc->toString(channelId)<<" T0 "<< t0 <<std::endl;
271  }
272  }
273  }
274  }
275 
276  if (!m_logName.empty()){
277  std::ofstream ostr{m_logName+"_T0.txt"};
278  ostr<<sstr.str()<<std::endl;
279  }
280 
282  timer += end1 - start1;
283  ATH_MSG_INFO("Ending at " << timestamp());
284  return StatusCode::SUCCESS;
285 }
286 
287 std::string NswCondTestAlg::timestamp() const {
288  const boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
289  const boost::posix_time::time_duration td = now.time_of_day();
290  const long hours = td.hours();
291  const long minutes = td.minutes();
292  const long seconds = td.seconds();
293  const long milliseconds = td.total_milliseconds() - ((hours * 3600 + minutes * 60 + seconds) * 1000);
294  char buf[40];
295  sprintf(buf, "%02ld:%02ld:%02ld.%03ld", hours, minutes, seconds, milliseconds);
296  return buf;
297 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
NswCalibDbThresholdData
Definition: NswCalibDbThresholdData.h:21
NswCalibDbTimeChargeData::CalibConstants
Helper struct to cache all calibration constants in a common place of the memory.
Definition: NswCalibDbTimeChargeData.h:28
MuonIdHelper::detectorElement_begin
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
Definition: MuonIdHelper.cxx:762
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
NswCalibDbTimeChargeData::CalibDataType::PDO
@ PDO
MmIdHelper::channelMax
static int channelMax()
Definition: MmIdHelper.cxx:831
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
IOVInfiniteRange::infiniteMixed
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Definition: IOVInfiniteRange.h:55
skel.it
it
Definition: skel.GENtoEVGEN.py:423
NswCondTestAlg::initialize
virtual StatusCode initialize() override
Definition: NswCondTestAlg.cxx:32
MuonIdHelper::detectorElement_end
const_id_iterator detectorElement_end() const
Definition: MuonIdHelper.cxx:764
NswCalibDbTimeChargeData::CalibDataType
CalibDataType
Definition: NswCalibDbTimeChargeData.h:22
NswCondTestAlg::m_logName
Gaudi::Property< std::string > m_logName
Definition: NswCondTestAlg.h:53
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
NswCondTestAlg::~NswCondTestAlg
virtual ~NswCondTestAlg() override
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MmIdHelper::multilayer
int multilayer(const Identifier &id) const
Definition: MmIdHelper.cxx:796
TRT::Hit::side
@ side
Definition: HitInfo.h:83
NswCondTestAlg::timestamp
std::string timestamp() const
Definition: NswCondTestAlg.cxx:287
python.handimod.now
now
Definition: handimod.py:675
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
NswCondTestAlg.h
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
NswT0Data
Definition: NswT0Data.h:16
MmIdHelper::gasGapMax
static int gasGapMax()
Definition: MmIdHelper.cxx:827
ATH_MSG_ALWAYS
#define ATH_MSG_ALWAYS(x)
Definition: AthMsgStreamMacros.h:35
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
NswCalibDbTimeChargeData::CalibDataType::TDO
@ TDO
python.LArCalib_HVCorrConfig.seconds
seconds
Definition: LArCalib_HVCorrConfig.py:86
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
IOVInfiniteRange.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
threshold
Definition: chainparser.cxx:74
NswCondTestAlg::retrieveTdoPdo
StatusCode retrieveTdoPdo(const EventContext &ctx, TimeChargeType data, const std::string &tech, const std::string &side, std::chrono::duration< double > &timer) const
Definition: NswCondTestAlg.cxx:116
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
NswCondTestAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: NswCondTestAlg.h:51
taskman.hours
hours
Definition: taskman.py:650
NswCondTestAlg::m_readKey_t0
SG::ReadCondHandleKey< NswT0Data > m_readKey_t0
Definition: NswCondTestAlg.h:49
MuonCond::CalibTechType::STGC
@ STGC
NswCondTestAlg::retrieveT0
StatusCode retrieveT0(const EventContext &, std::chrono::duration< double > &) const
Definition: NswCondTestAlg.cxx:231
NswCondTestAlg::m_readKey_vmm
SG::ReadCondHandleKey< NswCalibDbThresholdData > m_readKey_vmm
Definition: NswCondTestAlg.h:46
MmIdHelper
Definition: MmIdHelper.h:54
blobaccess.h
Amg::intersect
std::optional< double > intersect(const AmgVector(N)&posA, const AmgVector(N)&dirA, const AmgVector(N)&posB, const AmgVector(N)&dirB)
Calculates the closest approach of two lines.
Definition: GeoPrimitivesHelpers.h:302
MmIdHelper::channelMin
static int channelMin()
Definition: MmIdHelper.cxx:829
NswCondTestAlg::m_isMC
Gaudi::Property< bool > m_isMC
Definition: NswCondTestAlg.h:54
NswCondTestAlg::retrieveVmm
StatusCode retrieveVmm(const EventContext &, const std::string &, const std::string &, std::chrono::duration< double > &) const
Definition: NswCondTestAlg.cxx:177
NswCalibDbTimeChargeData
Definition: NswCalibDbTimeChargeData.h:19
NswCondTestAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: NswCondTestAlg.cxx:42
MmIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channel) const
Definition: MmIdHelper.cxx:736
NswCondTestAlg::NswCondTestAlg
NswCondTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: NswCondTestAlg.cxx:26
MuonCond::CalibTechType::MM
@ MM
NswCondTestAlg::m_readKey_tdopdo
SG::ReadCondHandleKey< NswCalibDbTimeChargeData > m_readKey_tdopdo
Definition: NswCondTestAlg.h:43
MmIdHelper::gasGapMin
static int gasGapMin()
Definition: MmIdHelper.cxx:815