ATLAS Offline Software
Loading...
Searching...
No Matches
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
14static const InterfaceID
15 IID_TBCONDRUNPAR_TBCondRunParTool("TBCondRunParTool",1,0);
16
18 const std::string&name, const IInterface* parent)
19 : AthAlgTool(type,name,parent)
20{
21 declareInterface<TBCondRunParTool>(this);
22 declareProperty("RunParamFolder",m_runpfolder);
23}
24
27
30
32{
33 ATH_MSG_INFO ( "In initialize of TBCondRunParTool" );
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;
55 m_cevent=event;
56 // access the database and update cached values
57 update=true;
58 m_run_number=-1;
60 m_det_mask=-1;
61 m_beam_type=-1;
63 m_file_tag="";
64
65 update=extractCool(run);
66 }
67 return update;
68}
69
70StatusCode 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
136void 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
142StatusCode 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
195bool 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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
static const InterfaceID IID_TBCONDRUNPAR_TBCondRunParTool("TBCondRunParTool", 1, 0)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
An AttributeList represents a logical row of attributes in a metadata table.
This class is a collection of AttributeLists where each one is associated with a channel number.
const_iterator end() const
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
void dump() const
Dump our contents to std::cout.
ChanAttrListMap::const_iterator const_iterator
StatusCode extractVal(const std::vector< std::string > &names, const std::vector< std::string > &rows, const std::string &name, int &ival) const
StatusCode initialize()
StatusCode getVal(const std::string &folder, const unsigned int chnum, float &fval)
bool extractCoolTest(const std::string &folder, int run) const
std::string m_time_SOR
std::string m_runpfolder
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
void printTable(const std::vector< std::string > &names, const std::vector< std::string > &rows) const
TBCondRunParTool(const std::string &type, const std::string &name, const IInterface *parent)
static const InterfaceID & interfaceID()
std::string m_file_tag
bool extractCool(const int run)
Definition run.py:1