ATLAS Offline Software
Loading...
Searching...
No Matches
TgcDigitASDposCondAlg.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
12
13TgcDigitASDposCondAlg::TgcDigitASDposCondAlg(const std::string& name, ISvcLocator* pSvcLocator) :
14 AthCondAlgorithm(name, pSvcLocator)
15{}
16
18{
19 ATH_MSG_DEBUG("initialize " << name());
20
21 ATH_CHECK(m_readKey_ASDpos.initialize());
22 ATH_CHECK(m_writeKey.initialize());
23
24 return StatusCode::SUCCESS;
25}
26
27StatusCode TgcDigitASDposCondAlg::execute(const EventContext& ctx) const
28{
30 if (writeHandle.isValid()) {
31 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
32 << ". In theory this should not be called, but may happen"
33 << " if multiple concurrent events are being processed out of order.");
34 return StatusCode::SUCCESS;
35 }
36
38 if (!readHandle_ASDpos.isValid()) {
39 ATH_MSG_ERROR("Null pointer to the read conditions object");
40 return StatusCode::FAILURE;
41 }
42 writeHandle.addDependency(readHandle_ASDpos);
43
44 // Fill
45 auto outputCdo = std::make_unique<TgcDigitASDposData>();
46 constexpr std::string_view delimiter{";"};
47 for(const auto &[channel, attribute] : **readHandle_ASDpos) {
48 const coral::Blob& blob = attribute["bASDPos"].data<coral::Blob>();
49 const std::string blobline{static_cast<const char*>(blob.startingAddress())};
50 std::vector<std::string> tokens = CxxUtils::tokenize(blobline, delimiter);
51 auto it = std::begin(tokens);
52 uint16_t station = static_cast<uint16_t>(CxxUtils::atoi(*it));
53 ++it;
54 uint16_t eta = static_cast<uint16_t>(CxxUtils::atoi(*it));
55 ++it;
56 uint16_t phi = (CxxUtils::atoi(*it) == -99) ? 0x1f : static_cast<uint16_t>(CxxUtils::atoi(*it));
57 uint16_t chamberId = (station << 8) + (eta << 5) + phi;
58
59 std::vector<float> strip_pos(TgcDigitASDposData::N_STRIPASDPOS, 0);
60 //strip_pos initialized to size N_STRIPASDPOS
61 for (int i=0; i < TgcDigitASDposData::N_STRIPASDPOS; i++) {
62 ++it;
63 strip_pos[i] = CxxUtils::atof(*it);
64 }
65 outputCdo->stripAsdPos.emplace(chamberId, std::move(strip_pos));
66
67 std::vector<float> wire_pos(TgcDigitASDposData::N_WIREASDPOS, 0);
68 //TgcDigitASDposData initialized to size N_WIREASDPOS
69 for (int i=0; i < TgcDigitASDposData::N_WIREASDPOS; i++) {
70 ++it;
71 wire_pos[i] = CxxUtils::atof(*it);
72 }
73 outputCdo->wireAsdPos.emplace(chamberId, std::move(wire_pos));
74 } // end of for(attrmap)
75
76 // Record
77 ATH_CHECK(writeHandle.record(std::move(outputCdo)));
78 ATH_MSG_DEBUG("recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
79
80 return StatusCode::SUCCESS;
81}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Base class for conditions algorithms.
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
virtual StatusCode initialize() override
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_ASDpos
SG::WriteCondHandleKey< TgcDigitASDposData > m_writeKey
TgcDigitASDposCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &ctx) const override
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...