ATLAS Offline Software
MdtCalibFormatAlgTest.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 // constructor
8 MdtCalibFormatAlgTest::MdtCalibFormatAlgTest(const std::string& name, ISvcLocator* pSvcLocator) :
9  AthReentrantAlgorithm(name, pSvcLocator) {}
10 
11 // destructor
13 
14 // initialize
16  ATH_MSG_INFO("Calling initialize");
21  return StatusCode::SUCCESS;
22 }
23 
24 // execute
25 StatusCode MdtCalibFormatAlgTest::execute(const EventContext& ctx) const {
26  ATH_MSG_INFO("Calling execute");
27 
28  // setup parameters
29  std::chrono::duration<double> retrieving_RT_old{};
30  std::chrono::duration<double> retrieving_RT_new{};
31  std::chrono::duration<double> retrieving_T0_old{};
32  std::chrono::duration<double> retrieving_T0_new{};
33 
34  // retrieve all folders
35  if (!retrieve(ctx, "RT", "old", retrieving_RT_old).isSuccess()) return StatusCode::FAILURE;
36  if (!retrieve(ctx, "RT", "new", retrieving_RT_new).isSuccess()) return StatusCode::FAILURE;
37  if (!retrieve(ctx, "T0", "old", retrieving_T0_old).isSuccess()) return StatusCode::FAILURE;
38  if (!retrieve(ctx, "T0", "new", retrieving_T0_new).isSuccess()) return StatusCode::FAILURE;
39 
40  // postprocess
41  ATH_MSG_INFO("Retrieving time for (RT, old) = "
42  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_RT_old).count() * 1.0) << "s ");
43  ATH_MSG_INFO("Retrieving time for (RT, new) = "
44  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_RT_new).count() * 1.0) << "s ");
45  ATH_MSG_INFO("Retrieving time for (T0, old) = "
46  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_T0_old).count() * 1.0) << "s ");
47  ATH_MSG_INFO("Retrieving time for (T0, new) = "
48  << (std::chrono::duration_cast<std::chrono::microseconds>(retrieving_T0_new).count() * 1.0) << "s ");
49 
50  ATH_MSG_INFO("MADE IT TO THE END!!");
51  return StatusCode::SUCCESS;
52 }
53 
54 // finalize
56  ATH_MSG_INFO("Calling finalize");
57  return StatusCode::SUCCESS;
58 }
59 
60 // retrieve
61 StatusCode MdtCalibFormatAlgTest::retrieve(const EventContext& ctx, const std::string& folder, const std::string& setup,
62  std::chrono::duration<double>& timer) const {
63  ATH_MSG_INFO("Starting with " << folder << " and " << setup << " at " << timestamp());
64 
65  // Start with an infinte range and narrow it down as needed
66  EventIDRange rangeW = IOVInfiniteRange::infiniteMixed();
67 
69  if (setup == "new" && folder == "T0")
70  readKey = m_readKey_T0_new;
71  else if (setup == "new" && folder == "RT")
72  readKey = m_readKey_RT_new;
73  else if (setup == "old" && folder == "T0")
74  readKey = m_readKey_T0_old;
75 
76  SG::ReadCondHandle<CondAttrListCollection> readHandle{readKey, ctx};
77  const CondAttrListCollection* readCdo{*readHandle};
78  if (readCdo == nullptr) {
79  ATH_MSG_ERROR("Null pointer to the read conditions object");
80  return StatusCode::FAILURE;
81  }
82 
83  EventIDRange range;
84  if (!readHandle.range(range)) {
85  ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle.key());
86  return StatusCode::FAILURE;
87  }
88 
89  // intersect validity range of this obj with the validity of already-loaded objs
90  rangeW = EventIDRange::intersect(range, rangeW);
91 
92  ATH_MSG_DEBUG("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdo->size()= " << readCdo->size());
93  ATH_MSG_DEBUG("Range of input is " << range << ", range of output is " << rangeW);
94 
96  for (itr = readCdo->begin(); itr != readCdo->end(); ++itr) {
98  const coral::AttributeList& atr = itr->second;
100  timer += end1 - start1;
101  // m_retrieving[folder][setup] += end1-start1;
102 
103  std::string data;
104  if (atr["data"].specification().type() == typeid(coral::Blob)) {
105  ATH_MSG_VERBOSE("Loading data as a BLOB, uncompressing...");
106  if (!CoralUtilities::readBlobAsString(atr["data"].data<coral::Blob>(), data)) {
107  ATH_MSG_FATAL("Cannot uncompress BLOB! Aborting...");
108  return StatusCode::FAILURE;
109  }
110  } else {
111  ATH_MSG_VERBOSE("Loading data as a STRING");
112  data = *(static_cast<const std::string*>((atr["data"]).addressOfData()));
113  }
114 
115  // write it to the buffer to compare it
116  if (processBlob(folder, setup, data).isFailure()) return StatusCode::FAILURE;
117  }
118  ATH_MSG_INFO("Ending at " << timestamp());
119  return StatusCode::SUCCESS;
120 }
121 
122 // processBlob
123 StatusCode MdtCalibFormatAlgTest::processBlob(const std::string& folder, const std::string& setup, const std::string& data) const {
124  // ATH_CHECK( extractString(istr, header, "\n") );
125  // ATH_CHECK( extractString(istr, payload, "\n") );
126  // if( istr.size() ) ATH_CHECK( extractString(istr, trailer, "\n") );
127  ATH_MSG_DEBUG("processing Blob " << folder << "," << setup << "," << data); // leave for now
128  return StatusCode::SUCCESS;
129 }
130 
131 // extractString
132 StatusCode MdtCalibFormatAlgTest::extractString(std::string& input, std::string& output, const std::string& separator) const {
133  /* stolen from here: MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibDbCoolStrTool/src/MdtCalibDbCoolStrTool.cxx */
134  unsigned long int pos = 0;
135  std::string::size_type start = input.find_first_not_of(separator.c_str(), pos);
136  if (start == std::string::npos) {
137  ATH_MSG_ERROR("Cannot extract string in a proper way!");
138  return StatusCode::FAILURE;
139  }
140  std::string::size_type stop = input.find_first_of(separator.c_str(), start + 1);
141  if (stop == std::string::npos) stop = input.size();
142  output = input.substr(start, stop - start);
143  input.erase(pos, stop - pos);
144 
145  return StatusCode::SUCCESS;
146 }
147 
149  const boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
150  const boost::posix_time::time_duration td = now.time_of_day();
151  const long hours = td.hours();
152  const long minutes = td.minutes();
153  const long seconds = td.seconds();
154  const long milliseconds = td.total_milliseconds() - ((hours * 3600 + minutes * 60 + seconds) * 1000);
155  char buf[40];
156  sprintf(buf, "%02ld:%02ld:%02ld.%03ld", hours, minutes, seconds, milliseconds);
157  return buf;
158 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MdtCalibFormatAlgTest::m_readKey_RT_new
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_RT_new
Definition: MdtCalibFormatAlgTest.h:63
MdtCalibFormatAlgTest::initialize
virtual StatusCode initialize() override
Definition: MdtCalibFormatAlgTest.cxx:15
MdtCalibFormatAlgTest::~MdtCalibFormatAlgTest
virtual ~MdtCalibFormatAlgTest() override
Definition: MdtCalibFormatAlgTest.cxx:12
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
IOVInfiniteRange::infiniteMixed
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Definition: IOVInfiniteRange.h:55
MdtCalibFormatAlgTest::MdtCalibFormatAlgTest
MdtCalibFormatAlgTest(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MdtCalibFormatAlgTest.cxx:8
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MdtCalibFormatAlgTest::finalize
virtual StatusCode finalize() override
Definition: MdtCalibFormatAlgTest.cxx:55
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
MdtCalibFormatAlgTest::m_readKey_T0_new
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_T0_new
Definition: MdtCalibFormatAlgTest.h:67
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
MdtCalibFormatAlgTest::execute
virtual StatusCode execute(const EventContext &) const override
Definition: MdtCalibFormatAlgTest.cxx:25
python.handimod.now
now
Definition: handimod.py:675
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MdtCalibFormatAlgTest::extractString
StatusCode extractString(std::string &input, std::string &output, const std::string &separator) const
Definition: MdtCalibFormatAlgTest.cxx:132
CoralUtilities::readBlobAsString
bool readBlobAsString(const coral::Blob &, std::string &)
Definition: blobaccess.cxx:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.LArCalib_HVCorrConfig.seconds
seconds
Definition: LArCalib_HVCorrConfig.py:86
MdtCalibFormatAlgTest::processBlob
StatusCode processBlob(const std::string &, const std::string &, const std::string &) const
Definition: MdtCalibFormatAlgTest.cxx:123
merge.output
output
Definition: merge.py:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
taskman.hours
hours
Definition: taskman.py:650
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
SG::ReadCondHandleKey< CondAttrListCollection >
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
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
MdtCalibFormatAlgTest::m_readKey_RT_old
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_RT_old
Definition: MdtCalibFormatAlgTest.h:61
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
MdtCalibFormatAlgTest::m_readKey_T0_old
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_T0_old
Definition: MdtCalibFormatAlgTest.h:65
setup
bool setup(asg::AnaToolHandle< Interface > &tool, const std::string &type)
mostly useful for athena, which will otherwise re-use the previous tool
Definition: fbtTestBasics.cxx:193
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
MdtCalibFormatAlgTest::timestamp
static std::string timestamp()
Definition: MdtCalibFormatAlgTest.cxx:148
MdtCalibFormatAlgTest.h
MdtCalibFormatAlgTest::retrieve
StatusCode retrieve(const EventContext &, const std::string &, const std::string &, std::chrono::duration< double > &) const
Definition: MdtCalibFormatAlgTest.cxx:61