ATLAS Offline Software
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 
6 #include "CxxUtils/StringUtils.h"
9 #include "CoralBase/Blob.h"
10 #include <string_view>
11 
12 TgcDigitCrosstalkCondAlg::TgcDigitCrosstalkCondAlg(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 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;
62  ++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();
81  it = std::begin(tokens);
82  station_number = CxxUtils::atoi(*it);
83  ++it;
85  ++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 
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
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
TgcDigitCrosstalkCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TgcDigitCrosstalkCondAlg.cxx:23
TgcDigitCrosstalkCondAlg::m_readKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Definition: TgcDigitCrosstalkCondAlg.h:24
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:396
StringUtils.h
TgcDigitCrosstalkCondAlg::initialize
virtual StatusCode initialize() override
Definition: TgcDigitCrosstalkCondAlg.cxx:16
TgcDigitCrosstalkCondAlg::m_writeKey
SG::WriteCondHandleKey< TgcDigitCrosstalkData > m_writeKey
Definition: TgcDigitCrosstalkCondAlg.h:25
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
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
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:221
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TgcDigitCrosstalkCondAlg.h
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 point of closest approach of two lines.
Definition: GeoPrimitivesHelpers.h:325
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
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TgcDigitCrosstalkCondAlg::TgcDigitCrosstalkCondAlg
TgcDigitCrosstalkCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TgcDigitCrosstalkCondAlg.cxx:12