ATLAS Offline Software
Loading...
Searching...
No Matches
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
9#include "CoralBase/Blob.h"
10#include <string_view>
11
12TgcDigitTimeOffsetCondAlg::TgcDigitTimeOffsetCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
13: AthCondAlgorithm(name, pSvcLocator) {
14}
15
17 ATH_MSG_DEBUG("initialize " << name());
18 ATH_CHECK(m_readKey.initialize());
19 ATH_CHECK(m_writeKey.initialize());
20 return StatusCode::SUCCESS;
21}
22
23StatusCode 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;
61 uint16_t station_eta = CxxUtils::atoi(*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();
72 tokens = CxxUtils::tokenize(strwire, delimiter);
73 it = std::begin(tokens);
74 station_number = CxxUtils::atoi(*it);
75 ++it;
76 station_eta = CxxUtils::atoi(*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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
Base class for conditions algorithms.
bool range(EventIDRange &r)
const std::string & key() const
const DataObjID & fullKey() const
const_pointer_type cptr()
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
TgcDigitTimeOffsetCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteCondHandleKey< TgcDigitTimeOffsetData > m_writeKey
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
double atof(std::string_view str)
Converts a string into a double / float.
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...