ATLAS Offline Software
Loading...
Searching...
No Matches
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 <chrono>
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
24NswPassivationTestAlg::NswPassivationTestAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
25
26// destructor
28
29// initialize
31 ATH_MSG_INFO("Calling initialize");
32 ATH_CHECK(m_readKey.initialize());
33 ATH_CHECK(m_idHelperSvc.retrieve());
34 return StatusCode::SUCCESS;
35}
36
37// execute
38StatusCode 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
55StatusCode NswPassivationTestAlg::retrieve(const EventContext& ctx, std::chrono::duration<double>& timer) const {
56 ATH_MSG_INFO("Starting retrieval " << timestamp());
57 auto start1 = std::chrono::high_resolution_clock::now();
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];
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
102 auto end1 = std::chrono::high_resolution_clock::now();
103 timer += end1 - start1;
104 ATH_MSG_INFO("Ending at " << timestamp());
105 return StatusCode::SUCCESS;
106}
107
109 auto now = std::chrono::system_clock::now();
110 std::time_t time_now = std::chrono::system_clock::to_time_t(now);
111 std::tm local_tm;
112 localtime_r(&time_now, &local_tm);
113 auto duration_since_epoch = now.time_since_epoch();
114 auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(duration_since_epoch) % 1000;
115 std::ostringstream oss;
116 oss << std::put_time(&local_tm, "%H:%M:%S") << '.' << std::setw(3) << std::setfill('0') << milliseconds.count();
117 return oss.str();
118}
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
An algorithm that can be simultaneously executed in multiple threads.
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
std::vector< Identifier > getChannelIds() const
const PCBPassivation & getPassivation(const Identifier &id) const
virtual StatusCode execute(const EventContext &) const override
virtual ~NswPassivationTestAlg() override
NswPassivationTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode retrieve(const EventContext &, std::chrono::duration< double > &) const
SG::ReadCondHandleKey< NswPassivationDbData > m_readKey
virtual StatusCode initialize() override
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
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
Helper struct to save the four passivation values of each PCB.