ATLAS Offline Software
TBCondRunParTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 {
21  declareInterface<TBCondRunParTool>(this);
22  declareProperty("RunParamFolder",m_runpfolder);
23 }
24 
26 {}
27 
28 const InterfaceID& TBCondRunParTool::interfaceID()
29 { return IID_TBCONDRUNPAR_TBCondRunParTool; }
30 
32 {
33  ATH_MSG_INFO ( "In initialize of TBCondRunParTool" );
34  ATH_MSG_INFO (
35  "RunParams will be read from folder: " << m_runpfolder <<
36  " in COOL database" );
37  // check StoreGate service available
38  return StatusCode::SUCCESS;
39 }
40 
42  ATH_MSG_DEBUG ( "Finalize called" );
43  return StatusCode::SUCCESS;
44 }
45 
47  // find the current run and event - check if data structure may have changed
48  const EventContext& ctx = Gaudi::Hive::currentContext();
49  int run = ctx.eventID().run_number();
50  int event = ctx.eventID().event_number();
51  bool update=false;
52  if (run!=m_crun || event!=m_cevent) {
53  ATH_MSG_DEBUG ( "Retrieve new data for run/event " << run << "/" << event );
54  m_crun=run;
56  // access the database and update cached values
57  update=true;
58  m_run_number=-1;
59  m_trigger_type=-1;
60  m_det_mask=-1;
61  m_beam_type=-1;
62  m_beam_energy=-1;
63  m_file_tag="";
64 
66  }
67  return update;
68 }
69 
70 StatusCode TBCondRunParTool::getTable(const std::string& table,const int /*irow*/,
71  const void* /*tblptr*/,
72  int& ncol,int& nrow, std::vector<std::string>& names,
73  std::vector<std::string>& rows) const {
74  // this implementation is dummy - at present it does not return anything
75  //tblptr=0;
76  ncol=0;
77  nrow=0;
78  names.clear();
79  rows.clear();
80  ATH_MSG_DEBUG ( "getTable: " << table );
81  bool iret = extractCoolTest(std::string("/TILE/DCS/TILE_LV_62/BEAM"), 0);
82  // get number of columns and rows
83  if(!iret)
84  ATH_MSG_DEBUG ( "extractCoolTest: /TILE/DCS/TILE_LV_62/BEAM failed !" );
85  return StatusCode::SUCCESS;
86 }
87 
89  const std::vector<std::string>& names,
90  const std::vector<std::string>& rows,
91  const std::string& name,int& ival) const {
92  StatusCode found=StatusCode::FAILURE;
93  for (unsigned int icol=0;icol<names.size();++icol) {
94  ATH_MSG_DEBUG ( "Check " << icol << " " << names[icol] << rows[icol] );
95  if (names[icol]==name) {
96  ival=atoi(rows[icol].c_str());
97  found=StatusCode::SUCCESS;
98  break;
99  }
100  }
101  return found;
102 }
103 
105  const std::vector<std::string>& names,
106  const std::vector<std::string>& rows,
107  const std::string& name,float& fval) const {
108  StatusCode found=StatusCode::FAILURE;
109  for (unsigned int icol=0;icol<names.size();++icol) {
110  ATH_MSG_DEBUG ( "Check " << icol << " " << names[icol] << rows[icol] );
111  if (names[icol]==name) {
112  fval=atof(rows[icol].c_str());
113  found=StatusCode::SUCCESS;
114  break;
115  }
116  }
117  return found;
118 }
119 
121  const std::vector<std::string>& names,
122  const std::vector<std::string>& rows,
123  const std::string& name,std::string& sval) const {
124  StatusCode found=StatusCode::FAILURE;
125  for (unsigned int icol=0;icol<names.size();++icol) {
126  ATH_MSG_DEBUG ( "Check " << icol << " " << names[icol] << rows[icol] );
127  if (names[icol]==name) {
128  sval=rows[icol];
129  found=StatusCode::SUCCESS;
130  break;
131  }
132  }
133  return found;
134 }
135 
136 void TBCondRunParTool::printTable(const std::vector<std::string>& names,
137  const std::vector<std::string>& rows) const {
138  for (unsigned int icol=0;icol<names.size();++icol)
139  ATH_MSG_INFO ( "Column: " << icol << " " << names[icol] << rows[icol] );
140 }
141 
142 StatusCode TBCondRunParTool::getVal(const std::string& folder, const unsigned int chnum, float& fval){
143  StatusCode found=StatusCode::FAILURE;
144  const CondAttrListCollection* atrlist=0;
145  if (StatusCode::SUCCESS==detStore()->retrieve(atrlist,folder)) {
148  for (; it != last; ++it) {
149  if(chnum == (*it).first) {
150 // std::cout << "chan, attr: " << (*it).first << " / "<<(*it).second.toOutputStream(std::cout)<< std::endl;
151  fval = (*it).second[0].data<float>();
152  found = StatusCode::SUCCESS;
153  ATH_MSG_DEBUG ( "chnum: "<<chnum<<" chan, attr: " << (*it).first <<" fval: "<<fval);
154  break;
155  }
156  }
157  }
158 
159  return found;
160 }
161 
162 
163 
165  bool update=true;
166  const AthenaAttributeList* atrlist=0;
167  std::string table=m_runpfolder+"/RunParams.RunParams";
168  if (StatusCode::SUCCESS==detStore()->retrieve(atrlist,table)) {
169  // std::ostringstream atrs;
170  // atrlist->print(atrs);
171  // m_log << "Attribute list contents: " << atrs.str() << endmsg;
172  long ldata;
173  m_run_number=(*atrlist)["run_number"].data<int>();
174  m_trigger_type=(*atrlist)["trigger_type"].data<int>();
175  m_det_mask=(*atrlist)["detector_mask"].data<int>();
176  m_beam_type=(*atrlist)["beam_type"].data<int>();
177  m_beam_energy=(*atrlist)["beam_energy"].data<int>();
178  m_file_tag=(*atrlist)["filename_tag"].data<std::string>();
179  // FIXME should be long
180  ldata=(*atrlist)["timeSOR"].data<int>();
181  std::ostringstream timeSOR;
182  timeSOR << ldata;
183  m_time_SOR=timeSOR.str();
184  ATH_MSG_DEBUG ("run_number: "<<m_run_number<<" m_beam_energy: "<<m_beam_energy);
185  // check consistency
186  m_status=0;
187  if (m_run_number!=run) m_status=1;
188  } else {
189  ATH_MSG_ERROR ( "Cannot retrieve AttributeList for " << table );
190  m_status=1;
191  }
192  return update;
193 }
194 
195 bool TBCondRunParTool::extractCoolTest(const std::string& folder, const int /*run*/) const{
196  bool update=true;
197  const CondAttrListCollection* atrlist=0;
198  if (StatusCode::SUCCESS==detStore()->retrieve(atrlist,folder)) {
199 // std::ostringstream atrs;
200  ATH_MSG_DEBUG ( "Attribute list contents: " );
201  atrlist->dump();
202  }
203  return update;
204 }
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:396
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:70
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:46
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:28
TBCondRunParTool::extractCool
bool extractCool(const int run)
Definition: TBCondRunParTool.cxx:164
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:136
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:41
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:228
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:142
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:88
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:31
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
WriteBchToCool.update
update
Definition: WriteBchToCool.py:67
TBCondRunParTool::extractCoolTest
bool extractCoolTest(const std::string &folder, int run) const
Definition: TBCondRunParTool.cxx:195
TBCondRunParTool::~TBCondRunParTool
~TBCondRunParTool()
Definition: TBCondRunParTool.cxx:25