ATLAS Offline Software
IOVDbTestCoolDCS.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 // IOVDbTestCoolDCS.cxx
6 // Algorithm to demonstrate simple reading of COOL DCS data into Athena
7 // Richard Hawkings started 9/9/05
8 
11 #include "IOVDbTestCoolDCS.h"
12 
14  ISvcLocator* pSvcLocator) :
15  AthReentrantAlgorithm(name, pSvcLocator)
16 {
17  declareProperty("AttrListFolders",m_par_atrlist);
18  declareProperty("AttrListCollFolders",m_par_atrcollist);
19 }
20 
22 {}
23 
25 
26  ATH_MSG_INFO("DCS conditions data folders to be read as AthenaAttributeList (single channel)");
27  for (std::vector<std::string>::const_iterator itr=m_par_atrlist.begin();
28  itr!=m_par_atrlist.end();++itr) ATH_MSG_INFO(*itr);
29  ATH_MSG_INFO("DCS conditions data folders to be read as CondAttrListCollection (multichannel)");
30  for (std::vector<std::string>::const_iterator itr=m_par_atrcollist.begin();
31  itr!=m_par_atrcollist.end();++itr) ATH_MSG_INFO(*itr);
32 
33  return StatusCode::SUCCESS;
34 }
35 
36 StatusCode IOVDbTestCoolDCS::execute (const EventContext& ctx) const {
37  // first print event number and time details
38  int time=ctx.eventID().time_stamp();
39  ATH_MSG_INFO("In run/event [" << ctx.eventID().run_number() <<
40  "," << ctx.eventID().event_number() << "] timestamp " << time);
41  // print the timestamp in UTC
42  time_t ttime=static_cast<time_t>(time);
43  struct tm tm;
44  char tmbuf[32];
45  ATH_MSG_INFO("Timestamp UTC: " << asctime_r(gmtime_r(&ttime, &tm), tmbuf));
46 
47  // print all the AthenaAttributeList
48  const AthenaAttributeList* atrlist = nullptr;;
49  for (std::vector<std::string>::const_iterator itr=m_par_atrlist.begin();
50  itr!=m_par_atrlist.end();++itr) {
51  if (StatusCode::SUCCESS==detStore()->retrieve(atrlist,*itr)) {
52  // the following code dumps the attribute list into a string for printing
53  // to access individual elements by name, use e.g.
54  // float var1=(*atrlist)["T04"].data<float>();
55  // to get the value of a float column called T04 into var1
56  std::ostringstream atrstring;
57  atrlist->print(atrstring);
58  ATH_MSG_INFO("Values for folder " << *itr << ":");
59  ATH_MSG_INFO(atrstring.str());
60  } else {
61  ATH_MSG_ERROR("Could not retrieve AthenaAttributeList ");
62  }
63  }
64 
65  // print all CondAttrListCollection
66  const CondAttrListCollection* atrlistcol;
67  for (std::vector<std::string>::const_iterator itr=m_par_atrcollist.begin();
68  itr!=m_par_atrcollist.end();++itr) {
69  if (StatusCode::SUCCESS==detStore()->retrieve(atrlistcol,*itr)) {
70  // loop over collection
71  for (CondAttrListCollection::const_iterator citr=atrlistcol->begin();
72  citr!=atrlistcol->end();++citr) {
73  // the following code dumps the attribute list into a string for printing
74  // to access individual elements by name, use e.g.
75  // float var1=(((*citr).second)["T04"]).data<float>();
76  // to get the value of a float column called T04 into var1
77  std::ostringstream atrstring;
78  (*citr).second.toOutputStream(atrstring);
79  ATH_MSG_INFO("Channel " << (*citr).first << " "
80  << atrstring.str());
81  }
82  } else {
83  ATH_MSG_INFO("Could not retrieve CondAttrListCollection " << *itr);
84  }
85  }
86  return StatusCode::SUCCESS;
87 }
88 
90 {
91  return StatusCode::SUCCESS;
92 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
IOVDbTestCoolDCS::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: IOVDbTestCoolDCS.cxx:36
CondAttrListCollection::end
const_iterator end() const
Definition: CondAttrListCollection.h:315
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
AthenaAttributeList::print
void print(std::ostream &os) const
print to simulate function provided by old POOL AttributeList
Definition: AthenaAttributeList.cxx:16
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
IOVDbTestCoolDCS.h
IOVDbTestCoolDCS::finalize
virtual StatusCode finalize() override
Definition: IOVDbTestCoolDCS.cxx:89
CondAttrListCollection::begin
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
Definition: CondAttrListCollection.h:309
IOVDbTestCoolDCS::IOVDbTestCoolDCS
IOVDbTestCoolDCS(const std::string &name, ISvcLocator *pSvcLocator)
Definition: IOVDbTestCoolDCS.cxx:13
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
AthenaAttributeList.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IOVDbTestCoolDCS::~IOVDbTestCoolDCS
virtual ~IOVDbTestCoolDCS()
Definition: IOVDbTestCoolDCS.cxx:21
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IOVDbTestCoolDCS::initialize
virtual StatusCode initialize() override
Definition: IOVDbTestCoolDCS.cxx:24
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
IOVDbTestCoolDCS::m_par_atrcollist
std::vector< std::string > m_par_atrcollist
Definition: IOVDbTestCoolDCS.h:30
IOVDbTestCoolDCS::m_par_atrlist
std::vector< std::string > m_par_atrlist
Definition: IOVDbTestCoolDCS.h:28