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