ATLAS Offline Software
TBCondRunParTool.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 // TBCondRunParTool.cxx
6 // Richard Hawkings, started 2/7/04
7 
8 #include "GaudiKernel/SmartDataPtr.h"
12 
13 // magic copied from TRT_IdentifierConversionTool
14 static const InterfaceID
15  IID_TBCONDRUNPAR_TBCondRunParTool("TBCondRunParTool",1,0);
16 
18  const std::string&name, const IInterface* parent)
20  m_crun(-1),m_cevent(-1),m_runpfolder("")
21 {
22  declareInterface<TBCondRunParTool>(this);
23  declareProperty("RunParamFolder",m_runpfolder);
24 }
25 
27 {}
28 
29 const InterfaceID& TBCondRunParTool::interfaceID()
30 { return IID_TBCONDRUNPAR_TBCondRunParTool; }
31 
33 {
34  ATH_MSG_INFO ( "In initialize of TBCondRunParTool" );
35  ATH_MSG_INFO (
36  "RunParams will be read from folder: " << m_runpfolder <<
37  " in COOL database" );
38  // check StoreGate service available
39  return StatusCode::SUCCESS;
40 }
41 
43  ATH_MSG_DEBUG ( "Finalize called" );
44  return StatusCode::SUCCESS;
45 }
46 
48  // find the current run and event - check if data structure may have changed
49  const EventContext& ctx = Gaudi::Hive::currentContext();
50  int run = ctx.eventID().run_number();
51  int event = ctx.eventID().event_number();
52  bool update=false;
53  if (run!=m_crun || event!=m_cevent) {
54  ATH_MSG_DEBUG ( "Retrieve new data for run/event " << run << "/" << event );
55  m_crun=run;
57  // access the database and update cached values
58  update=true;
59  m_run_number=-1;
60  m_trigger_type=-1;
61  m_det_mask=-1;
62  m_beam_type=-1;
63  m_beam_energy=-1;
64  m_file_tag="";
65 
67  }
68  return update;
69 }
70 
71 StatusCode TBCondRunParTool::getTable(const std::string& table,const int /*irow*/,
72  const void* /*tblptr*/,
73  int& ncol,int& nrow, std::vector<std::string>& names,
74  std::vector<std::string>& rows) const {
75  // this implementation is dummy - at present it does not return anything
76  //tblptr=0;
77  ncol=0;
78  nrow=0;
79  names.clear();
80  rows.clear();
81  ATH_MSG_DEBUG ( "getTable: " << table );
82  bool iret = extractCoolTest(std::string("/TILE/DCS/TILE_LV_62/BEAM"), 0);
83  // get number of columns and rows
84  if(!iret)
85  ATH_MSG_DEBUG ( "extractCoolTest: /TILE/DCS/TILE_LV_62/BEAM failed !" );
86  return StatusCode::SUCCESS;
87 }
88 
90  const std::vector<std::string>& names,
91  const std::vector<std::string>& rows,
92  const std::string& name,int& ival) const {
93  StatusCode found=StatusCode::FAILURE;
94  for (unsigned int icol=0;icol<names.size();++icol) {
95  ATH_MSG_DEBUG ( "Check " << icol << " " << names[icol] << rows[icol] );
96  if (names[icol]==name) {
97  ival=atoi(rows[icol].c_str());
98  found=StatusCode::SUCCESS;
99  break;
100  }
101  }
102  return found;
103 }
104 
106  const std::vector<std::string>& names,
107  const std::vector<std::string>& rows,
108  const std::string& name,float& fval) const {
109  StatusCode found=StatusCode::FAILURE;
110  for (unsigned int icol=0;icol<names.size();++icol) {
111  ATH_MSG_DEBUG ( "Check " << icol << " " << names[icol] << rows[icol] );
112  if (names[icol]==name) {
113  fval=atof(rows[icol].c_str());
114  found=StatusCode::SUCCESS;
115  break;
116  }
117  }
118  return found;
119 }
120 
122  const std::vector<std::string>& names,
123  const std::vector<std::string>& rows,
124  const std::string& name,std::string& sval) const {
125  StatusCode found=StatusCode::FAILURE;
126  for (unsigned int icol=0;icol<names.size();++icol) {
127  ATH_MSG_DEBUG ( "Check " << icol << " " << names[icol] << rows[icol] );
128  if (names[icol]==name) {
129  sval=rows[icol];
130  found=StatusCode::SUCCESS;
131  break;
132  }
133  }
134  return found;
135 }
136 
137 void TBCondRunParTool::printTable(const std::vector<std::string>& names,
138  const std::vector<std::string>& rows) const {
139  for (unsigned int icol=0;icol<names.size();++icol)
140  ATH_MSG_INFO ( "Column: " << icol << " " << names[icol] << rows[icol] );
141 }
142 
143 StatusCode TBCondRunParTool::getVal(const std::string& folder, const unsigned int chnum, float& fval){
144  StatusCode found=StatusCode::FAILURE;
145  const CondAttrListCollection* atrlist=0;
146  if (StatusCode::SUCCESS==detStore()->retrieve(atrlist,folder)) {
149  for (; it != last; ++it) {
150  if(chnum == (*it).first) {
151 // std::cout << "chan, attr: " << (*it).first << " / "<<(*it).second.toOutputStream(std::cout)<< std::endl;
152  fval = (*it).second[0].data<float>();
153  found = StatusCode::SUCCESS;
154  ATH_MSG_DEBUG ( "chnum: "<<chnum<<" chan, attr: " << (*it).first <<" fval: "<<fval);
155  break;
156  }
157  }
158  }
159 
160  return found;
161 }
162 
163 
164 
166  bool update=true;
167  const AthenaAttributeList* atrlist=0;
168  std::string table=m_runpfolder+"/RunParams.RunParams";
169  if (StatusCode::SUCCESS==detStore()->retrieve(atrlist,table)) {
170  // std::ostringstream atrs;
171  // atrlist->print(atrs);
172  // m_log << "Attribute list contents: " << atrs.str() << endmsg;
173  long ldata;
174  m_run_number=(*atrlist)["run_number"].data<int>();
175  m_trigger_type=(*atrlist)["trigger_type"].data<int>();
176  m_det_mask=(*atrlist)["detector_mask"].data<int>();
177  m_beam_type=(*atrlist)["beam_type"].data<int>();
178  m_beam_energy=(*atrlist)["beam_energy"].data<int>();
179  m_file_tag=(*atrlist)["filename_tag"].data<std::string>();
180  // FIXME should be long
181  ldata=(*atrlist)["timeSOR"].data<int>();
182  std::ostringstream timeSOR;
183  timeSOR << ldata;
184  m_time_SOR=timeSOR.str();
185  ATH_MSG_DEBUG ("run_number: "<<m_run_number<<" m_beam_energy: "<<m_beam_energy);
186  // check consistency
187  m_status=0;
188  if (m_run_number!=run) m_status=1;
189  } else {
190  ATH_MSG_ERROR ( "Cannot retrieve AttributeList for " << table );
191  m_status=1;
192  }
193  return update;
194 }
195 
196 bool TBCondRunParTool::extractCoolTest(const std::string& folder, const int /*run*/) const{
197  bool update=true;
198  const CondAttrListCollection* atrlist=0;
199  if (StatusCode::SUCCESS==detStore()->retrieve(atrlist,folder)) {
200 // std::ostringstream atrs;
201  ATH_MSG_DEBUG ( "Attribute list contents: " );
202  atrlist->dump();
203  }
204  return update;
205 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CondAttrListCollection::end
const_iterator end() const
Definition: CondAttrListCollection.h:315
TBCondRunParTool::m_beam_type
int m_beam_type
Definition: TBCondRunParTool.h:69
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
skel.it
it
Definition: skel.GENtoEVGEN.py:423
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
TBCondRunParTool::getTable
StatusCode getTable(const std::string &table, const int irow, const void *tblptr, int &ncol, int &nrow, std::vector< std::string > &names, std::vector< std::string > &rows) const
Definition: TBCondRunParTool.cxx:71
CondAttrListCollection::begin
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
Definition: CondAttrListCollection.h:309
TBCondRunParTool::m_status
int m_status
Definition: TBCondRunParTool.h:65
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
AthenaAttributeList.h
atlasStyleMacro.icol
int icol
Definition: atlasStyleMacro.py:13
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TBCondRunParTool::TBCondRunParTool
TBCondRunParTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TBCondRunParTool.cxx:17
TBCondRunParTool::checkcache
bool checkcache()
Definition: TBCondRunParTool.cxx:47
WriteCellNoiseToCool.ival
ival
Definition: WriteCellNoiseToCool.py:337
CondAttrListCollection::dump
void dump() const
Dump our contents to std::cout.
Definition: CondAttrListCollection.h:557
TBCondRunParTool::interfaceID
static const InterfaceID & interfaceID()
Definition: TBCondRunParTool.cxx:29
TBCondRunParTool::extractCool
bool extractCool(const int run)
Definition: TBCondRunParTool.cxx:165
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TBCondRunParTool::m_file_tag
std::string m_file_tag
Definition: TBCondRunParTool.h:71
TBCondRunParTool::printTable
void printTable(const std::vector< std::string > &names, const std::vector< std::string > &rows) const
Definition: TBCondRunParTool.cxx:137
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
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
python.subdetectors.mmg.names
names
Definition: mmg.py:8
TBCondRunParTool::finalize
StatusCode finalize()
Definition: TBCondRunParTool.cxx:42
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TBCondRunParTool::m_crun
int m_crun
Definition: TBCondRunParTool.h:61
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
run
Definition: run.py:1
beamspotnt.rows
list rows
Definition: bin/beamspotnt.py:1112
TBCondRunParTool::m_beam_energy
int m_beam_energy
Definition: TBCondRunParTool.h:70
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
TBCondRunParTool::m_runpfolder
std::string m_runpfolder
Definition: TBCondRunParTool.h:63
TBCondRunParTool::m_run_number
int m_run_number
Definition: TBCondRunParTool.h:66
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
python.ext.table_printer.table
list table
Definition: table_printer.py:81
TBCondRunParTool::getVal
StatusCode getVal(const std::string &folder, const unsigned int chnum, float &fval)
Definition: TBCondRunParTool.cxx:143
TBCondRunParTool::m_cevent
int m_cevent
Definition: TBCondRunParTool.h:62
TBCondRunParTool::extractVal
StatusCode extractVal(const std::vector< std::string > &names, const std::vector< std::string > &rows, const std::string &name, int &ival) const
Definition: TBCondRunParTool.cxx:89
dqt_zlumi_pandas.update
update
Definition: dqt_zlumi_pandas.py:42
TBCondRunParTool::m_time_SOR
std::string m_time_SOR
Definition: TBCondRunParTool.h:72
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TBCondRunParTool::m_det_mask
int m_det_mask
Definition: TBCondRunParTool.h:68
TBCondRunParTool::initialize
StatusCode initialize()
Definition: TBCondRunParTool.cxx:32
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
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
TBCondRunParTool.h
AthAlgTool
Definition: AthAlgTool.h:26
TBCondRunParTool::m_trigger_type
int m_trigger_type
Definition: TBCondRunParTool.h:67
TBCondRunParTool::extractCoolTest
bool extractCoolTest(const std::string &folder, int run) const
Definition: TBCondRunParTool.cxx:196
TBCondRunParTool::~TBCondRunParTool
~TBCondRunParTool()
Definition: TBCondRunParTool.cxx:26