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