ATLAS Offline Software
OutputConditionsAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // OutputConditionsAlg.cxx
6 // Algorithm to provide simple writing of conditions data to outputstream
7 // and optional registration in IOV database
8 // Richard Hawkings, started 1/9/05, from skeleton by Walter Lampl
9 
10 #include "GaudiKernel/IClassIDSvc.h"
13 #include "OutputConditionsAlg.h"
14 
15 
17  ISvcLocator* pSvcLocator) :
18  AthAlgorithm(name, pSvcLocator)
19 {}
20 
21 
23 {}
24 
25 
27  ATH_MSG_DEBUG ("in initialize()");
28 
29  // get pointer to ClassIDSvc
30  if (StatusCode::SUCCESS!= p_clidsvc.retrieve()) {
31  ATH_MSG_FATAL ("ClassIDSvc not found");
32  return StatusCode::FAILURE;
33  }
34  if (m_par_writeIOV) {
35  // get pointer to IOVRegistrationSvc
36  if (StatusCode::SUCCESS!=p_regsvc.retrieve()) {
37  ATH_MSG_FATAL ("IOVRegistrationSvc not found");
38  return StatusCode::FAILURE;
39  }
40  }
41  m_streamer = IAthenaOutputStreamTool_t("AthenaOutputStreamTool/"+
42  m_streamName);
43  StatusCode sc = m_streamer.retrieve();
44  if (sc.isFailure()) {
45  ATH_MSG_ERROR ("Unable to find AthenaOutputStreamTool with name " <<
46  m_streamName);
47  return StatusCode::FAILURE;
48  }
49  return StatusCode::SUCCESS;
50 }
51 
52 
54 
55  return StatusCode::SUCCESS;
56 }
57 
59  ATH_MSG_INFO ("Finalize: preparing to write conditions objects ");
60 
61  StatusCode sc = m_streamer->connectOutput();
62  if (sc.isFailure()) {
63  ATH_MSG_ERROR ("Could not connect stream to output");
64  return( StatusCode::FAILURE);
65  }
66  // create list of objects
67  std::vector<std::string> types;
68  std::vector<std::string> keys;
69  std::vector<std::string> folders;
70  std::vector<std::string> tags;
71  for (unsigned int iobj=0;iobj<m_objectList.size();++iobj) {
72  // if object name contains a '#', it represents a specific typename#key
73  std::string::size_type ihash=m_objectList[iobj].find_first_of("#");
74  if (ihash==std::string::npos) {
75  // no hash, get the default object for this class, and set key
76  // note this will only get ONE object
77  // first need to know CLID from typename
78  CLID clid;
79  if (StatusCode::SUCCESS==p_clidsvc->getIDOfTypeName(
80  m_objectList[iobj],clid)) {
81  SG::DataProxy* proxy=detStore()->proxy(clid);
82  if (proxy) {
83  types.push_back(m_objectList[iobj]);
84  keys.push_back(proxy->name());
85  folders.push_back(proxy->name());
86  if (iobj<m_par_iovtags.size()) {
87  tags.push_back(m_par_iovtags[iobj]);
88  } else {
89  tags.push_back("");
90  }
91  } else {
92  ATH_MSG_ERROR ("Could not get default proxy for CLID " <<
93  clid << " typename " << m_objectList[iobj]);
94  }
95  } else {
96  ATH_MSG_ERROR ("Could not get CLID from typename " <<
97  m_objectList[iobj]);
98  }
99  } else {
100  types.push_back(m_objectList[iobj].substr(0,ihash));
101  // a second hash allows the folder to be specified after the key
102  // otherwise the folder name is taken to be the same as the key name
103  std::string::size_type ihash2=m_objectList[iobj].find_first_of("#",ihash+1);
104  if (ihash2==std::string::npos) {
105  std::string key=m_objectList[iobj].substr(ihash+1,std::string::npos);
106  keys.push_back(key);
107  folders.push_back(key);
108  } else {
109  keys.push_back(m_objectList[iobj].substr(ihash+1,ihash2-ihash-1));
110  folders.push_back(m_objectList[iobj].substr(ihash2+1,
111  std::string::npos));
112  }
113  if (iobj<m_par_iovtags.size()) {
114  tags.push_back(m_par_iovtags[iobj]);
115  } else {
116  tags.push_back("");
117  }
118  }
119  }
120  // list out all typename/key pairs to be written and construct vector
121  int nObjects=types.size();
122  IAthenaOutputStreamTool::TypeKeyPairs typeKeys(nObjects);
123  ATH_MSG_INFO ("Identified a total of " << nObjects <<
124  " objects to write out:");
125  // leave now if nothing to write
126  if (nObjects==0) return StatusCode::SUCCESS;
127  for (int i=0;i<nObjects;i++) {
128  typeKeys[i]=IAthenaOutputStreamTool::TypeKeyPair(types[i],keys[i]);
129  ATH_MSG_INFO (i << ": " << types[i] << "#" << keys[i] <<
130  "#" << folders[i]);
131  // check object actually exists, else return failure
132  CLID clid;
133  SG::DataProxy* proxy=0;
134  if (StatusCode::SUCCESS==p_clidsvc->getIDOfTypeName(types[i],clid))
135  proxy=detStore()->proxy(clid,keys[i]);
136  if (proxy==0) {
137  ATH_MSG_ERROR ("Could not find proxy for object with key " <<
138  keys[i] << " - abort write");
139  return StatusCode::FAILURE;
140  }
141  }
142 
143  // stream output (write objects)
144  sc=m_streamer->streamObjects(typeKeys);
145  if (sc.isFailure()) {
146  ATH_MSG_ERROR ("Could not stream out objects");
147  return StatusCode::FAILURE;
148  }
149  // commit output
150  sc=m_streamer->commitOutput();
151  if (sc.isFailure()) {
152  ATH_MSG_ERROR ("Could not commit output stream");
153  return StatusCode::FAILURE;
154  }
155  ATH_MSG_INFO ("Written " << nObjects << " objects to output stream");
156 
157  if (m_par_writeIOV) {
158  msg() << MSG::INFO <<
159  "Register objects in IOV database, interval of validity ";
160  if (m_par_timestamp) {
161  msg() << "[time] from [" <<
162  m_par_time1.value() << "] to [" << m_par_time2.value() << "]" << endmsg;
163  } else {
164  msg() << "[run,LB] from [" <<
165  m_par_run1.value() << "," << m_par_lumib1.value() << "] to [" << m_par_run2.value() <<
166  "," << m_par_lumib2.value() << "]" << endmsg;
167  }
168  int nreg=0;
169  for (int iobj=0;iobj<nObjects;++iobj) {
170  msg() << MSG::INFO << "Register object " << types[iobj] << "#" <<
171  keys[iobj] << " in IOV database folder " << folders[iobj] << " ";
172  if (tags[iobj]=="") {
173  msg() << MSG::INFO << "without tagging" << endmsg;
174  } else {
175  msg() << MSG::INFO << "with tag " << tags[iobj] << endmsg;
176  }
177  if (m_par_timestamp) {
178  sc=p_regsvc->registerIOV(types[iobj],keys[iobj],
180  } else {
181  sc=p_regsvc->registerIOV(types[iobj],keys[iobj],
183  }
184  if (sc==StatusCode::SUCCESS) {
185  ++nreg;
186  } else {
187  ATH_MSG_ERROR ("Registration failed!");
188  }
189  }
190  ATH_MSG_INFO ("Registered " << nreg << " objects in IOV database");
191  } else {
192  ATH_MSG_INFO ("Objects NOT registered in IOV database");
193  }
194  return StatusCode::SUCCESS;
195 }
196 
197 uint64_t OutputConditionsAlg::timeToNano(unsigned long int timesec) const
198 {
199  // convert time specified in seconds to ns used by COOL
200  // use the magic value MAXEVENT to signal full range
201  if (timesec==IOVTime::MAXEVENT) {
202  return IOVTime::MAXTIMESTAMP;
203  } else {
204  return static_cast<uint64_t>(timesec)*1000000000;
205  }
206 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
IAthenaOutputStreamTool::TypeKeyPairs
std::vector< TypeKeyPair > TypeKeyPairs
Definition: IAthenaOutputStreamTool.h:100
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
OutputConditionsAlg::m_par_lumib2
Gaudi::Property< unsigned int > m_par_lumib2
Definition: OutputConditionsAlg.h:50
OutputConditionsAlg::OutputConditionsAlg
OutputConditionsAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: OutputConditionsAlg.cxx:16
IIOVRegistrationSvc.h
This is an interface to a tool used to register conditions objects in the Interval of Validity (IOV) ...
OutputConditionsAlg::p_regsvc
ServiceHandle< IIOVRegistrationSvc > p_regsvc
Definition: OutputConditionsAlg.h:37
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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
OutputConditionsAlg::m_streamer
IAthenaOutputStreamTool_t m_streamer
Definition: OutputConditionsAlg.h:42
IAthenaOutputStreamTool.h
Interface to an output stream tool.
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
OutputConditionsAlg::p_clidsvc
ServiceHandle< IClassIDSvc > p_clidsvc
Definition: OutputConditionsAlg.h:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
OutputConditionsAlg::initialize
StatusCode initialize()
Definition: OutputConditionsAlg.cxx:26
OutputConditionsAlg::m_par_iovtags
Gaudi::Property< std::vector< std::string > > m_par_iovtags
Definition: OutputConditionsAlg.h:54
OutputConditionsAlg::m_par_time1
UnsignedLongProperty m_par_time1
Definition: OutputConditionsAlg.h:51
IOVTime::MAXTIMESTAMP
static constexpr uint64_t MAXTIMESTAMP
Definition: IOVTime.h:58
IAthenaOutputStreamTool::TypeKeyPair
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
Definition: IAthenaOutputStreamTool.h:99
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
OutputConditionsAlg::finalize
StatusCode finalize()
Definition: OutputConditionsAlg.cxx:58
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
AthAlgorithm
Definition: AthAlgorithm.h:47
IOVTime::MAXEVENT
static constexpr uint32_t MAXEVENT
Definition: IOVTime.h:51
OutputConditionsAlg::m_par_writeIOV
Gaudi::Property< bool > m_par_writeIOV
Definition: OutputConditionsAlg.h:46
OutputConditionsAlg::execute
StatusCode execute()
Definition: OutputConditionsAlg.cxx:53
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
OutputConditionsAlg::timeToNano
uint64_t timeToNano(unsigned long int timesec) const
Definition: OutputConditionsAlg.cxx:197
OutputConditionsAlg::~OutputConditionsAlg
~OutputConditionsAlg()
Definition: OutputConditionsAlg.cxx:22
OutputConditionsAlg::m_par_timestamp
Gaudi::Property< bool > m_par_timestamp
Definition: OutputConditionsAlg.h:53
OutputConditionsAlg::IAthenaOutputStreamTool_t
ToolHandle< IAthenaOutputStreamTool > IAthenaOutputStreamTool_t
Definition: OutputConditionsAlg.h:41
OutputConditionsAlg.h
makeDTCalibBlob_pickPhase.folders
folders
Definition: makeDTCalibBlob_pickPhase.py:346
OutputConditionsAlg::m_par_time2
UnsignedLongProperty m_par_time2
Definition: OutputConditionsAlg.h:52
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
OutputConditionsAlg::m_streamName
Gaudi::Property< std::string > m_streamName
Definition: OutputConditionsAlg.h:45
OutputConditionsAlg::m_par_run1
Gaudi::Property< unsigned int > m_par_run1
Definition: OutputConditionsAlg.h:47
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
OutputConditionsAlg::m_par_run2
Gaudi::Property< unsigned int > m_par_run2
Definition: OutputConditionsAlg.h:49
SG::DataProxy
Definition: DataProxy.h:45
OutputConditionsAlg::m_par_lumib1
Gaudi::Property< unsigned int > m_par_lumib1
Definition: OutputConditionsAlg.h:48
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
OutputConditionsAlg::m_objectList
Gaudi::Property< std::vector< std::string > > m_objectList
Definition: OutputConditionsAlg.h:44