ATLAS Offline Software
Loading...
Searching...
No Matches
TgcDigitCrosstalkCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include "CoralBase/Blob.h"
10#include <string_view>
11
12namespace Muon{
14 ATH_MSG_DEBUG("initialize " << name());
15 ATH_CHECK(m_readKey.initialize());
16 ATH_CHECK(m_writeKey.initialize());
17 return StatusCode::SUCCESS;
18}
19
20StatusCode TgcDigitCrosstalkCondAlg::execute(const EventContext& ctx) const {
21 SG::WriteCondHandle writeHandle{m_writeKey, ctx};
22 if (writeHandle.isValid()) {
23 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
24 << ". In theory this should not be called, but may happen"
25 << " if multiple concurrent events are being processed out of order.");
26 return StatusCode::SUCCESS;
27 }
28 SG::ReadCondHandle readHandle_XTalk{m_readKey, ctx};
29 if (readHandle_XTalk.cptr() == nullptr) {
30 ATH_MSG_ERROR("Null pointer to the read conditions object");
31 return StatusCode::FAILURE;
32 }
33 ATH_MSG_DEBUG("Size of CondAttrListCollection" << readHandle_XTalk.fullKey() << " = " << readHandle_XTalk->size());
34 EventIDRange rangeW_XTalk;
35 if (!readHandle_XTalk.range(rangeW_XTalk)) {
36 ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle_XTalk.key());
37 return StatusCode::FAILURE;
38 }
39 ATH_MSG_DEBUG("Range of input is " << rangeW_XTalk);
40
41 // write condition object
42 EventIDRange rangeIntersection = EventIDRange::intersect(rangeW_XTalk);
43 if(rangeIntersection.start()>rangeIntersection.stop()) {
44 ATH_MSG_ERROR("Invalid intersection range: " << rangeIntersection);
45 return StatusCode::FAILURE;
46 }
47 // Fill
48 auto outputCdo = std::make_unique<TgcDigitCrosstalkData>();
49 constexpr std::string_view delimiter{";"};
50 for (const auto &[channel, attribute] : *readHandle_XTalk.cptr()) {
51 const coral::Blob& blob_strip = attribute["bXTalk_strip"].data<coral::Blob>();
52 const std::string strstrip{static_cast<const char*>(blob_strip.startingAddress())};
53
54 std::vector<std::string> tokens = CxxUtils::tokenize(strstrip, delimiter);
55 auto it = std::begin(tokens);
56 uint16_t station_number = CxxUtils::atoi(*it);
57 ++it;
58 uint16_t station_eta = CxxUtils::atoi(*it);
59 ++it;
60 uint16_t layer = CxxUtils::atoi(*it);
61 ++it;
62 float prob10 = CxxUtils::atof(*it);
63 ++it;
64 float prob11 = CxxUtils::atof(*it);
65 ++it;
66 float prob20 = CxxUtils::atof(*it);
67 ++it;
68 float prob21 = CxxUtils::atof(*it);
69 ++it;
70 uint16_t layerId = (station_number << 5) + (station_eta << 2) + layer;
71 std::array<float, TgcDigitCrosstalkData::N_PROB> prob_strip{prob10, prob11, prob20, prob21};
72 outputCdo->setStripProbability(layerId, prob_strip);
73
74 const coral::Blob& blob_wire = attribute["bXTalk_wire"].data<coral::Blob>();
75 const std::string strwire {static_cast<const char*>(blob_wire.startingAddress())};
76 tokens.clear();
77 tokens = CxxUtils::tokenize(strwire, delimiter);
78 it = std::begin(tokens);
79 station_number = CxxUtils::atoi(*it);
80 ++it;
81 station_eta = CxxUtils::atoi(*it);
82 ++it;
83 layer = CxxUtils::atoi(*it);
84 ++it;
85 prob10 = CxxUtils::atof(*it);
86 ++it;
87 prob11 = CxxUtils::atof(*it);
88 ++it;
89 prob20 = CxxUtils::atof(*it);
90 ++it;
91 prob21 = CxxUtils::atof(*it);
92 ++it;
93 layerId = (station_number << 5) + (station_eta << 2) + layer;
94 std::array<float, TgcDigitCrosstalkData::N_PROB> prob_wire{prob10, prob11, prob20, prob21};
95 outputCdo->setWireProbability(layerId, prob_wire);
96 } // end of for(attrmap)
97
98 // Record
99 if (writeHandle.record(rangeIntersection, std::move(outputCdo)).isFailure()) {
100 ATH_MSG_FATAL("Could not record TgcDigitCrosstalkData " << writeHandle.key()
101 << " with EventRange " << rangeIntersection
102 << " into Conditions Store");
103 return StatusCode::FAILURE;
104 }
105 ATH_MSG_DEBUG("recorded new " << writeHandle.key() << " with range " << rangeIntersection << " into Conditions Store");
106
107 return StatusCode::SUCCESS;
108}
109}
110
#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)
SG::WriteCondHandleKey< TgcDigitCrosstalkData > m_writeKey
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode initialize() override
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
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
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...
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.