Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
14 PixeldEdxAlg::PixeldEdxAlg(const std::string& name, ISvcLocator* pSvcLocator):
15  ::AthAlgorithm(name, pSvcLocator){ }
16 
18  ATH_MSG_DEBUG("PixeldEdxAlg::initialize()");
19 
20  ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
21 
24 
25  return StatusCode::SUCCESS;
26 }
27 
29  ATH_MSG_DEBUG("PixeldEdxAlg::execute()");
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PixeldEdxAlg::m_pixelID
const PixelID * m_pixelID
Definition: PixeldEdxAlg.h:37
PixeldEdxAlg::m_readKey
SG::ReadCondHandleKey< AthenaAttributeList > m_readKey
Definition: PixeldEdxAlg.h:49
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
PixeldEdxAlg::m_mindedxformass
Gaudi::Property< double > m_mindedxformass
Definition: PixeldEdxAlg.h:46
SG::ReadCondHandle::fullKey
const DataObjID & fullKey() const
Definition: ReadCondHandle.h:64
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
PixeldEdxAlg::m_readfromcool
Gaudi::Property< bool > m_readfromcool
Definition: PixeldEdxAlg.h:43
PixeldEdxAlg::execute
virtual StatusCode execute() override
Definition: PixeldEdxAlg.cxx:28
PixeldEdxAlg::initialize
virtual StatusCode initialize() override
Definition: PixeldEdxAlg.cxx:17
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
PixeldEdxAlg.h
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
PixeldEdxAlg::m_writeKey
SG::WriteCondHandleKey< PixeldEdxData > m_writeKey
Definition: PixeldEdxAlg.h:52
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:228
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:161
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
physics_parameters.file_name
string file_name
Definition: physics_parameters.py:32
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
AthAlgorithm
Definition: AthAlgorithm.h:47
PathResolver.h
PixeldEdxAlg::m_filename
Gaudi::Property< std::string > m_filename
Definition: PixeldEdxAlg.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:44
PixeldEdxAlg::PixeldEdxAlg
PixeldEdxAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixeldEdxAlg.cxx:14
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
dqt_zlumi_pandas.fit_type
string fit_type
Definition: dqt_zlumi_pandas.py:215
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:252
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:63
SG::WriteCondHandle
Definition: WriteCondHandle.h:26