ATLAS Offline Software
PixeldEdxAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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  m_pixelID(nullptr) { }
17 
19  ATH_MSG_DEBUG("PixeldEdxAlg::initialize()");
20 
21  ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
22 
25 
26  return StatusCode::SUCCESS;
27 }
28 
30  ATH_MSG_DEBUG("PixeldEdxAlg::execute()");
31 
33  if (writeHandle.isValid()) {
34  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.");
35  return StatusCode::SUCCESS;
36  }
37 
38  // Construct the output Cond Object and fill it in
39  std::unique_ptr<PixeldEdxData> writeCdo(std::make_unique<PixeldEdxData>());
40 
41  const EventIDBase start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
42  const EventIDBase stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
43 // const EventIDRange rangeW{start, stop};
44  EventIDRange rangeW{start, stop};
45 
46  int fit_type;
47  std::string fun_type;
48  std::string bb_type;
49 
50  if (m_readfromcool) {
52  const AthenaAttributeList* readCdo = *readHandle;
53  if (readCdo==nullptr) {
54  ATH_MSG_FATAL("Null pointer to the read conditions object");
55  return StatusCode::FAILURE;
56  }
57  // Get the validitiy range
58  ATH_MSG_DEBUG("Size of AthenaAttributeList " << readHandle.fullKey() << " readCdo->size()= " << readCdo->size());
59 
60  // Get the validitiy range
61  if (not readHandle.range(rangeW)) {
62  ATH_MSG_FATAL("Failed to retrieve validity range for " << readHandle.key());
63  return StatusCode::FAILURE;
64  }
65  ATH_MSG_DEBUG("Size of CondAttrListCollection " << readHandle.fullKey() << " readCdo->size()= " << readCdo->size());
66  ATH_MSG_DEBUG("Range of input is " << rangeW);
67 
68  // Get constants from string in DB.
69  std::string mystring=(*readCdo)["data"].data<std::string>();
70  std::istringstream mystringstream(mystring);
71 
72  if (mystringstream.eof() || mystringstream.fail()) {
73  ATH_MSG_ERROR("Failed to read DB contents. Check DB.");
74  return StatusCode::FAILURE;
75  }
76 
77  mystringstream >> fit_type;
78  mystringstream >> fun_type;
79  mystringstream >> bb_type;
80 
81  writeCdo -> setFunctionType(fun_type);
82  writeCdo -> setBetheBlochType(bb_type);
83  writeCdo -> setMinimumdEdxForMass(m_mindedxformass);
84 
85  if (fit_type==0) {
86  for (int i=0;i<5;i++) {
87  for (int j=0;j<9;j++) {
88  double param;
89  mystringstream >> param;
90  writeCdo -> setPar(i,param);
91  }
92  }
93  writeCdo -> setPosNeg(false);
94  }
95  else {
96  for (int i=0;i<2*5;i++) {
97  for (int j=0;j<9;j++) {
98  double param;
99  mystringstream >> param;
100  writeCdo -> setPar(i,param);
101  }
102  }
103  writeCdo -> setPosNeg(true);
104  }
105  }
106  else {
107  std::string file_name = PathResolver::find_file(m_filename,"DATAPATH");
108  if (file_name.empty()) {
109  ATH_MSG_ERROR("PixeldEdx input file " << m_filename << " not found.");
110  return StatusCode::FAILURE;
111  }
112  std::ifstream input(file_name.c_str());
113  if (!input.good()) {
114  ATH_MSG_ERROR("Cannot open " << file_name);
115  return StatusCode::FAILURE;
116  }
117  input >> fit_type;
118  input >> fun_type;
119  input >> bb_type;
120 
121  writeCdo -> setFunctionType(fun_type);
122  writeCdo -> setBetheBlochType(bb_type);
123  writeCdo -> setMinimumdEdxForMass(m_mindedxformass);
124 
125  if (fit_type==0) {
126  for (int i=0;i<5;i++) {
127  for (int j=0;j<9;j++) {
128  double param;
129  input >> param;
130  writeCdo -> setPar(i,param);
131  }
132  }
133  writeCdo -> setPosNeg(false);
134  }
135  else {
136  for (int i=0;i<2*5;i++) {
137  for (int j=0;j<9;j++) {
138  double param;
139  input >> param;
140  writeCdo -> setPar(i,param);
141  }
142  }
143  writeCdo -> setPosNeg(true);
144  }
145  input.close();
146  }
147 
148  if (writeHandle.record(rangeW, std::move(writeCdo)).isFailure()) {
149  ATH_MSG_FATAL("Could not record PixeldEdxData " << writeHandle.key() << " with EventRange " << rangeW << " into Conditions Store");
150  return StatusCode::FAILURE;
151  }
152  ATH_MSG_DEBUG("recorded new CDO " << writeHandle.key() << " with range " << rangeW << " into Conditions Store");
153 
154  return StatusCode::SUCCESS;
155 }
156 
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:60
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:29
PixeldEdxAlg::initialize
virtual StatusCode initialize() override
Definition: PixeldEdxAlg.cxx:18
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:223
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
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:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:195
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
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:226
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
SG::WriteCondHandle
Definition: WriteCondHandle.h:26