ATLAS Offline Software
Loading...
Searching...
No Matches
TgcDigitCrosstalkCondAlg.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
12TgcDigitCrosstalkCondAlg::TgcDigitCrosstalkCondAlg(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 TgcDigitCrosstalkCondAlg::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_XTalk.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_XTalk.fullKey() << " = " << readHandle_XTalk->size());
37 EventIDRange rangeW_XTalk;
38 if (!readHandle_XTalk.range(rangeW_XTalk)) {
39 ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle_XTalk.key());
40 return StatusCode::FAILURE;
41 }
42 ATH_MSG_DEBUG("Range of input is " << rangeW_XTalk);
43
44 // write condition object
45 EventIDRange rangeIntersection = EventIDRange::intersect(rangeW_XTalk);
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<TgcDigitCrosstalkData>();
52 constexpr std::string_view delimiter{";"};
53 for (const auto &[channel, attribute] : *readHandle_XTalk.cptr()) {
54 const coral::Blob& blob_strip = attribute["bXTalk_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 uint16_t layer = CxxUtils::atoi(*it);
64 ++it;
65 float prob10 = CxxUtils::atof(*it);
66 ++it;
67 float prob11 = CxxUtils::atof(*it);
68 ++it;
69 float prob20 = CxxUtils::atof(*it);
70 ++it;
71 float prob21 = CxxUtils::atof(*it);
72 ++it;
73 uint16_t layerId = (station_number << 5) + (station_eta << 2) + layer;
74 std::array<float, TgcDigitCrosstalkData::N_PROB> prob_strip{prob10, prob11, prob20, prob21};
75 outputCdo->setStripProbability(layerId, prob_strip);
76
77 const coral::Blob& blob_wire = attribute["bXTalk_wire"].data<coral::Blob>();
78 const std::string strwire {static_cast<const char*>(blob_wire.startingAddress())};
79 tokens.clear();
80 tokens = CxxUtils::tokenize(strwire, delimiter);
81 it = std::begin(tokens);
82 station_number = CxxUtils::atoi(*it);
83 ++it;
84 station_eta = CxxUtils::atoi(*it);
85 ++it;
86 layer = CxxUtils::atoi(*it);
87 ++it;
88 prob10 = CxxUtils::atof(*it);
89 ++it;
90 prob11 = CxxUtils::atof(*it);
91 ++it;
92 prob20 = CxxUtils::atof(*it);
93 ++it;
94 prob21 = CxxUtils::atof(*it);
95 ++it;
96 layerId = (station_number << 5) + (station_eta << 2) + layer;
97 std::array<float, TgcDigitCrosstalkData::N_PROB> prob_wire{prob10, prob11, prob20, prob21};
98 outputCdo->setWireProbability(layerId, prob_wire);
99 } // end of for(attrmap)
100
101 // Record
102 if (writeHandle.record(rangeIntersection, std::move(outputCdo)).isFailure()) {
103 ATH_MSG_FATAL("Could not record TgcDigitCrosstalkData " << writeHandle.key()
104 << " with EventRange " << rangeIntersection
105 << " into Conditions Store");
106 return StatusCode::FAILURE;
107 }
108 ATH_MSG_DEBUG("recorded new " << writeHandle.key() << " with range " << rangeIntersection << " into Conditions Store");
109
110 return StatusCode::SUCCESS;
111}
112
#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
TgcDigitCrosstalkCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteCondHandleKey< TgcDigitCrosstalkData > 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...