ATLAS Offline Software
Loading...
Searching...
No Matches
IOVDbFolder.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// IOVDbFolder.h
6// helper class for IOVDbSvc managing folder access
7// Richard Hawkings, started 24/11/08
8
9#ifndef IOVDBSVC_IOVDBFOLDER_H
10#define IOVDBSVC_IOVDBFOLDER_H
11
12#include <string>
13#include "GaudiKernel/IClassIDSvc.h"
14#include "GaudiKernel/ServiceHandle.h"
19
20#include "CoolKernel/ChannelSelection.h"
21#include "CoolKernel/ValidityKey.h"
22#include "CoolKernel/IFolder.h"
24#include "IOVDbParser.h"
25
28#include <memory>
29#include <algorithm>
30#include "FolderTypes.h"
31#include "IovStore.h"
32
33#include <map>
34#include "nlohmann/json.hpp"
35
36#include "CoralCrestManager.h"
37
38class MsgStream;
39class IOVDbConn;
40class IOpaqueAddress;
41class IAddressCreator;
42class StoreGateSvc;
45class ITagInfoMgr;
46
47namespace IOVDbNamespace {
48 class Cool2Json;
49}
50
51class IOVDbFolder : public AthMessaging {
52public:
53 IOVDbFolder(IOVDbConn* conn, const IOVDbParser& folderprop, MsgStream& msg,
54 IClassIDSvc* clidsvc, IIOVDbMetaDataTool* metadatatool,
55 const bool checklock, const bool outputToFile=false,
56 const std::string & source="COOL_DATABASE",
57 const std::string & crestServer="",const std::string & crestTag="",const bool crestCoolToFile=false);
59
60
61 // access methods to various internal information
62 const std::string& folderName() const;
63 const std::string& key() const;
64 IOVDbConn* conn();
65 bool multiVersion() const;
66 bool timeStamp() const;
67 bool tagOverride() const;
68 bool retrieved() const;
69 bool noOverride() const;
71 bool readMeta() const;
72 bool writeMeta() const;
73 // read from meta data only, otherwise ignore folder
74 bool fromMetaDataOnly() const;
75 // If true, then the end time for an open-ended range will be set to just
76 // past the current event. The end time will be automatically updated on accesses
77 // in subsequent events.
78 bool extensible() const;
79 bool dropped() const;
80 bool iovOverridden() const;
81 const std::string& joTag() const;
82 const std::string& resolvedTag() const;
83 const std::string& eventStore() const;
84 CLID clid() const;
85 unsigned long long bytesRead() const;
86 float readTime() const;
87 const IOVRange& currentRange() const;
88
89 // set methods - used after folder creation to set properties externally
90
91 // mark this folder as using metadata from an input file
92 void useFileMetaData();
93 // set folder description
94 void setFolderDescription(const std::string& description);
95 // set tag override, set override flag as well if setFlag is true
96 // override flag prevents reading of FLMD for this folder if present
97 void setTagOverride(const std::string& tag,const bool setFlag);
98 // set writeMeta flag
99 void setWriteMeta();
100 // set IOV overrides
101 void setIOVOverride(const unsigned int run,const unsigned int lumiblock,
102 const unsigned int time);
103 // mark object as dropped from Storegate
104 void setDropped(const bool dropped);
105
106 // get validityKey for folder, given current time (accounting for overrides)
107 cool::ValidityKey iovTime(const IOVTime& reftime) const;
108
109 // check cache is valid for current time
110 bool cacheValid(const cool::ValidityKey reftime) const;
111
112 // load cache for given validitykey and globalTag
113 bool loadCache(const cool::ValidityKey vkey, const unsigned int cacheDiv,
114 const std::string& globalTag, const bool ignoreMissChan);
115
116 // reset cache to empty
117 void resetCache();
118
119 // fill in object details from cache
120 // set poolPayloadRequested flag if a POOL file was referenced
121 bool getAddress(const cool::ValidityKey reftime,IAddressCreator* persSvc,
122 const unsigned int poolSvcContext,
123 std::unique_ptr<IOpaqueAddress>& address,
124 IOVRange& range,bool& poolPayloadRequested);
125
126 // make summary of usage
127 void summary();
128 // preload address to Storegate (does folder initialisation from COOL)
129 std::unique_ptr<SG::TransientAddress>
130 preLoadFolder(ITagInfoMgr *tagInfoMgr,
131 const unsigned int cacheRun,
132 const unsigned int cacheTime);
133
134 // print out cache
135 void printCache();
136 // reload cache in online mode if ValidityKey returns a new object
137 // with start > previously used start
138 bool loadCacheIfDbChanged(const cool::ValidityKey vkey,
139 const std::string& globalTag,
140 const cool::IDatabasePtr& dbPtr,
141 const ServiceHandle<IIOVSvc>& iovSvc);
142
143private:
144 // clear cache vectors
145 void clearCache();
146 // resolve tag in given folder, using global tag if needed
147 bool resolveTag(const cool::IFolderPtr& fptr, const std::string& globalTag);
148 // interpret given tag as a magic tag
149 bool magicTag(std::string& tag);
150 // call metadata writing tool for given list and range
151 // - version for single channel AttributeList
152 bool addMetaAttrList(const coral::AttributeList& atrlist,
153 const IOVRange& range);
154 // - version for multichannel collection
156
157 // setup shared AttributeListSpecification cache
158 void setSharedSpec(const coral::AttributeList& atrlist);
159
160 // add this IOV to cache, including channel counting if over edge of cache
161 void addIOVtoCache(cool::ValidityKey since, cool::ValidityKey until);
162
163 //override intrinsic (member variable) options from the from a parsed folder description
164 bool overrideOptionsFromParsedDescription(const IOVDbParser & parsedDescription);
165
166 //create transient address, processing symlinks if given
167 std::unique_ptr<SG::TransientAddress>
168 createTransientAddress(const std::vector<std::string> & symlinks);
169
170 //setup cache length according to whether timestamp==ns of epoch
171 void setCacheLength(const bool timeIs_nsOfEpoch, const unsigned int cacheRun, const unsigned int cacheTime);
172
173 //update the cache using either a Cool or CoraCool object (templated)
174 template<class T>
175 unsigned int
177 const auto & objSince = obj.since();
178 const auto & objUntil = obj.until();
179 const auto & objChannel = obj.channelId();
180 ATH_MSG_DEBUG("from DB \t chID: "<<objChannel<<"\tobjstart:\t"<<objSince<<"\t objstop: \t"
181 << objUntil );
182 // The covered flag is used to check whether the
183 // requested IOV time is inside the range covered
184 // by the current cache. If not, a cache reset
185 // will be done.
186 unsigned int counter{};
187 bool covered{false};
188 //find the iterator distance into the channel array which gives the sought ChannelId
189 const auto pCacheChannel = std::find(m_cachechan.begin(), m_cachechan.end(), objChannel);
190 if (pCacheChannel != m_cachechan.end()){
191 //find corresponding iov, which we shall modify
192 const auto iovIdx = std::distance(m_cachechan.begin(), pCacheChannel);
193 const auto & iov = m_iovs.at(iovIdx);
194 if ((iov.first < objSince) and (objSince < iov.second)){
195 // obj time is larger than cache start (and less than cache stop)
196 // ==> update cache
197 ++counter;
198 ATH_MSG_DEBUG("special reload needed on THIS ONE !!!!!!!!!!!");
199 // just change existing IOVRange
200 ATH_MSG_DEBUG("changing "<<iov.second<<" to "<<objSince-1);
201 m_iovs.extendIov(iovIdx, objSince-1);
202 specialCacheUpdate(obj, iovSvc); // reset proxy, add to cache, addIOV
203 covered = true;
204 }
205 if ( (objSince>=iov.first and objSince<iov.second) or (objUntil>iov.first and objUntil<=iov.second) ) covered=true;
206 }
207 if (!covered) {
208 // cache range has not been covered, so update the cache
209 ++counter;
210 specialCacheUpdate(obj, iovSvc);
211 }
212 return counter;
213 }
214
215
216 bool
217 objectIteratorIsValid( cool::IObjectIteratorPtr & objItr){
218 return objItr->goToNext();
219 }
220
221 bool
223 return objItr->hasNext();
224 }
225
226
227 // cache update for online mode
228 void
230
231 void
232 specialCacheUpdate(const cool::IObject& obj,const ServiceHandle<IIOVSvc>& iovSvc);
233
234 // _________ Helper functions for the CREST reading _________
235 using IOVHash=std::pair<IOVDbNamespace::IovStore::Iov_t,std::string>;
236 using IOV2Index=std::pair<cool::ValidityKey,size_t>;
237
238 // Function which converts openended CREST IOVs into non-overlapping IOVs
239 // It returns a vector of non-overlapping IOVs + corresponding Hashes
240 std::vector<IOVHash> fetchCrestIOVs(cool::ValidityKey since, cool::ValidityKey until);
241
242 // Function which reads CREST objects by the cache IOV boundaries
243 std::vector<IOVHash> fetchCrestObjects(cool::ValidityKey since, cool::ValidityKey until, cool::ValidityKey vkey);
244
245 // __________________________________________________________
246
247 // Function for generating dump files
248 void dumpFile(const std::string& dumpName
249 , const cool::ValidityKey& vkey
250 , IOVDbNamespace::Cool2Json* json // Argument for dumping COOL data
251 , bool skipCoolIoV // Argument for dumping COOL data
252 , CoralCrestManager* mng=NULL // Argument for dumping CREST data
253 , const cool::ValidityKey crestVkey=0 // Argument for dumping CREST data
254 ) const;
255
256 ITagInfoMgr* p_tagInfoMgr{nullptr}; // pointer to TagInfoMgr
257 IClassIDSvc* p_clidSvc{nullptr}; // pointer to CLID service
258 IIOVDbMetaDataTool* p_metaDataTool{nullptr}; // pointer to metadata tool (writing)
259 IOVDbConn* m_conn{nullptr}; // pointer to corresponding IOVDbConn object (=0 FLMD)
260 std::string m_foldername; // COOL foldername
261 std::string m_key; // SG key where data is loaded (unique)
262 std::string m_folderDescription;// folder description
263 bool m_multiversion{false}; // is folder multiversion
264 bool m_timestamp{false}; // is folder indexed by timestamp (else runLB)
265 bool m_tagoverride{false}; // is tag reset from override (needed for FLMD)
266 bool m_notagoverride{false}; // tag must not be overridden from input file
267 bool m_writemeta{false}; // is writing to metadata
268 bool m_useFileMetaData{false}; // is using input File MetaData
269 bool m_fromMetaDataOnly{false}; // to be read from metadata only
270 bool m_extensible{false}; // is this an extensible folder?
271 bool m_named{false}; // folder has named channels
272 bool m_iovoverridden{false}; // folder has IOV override
273 bool m_jokey{false}; // folder has non-default key from joboptions
274 bool m_dropped{false}; // data object was dropped from SG
275 bool m_autocache{true}; // indicates if cache length was automatically set
276 bool m_checklock{true}; // indicates if global tags should be checked locked
277 cool::ValidityKey m_iovoverride{0}; // validity key to use
278 IOVDbNamespace::FolderType m_foldertype; // type of data in folder (enum)
279
280 cool::ValidityKey m_cachelength{0}; // length of cache
281 int m_cachehint{0}; // cachehint value (set initial size to Nxchan)
282 int m_cacheinc{0}; // number of cache increments performed
283
284 cool::ChannelSelection m_chansel; // COOL channel selection
285 typedef std::pair<cool::ChannelId,cool::ChannelId> ChanRange;
286 std::vector<ChanRange> m_chanrange; // explicit list of channel ranges
287 // channel range list needed to work around COOL bug 42708 which does not
288 // properly select channels in non-contiguous ranges
289 std::string m_jotag; // raw tag found on job options
290 std::string m_tag; // resolved tag actually used for lookup
291 std::string m_typename; // typename, read from folder description
292 std::string m_eventstore; // associated event store name
293 std::string m_cachepar; // folder cache parameter read from jobopt/desc
294 std::string m_addrheader; // address header string from folder description
295 CLID m_clid{0}; // CLID, read from folder description or ClassIDSvc
296
297 unsigned int m_ndbread{0}; // number of times data read from DB
298 unsigned int m_ncacheread{0}; // number of times data read from cache
299 unsigned int m_nobjread{0}; // number of objects read from DB
300 unsigned long long m_nbytesread{0}; // number of bytes read from DB
301 float m_readtime{0}; // time spent reading data from COOL (in loadcache)
302
303 // channel number and names (latter only filled for 'named' folders)
304 unsigned int m_nchan{0};
305 std::vector<cool::ChannelId> m_channums;
306 std::vector<std::string> m_channames;
307
308 // current range and validity flag
309 bool m_retrieved{false};
311
312 // COOL data cache and limits
313 coral::AttributeListSpecification* m_cachespec{nullptr};
314 std::vector<cool::ChannelId> m_cachechan;
315 std::vector<coral::AttributeList> m_cacheattr;
316 std::vector<unsigned int> m_cacheccstart;
317 std::vector<unsigned int> m_cacheccend;
319 const bool m_outputToFile{false};
320 const bool m_crestCoolToFile{false};
321 const std::string m_source;
322 const std::string m_crestServer;
323 const std::string m_crestTag;
324
325 std::optional<CoralCrestManager> m_crest_mng;
326};
327
328inline const std::string& IOVDbFolder::folderName() const {return m_foldername;}
329inline const std::string& IOVDbFolder::key() const { return m_key;}
330
332
333inline bool IOVDbFolder::multiVersion() const { return m_multiversion; }
334
335inline bool IOVDbFolder::timeStamp() const { return m_timestamp; }
336
337inline bool IOVDbFolder::tagOverride() const { return m_tagoverride; }
338
339inline bool IOVDbFolder::noOverride() const { return m_notagoverride; }
340
341inline bool IOVDbFolder::retrieved() const { return m_retrieved; }
342
345
348
349inline bool IOVDbFolder::readMeta() const { return m_useFileMetaData; }
350
351inline bool IOVDbFolder::writeMeta() const { return m_writemeta; }
352
354
355inline bool IOVDbFolder::extensible() const { return m_extensible; }
356
357inline bool IOVDbFolder::dropped() const { return m_dropped; }
358
359inline bool IOVDbFolder::iovOverridden() const { return m_iovoverridden; }
360
361inline const std::string& IOVDbFolder::joTag() const { return m_jotag; }
362
363inline const std::string& IOVDbFolder::resolvedTag() const { return m_tag; }
364
365inline const std::string& IOVDbFolder::eventStore() const
366{ return m_eventstore; }
367
368inline CLID IOVDbFolder::clid() const { return m_clid; }
369
370inline unsigned long long IOVDbFolder::bytesRead() const
371{ return m_nbytesread; }
372
373inline float IOVDbFolder::readTime() const
374{ return m_readtime; }
375
376inline const IOVRange& IOVDbFolder::currentRange() const { return m_currange; }
377
378inline bool IOVDbFolder::cacheValid(const cool::ValidityKey reftime) const {
379 const auto & [cacheStart, cacheStop]=m_iovs.getCacheBounds();
380 return ((reftime>cacheStart) and (reftime<cacheStop));
381}
382
384
385#endif // IOVDBSVC_IOVDBFOLDER_H
386
#define ATH_MSG_DEBUG(x)
boost::shared_ptr< CoraCoolObjectIter > CoraCoolObjectIterPtr
Header for CoralCrestManager class.
uint32_t CLID
The Class ID type.
nlohmann::json json
Validity Range object.
Basic time unit for IOVSvc.
helper class for IOVDbFolder managing cached iov since/until pairs
MsgStream & msg() const
The standard message stream.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
This class is a collection of AttributeLists where each one is associated with a channel number.
This is an interface to a tool used to manage the IOV Meta Data for a given object in the MetaData St...
const bool m_crestCoolToFile
bool m_fromMetaDataOnly
std::pair< IOVDbNamespace::IovStore::Iov_t, std::string > IOVHash
CLID clid() const
std::vector< unsigned int > m_cacheccend
std::vector< std::string > m_channames
bool multiVersion() const
bool m_notagoverride
coral::AttributeListSpecification * m_cachespec
const std::string m_crestServer
IOVDbConn * m_conn
ITagInfoMgr * p_tagInfoMgr
bool m_tagoverride
bool m_multiversion
bool m_extensible
bool writeMeta() const
IOVDbFolder(IOVDbConn *conn, const IOVDbParser &folderprop, MsgStream &msg, IClassIDSvc *clidsvc, IIOVDbMetaDataTool *metadatatool, const bool checklock, const bool outputToFile=false, const std::string &source="COOL_DATABASE", const std::string &crestServer="", const std::string &crestTag="", const bool crestCoolToFile=false)
cool::ValidityKey m_cachelength
unsigned int m_ndbread
bool loadCacheIfDbChanged(const cool::ValidityKey vkey, const std::string &globalTag, const cool::IDatabasePtr &dbPtr, const ServiceHandle< IIOVSvc > &iovSvc)
bool objectIteratorIsValid(CoraCoolObjectIterPtr &objItr)
void clearCache()
std::string m_eventstore
std::vector< IOVHash > fetchCrestObjects(cool::ValidityKey since, cool::ValidityKey until, cool::ValidityKey vkey)
std::vector< coral::AttributeList > m_cacheattr
bool timeStamp() const
bool readMeta() const
const std::string m_crestTag
std::string m_key
unsigned int cacheUpdateImplementation(T &obj, const ServiceHandle< IIOVSvc > &iovSvc)
bool tagOverride() const
void specialCacheUpdate(CoraCoolObject &obj, const ServiceHandle< IIOVSvc > &iovSvc)
unsigned long long bytesRead() const
std::pair< cool::ValidityKey, size_t > IOV2Index
void dumpFile(const std::string &dumpName, const cool::ValidityKey &vkey, IOVDbNamespace::Cool2Json *json, bool skipCoolIoV, CoralCrestManager *mng=NULL, const cool::ValidityKey crestVkey=0) const
bool magicTag(std::string &tag)
cool::ValidityKey m_iovoverride
bool iovOverridden() const
IOVDbConn * conn()
IOVDbNamespace::FolderType m_foldertype
std::optional< CoralCrestManager > m_crest_mng
bool m_iovoverridden
bool objectIteratorIsValid(cool::IObjectIteratorPtr &objItr)
bool fromMetaDataOnly() const
bool overrideOptionsFromParsedDescription(const IOVDbParser &parsedDescription)
cool::ValidityKey iovTime(const IOVTime &reftime) const
bool retrieved() const
void setTagOverride(const std::string &tag, const bool setFlag)
bool addMetaAttrList(const coral::AttributeList &atrlist, const IOVRange &range)
void setCacheLength(const bool timeIs_nsOfEpoch, const unsigned int cacheRun, const unsigned int cacheTime)
std::vector< IOVHash > fetchCrestIOVs(cool::ValidityKey since, cool::ValidityKey until)
unsigned long long m_nbytesread
const std::string & key() const
void setWriteMeta()
const IOVRange & currentRange() const
bool extensible() const
bool m_useFileMetaData
bool dropped() const
std::vector< cool::ChannelId > m_cachechan
std::string m_folderDescription
bool loadCache(const cool::ValidityKey vkey, const unsigned int cacheDiv, const std::string &globalTag, const bool ignoreMissChan)
void setIOVOverride(const unsigned int run, const unsigned int lumiblock, const unsigned int time)
unsigned int m_nobjread
void setDropped(const bool dropped)
std::unique_ptr< SG::TransientAddress > createTransientAddress(const std::vector< std::string > &symlinks)
IIOVDbMetaDataTool * p_metaDataTool
void setFolderDescription(const std::string &description)
std::unique_ptr< SG::TransientAddress > preLoadFolder(ITagInfoMgr *tagInfoMgr, const unsigned int cacheRun, const unsigned int cacheTime)
bool addMetaAttrListColl(const CondAttrListCollection *coll)
std::pair< cool::ChannelId, cool::ChannelId > ChanRange
float m_readtime
bool cacheValid(const cool::ValidityKey reftime) const
IOVRange m_currange
void addIOVtoCache(cool::ValidityKey since, cool::ValidityKey until)
std::string m_jotag
std::vector< unsigned int > m_cacheccstart
float readTime() const
bool getAddress(const cool::ValidityKey reftime, IAddressCreator *persSvc, const unsigned int poolSvcContext, std::unique_ptr< IOpaqueAddress > &address, IOVRange &range, bool &poolPayloadRequested)
bool resolveTag(const cool::IFolderPtr &fptr, const std::string &globalTag)
std::string m_cachepar
const std::string & eventStore() const
std::string m_typename
const bool m_outputToFile
IOVDbNamespace::FolderType folderType() const
std::vector< cool::ChannelId > m_channums
const std::string & joTag() const
void resetCache()
unsigned int m_ncacheread
cool::ChannelSelection m_chansel
IClassIDSvc * p_clidSvc
std::string m_addrheader
const std::string & resolvedTag() const
IOVDbNamespace::IovStore m_iovs
void setSharedSpec(const coral::AttributeList &atrlist)
const std::string m_source
std::string m_foldername
bool noOverride() const
std::string m_tag
std::vector< ChanRange > m_chanrange
void useFileMetaData()
const std::string & folderName() const
unsigned int m_nchan
Validity Range object.
Definition IOVRange.h:30
Basic time unit for IOVSvc.
Definition IOVTime.h:33
This is a Athena service which manages detector description tag information.
Definition ITagInfoMgr.h:58
The Athena Transient Store API.
std::vector< TFile * > fptr
Definition hcg.cxx:51
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91
int run(int argc, char *argv[])