ATLAS Offline Software
TgcDigitTimeOffsetCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "CxxUtils/StringUtils.h"
9 #include "CoralBase/Blob.h"
10 #include <string_view>
11 
12 TgcDigitTimeOffsetCondAlg::TgcDigitTimeOffsetCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
13 : AthReentrantAlgorithm(name, pSvcLocator) {
14 }
15 
17  ATH_MSG_DEBUG("initialize " << name());
20  return StatusCode::SUCCESS;
21 }
22 
23 StatusCode TgcDigitTimeOffsetCondAlg::execute(const EventContext& ctx) const {
25  if (writeHandle.isValid()) {
26  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
27  << ". In theory this should not be called, but may happen"
28  << " if multiple concurrent events are being processed out of order.");
29  return StatusCode::SUCCESS;
30  }
32  if (readHandle_TOffset.cptr() == nullptr) {
33  ATH_MSG_ERROR("Null pointer to the read conditions object");
34  return StatusCode::FAILURE;
35  }
36  ATH_MSG_DEBUG("Size of CondAttrListCollection" << readHandle_TOffset.fullKey() << " = " << readHandle_TOffset->size());
37  EventIDRange rangeW_TOffset;
38  if (!readHandle_TOffset.range(rangeW_TOffset)) {
39  ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle_TOffset.key());
40  return StatusCode::FAILURE;
41  }
42  ATH_MSG_DEBUG("Range of input is " << rangeW_TOffset);
43 
44  // write condition object
45  EventIDRange rangeIntersection = EventIDRange::intersect(rangeW_TOffset);
46  if(rangeIntersection.start()>rangeIntersection.stop()) {
47  ATH_MSG_ERROR("Invalid intersection range: " << rangeIntersection);
48  return StatusCode::FAILURE;
49  }
50  // Fill
51  auto outputCdo = std::make_unique<TgcDigitTimeOffsetData>();
52  constexpr std::string_view delimiter{";"};
53  for (const auto &[channel, attribute] : *readHandle_TOffset.cptr()) {
54  const coral::Blob& blob_strip = attribute["bTimeOffset_strip"].data<coral::Blob>();
55  const std::string strstrip{static_cast<const char*>(blob_strip.startingAddress())};
56 
57  std::vector<std::string> tokens = CxxUtils::tokenize(strstrip, delimiter);
58  auto it = std::begin(tokens);
59  uint16_t station_number = CxxUtils::atoi(*it);
60  ++it;
62  ++it;
63  float offset_strip = CxxUtils::atof(*it);
64  ++it;
65  uint16_t chamberId = (station_number << 3) + station_eta;
66  outputCdo->stripOffset.emplace(chamberId, offset_strip);
67 
68  const coral::Blob& blob_wire = attribute["bTimeOffset_wire"].data<coral::Blob>();
69  const std::string strwire{static_cast<const char*>(blob_wire.startingAddress())};
70 
71  tokens.clear();
73  it = std::begin(tokens);
74  station_number = CxxUtils::atoi(*it);
75  ++it;
77  ++it;
78  float offset_wire = CxxUtils::atof(*it);
79  ++it;
80  chamberId = (station_number << 3) + station_eta;
81  outputCdo->wireOffset.emplace(chamberId, offset_wire);
82  } // end of for(attrmap)
83 
84  // Record
85  if (writeHandle.record(rangeIntersection, std::move(outputCdo)).isFailure()) {
86  ATH_MSG_FATAL("Could not record TgcDigitTimeOffsetData " << writeHandle.key()
87  << " with EventRange " << rangeIntersection
88  << " into Conditions Store");
89  return StatusCode::FAILURE;
90  }
91  ATH_MSG_DEBUG("recorded new " << writeHandle.key() << " with range " << rangeIntersection << " into Conditions Store");
92 
93  return StatusCode::SUCCESS;
94 }
95 
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
CxxUtils::tokenize
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
Definition: Control/CxxUtils/Root/StringUtils.cxx:15
TgcDigitTimeOffsetCondAlg::m_writeKey
SG::WriteCondHandleKey< TgcDigitTimeOffsetData > m_writeKey
Definition: TgcDigitTimeOffsetCondAlg.h:25
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:423
StringUtils.h
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
ReadCondHandle.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TgcDigitTimeOffsetCondAlg.h
TgcDigitTimeOffsetCondAlg::initialize
virtual StatusCode initialize() override
Definition: TgcDigitTimeOffsetCondAlg.cxx:16
python.AthDsoLogger.delimiter
delimiter
Definition: AthDsoLogger.py:71
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
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
WriteCondHandle.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TgcDigitTimeOffsetCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TgcDigitTimeOffsetCondAlg.cxx:23
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TgcDigitTimeOffsetCondAlg::m_readKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Definition: TgcDigitTimeOffsetCondAlg.h:24
CalibCoolCompareRT.station_eta
station_eta
Definition: CalibCoolCompareRT.py:88
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
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
TgcDigitTimeOffsetCondAlg::TgcDigitTimeOffsetCondAlg
TgcDigitTimeOffsetCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TgcDigitTimeOffsetCondAlg.cxx:12
SG::WriteCondHandle
Definition: WriteCondHandle.h:26