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