ATLAS Offline Software
Loading...
Searching...
No Matches
OutputConditionsAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
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/"+
43 StatusCode sc = m_streamer.retrieve();
44 if (sc.isFailure()) {
45 ATH_MSG_ERROR ("Unable to find AthenaOutputStreamTool with name " <<
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(std::move(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],
179 folders[iobj],tags[iobj],timeToNano(m_par_time1),timeToNano(m_par_time2));
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
197uint64_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) {
203 } else {
204 return static_cast<uint64_t>(timesec)*1000000000;
205 }
206}
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
uint32_t CLID
The Class ID type.
Interface to an output stream tool.
This is an interface to a tool used to register conditions objects in the Interval of Validity (IOV) ...
static Double_t sc
static const std::vector< std::string > types
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
std::vector< TypeKeyPair > TypeKeyPairs
static constexpr uint64_t MAXTIMESTAMP
Definition IOVTime.h:58
static constexpr uint32_t MAXEVENT
Definition IOVTime.h:51
uint64_t timeToNano(unsigned long int timesec) const
UnsignedLongProperty m_par_time2
ServiceHandle< IClassIDSvc > p_clidsvc
Gaudi::Property< bool > m_par_writeIOV
ServiceHandle< IIOVRegistrationSvc > p_regsvc
OutputConditionsAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< unsigned int > m_par_lumib2
Gaudi::Property< std::vector< std::string > > m_par_iovtags
ToolHandle< IAthenaOutputStreamTool > IAthenaOutputStreamTool_t
Gaudi::Property< bool > m_par_timestamp
IAthenaOutputStreamTool_t m_streamer
Gaudi::Property< std::string > m_streamName
Gaudi::Property< std::vector< std::string > > m_objectList
Gaudi::Property< unsigned int > m_par_run2
UnsignedLongProperty m_par_time1
Gaudi::Property< unsigned int > m_par_lumib1
Gaudi::Property< unsigned int > m_par_run1
std::vector< std::string > tags
Definition hcg.cxx:105