ATLAS Offline Software
NswPassivationTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
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 <fstream>
14 #include <sstream>
15 #include <vector>
16 
17 // Gaudi and Athena
19 #include "CoralBase/Blob.h"
21 #include "Identifier/Identifier.h"
22 
23 // constructor
24 NswPassivationTestAlg::NswPassivationTestAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
25 
26 // destructor
28 
29 // initialize
31  ATH_MSG_INFO("Calling initialize");
33  ATH_CHECK(m_idHelperSvc.retrieve());
34  return StatusCode::SUCCESS;
35 }
36 
37 // execute
38 StatusCode NswPassivationTestAlg::execute(const EventContext& ctx) const {
39  ATH_MSG_INFO("Calling execute");
40 
41  // setup parameters
42  std::chrono::duration<double> retrieving{};
43 
44  // retrieve all folders
45  if (!retrieve(ctx, retrieving).isSuccess()) return StatusCode::FAILURE;
46 
47  // postprocess
48  ATH_MSG_INFO("Retrieving time = " << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving).count() * 1.0) << "s ");
49 
50  ATH_MSG_INFO("MADE IT TO THE END!!");
51  return StatusCode::SUCCESS;
52 }
53 
54 // retrieveVmm
55 StatusCode NswPassivationTestAlg::retrieve(const EventContext& ctx, std::chrono::duration<double>& timer) const {
56  ATH_MSG_INFO("Starting retrieval " << timestamp());
58 
59  // Start with an infinte range and narrow it down as needed
60  EventIDRange rangeW = IOVInfiniteRange::infiniteMixed();
61 
62  // Retrieve Data Object
64  const NswPassivationDbData* readCdo{*readHandle};
65  if (!readCdo) {
66  ATH_MSG_ERROR("Null pointer to the read conditions object");
67  return StatusCode::FAILURE;
68  }
69 
70  EventIDRange range;
71  if (!readHandle.range(range)) {
72  ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle.key());
73  return StatusCode::FAILURE;
74  }
75 
76  // Intersect validity range of this obj with the validity of already-loaded objs
77  rangeW = EventIDRange::intersect(range, rangeW);
78 
79  // retrieve all channels
80  std::vector<Identifier> channelIds = readCdo->getChannelIds();
81  ATH_MSG_INFO("Found data for " << channelIds.size() << " channels!");
82  ATH_MSG_INFO("Going to display passivation params for all channels (left, right, top, bottom)");
83 
84  std::ofstream fout;
85  fout.open("passivationDump.txt");
86  fout << "athenaId,PCB,stationName,stationEta,stationPhi,multiLayer,gasGap,left,right,top,bottom\n";
87 
88  // retrieve data for the first channel
89  for(unsigned int i=0; i<channelIds.size(); ++i){
90  const Identifier& channel = channelIds[i];
91  NswPassivationDbData::PCBPassivation passiv = readCdo->getPassivation(channel);
92  int eta = m_idHelperSvc->mmIdHelper().stationEta(channel);
93  int chnl = m_idHelperSvc->mmIdHelper().channel (channel);
94  int pcb = (chnl-1)/1024+1; // int division should round downwards
95  if(std::abs(eta)>1) pcb+=5;
96  ATH_MSG_INFO("Board "<<i<<" ("<<channel.get_compact()<<"): "<<passiv.left<<", "<<passiv.right<<", "<<passiv.top<<", "<<passiv.bottom);
97  fout << channel.get_compact()<<","<<pcb<<","<<m_idHelperSvc->toString(channel)<<","<<passiv.left<<","<<passiv.right<<","<<passiv.top<<","<<passiv.bottom<<std::endl;
98  }
99 
100  fout.close();
101 
103  timer += end1 - start1;
104  ATH_MSG_INFO("Ending at " << timestamp());
105  return StatusCode::SUCCESS;
106 }
107 
108 std::string NswPassivationTestAlg::timestamp() const {
109  const boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
110  const boost::posix_time::time_duration td = now.time_of_day();
111  const long hours = td.hours();
112  const long minutes = td.minutes();
113  const long seconds = td.seconds();
114  const long milliseconds = td.total_milliseconds() - ((hours * 3600 + minutes * 60 + seconds) * 1000);
115  char buf[40];
116  sprintf(buf, "%02ld:%02ld:%02ld.%03ld", hours, minutes, seconds, milliseconds);
117  return buf;
118 }
NswPassivationTestAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: NswPassivationTestAlg.cxx:38
NswPassivationTestAlg.h
NswPassivationTestAlg::NswPassivationTestAlg
NswPassivationTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: NswPassivationTestAlg.cxx:24
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
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
NswPassivationTestAlg::retrieve
StatusCode retrieve(const EventContext &, std::chrono::duration< double > &) const
Definition: NswPassivationTestAlg.cxx:55
IOVInfiniteRange::infiniteMixed
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Definition: IOVInfiniteRange.h:55
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
NswPassivationDbData::PCBPassivation
Helper struct to save the four passivation values of each PCB.
Definition: NswPassivationDbData.h:24
python.handimod.now
now
Definition: handimod.py:675
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
NswPassivationDbData
Definition: NswPassivationDbData.h:20
lumiFormat.i
int i
Definition: lumiFormat.py:85
dqt_zlumi_alleff_HIST.fout
fout
Definition: dqt_zlumi_alleff_HIST.py:59
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
NswPassivationTestAlg::~NswPassivationTestAlg
virtual ~NswPassivationTestAlg() override
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
NswPassivationDbData::PCBPassivation::bottom
double bottom
Definition: NswPassivationDbData.h:28
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.LArCalib_HVCorrConfig.seconds
seconds
Definition: LArCalib_HVCorrConfig.py:86
IOVInfiniteRange.h
NswPassivationDbData::PCBPassivation::top
double top
Definition: NswPassivationDbData.h:27
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
NswPassivationTestAlg::initialize
virtual StatusCode initialize() override
Definition: NswPassivationTestAlg.cxx:30
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
taskman.hours
hours
Definition: taskman.py:650
NswPassivationTestAlg::timestamp
std::string timestamp() const
Definition: NswPassivationTestAlg.cxx:108
blobaccess.h
NswPassivationTestAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: NswPassivationTestAlg.h:34
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 B' along the line B that's closest to a second line A.
Definition: GeoPrimitivesHelpers.h:347
NswPassivationDbData::PCBPassivation::right
double right
Definition: NswPassivationDbData.h:26
NswPassivationTestAlg::m_readKey
SG::ReadCondHandleKey< NswPassivationDbData > m_readKey
Definition: NswPassivationTestAlg.h:31
NswPassivationDbData::PCBPassivation::left
double left
Definition: NswPassivationDbData.h:25
Identifier
Definition: IdentifierFieldParser.cxx:14