ATLAS Offline Software
Loading...
Searching...
No Matches
PixeldEdxAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "PixeldEdxAlg.h"
6#include "GaudiKernel/EventIDRange.h"
7
9
10#include <cstdint>
11#include <istream>
12#include <fstream>
13
14PixeldEdxAlg::PixeldEdxAlg(const std::string& name, ISvcLocator* pSvcLocator):
15 ::AthCondAlgorithm(name, pSvcLocator){ }
16
18 ATH_MSG_DEBUG("PixeldEdxAlg::initialize()");
19
20 ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
21
23 ATH_CHECK(m_writeKey.initialize());
24
25 return StatusCode::SUCCESS;
26}
27
28StatusCode PixeldEdxAlg::execute(const EventContext& ctx) const {
29 ATH_MSG_DEBUG("PixeldEdxAlg::execute(const EventContext& ctx) const");
30
32 if (writeHandle.isValid()) {
33 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid.. In theory this should not be called, but may happen if multiple concurrent events are being processed out of order.");
34 return StatusCode::SUCCESS;
35 }
36
37 // Construct the output Cond Object and fill it in
38 std::unique_ptr<PixeldEdxData> writeCdo(std::make_unique<PixeldEdxData>());
39
40 const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
41 const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
42// const EventIDRange rangeW{start, stop};
43 EventIDRange rangeW{start, stop};
44
45 int fit_type{};
46 std::string fun_type;
47 std::string bb_type;
48
49 if (m_readfromcool) {
51 const AthenaAttributeList* readCdo = *readHandle;
52 if (readCdo==nullptr) {
53 ATH_MSG_FATAL("Null pointer to the read conditions object");
54 return StatusCode::FAILURE;
55 }
56 // Get the validitiy range
57 ATH_MSG_DEBUG("Size of AthenaAttributeList " << readHandle.fullKey() << " readCdo->size()= " << readCdo->size());
58
59 // Get the validitiy range
60 if (not readHandle.range(rangeW)) {
61 ATH_MSG_FATAL("Failed to retrieve validity range for " << readHandle.key());
62 return StatusCode::FAILURE;
63 }
64 ATH_MSG_DEBUG("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdo->size()= " << readCdo->size());
65 ATH_MSG_DEBUG("Range of input is " << rangeW);
66
67 // Get constants from string in DB.
68 std::string mystring=(*readCdo)["data"].data<std::string>();
69 std::istringstream mystringstream(mystring);
70
71 if (mystringstream.eof() || mystringstream.fail()) {
72 ATH_MSG_ERROR("Failed to read DB contents. Check DB.");
73 return StatusCode::FAILURE;
74 }
75
76 mystringstream >> fit_type;
77 mystringstream >> fun_type;
78 mystringstream >> bb_type;
79
80 writeCdo -> setFunctionType(fun_type);
81 writeCdo -> setBetheBlochType(bb_type);
82 writeCdo -> setMinimumdEdxForMass(m_mindedxformass);
83
84 if (fit_type==0) {
85 for (int i=0;i<5;i++) {
86 for (int j=0;j<9;j++) {
87 double param;
88 mystringstream >> param;
89 writeCdo -> setPar(i,param);
90 }
91 }
92 writeCdo -> setPosNeg(false);
93 }
94 else {
95 for (int i=0;i<2*5;i++) {
96 for (int j=0;j<9;j++) {
97 double param;
98 mystringstream >> param;
99 writeCdo -> setPar(i,param);
100 }
101 }
102 writeCdo -> setPosNeg(true);
103 }
104 }
105 else {
106 std::string file_name = PathResolver::find_file(m_filename,"DATAPATH");
107 if (file_name.empty()) {
108 ATH_MSG_ERROR("PixeldEdx input file " << m_filename << " not found.");
109 return StatusCode::FAILURE;
110 }
111 std::ifstream input(file_name.c_str());
112 if (!input.good()) {
113 ATH_MSG_ERROR("Cannot open " << file_name);
114 return StatusCode::FAILURE;
115 }
116 input >> fit_type;
117 input >> fun_type;
118 input >> bb_type;
119
120 writeCdo -> setFunctionType(fun_type);
121 writeCdo -> setBetheBlochType(bb_type);
122 writeCdo -> setMinimumdEdxForMass(m_mindedxformass);
123
124 if (fit_type==0) {
125 for (int i=0;i<5;i++) {
126 for (int j=0;j<9;j++) {
127 double param;
128 input >> param;
129 writeCdo -> setPar(i,param);
130 }
131 }
132 writeCdo -> setPosNeg(false);
133 }
134 else {
135 for (int i=0;i<2*5;i++) {
136 for (int j=0;j<9;j++) {
137 double param;
138 input >> param;
139 writeCdo -> setPar(i,param);
140 }
141 }
142 writeCdo -> setPosNeg(true);
143 }
144 input.close();
145 }
146
147 if (writeHandle.record(rangeW, std::move(writeCdo)).isFailure()) {
148 ATH_MSG_FATAL("Could not record PixeldEdxData " << writeHandle.key() << " with EventRange " << rangeW << " into Conditions Store");
149 return StatusCode::FAILURE;
150 }
151 ATH_MSG_DEBUG("recorded new CDO " << writeHandle.key() << " with range " << rangeW << " into Conditions Store");
152
153 return StatusCode::SUCCESS;
154}
155
#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)
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
An AttributeList represents a logical row of attributes in a metadata table.
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Gaudi::Property< bool > m_readfromcool
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< std::string > m_filename
virtual StatusCode initialize() override
const PixelID * m_pixelID
Gaudi::Property< double > m_mindedxformass
SG::ReadCondHandleKey< AthenaAttributeList > m_readKey
SG::WriteCondHandleKey< PixeldEdxData > m_writeKey
PixeldEdxAlg(const std::string &name, ISvcLocator *pSvcLocator)
bool range(EventIDRange &r)
const std::string & key() const
const DataObjID & fullKey() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const