ATLAS Offline Software
IOVDbFolder.cxx
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.cxx - helper class for IOVDbSvc to manage folder & data cache
6 // Richard Hawkings, started 24/11/08
7 
8 #include "GaudiKernel/Bootstrap.h"
9 #include "GaudiKernel/IOpaqueAddress.h"
10 #include "GaudiKernel/GenericAddress.h"
11 #include "GaudiKernel/IAddressCreator.h"
12 #include "GaudiKernel/ISvcLocator.h"
13 
14 #include "StoreGate/StoreGateSvc.h"
15 #include "CoolKernel/IObject.h"
16 #include "CoolKernel/IObjectIterator.h"
17 #include "CoolKernel/IRecord.h"
18 #include "CoolKernel/IRecordIterator.h"
19 #include "CoralBase/AttributeList.h"
20 #include "CoralBase/AttributeListSpecification.h"
21 #include "CoralBase/Attribute.h"
22 #include "CoralBase/AttributeSpecification.h"
23 #include "CoralBase/Blob.h"
24 #include "TStopwatch.h"
25 
30 
37 
39 
41 
42 #include "IOVDbConn.h"
43 
44 #include "ReadFromFileMetaData.h"
45 #include "IOVDbFolder.h"
46 #include "IOVDbStringFunctions.h"
47 #include "IOVDbCoolFunctions.h"
48 #include "TagFunctions.h"
49 
50 #include "Cool2Json.h"
51 #include "Json2Cool.h"
52 
53 #include "CrestFunctions.h"
54 #include <sstream>
55 #include <stdexcept>
56 #include <fstream>
57 #include <filesystem>
58 
59 #include "CrestApi/CrestApi.h"
61 
62 using namespace IOVDbNamespace;
63 
64 namespace{
65  const std::string fileSuffix{".json"};
66  const std::string delimiter{"."};
67 
68 }
69 
71  const IOVDbParser& folderprop, MsgStream& msg,
72  IClassIDSvc* clidsvc, IIOVDbMetaDataTool* metadatatool,
73  const bool checklock, const bool outputToFile,
74  const std::string & source, const bool crestToFile,
75  const std::string & crestServer, const std::string & crestTag,
76  const bool crestCoolToFile):
77  AthMessaging("IOVDbFolder"),
78  p_clidSvc(clidsvc),
79  p_metaDataTool(metadatatool),
80  m_conn(conn),
81  m_checklock(checklock),
82  m_foldertype(AttrList),
83  m_chansel(cool::ChannelSelection::all()),
84  m_outputToFile{outputToFile},
85  m_crestToFile{crestToFile},
86  m_crestCoolToFile{crestCoolToFile},
87  m_source{source},
88  m_crestServer{crestServer},
89  m_crestTag{crestTag}
90 {
91  // set message same message level as our parent (IOVDbSvc)
92  setLevel(msg.level());
93  // extract settings from the properties
94  // foldername from the 'unnamed' property
95  m_foldername=folderprop.folderName();
96  // SG key from 'key' property, otherwise same as foldername
97  // m_jokey is true if the 'key' property was set - need to remember this
98  // to avoid using folder description <key> if present later
99  m_key=folderprop.key();
100  m_jokey=folderprop.hasKey();
101  // tag from 'tag' property
102  m_jotag=folderprop.tag();
103  // event store from 'eventStoreName' property, default 'StoreGateSvc'
104  m_eventstore=folderprop.eventStoreName();
105  // cachelength (seconds or LB)
106  m_cachepar = folderprop.cache();
107  // check for <noover> - disables using tag override read from input file
108  m_notagoverride=folderprop.noTagOverride();
109  if (m_notagoverride) ATH_MSG_INFO( "Inputfile tag override disabled for " << m_foldername );
110 
111  // channel selection from 'channelSelection' property
112  // syntax is A:B,C:D,E:F
113  // :B implies zero lower limit, A: implies zero upper limit
114  std::string chanspec;
115  if (folderprop.getKey("channelSelection","",chanspec) && !chanspec.empty()) {
116  m_chanrange=IOVDbNamespace::parseChannelSpec<cool::ChannelId>(chanspec);
117  // explicit setting of channel selection
118  // push to the channel selection
119  try{
120  bool first(true);
121  for(const auto & i:m_chanrange){
122  if (first){
123  first = false;
124  m_chansel = cool::ChannelSelection(i.first,i.second);
125  } else {
126  m_chansel.addRange(i.first,i.second);
127  }
128  }
129  } catch (cool::Exception& e) {
130  ATH_MSG_ERROR("defining channel range (must be given in ascending order)");
131  throw;
132  }
133  }
134  if (folderprop.overridesIov(msg)){
135  m_iovoverridden=true;
136  m_iovoverride=folderprop.iovOverrideValue(msg);
137  if (m_timestamp){
138  ATH_MSG_INFO( "Override timestamp to " << m_iovoverride << " for folder " << m_foldername );
139  } else {
140  const auto[run,lumi]=IOVDbNamespace::runLumiFromIovTime(m_iovoverride);
141  ATH_MSG_INFO( "Override run/LB number to [" << run << ":" << lumi << "] for folder " << m_foldername );
142  }
143  }
144 
145  m_fromMetaDataOnly=folderprop.onlyReadMetadata();
146  if (m_fromMetaDataOnly) {
147  ATH_MSG_INFO( "Read from meta data only for folder " << m_foldername );
148  }
149 
150  m_extensible=folderprop.extensible();
151  if (m_extensible) {
152  ATH_MSG_INFO( "Extensible folder " << m_foldername );
153  }
154 
155 }
156 
158  if (m_cachespec!=nullptr) m_cachespec->release();
159 }
160 
162  // enable folder from FLMD at given connection
163  m_useFileMetaData = true;
164  // if previously connected to a real DB connection, remove association
165  if (m_conn!=nullptr) {
166  m_conn->decUsage();
167  m_conn=nullptr;
168  }
169 }
170 
171 void
172 IOVDbFolder::setTagOverride(const std::string& tag,const bool setFlag) {
173  if (m_tagoverride) {
174  ATH_MSG_WARNING( "Request to override tag for folder " <<
175  m_foldername << " to " << tag << " supercedes earlier override to " << m_jotag );
176  } else {
177  if (setFlag) m_tagoverride=true;
178  }
180 }
181 
183  m_writemeta=true;
184 }
185 
186 void
187 IOVDbFolder::setIOVOverride(const unsigned int run,
188  const unsigned int lumiblock,
189  const unsigned int time) {
190  // set IOV override for this folder if run!=0 or time!=0
191  // folder-specific override takes precedence if set
192  if (m_iovoverridden) return;
193  if (m_timestamp) {
194  if (time!=0) {
196  ATH_MSG_INFO( "Override timestamp to " << m_iovoverride << " for folder "<< m_foldername );
197  m_iovoverridden=true;
198  }
199  } else {
200  if (run!=0 || lumiblock!=0) {
202  ATH_MSG_INFO( "Override run/LB number to [" << run << ":" << lumiblock <<
203  "] for folder " << m_foldername );
204  m_iovoverridden=true;
205  }
206  }
207 }
208 
209 // return validitykey for folder, given input reftime
210 // take into account an overridden IOV, if present for folder
211 cool::ValidityKey
212 IOVDbFolder::iovTime(const IOVTime& reftime) const {
213  if (m_iovoverridden) {
214  return m_iovoverride;
215  } else {
216  return (m_timestamp ? reftime.timestamp() : reftime.re_time());
217  }
218 }
219 
220 bool
221 IOVDbFolder::loadCache(const cool::ValidityKey vkey,
222  const unsigned int cacheDiv,
223  const std::string& globalTag,
224  const bool ignoreMissChan) {
225  // load the cache for the given IOVTime, making a range around this time
226  // according to the caching policy
227  // if cacheDiv > 0, specifies number of slices of cache for query alignment
228  // if ignoreMissChan set, don't worry about missing channels outside the cache range
229  // return false if any problem
230  // timer to track amount of time in loadCache
231  TStopwatch cachetimer;
232  const auto & [cachestart, cachestop] = m_iovs.getCacheBounds();
233 
234  bool vectorPayload{};
235  std::string strCrestNodeDesc;
236  if (m_source == "CREST"){
237  CrestFunctions cfunctions(m_crestServer);
238  ATH_MSG_INFO("Download tag would be: "<<m_crestTag);
239 
240  if (m_crest_tag != m_crestTag){
242  m_tag_info = cfunctions.getTagInfo(m_crestTag);
243  }
244 
245  strCrestNodeDesc = cfunctions.getTagInfoElement(m_tag_info,"node_description");
246  vectorPayload = (strCrestNodeDesc.find("CondAttrListVec") != std::string::npos);
247  }
248  else {
249  vectorPayload = (m_foldertype ==CoraCool) or (m_foldertype == CoolVector);
250  }
251 
252  ATH_MSG_DEBUG( "Load cache for folder " << m_foldername << " validitykey " << vkey);
253  // if not first time through, and limit not reached,and cache was not reset,
254  // and we are going forwards in time, double cachesize
255  if (m_ndbread>0 && m_cacheinc<3 && (cachestop!=cachestart) && vkey>cachestart && m_autocache) {
256  m_cachelength*=2;
257  ++m_cacheinc;
258  ATH_MSG_INFO( "Increase cache length (step " << m_cacheinc << ") for folder " << m_foldername << " to " << m_cachelength << " at validityKey " << vkey );
259  }
260  ++m_ndbread;
261  auto [changedCacheLo, changedCacheHi] = m_iovs.getCacheBounds();
262  if (cacheDiv>0) {
263  // quantise queries on boundaries that are sub-multiples of cache length
264  unsigned long long cacheq=m_cachelength/cacheDiv;
265  if (cacheq>0) changedCacheLo=vkey - vkey % cacheq;
266  changedCacheHi=changedCacheLo+m_cachelength;
267  } else {
268  // for run/LB indexed folders and cache of at least one run
269  // align the query to the run start
271  changedCacheLo=vkey & (0x7FFFFFFFLL << 32);
272  } else {
273  changedCacheLo=vkey;
274  }
275  changedCacheHi=vkey+m_cachelength;
276  }
277  if (changedCacheHi>cool::ValidityKeyMax) changedCacheHi=cool::ValidityKeyMax;
278  //
279  //
280  m_iovs.setCacheBounds(IovStore::Iov_t(changedCacheLo, changedCacheHi));
281  //
282  const auto & [since, until] = m_iovs.getCacheBounds();
283  ATH_MSG_DEBUG( "IOVDbFolder:loadCache limits set to [" << since << "," << until << "]" );
284 
285  if (m_cachespec==nullptr) {
286  // on first init, guess size based on channel count
287  unsigned int estsize=m_nchan;
288  if (m_cachehint > 0) {
289  estsize=estsize*m_cachehint;
290  } else if (m_timestamp) {
291  // for timestamp indexed folder (likely to be DCS), increase this
292  estsize=estsize*3;
293  }
294  // note this is only reserved size of the cache vectors
295  // actual datastorage is mainly allocated by pointer elsewhere
296  m_cachechan.reserve(estsize);
297  m_cacheattr.reserve(estsize);
298  if (vectorPayload) {
299  m_cacheccstart.reserve(estsize);
300  m_cacheccend.reserve(estsize);
301  }
302  } else {
303  // reset cache if it already contained data
304  // TBIO - could keep the attributelists and only change the data on reload
305  // avoiding some attributelist construction/destruction
306  clearCache();
307  }
308  bool retrievedone=false;
309  unsigned int nChannelsExpected = (m_chanrange.empty())? (m_nchan) : (IOVDbNamespace::countSelectedChannels(m_channums, m_chansel));
310  if (m_source == "COOL_DATABASE"){
311  // query to fill cache - request for database activates connection
312  if (not m_conn->open()) {
313  ATH_MSG_FATAL( "Conditions database connection " <<m_conn->name() << " cannot be opened - STOP" );
314  return false;
315  }
316  // access COOL inside try/catch in case of using stale connection
317  unsigned int attempts=0;
318 
319  ATH_MSG_DEBUG( "loadCache: Expecting to see " << nChannelsExpected << " channels" );
320  //
321  while (attempts<2 && !retrievedone) {
322  ++attempts;
323  try {
324  unsigned int iadd=0;
325  m_iovs.setIovSpan(IovStore::Iov_t(0,cool::ValidityKeyMax));
326  // check pointer is still valid - can go stale in AthenaMT environment
327  // according to CORAL server tests done by Andrea Valassi (23/6/09)
328  if (not m_conn->valid()) throw std::runtime_error("COOL database pointer invalidated");
329  // access COOL folder in case needed to resolve tag (even for CoraCool)
330  cool::IFolderPtr folder=m_conn->getFolderPtr(m_foldername);
331 
332  // resolve the tag for MV folders if not already done so
333  if (m_multiversion && m_tag.empty()) {
334  if (!resolveTag(folder,globalTag)) return false;
335 
336  }
337  if (m_foldertype==CoraCool) {
338  // CoraCool retrieve
340  CoraCoolFolderPtr ccfolder=ccDbPtr->getFolder(m_foldername);
341 
342  auto [since,until] = m_iovs.getCacheBounds();
343  CoraCoolObjectIterPtr itr=ccfolder->browseObjects(since, until,m_chansel,m_tag);
344  while (itr->hasNext()) {
345  CoraCoolObjectPtr obj=itr->next();
346  //should be skipping non-selected channels here?
347  addIOVtoCache(obj->since(),obj->until());
348  m_cachechan.push_back(obj->channelId());
349  // store all the attributeLists in the buffer
350  // save pointer to start
351  const unsigned int istart=m_cacheattr.size();
352  for (CoraCoolObject::const_iterator pitr=obj->begin();pitr!=obj->end(); ++pitr) {
353  // setup shared specification on first store
354  if (m_cachespec==nullptr) setSharedSpec(*pitr);
355  // use the shared specification in storing the payload
356  m_cacheattr.emplace_back(*m_cachespec,true);
357  m_cacheattr.back().fastCopyData(*pitr);
359  }
360  // save pointers to start and end
361  m_cacheccstart.push_back(istart);
362  m_cacheccend.push_back(m_cacheattr.size());
363  ++iadd;
364  }
365  itr->close();
366  retrievedone=true;
367  } else {
368  auto [since,until] = m_iovs.getCacheBounds();
369  cool::IObjectIteratorPtr itr=folder->browseObjects(since,until,m_chansel,m_tag);
372  dumpFile("cool_dump",vkey,&json,m_crestCoolToFile,nullptr,"","");
373  }
374  while (itr->goToNext()) {
375  const cool::IObject& ref=itr->currentRef();
376  addIOVtoCache(ref.since(),ref.until());
377  m_cachechan.push_back(ref.channelId());
378  if (m_foldertype==CoolVector) {
379  // store all the attributeLists in the buffer
380  // save pointer to start
381  const unsigned int istart=m_cacheattr.size();
382  // get payload iterator and vector of payload records
383  cool::IRecordIterator& pitr=ref.payloadIterator();
384  const cool::IRecordVectorPtr& pvec=pitr.fetchAllAsVector();
385  for (cool::IRecordVector::const_iterator vitr=pvec->begin();vitr!=pvec->end();++vitr) {
386  const coral::AttributeList& atrlist=(*vitr)->attributeList();
387  // setup shared specification on first store
388  if (m_cachespec==nullptr) setSharedSpec(atrlist);
389  // use the shared specification in storing the payload
390  m_cacheattr.emplace_back(*m_cachespec,true);
391  m_cacheattr.back().fastCopyData(atrlist);
393  }
394  // save pointers to start and end
395  m_cacheccstart.push_back(istart);
396  m_cacheccend.push_back(m_cacheattr.size());
397  ++iadd;
398  pitr.close();
399  } else {
400  // standard COOL retrieve
401  const coral::AttributeList& atrlist=ref.payload().attributeList();
402  // setup shared specification on first store
403  if (m_cachespec==nullptr) setSharedSpec(atrlist);
404  // use the shared specification in storing the payload
405  m_cacheattr.emplace_back(*m_cachespec,true);
406  m_cacheattr[iadd].fastCopyData(atrlist);
407  ++iadd;
409  }
410  }
411  itr->close();
412  retrievedone=true;
413  }
414  ATH_MSG_DEBUG( "Retrieved " << iadd << " objects for "<< m_nchan << " channels into cache" );
415  m_nobjread+=iadd;
416  } catch (std::exception& e) {
417  ATH_MSG_WARNING( "COOL retrieve attempt " << attempts << " failed: " << e.what() );
418  // disconnect and reconnect
419  if (not m_conn->dropAndReconnect()) ATH_MSG_ERROR("Tried to reconnect in 'loadCache' but failed");
420  }
421  }
422  } // End of COOL reading section
423  else {
424  // CREST reading section
425  auto [since,until] = m_iovs.getCacheBounds();
426  std::vector<BasicFolder> crestObjs;
427  try {
428  crestObjs = fetchCrestObjects(since,until,vectorPayload,vkey,strCrestNodeDesc);
429  }
430  catch(std::exception&) {
431  return false;
432  }
433 
434  unsigned int iadd = 0;
435 
436  if (!resolveTag(nullptr,globalTag)) return false;
437  ATH_MSG_DEBUG( "loadCache: Expecting to see " << nChannelsExpected << " channels" );
438 
439  for(BasicFolder& basicFolder : crestObjs) {
440  const auto & channelNumbers=basicFolder.channelIds();
441  ATH_MSG_DEBUG( "ChannelIds is " << channelNumbers.size() << " long" );
442  for (const auto & chan: channelNumbers){
443  addIOVtoCache(basicFolder.iov().first, basicFolder.iov().second);
444  m_cachechan.push_back(chan);
445  if (basicFolder.isVectorPayload()) {
446  const auto & vPayload = basicFolder.getVectorPayload(chan);
447  const unsigned int istart=m_cacheattr.size();
448  for (const auto & attList:vPayload){
449  if (m_cachespec==nullptr) setSharedSpec(attList);
450  m_cacheattr.emplace_back(*m_cachespec,true);// maybe needs to be cleared before
451  m_cacheattr.back().fastCopyData(attList);
453  }
454  m_cacheccstart.push_back(istart);
455  m_cacheccend.push_back(m_cacheattr.size());
456  ++iadd;
457  } else {
458  auto const & attList = basicFolder.getPayload(chan);
459  if (m_cachespec==nullptr) setSharedSpec(attList);
460  const coral::AttributeList c(*m_cachespec,true);
461  m_cacheattr.push_back(c);// maybe needs to be cleared before
462  m_cacheattr.back().fastCopyData(attList);
464  ++iadd;
465  }
466  }
467  }
468  retrievedone=true;
469  ATH_MSG_DEBUG( "Retrieved " << iadd << " objects for "<< m_nchan << " channels into cache" );
470  m_nobjread+=iadd;
471  } // End of reading from CREST
472 
473  if (!retrievedone) {
474  const auto & [since,until] = m_iovs.getCacheBounds();
475  ATH_MSG_ERROR( "Could not retrieve Cond data for folder " <<
476  m_foldername << " tag " << m_tag << " validityKeys [" << since <<
477  "," << until << "]" );
478  return false;
479  }
480  // check if cache can be stretched according to extent of IOVs crossing
481  // boundaries - this requires all channels to have been seen
482  const auto & [nChannelsLo, nChannelsHi] = m_iovs.numberOfIovsOnBoundaries();
483  const auto missing=std::pair<unsigned int, unsigned int>(nChannelsExpected-nChannelsLo, nChannelsExpected-nChannelsHi);
484  ATH_MSG_DEBUG( "Cache retrieve missing " << missing.first << " lower and " << missing.second << " upper channels" );
485  //
486  const auto & span = m_iovs.getMinimumStraddlingSpan();
487  const auto & [cacheStart, cacheStop] =m_iovs.getCacheBounds();
488  //new code
489  if ((missing.first==0 or ignoreMissChan) and m_iovs.extendCacheLo()){
490  ATH_MSG_DEBUG( "Lower cache limit extended from " << cacheStart << " to " << span.first );
491  }
492 
493  if ((missing.second==0 or ignoreMissChan) and m_iovs.extendCacheHi()){
494  ATH_MSG_DEBUG( "Upper cache limit extended from " << cacheStop << " tp " << span.second );
495  }
496  //
497  // keep track of time spent
498  const float timeinc=cachetimer.RealTime();
499  m_readtime+=timeinc;
500  ATH_MSG_DEBUG( "Cache retrieve done for " << m_foldername << " with " <<
501  m_iovs.size() << " objects stored in" << std::fixed <<
502  std::setw(8) << std::setprecision(2) << timeinc << " s" );
503  return true;
504 }
505 
506 bool IOVDbFolder::loadCacheIfDbChanged(const cool::ValidityKey vkey,
507  const std::string& globalTag,
508  const cool::IDatabasePtr& /*dbPtr*/,
509  const ServiceHandle<IIOVSvc>& iovSvc) {
510  ATH_MSG_DEBUG( "IOVDbFolder::recheck with DB for folder " << m_foldername<< " validitykey: " << vkey );
511  if (m_iovs.empty()) {
512  ATH_MSG_DEBUG( "Cache empty ! returning ..." );
513  return true;
514  }
515  ++m_ndbread;
516  // access COOL inside try/catch in case of using stale connection
517  unsigned int attempts = 0;
518  bool retrievedone = false;
519  //
520  unsigned int nChannelsExpected = (m_chanrange.empty())? (m_nchan) : (IOVDbNamespace::countSelectedChannels(m_channums, m_chansel));
521  ATH_MSG_DEBUG( "loadCacheIfDbChanged: Expecting to see " << nChannelsExpected << " channels" );
522  //
523  while (attempts<2 && !retrievedone) {
524  ++attempts;
525  try {
526  m_iovs.setIovSpan(IovStore::Iov_t(0,cool::ValidityKeyMax));
527  // access COOL folder in case needed to resolve tag (even for CoraCool)
528  cool::IFolderPtr folder=m_conn->getFolderPtr(m_foldername);
529  // resolve the tag for MV folders if not already done so
530  if (m_multiversion && m_tag.empty()) { // NEEDED OR NOT?
531  if (!resolveTag(folder,globalTag)) return false;
532  }
533  int counter=0;
534  const auto & [since,until] = m_iovs.getCacheBounds();
535  ATH_MSG_DEBUG(IOVDbNamespace::folderTypeName(m_foldertype)<<" type. cachestart:\t"<<since<<" \t cachestop:"<< until);
536  ATH_MSG_DEBUG("checking range: "<<vkey+1<<" - "<<vkey+2);
537  if (m_foldertype==CoraCool) {
538  // CoraCool retrieve initialise CoraCool connection
540  // this returns all the objects whose IOVRanges crosses this range .
541  CoraCoolObjectIterPtr itr = ccfolder->browseObjects(vkey+1, vkey+2,m_chansel,m_tag);
542  while (objectIteratorIsValid(itr)) {
543  CoraCoolObjectPtr obj = itr->next();
544  //code delegated to templated member, allowing for difference between CoraCoolObjectPtr and IObject
546  }
547  itr->close();
548  } else {
549  // this returns all the objects whose IOVRanges crosses this range .
550  cool::IObjectIteratorPtr itr=folder->browseObjects(vkey+1, vkey+2, m_chansel,m_tag);
551  while (objectIteratorIsValid(itr)) {
552  const cool::IObject& ref=itr->currentRef();
553  //code delegated to templated member, allowing for difference between CoraCoolObjectPtr and IObject
555  }
556  itr->close();
557  }
558  retrievedone=true;
559  ATH_MSG_DEBUG( "Need a special update for " << counter << " objects " );
561  }catch (std::exception& e) {
562  ATH_MSG_WARNING( "COOL retrieve attempt " << attempts << " failed: " << e.what() );
563  if (not m_conn->dropAndReconnect()) ATH_MSG_ERROR("Tried reconnecting in loadCacheIfDbChanged but failed");
564  }
565  }
566  return true;
567 }
568 
569 void
571 
572  // reset IOVRange in IOVSvc to trigger reset of object. Set to a
573  // time earlier than since.
574  IOVRange range = IOVDbNamespace::makeRange(obj.since()-2, obj.since()-1, m_timestamp);
575  if (StatusCode::SUCCESS != iovSvc->setRange(clid(), key(), range, eventStore())) {
576  ATH_MSG_ERROR( "IOVDbFolder::specialCacheUpdate - setRange failed for folder "
577  << folderName() );
578  return;
579  }
580  addIOVtoCache(obj.since(),obj.until());
581  m_cachechan.push_back(obj.channelId());
582  // store all the attributeLists in the buffer save pointer to start
583  const unsigned int istart=m_cacheattr.size();
584  for (CoraCoolObject::const_iterator pitr=obj.begin(); pitr!=obj.end();++pitr) {
585  // use the shared specification in storing the payload
586  m_cacheattr.emplace_back(*m_cachespec,true);
587  m_cacheattr.back().fastCopyData(*pitr);
589  }
590  // save pointers to start and end
591  m_cacheccstart.push_back(istart);
592  m_cacheccend.push_back(m_cacheattr.size());
593 }
594 
595 void
596 IOVDbFolder::specialCacheUpdate(const cool::IObject& ref,const ServiceHandle<IIOVSvc>& iovSvc) {
597 
598  // reset IOVRange in IOVSvc to trigger reset of object. Set to a
599  // time earlier than since.
600  IOVRange range = IOVDbNamespace::makeRange(ref.since()-2, ref.since()-1, m_timestamp);
601  if (StatusCode::SUCCESS != iovSvc->setRange(clid(), key(), range, eventStore())) {
602  ATH_MSG_ERROR( "IOVDbFolder::specialCacheUpdate - setRange failed for folder "
603  << folderName() );
604  return;
605  }
606  // add new object.
607  addIOVtoCache(ref.since(),ref.until());
608  m_cachechan.push_back(ref.channelId());
609  const coral::AttributeList& atrlist = ref.payload().attributeList();
610  // use the shared specification in storing the payload
611  const unsigned int istart=m_cacheattr.size();
612  m_cacheattr.emplace_back(*m_cachespec,true);// maybe needs to be cleared before
613  m_cacheattr.back().fastCopyData(atrlist);
615  if (m_foldertype==CoolVector) {
616  // save pointers to start and end
617  m_cacheccstart.push_back(istart);
618  m_cacheccend.push_back(m_cacheattr.size());
619  }
620 }
621 
622 void
624  // reset the cache to unfilled state, used if no more data will be required
625  // from this folder
627  clearCache();
628 }
629 
630 bool
631 IOVDbFolder::getAddress(const cool::ValidityKey reftime,
632  IAddressCreator* persSvc,
633  const unsigned int poolSvcContext,
634  std::unique_ptr<IOpaqueAddress>& address,
635  IOVRange& range, bool& poolPayloadReq) {
636 
637  ++m_ncacheread;
638  // will produce strAddress and one pointer type depending on folder data
639  std::string strAddress;
640  AthenaAttributeList* attrList=nullptr;
641  CondAttrListCollection* attrListColl=nullptr;
642  CondAttrListVec* attrListVec=nullptr;
643  cool::ValidityKey naystart=0;
644  cool::ValidityKey naystop=cool::ValidityKeyMax;
645  if( m_useFileMetaData ) {
647  readFromMetaData(m_foldername, p_metaDataTool, reftime, m_timestamp);
648  if (not readFromMetaData.isValid()){
649  ATH_MSG_ERROR( "read:Could not find IOVPayloadContainer for folder "<< m_foldername );
650  return false;
651  }
652  // read from file metadata
653  m_foldertype=readFromMetaData.folderType();
654  m_nobjread+=readFromMetaData.numberOfObjects();
655  poolPayloadReq=readFromMetaData.poolPayloadRequested();
656  strAddress = readFromMetaData.stringAddress();
657  range = readFromMetaData.range();
658  attrList = readFromMetaData.attributeList();
659  attrListColl = readFromMetaData.attrListCollection();
660  ATH_MSG_DEBUG( "Read file metadata for folder " << m_foldername << " foldertype is " << m_foldertype );
661  } else {
662  // COOL/CoraCool data to be read from cache
663  // for AttrListColl or PoolRefColl, need a CondAttrListCollection ready
664  // to receive the data
666  attrListColl=new CondAttrListCollection(!m_timestamp);
667  } else if (m_foldertype==CoraCool || m_foldertype==CoolVector) {
668  // for CoraCool/CoolVector, assume we will get everything in the cache
669  attrListVec=new CondAttrListVec(!m_timestamp, m_cacheattr.size());
670  }
671  // loop over cached data
672  unsigned int nobj=0;
673  // keep track of closest neighbouring IOVs
674  std::tie(naystart, naystop) = m_iovs.getCacheBounds();
675 
676  for (unsigned int ic=0; ic!=m_iovs.size();++ic) {
677  const auto & thisIov = m_iovs.at(ic);
678  if (thisIov.first<=reftime && reftime<thisIov.second) {
679  ++nobj;
681  // retrieve of AthenaAttributeList or single PoolRef
682  if (m_foldertype==AttrList) {
683  attrList=new AthenaAttributeList(m_cacheattr[ic]);
684  strAddress="POOLContainer_AthenaAttributeList][CLID=x";
685  } else {
686  strAddress=(m_cacheattr[ic])["PoolRef"].data<std::string>();
687  }
688  range=IOVDbNamespace::makeRange(thisIov.first,thisIov.second, m_timestamp);
689  // write meta-data if required
690  if (m_writemeta)
691  if (!addMetaAttrList(m_cacheattr[ic],range)) return false;
693  // retrieve of CondAttrListCollection
694  attrListColl->addShared(m_cachechan[ic],m_cacheattr[ic]);
695  attrListColl->add(m_cachechan[ic],IOVDbNamespace::makeRange(thisIov.first,thisIov.second, m_timestamp));
696  } else if (m_foldertype==CoraCool || m_foldertype==CoolVector) {
697  // retrieval of CoraCool data
698  attrListVec->addSlice(IOVDbNamespace::makeRange(thisIov.first,thisIov.second, m_timestamp),
701  if (m_writemeta) {
702  ATH_MSG_ERROR( "Writing of CoraCool folders to file metadata not implemented");
703  return false;
704  }
705  } else {
706  ATH_MSG_ERROR( "Unhandled folder type " << m_foldertype);
707  return false;
708  }
709  } else if (thisIov.second<=reftime && thisIov.second>naystart) {
710  naystart=thisIov.second;
711  } else if (thisIov.first>reftime && thisIov.first<naystop) {
712  naystop=thisIov.first;
713  }
714  }
715  // post-loop actions
717  // set up channel names if required
718  if (m_named) {
719  std::vector<std::string>::const_iterator nitr=m_channames.begin();
720  for (std::vector<cool::ChannelId>::const_iterator chitr=m_channums.begin();
721  chitr!=m_channums.end(); ++chitr,++nitr) {
722  attrListColl->add(*chitr,*nitr);
723  }
724  }
725  // set range
726  range=attrListColl->minRange();
727  strAddress="POOLContainer_CondAttrListCollection][CLID=x";
728  } else if (m_foldertype==CoraCool || m_foldertype==CoolVector) {
729  range=attrListVec->minRange();
730  strAddress="POOLContainer_CondAttrListVec][CLID=x";
731  } else if (m_foldertype==AttrList || m_foldertype==PoolRef) {
732  // single object retrieve - should have exactly one object
733  if (nobj==0) {
734  ATH_MSG_ERROR("COOL object not found in single-channel retrieve, folder "
735  << m_foldername << " currentTime " << reftime );
736  return false;
737  } else if (nobj>1) {
738  ATH_MSG_ERROR( nobj <<
739  " valid objects found for single-channel retrieve, folder " <<
740  m_foldername << " currentTime " << reftime );
741  return false;
742  }
743  }
744  ATH_MSG_DEBUG( "Retrieved object: folder " << m_foldername
745  << " at IOV " << reftime << " channels " << nobj << " has range "
746  << range );
747  // shrink range so it does not extend into 'gap' channels or outside cache
748  IOVTime tnaystart=makeEpochOrRunLumi(naystart, m_timestamp);
749  IOVTime tnaystop=makeEpochOrRunLumi(naystop, m_timestamp);
750  IOVTime rstart=range.start();
751  IOVTime rstop=range.stop();
752  if (tnaystart > rstart || rstop > tnaystop) {
753  ATH_MSG_DEBUG( "Shrink IOV range for " << m_foldername
754  << " from [" << rstart << ":" << rstop << "] to ["
755  << tnaystart << ":" << tnaystop << "]" );
756  if (tnaystart > rstart) rstart=tnaystart;
757  if (tnaystop < rstop) rstop=tnaystop;
758  range=IOVRange(rstart,rstop);
760  attrListColl->addNewStart(rstart);
761  attrListColl->addNewStop(rstop);
762  }
763  }
764  }
765  // save the range for possible later lookup in IOVDbSvc::getKeyInfo
767  m_retrieved=true;
768  // write metadata for attrListColl if required (after range shrinking)
769  if (m_writemeta &&
771  if (!addMetaAttrListColl(attrListColl)) return false;
772  }
773 
774  // turn the data into an IOpaqueAddress
775  strAddress=m_addrheader+strAddress;
776  IOpaqueAddress* addrp = nullptr;
777  if (StatusCode::SUCCESS!=persSvc->createAddress(0,0,strAddress,addrp)) {
778  ATH_MSG_ERROR( "Could not get IOpaqueAddress from string address "<< strAddress );
779  return false;
780  }
781  address = std::unique_ptr<IOpaqueAddress>(addrp);
782  GenericAddress* gAddr=dynamic_cast<GenericAddress*>(address.get());
783  if (!gAddr) {
784  ATH_MSG_ERROR( "Could not cast IOpaqueAddress to GenericAddress");
785  return false;
786  }
787  // create a new GenericAddress to set pool context
788  if (m_foldertype==AttrListColl) {
789  auto addr = std::make_unique<CondAttrListCollAddress>(*gAddr);
790  addr->setAttrListColl(attrListColl);
791  address = std::move(addr);
792  } else if (m_foldertype==PoolRefColl || m_foldertype==PoolRef) {
793  auto addr = std::make_unique<CondAttrListCollAddress>(gAddr->svcType(),
794  gAddr->clID(),gAddr->par()[0],gAddr->par()[1],
795  poolSvcContext,gAddr->ipar()[1]);
796  if (m_foldertype==PoolRefColl) {
797  addr->setAttrListColl(attrListColl);
798  }
799  address = std::move(addr);
800  poolPayloadReq=true;
801  } else if (m_foldertype==AttrList) {
802  auto addr = std::make_unique<AthenaAttrListAddress>(*gAddr);
803  addr->setAttrList(attrList);
804  address = std::move(addr);
805  } else if (m_foldertype==CoraCool || m_foldertype==CoolVector) {
806  auto addr = std::make_unique<CondAttrListVecAddress>(*gAddr);
807  addr->setAttrListVec(attrListVec);
808  address = std::move(addr);
809  }
810  return true;
811 }
812 
813 
816  // summarise the read statistics for this folder
817  ATH_MSG_INFO( "Folder " << m_foldername << " ("<<folderTypeName
818  << ") db-read " << m_ndbread << "/" <<
819  m_ncacheread << " objs/chan/bytes " << m_nobjread << "/" <<
820  m_nchan << "/" << m_nbytesread << " (( " << std::fixed << std::setw(8)
821  << std::setprecision(2) << m_readtime << " ))s" );
822  // print WARNING if data for this folder was never read from Storegate
823  if (m_ncacheread==0 && m_ndbread>0) {
824  ATH_MSG_WARNING( "Folder " << m_foldername << " is requested but no data retrieved" );
825  }
826 }
827 
828 bool
830  bool success{true};
831  // check for timeStamp indicating folder is timestamp indexed
832  m_timestamp=parsedDescription.timebaseIs_nsOfEpoch();
833  // check for key, giving a different key to the foldername
834  if (auto newkey=parsedDescription.key(); not newkey.empty() and not m_jokey) {
835  ATH_MSG_DEBUG( "Key for folder " << m_foldername << " set to "<< newkey << " from description string" );
836  m_key=newkey;
837  }
838  // check for 'cache' but only if not already found in joboptions
839  if (m_cachepar.empty()) m_cachepar=parsedDescription.cache();
840  // check for cachehint
841  if (int newCachehint=parsedDescription.cachehint();newCachehint!=0) m_cachehint=newCachehint;
842  // check for <named/>
843  m_named=parsedDescription.named();
844  // get addressHeader
845  if (auto newAddrHeader = parsedDescription.addressHeader();not newAddrHeader.empty()){
847  m_addrheader=newAddrHeader;
848  }
849  //get clid, if it exists (set to zero otherwise)
850  m_clid=parsedDescription.classId(msg());
851  // decode the typeName
852  if (!parsedDescription.getKey("typeName","",m_typename)) {
853  ATH_MSG_ERROR( "Primary type name is empty" );
854  return false;
855  }
856  bool gotCLID=(m_clid!=0);
857 
858  ATH_MSG_DEBUG( "Got folder typename " << m_typename );
859  if (!gotCLID)
860  if (StatusCode::SUCCESS==p_clidSvc->getIDOfTypeName(m_typename,m_clid))
861  gotCLID=true;
862  if (!gotCLID) {
863  ATH_MSG_ERROR("Could not get clid for typeName: " << m_typename);
864  return false;
865  }
866  ATH_MSG_DEBUG( "Got folder typename " << m_typename << " with CLID " << m_clid );
867  return success;
868 }
869 
870 std::unique_ptr<SG::TransientAddress>
871 IOVDbFolder::createTransientAddress(const std::vector<std::string> & symlinks){
872  auto tad = std::make_unique<SG::TransientAddress>(m_clid,m_key);
873  //
874  for (const auto & linkname:symlinks){
875  if (not linkname.empty()) {
876  CLID sclid;
877  if (StatusCode::SUCCESS==p_clidSvc->getIDOfTypeName(linkname,sclid)) {
878  tad->setTransientID(sclid);
879  ATH_MSG_DEBUG( "Setup symlink " << linkname << " CLID " <<sclid << " for folder " << m_foldername );
880  } else {
881  ATH_MSG_ERROR( "Could not get clid for symlink: "<< linkname );
882  return nullptr;
883  }
884  }
885  }
886  return tad;
887 }
888 
889 std::unique_ptr<SG::TransientAddress>
890 IOVDbFolder::preLoadFolder(ITagInfoMgr *tagInfoMgr , const unsigned int cacheRun, const unsigned int cacheTime) {
891  // preload Address from SG - does folder setup including COOL access
892  // also set detector store location - cannot be done in constructor
893  // as detector store does not exist yet in IOVDbSvc initialisation
894  // and sets up cache length, taking into account optional overrides
895  // returns null pointer in case of problem
896  p_tagInfoMgr = tagInfoMgr;
897  if( not m_useFileMetaData ) {
898  if(m_source=="CREST"){
899  CrestFunctions cfunctions(m_crestServer);
900 
901  if (m_crest_tag != m_crestTag){
903  m_tag_info = cfunctions.getTagInfo(m_crestTag);
904  }
905  m_folderDescription = cfunctions.getTagInfoElement(m_tag_info,"node_description");
906  } else {
907  //folder desc from db
909  }
910  } else {
911  // folder description from meta-data set already earlier
912  }
913  ATH_MSG_DEBUG( "Folder description for " << m_foldername << ": " << m_folderDescription);
914  // register folder with meta-data tool if writing metadata
915  if (m_writemeta) {
916  if (StatusCode::SUCCESS!=p_metaDataTool->registerFolder(m_foldername,m_folderDescription)) {
917  ATH_MSG_ERROR( "Failed to register folder " << m_foldername<< " for meta-data write" );
918  return nullptr;
919  }
920  }
921  // parse the description string
922  IOVDbParser folderpar(m_folderDescription, msg());
923  //use the overrides in the folderdescription, return nullptr immediately if something went wrong
924  if (not overrideOptionsFromParsedDescription(folderpar)) return nullptr;
925  // setup channel list and folder type
926  if( not m_useFileMetaData ) {
927  if(m_source=="CREST"){
928  CrestFunctions cfunctions(m_crestServer);
929 
930  const std::string & payloadSpec = cfunctions.getTagInfoElement(m_tag_info,"payload_spec");
931  std::string chanList = cfunctions.getTagInfoElement(m_tag_info,"channel_list");
932  std::tie(m_channums, m_channames) = cfunctions.extractChannelListFromString(chanList);
933 
934  //determine foldertype from the description, the spec and the number of channels
936 
937  if (m_crestToFile){
938  int n_size = m_channums.size();
940  for (int i = 0; i < n_size; i++) {
941 
942  nlohmann::json elem;
943  std::string key = std::to_string(m_channums[i]);
944  elem[key] = m_channames[i];
945  chan_list.push_back(elem);
946  }
947 
948  char ch = ':';
949  int colsize = std::count(payloadSpec.begin(), payloadSpec.end(), ch);
950 
951  nlohmann::json tag_meta;
952  tag_meta["tagName"] = m_crestTag;
953  tag_meta["description"] = "";
954  tag_meta["chansize"] = n_size;
955  tag_meta["colsize"] = colsize;
956 
957  nlohmann::json tagInfo;
958  tagInfo["channel_list"] = chan_list;
959  tagInfo["node_description"] = m_folderDescription;
960  tagInfo["payload_spec"] = payloadSpec;
961 
962  tag_meta["tagInfo"] = tagInfo;
963 
964  std::string crest_work_dir=std::filesystem::current_path();
965  crest_work_dir += "/crest_data";
966  bool crest_rewrite = true;
967  Crest::CrestClient crestFSClient = Crest::CrestClient(crest_rewrite, crest_work_dir);
968 
969  try{
970  crestFSClient.createTagMetaInfo(tag_meta);;
971  ATH_MSG_INFO("Tag meta info for " << m_crestTag << " saved to disk.");
972  ATH_MSG_INFO("CREST Dump dir = " << crest_work_dir);
973  }
974  catch (const std::exception& e) {
975  ATH_MSG_WARNING("Tag meta info saving for tag " << m_crestTag << " failed: " << e.what());
976  }
977  } // m_crestToFile
978 
979  } else {
980  // data being read from COOL
981  auto fldPtr=m_conn->getFolderPtr<cool::IFolderPtr>(m_foldername);
982  // get the list of channels
984  // set folder type
986  }
987  }
988  m_nchan=m_channums.size();
989  ATH_MSG_DEBUG( "Folder identified as type " << m_foldertype );
990  // note that for folders read from metadata, folder type identification
991  // is deferred until getAddress when first data is read
992  // and channel number/name information is not read
993 
994  // change channel selection for single-object read
995  if (m_foldertype==AttrList || m_foldertype==PoolRef) m_chansel=cool::ChannelSelection(0);
996  const auto & linknameVector = folderpar.symLinks();
997  // now create TAD
998  auto tad{createTransientAddress(linknameVector)};
999  if (not tad) {
1000  ATH_MSG_WARNING("Transient address is null in "<<__func__);
1001  return nullptr;
1002  }
1003  setCacheLength(m_timestamp, cacheRun, cacheTime);
1004  return tad;
1005 }
1006 
1007 void IOVDbFolder::setCacheLength(const bool timeIs_nsOfEpoch, const unsigned int cacheRun, const unsigned int cacheTime){
1008  if (timeIs_nsOfEpoch){
1009  long long int clen=600; // default value of 10 minutes
1010  if (cacheTime!=0) {
1011  clen=cacheTime;
1012  m_autocache=false;
1013  } else {
1014  // for timestamp, cache parameter (if set) sets length in seconds
1015  if (not m_cachepar.empty()) clen=std::stoi(m_cachepar);
1016  }
1018  ATH_MSG_DEBUG( "Cache length set to " << clen << " seconds" );
1019  } else {
1020  // for run/event, cache parameter sets length in LB
1021  // default value is 1 whole run
1023  if (cacheRun!=0) {
1025  m_autocache=false;
1026  } else {
1027  if (not m_cachepar.empty()) m_cachelength=std::stoi(m_cachepar);
1028  }
1030  ATH_MSG_DEBUG( "Cache length set to " << run <<" runs " << lumi << " lumiblocks" );
1031  }
1032 }
1033 
1034 void
1036  // clear all the cache vectors of information
1037  m_iovs.clear();
1038  m_cachechan.clear();
1039  m_cacheattr.clear();
1040  m_cacheccstart.clear();
1041  m_cacheccend.clear();
1042 }
1043 
1044 bool
1045 IOVDbFolder::resolveTag(const cool::IFolderPtr& fptr,const std::string& globalTag) {
1046  // resolve the tag
1047  // if specified in job options or already-processed override use that,
1048  // else use global tag
1049  // return false for failure
1050  std::string tag=m_jotag;
1051  if (tag=="HEAD") return true;
1052  if (tag.empty()) tag=globalTag;
1053  if (tag.empty()) {
1054  ATH_MSG_ERROR( "No IOVDbSvc.GlobalTag specified on job options or input file" );
1055  return false;
1056  }
1057  if(m_source=="CREST"){
1058 
1059  m_tag = m_crestTag;
1060 
1061  ATH_MSG_DEBUG( "resolveTag returns " << m_tag );
1062  return true;
1063  }
1064  // check for magic tags
1065  if (IOVDbNamespace::looksLikeMagicTag(tag) and not magicTag(tag)) return false;
1066  // check tag exists - if not, lookup hierarchically
1067  const std::vector<std::string>& taglist=fptr->listTags();
1068  if (find(taglist.begin(),taglist.end(),tag)!=taglist.end()) {
1069  // tag exists directly in folder
1070  ATH_MSG_DEBUG( "Using tag "<< tag << " for folder " << m_foldername );
1071  } else {
1072  // tag maybe an HVS tag
1073  try {
1074  std::string restag=fptr->resolveTag(tag);
1075  ATH_MSG_INFO( "HVS tag " << tag << " resolved to "<< restag << " for folder " << m_foldername );
1076  // HVS tag may itself be magic
1077  if (IOVDbNamespace::looksLikeMagicTag(restag) and not magicTag(restag)) return false;
1078  tag=restag;
1079  }catch (cool::Exception& e) {
1080  ATH_MSG_ERROR( "Tag " << tag <<" cannot be resolved for folder " << m_foldername );
1081  return false;
1082  }
1083  }
1084  m_tag=tag;
1085  // optionally check if tag is locked
1086  if (m_checklock) {
1087  const auto tagLock=IOVDbNamespace::checkTagLock(fptr,tag);
1088  if (not tagLock.has_value()){
1089  ATH_MSG_ERROR( "Could not check tag lock status for " << tag );
1090  return false;
1091  }
1092  if (not tagLock.value()){
1093  ATH_MSG_ERROR("Tag " << tag <<" is not locked and IOVDbSvc.CheckLock is set" );
1094  return false;
1095  }
1096  }
1097  ATH_MSG_DEBUG( "resolveTag returns " << m_tag );
1098  return true;
1099 }
1100 
1101 bool
1102 IOVDbFolder::magicTag(std::string& tag) { //alters the argument
1104  return (not tag.empty());
1105 }
1106 
1107 
1108 
1109 bool
1111  const IOVRange& range) {
1112  // make a temporary CondAttrListCollection with channel 0xFFFF
1113  // This channel number is used to flag on readback that an
1114  // AthenaAttributeList and not a CondAttrListCollection must be created
1116  tmpColl.add(0xFFFF,atrlist);
1117  tmpColl.add(0xFFFF,range);
1118  return addMetaAttrListColl(&tmpColl);
1119 }
1120 
1121 bool
1123  // send given payload to folder metadata
1124  // make a new CondAttrListCollection for the payload
1125  CondAttrListCollection* flmdColl=new CondAttrListCollection(*coll);
1126  if (StatusCode::SUCCESS!=p_metaDataTool->addPayload(m_foldername,flmdColl)) {
1127  ATH_MSG_ERROR( "addMetaAttrList: Failed to write metadata for folder " << m_foldername);
1128  return false;
1129  } else {
1130  ATH_MSG_DEBUG( "addMetaAttrList: write metadata for folder " << m_foldername );
1131  return true;
1132  }
1133 }
1134 
1135 void
1137  m_cachespec=new coral::AttributeListSpecification;
1138  for (const auto & attribute:atrlist){
1139  const coral::AttributeSpecification& aspec=attribute.specification();
1140  m_cachespec->extend(aspec.name(),aspec.type());
1141  if (not typeSizeIsKnown(attribute)) {
1142  ATH_MSG_WARNING( "addType: unknown type " << aspec.typeName()<<
1143  " in folder " << m_foldername << " will not be counted for bytes-read statistics" );
1144  }
1145  }
1146  ATH_MSG_DEBUG( "Setup shared AttributeListSpecification with " << m_cachespec->size() << " elements" );
1147 }
1148 
1149 void
1150 IOVDbFolder::addIOVtoCache(cool::ValidityKey since,cool::ValidityKey until) {
1151  // add IOV to the cache
1152  ATH_MSG_DEBUG("Adding IOV to cache, from "<<since<<" to "<<until);
1154 }
1155 
1156 void
1158  const auto & [since,until] = m_iovs.getCacheBounds();
1159  ATH_MSG_DEBUG("folder cache printout -------------------");
1160  ATH_MSG_DEBUG(m_foldername << " length: "<<m_cachelength<<"\tstart: "<<since<<"\tstop: "<<until);
1161  ATH_MSG_DEBUG("current range: "<<m_currange);
1162  const auto & iovs = m_iovs.vectorStore();
1164  for (const auto & iov:iovs){
1165  ATH_MSG_DEBUG("channelID:\t"<<(*ci++)<<"\t since: "<<iov.first<<"\t until: "<<iov.second);
1166  }
1167  ATH_MSG_DEBUG("folder cache printout -------------------");
1168 
1169 }
1170 
1171 std::vector<IOVDbFolder::IOVHash> IOVDbFolder::fetchCrestIOVs()
1172 {
1173  std::vector<IOVHash> result;
1174  CrestFunctions cfunctions(m_crestServer);
1175 
1176  // Get a vector of pairs retrieved from crest
1177  // <IOV_SINCE(string),HASH(string)>
1178  auto crestIOVs = cfunctions.getIovsForTag(m_crestTag);
1179  if(crestIOVs.empty()){
1180  ATH_MSG_WARNING("Load cache failed for " << m_foldername << ". No IOVs retrieved from the DB");
1181  }
1182  std::vector<IOV2Index> iov2IndexVect; // Temporary vector for sorting IOV_SINCE values
1183  iov2IndexVect.reserve(crestIOVs.size());
1184  size_t hashInd{0};
1185  for(const auto& crestIOV : crestIOVs) {
1186  iov2IndexVect.emplace_back(std::stoull(crestIOV.first),hashInd++);
1187  }
1188 
1189  std::sort(iov2IndexVect.begin(),iov2IndexVect.end(),
1190  [](const IOV2Index& a, const IOV2Index& b)
1191  {
1192  return a.first < b.first;
1193  });
1194 
1195  size_t nIOVs = iov2IndexVect.size();
1196  result.reserve(nIOVs);
1197  if(nIOVs>0) {
1198  if(nIOVs>1) {
1199  for(size_t ind=0; ind<nIOVs-1; ++ind) {
1200  result.emplace_back(IovStore::Iov_t(iov2IndexVect[ind].first
1201  , iov2IndexVect[ind+1].first)
1202  , crestIOVs[iov2IndexVect[ind].second].second);
1203  }
1204  }
1205  result.emplace_back(IovStore::Iov_t(iov2IndexVect[nIOVs-1].first
1206  , cool::ValidityKeyMax)
1207  , crestIOVs[iov2IndexVect[nIOVs-1].second].second);
1208  }
1209 
1210  return result;
1211 }
1212 
1213 void IOVDbFolder::dumpFile(const std::string& dumpName
1214  , const cool::ValidityKey& vkey
1215  , Cool2Json* json
1216  , bool skipCoolIoV
1217  , BasicFolder* basicFolder
1218  , const std::string& crestNodeDescr
1219  , const std::string& specString) const
1220 {
1221  std::ofstream myFile;
1222  std::string fMain(dumpName);
1223  const std::string sanitisedFolder=fMain+"/"+sanitiseFilename(m_foldername);
1224  const std::string fabricatedName=sanitisedFolder+delimiter+std::to_string(vkey)+fileSuffix;
1225  std::filesystem::create_directory(fMain);
1226  myFile.open(fabricatedName,std::ios::out);
1227  if (not myFile.is_open()) {
1228  std::string errorMessage{"File creation for "+fabricatedName+" failed."};
1229  ATH_MSG_FATAL(errorMessage);
1230  throw std::runtime_error(errorMessage);
1231  }
1232  else {
1233  ATH_MSG_INFO("File "<<fabricatedName<<" created.");
1234  }
1235 
1236  myFile<<s_openJson;
1237  if(json) {
1238  // Dump COOL data
1239  myFile<<json->description()<<s_delimiterJson<<std::endl;
1240  myFile<<json->payloadSpec()<<s_delimiterJson<<std::endl;
1241  if(!skipCoolIoV) {
1242  myFile<<json->iov()<<s_delimiterJson<<std::endl;
1243  }
1244  myFile<<json->payload()<<std::endl;
1245  }
1246  else {
1247  // Dump CREST data
1248  std::string newNodeDescription = std::regex_replace(crestNodeDescr, std::regex("\""), "\\\"");
1249  std::string newSpecString = std::regex_replace(specString, std::regex(":"), ": ");
1250  newSpecString = std::regex_replace(newSpecString, std::regex(","), s_delimiterJson);
1251  myFile<<"\"node_description\" : \""<<newNodeDescription<< '\"'<<s_delimiterJson<<std::endl;
1252  myFile<<"\"folder_payloadspec\": \""<<newSpecString<< '\"'<<s_delimiterJson<<std::endl;
1253  myFile<<basicFolder->jsonPayload(newNodeDescription,newSpecString)<<std::endl;
1254  }
1255  myFile<<s_closeJson;
1256 }
1257 
1258 std::vector<BasicFolder> IOVDbFolder::fetchCrestObjects(cool::ValidityKey since
1259  , cool::ValidityKey until
1260  , bool vectorPayloadFlag
1261  , cool::ValidityKey vkey
1262  , const std::string& nodeDesc)
1263 {
1264  CrestFunctions cfunctions(m_crestServer);
1265 
1266  std::string crestPayloadType="crest-json-single-iov";
1267  nlohmann::json tagProperties = cfunctions.getTagProperties(m_crestTag);
1268  if(tagProperties!=nullptr
1269  && tagProperties.contains("payloadSpec")) {
1270  crestPayloadType=tagProperties["payloadSpec"].get<std::string>();
1271  }
1272 
1273  if(crestPayloadType.compare("crest-json-multi-iov")==0) {
1274 /*
1275  try {
1276  nlohmann::json multiPayload = nlohmann::json::parse(reply);
1277  nlohmann::json jsIovs=multiPayload["obj"];
1278  std::vector<IOV2Index> iov2IndexVect;
1279  iov2IndexVect.reserve(jsIovs.size());
1280  size_t hashInd{0};
1281  for(const auto& jsIov : jsIovs.items()) {
1282  iov2IndexVect.emplace_back(std::stoull(jsIov.key()),hashInd++);
1283  }
1284  std::sort(iov2IndexVect.begin(),iov2IndexVect.end(),
1285  [](const IOV2Index& a, const IOV2Index& b)
1286  {
1287  return a.first < b.first;
1288  });
1289  if(vkey < iov2IndexVect[0].first) {
1290  std::string errorMessage{"Load cache failed for "+m_foldername+". No valid IOV retrieved from the payload"};
1291  ATH_MSG_FATAL(errorMessage);
1292  throw std::runtime_error{errorMessage};
1293  }
1294 
1295  uint64_t iov = 0;
1296  for(const auto& iovhash : iov2IndexVect) {
1297  if(vkey >= iovhash.first) {
1298  iov=iovhash.first;
1299  continue;
1300  }
1301  else {
1302  break;
1303  }
1304  }
1305  if (indIOV>=0){
1306  iovHashVect[indIOV].first.first=iov;
1307  nlohmann::json payload={};
1308  payload["data"]=jsIovs[std::to_string(iov)];
1309  reply=payload.dump();
1310  } else {
1311  ATH_MSG_FATAL("indIOV is negative in IOVDbFolder::dumpFile");
1312  }
1313  }
1314  catch (std::exception & e) {
1315  std::string errorMessage = "Failed of parse multi iovs struct of internal iovs from payload for DCS type: " + std::string{e.what()};
1316  ATH_MSG_FATAL(errorMessage);
1317  throw std::runtime_error{errorMessage};
1318  }
1319  }
1320  ATH_MSG_DEBUG("Found IOV for " << m_foldername << " and VKEY " << vkey
1321  << " " << iovHashVect[indIOV].first);
1322 
1323  if (m_crestToFile and (indIOV>=0)) { //indIOV must be >=0, it's used as a vector index in this block
1324  unsigned long long sinceT = iovHashVect[indIOV].first.first;
1325 
1326  std::string crest_work_dir=std::filesystem::current_path();
1327  crest_work_dir += "/crest_data";
1328  bool crest_rewrite = true;
1329  Crest::CrestClient crestFSClient = Crest::CrestClient(crest_rewrite, crest_work_dir);
1330 
1331  nlohmann::json js =
1332  {
1333  {"name", m_crestTag}
1334  };
1335 
1336  try{
1337  crestFSClient.createTag(js);
1338  ATH_MSG_INFO("Tag " << m_crestTag << " saved to disk.");
1339  ATH_MSG_INFO("CREST Dump dir = " << crest_work_dir);
1340  }
1341  catch (const std::exception& e) {
1342  ATH_MSG_WARNING("Data saving for tag " << m_crestTag << " failed: " << e.what());
1343  }
1344 
1345  try{
1346  crestFSClient.storePayloadDump(m_crestTag, sinceT, reply);
1347  ATH_MSG_INFO("Data (payload and IOV) saved for tag " << m_crestTag << ".");
1348  }
1349  catch (const std::exception& e) {
1350  ATH_MSG_WARNING("Data (payload and IOV) saving for tag " << m_crestTag<<" failed; " << e.what());
1351  }
1352  }
1353 
1354  const std::string& specString = cfunctions.getTagInfoElement(m_tag_info,"payload_spec");
1355  if (specString.empty()) {
1356  std::string errorMessage = "Reading payload spec from "+m_foldername+" failed.";
1357 */
1358  // Support for this type of payload will be added later
1359  std::string errorMessage = m_foldername + ": has multi-iov payload. Folders with multi-iov payloads currently not supported!";
1360  ATH_MSG_FATAL(errorMessage);
1361  throw std::runtime_error{errorMessage};
1362  }
1363 
1364  const std::string& specString = cfunctions.getTagInfoElement(m_tag_info,"payload_spec");
1365  if (specString.empty()) {
1366  std::string errorMessage = "Reading payload spec from " + m_foldername + " failed.";
1367  ATH_MSG_FATAL(errorMessage);
1368  throw std::runtime_error{errorMessage};
1369  }
1370 
1371  std::vector<BasicFolder> retVector;
1372 
1373  // Vector of non-overlapping IOVs + corresponding Hashes
1374  std::vector<IOVHash> iovHashVect = fetchCrestIOVs();
1375 
1376  if(iovHashVect.empty() || until<=iovHashVect[0].first.first) {
1377  if(iovHashVect.empty()) {
1378  ATH_MSG_INFO("NO IOVs retrieved for the folder "+ m_foldername);
1379  }
1380  else {
1381  ATH_MSG_INFO("Cache boundaries outside available IOVs for the folder "+ m_foldername);
1382  }
1383  BasicFolder basicFolder;
1384  basicFolder.setVectorPayloadFlag(vectorPayloadFlag);
1385  retVector.push_back(basicFolder);
1386  return retVector;
1387  }
1388 
1389  unsigned indIOVStart = 0;
1390  for(const auto& iovhash : iovHashVect) {
1391  if(since < iovhash.first.first) break; // 'since' is earlier that the first IOV segment. indIOVStart=0
1392  if(since < iovhash.first.second
1393  && since >= iovhash.first.first) {
1394  break;
1395  }
1396  ++indIOVStart;
1397  }
1398  unsigned indIOVEnd = indIOVStart;
1399  while(indIOVEnd < iovHashVect.size()) {
1400  if(iovHashVect[indIOVEnd].first.first < until
1401  && iovHashVect[indIOVEnd].first.second >= until) {
1402  break;
1403  }
1404  ++indIOVEnd;
1405  }
1406 
1407  for(unsigned ind = indIOVStart; ind <= indIOVEnd; ++ind) {
1408  std::string reply = cfunctions.getPayloadForHash(iovHashVect[ind].second);
1409 
1410  if (m_crestToFile) {
1411  unsigned long long sinceT = iovHashVect[ind].first.first;
1412 
1413  std::string crest_work_dir=std::filesystem::current_path();
1414  crest_work_dir += "/crest_data";
1415  bool crest_rewrite = true;
1416  Crest::CrestClient crestFSClient = Crest::CrestClient(crest_rewrite, crest_work_dir);
1417 
1418  nlohmann::json js =
1419  {
1420  {"name", m_crestTag}
1421  };
1422 
1423  try{
1424  crestFSClient.createTag(js);
1425  ATH_MSG_INFO("Tag " << m_crestTag << " saved to disk.");
1426  ATH_MSG_INFO("CREST Dump dir = " << crest_work_dir);
1427  }
1428  catch (const std::exception& e) {
1429  ATH_MSG_WARNING("Data saving for tag " << m_crestTag << " failed: " << e.what());
1430  }
1431 
1432  try{
1433  crestFSClient.storePayloadDump(m_crestTag, sinceT, reply);
1434  ATH_MSG_INFO("Data (payload and IOV) saved for tag " << m_crestTag << ".");
1435  }
1436  catch (const std::exception& e) {
1437  ATH_MSG_WARNING("Data (payload and IOV) saving for tag " << m_crestTag<<" failed; " << e.what());
1438  }
1439  }
1440 
1441  //basic folder now contains the info
1442  BasicFolder basicFolder;
1443  basicFolder.setVectorPayloadFlag(vectorPayloadFlag);
1444  std::istringstream ss(reply);
1445  Json2Cool inputJson(ss, basicFolder, specString, &(iovHashVect[ind].first));
1446  if (basicFolder.empty()){
1447  std::string errorMessage = "Reading channel data from "+m_foldername+" failed.";
1448  ATH_MSG_FATAL(errorMessage);
1449  throw std::runtime_error{errorMessage};
1450  }
1451 
1452  if(m_crestCoolToFile) {
1453  dumpFile("crest_dump",vkey,nullptr,false,&basicFolder,nodeDesc,specString);
1454  }
1455 
1456  retVector.push_back(basicFolder);
1457  }
1458  return retVector;
1459 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
IOVDbNamespace::spaceStrip
std::string spaceStrip(const std::string &input)
Trim leading and trailing spaces,return a new trimmed string.
Definition: IOVDbStringFunctions.cxx:11
IOVDbNamespace::ReadFromFileMetaData::numberOfObjects
unsigned int numberOfObjects()
Definition: ReadFromFileMetaData.cxx:58
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
IOVDbFolder.h
IOVDbFolder::m_outputToFile
const bool m_outputToFile
Definition: IOVDbFolder.h:323
CxxUtils::span
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
IOVDbFolder::m_cacheccend
std::vector< unsigned int > m_cacheccend
Definition: IOVDbFolder.h:321
IOVDbNamespace::Cool2Json
Definition: Cool2Json.h:26
CoraCoolObject
Definition: CoraCoolObject.h:20
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
checkCorrelInHIST.conn
conn
Definition: checkCorrelInHIST.py:25
IOVDbFolder::m_crestCoolToFile
const bool m_crestCoolToFile
Definition: IOVDbFolder.h:325
Json2Cool.h
IOVDbFolder::m_useFileMetaData
bool m_useFileMetaData
Definition: IOVDbFolder.h:272
IOVDbFolder::magicTag
bool magicTag(std::string &tag)
Definition: IOVDbFolder.cxx:1102
IOVDbNamespace::ReadFromFileMetaData::attrListCollection
CondAttrListCollection * attrListCollection()
Definition: ReadFromFileMetaData.cxx:94
get_generator_info.result
result
Definition: get_generator_info.py:21
IOVDbFolder::m_checklock
bool m_checklock
Definition: IOVDbFolder.h:280
IOVDbFolder::p_metaDataTool
IIOVDbMetaDataTool * p_metaDataTool
Definition: IOVDbFolder.h:262
dqt_zlumi_alleff_HIST.iov
iov
Definition: dqt_zlumi_alleff_HIST.py:119
IOVDbNamespace::ReadFromFileMetaData::poolPayloadRequested
bool poolPayloadRequested()
Definition: ReadFromFileMetaData.cxx:80
IOVDbFolder::m_foldername
std::string m_foldername
Definition: IOVDbFolder.h:264
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
IOVDbFolder::m_tagoverride
bool m_tagoverride
Definition: IOVDbFolder.h:269
IOVDbFolder::m_retrieved
bool m_retrieved
Definition: IOVDbFolder.h:313
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
IOVDbFolder::m_ncacheread
unsigned int m_ncacheread
Definition: IOVDbFolder.h:302
python.MagFieldUtils.lumiblock
lumiblock
Definition: MagFieldUtils.py:188
IOVDbFolder::fetchCrestObjects
std::vector< IOVDbNamespace::BasicFolder > fetchCrestObjects(cool::ValidityKey since, cool::ValidityKey until, bool vectorPayloadFlag, cool::ValidityKey vkey, const std::string &nodeDesc)
Definition: IOVDbFolder.cxx:1258
IOVDbNamespace::IovStore::vectorStore
std::vector< Iov_t > & vectorStore()
Return the internal vector store.
Definition: IovStore.cxx:64
CondAttrListCollAddress.h
This file contains the class definition for the CondAttrListCollAddress class.
json
nlohmann::json json
Definition: HistogramDef.cxx:9
Crest::CrestClient::createTag
void createTag(nlohmann::json &js)
This method creates a tag in the CREST database.
Definition: CrestApi.cxx:262
IOVDbParser::cachehint
int cachehint() const
Definition: IOVDbParser.cxx:168
CondAttrListCollection::minRange
IOVRange minRange() const
Current minimal IOVRange.
Definition: CondAttrListCollection.h:438
IOVDbFolder::m_jokey
bool m_jokey
Definition: IOVDbFolder.h:277
IOVDbNamespace::ReadFromFileMetaData::range
IOVRange range()
Definition: ReadFromFileMetaData.cxx:85
find_tgc_unfilled_channelids.iovs
iovs
Definition: find_tgc_unfilled_channelids.py:12
IOVDbNamespace::IovStore::getMinimumStraddlingSpan
Iov_t getMinimumStraddlingSpan() const
Get the minimum straddling span (max 'since' to min 'until')
Definition: IovStore.cxx:45
CondAttrListCollection::addNewStop
void addNewStop(const IOVTime &stop)
Add new stop time to minRange - make sure that stop is <= to new stop
Definition: CondAttrListCollection.h:518
IOVDbConn::open
bool open()
Definition: IOVDbConn.cxx:68
IOVDbFolder::m_crestTag
const std::string m_crestTag
Definition: IOVDbFolder.h:328
IOVDbFolder::m_crestServer
const std::string m_crestServer
Definition: IOVDbFolder.h:327
IOVDbNamespace::ALL_LUMI_BLOCKS
constexpr unsigned long long ALL_LUMI_BLOCKS
All the lumi blocks in one run.
Definition: IOVDbCoolFunctions.h:36
IOVDbFolder::iovTime
cool::ValidityKey iovTime(const IOVTime &reftime) const
Definition: IOVDbFolder.cxx:212
IOVDbNamespace::IovStore::numberOfIovsOnBoundaries
std::pair< unsigned int, unsigned int > numberOfIovsOnBoundaries() const
Return the current count of added Iovs which straddled cache boundaries.
Definition: IovStore.cxx:51
IOVDbConn.h
IOVDbFolder::m_currange
IOVRange m_currange
Definition: IOVDbFolder.h:314
IOVDbConn::name
const std::string & name() const
Definition: IOVDbConn.h:70
IOVDbFolder::fetchCrestIOVs
std::vector< IOVHash > fetchCrestIOVs()
Definition: IOVDbFolder.cxx:1171
IOVDbFolder::m_cacheinc
int m_cacheinc
Definition: IOVDbFolder.h:286
IOVDbNamespace::IovStore::clear
void clear()
clear the store
Definition: IovStore.cxx:56
IOVDbFolder::createTransientAddress
std::unique_ptr< SG::TransientAddress > createTransientAddress(const std::vector< std::string > &symlinks)
Definition: IOVDbFolder.cxx:871
IIOVDbMetaDataTool::registerFolder
virtual StatusCode registerFolder(const std::string &folderName, const std::string &folderDescription) const =0
Register folder in the IOV Db MetaData.
IOVDbNamespace::IovStore::size
unsigned int size() const
length of store
Definition: IovStore.h:45
IOVDbFolder::useFileMetaData
void useFileMetaData()
Definition: IOVDbFolder.cxx:161
IOVDbFolder::specialCacheUpdate
void specialCacheUpdate(CoraCoolObject &obj, const ServiceHandle< IIOVSvc > &iovSvc)
Definition: IOVDbFolder.cxx:570
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
IOVDbNamespace::ReadFromFileMetaData::stringAddress
std::string stringAddress()
Definition: ReadFromFileMetaData.cxx:63
IOVDbFolder::m_tag_info
nlohmann::json m_tag_info
Definition: IOVDbFolder.h:330
IOVDbFolder::m_cachelength
cool::ValidityKey m_cachelength
Definition: IOVDbFolder.h:284
IOVDbFolder::getAddress
bool getAddress(const cool::ValidityKey reftime, IAddressCreator *persSvc, const unsigned int poolSvcContext, std::unique_ptr< IOpaqueAddress > &address, IOVRange &range, bool &poolPayloadRequested)
Definition: IOVDbFolder.cxx:631
CheckTagAssociation.taglist
taglist
Definition: CheckTagAssociation.py:103
IOVDbNamespace::PoolRefColl
@ PoolRefColl
Definition: FolderTypes.h:31
AthTPCnvSvc_test.clidsvc
clidsvc
Definition: AthTPCnvSvc_test.py:10
IOVDbNamespace::CrestFunctions::getTagProperties
nlohmann::json getTagProperties(const std::string &tag)
CondAttrListCollection::addNewStart
void addNewStart(const IOVTime &start)
Add new start time to minRange - make sure that start is >= to new start.
Definition: CondAttrListCollection.h:508
IOVDbNamespace::iovTimeFromSeconds
unsigned long long iovTimeFromSeconds(const unsigned long long seconds)
Create a long long time in ns from s.
Definition: IOVDbCoolFunctions.cxx:98
IOVDbFolder::m_tag
std::string m_tag
Definition: IOVDbFolder.h:294
IOVDbFolder::eventStore
const std::string & eventStore() const
Definition: IOVDbFolder.h:370
IOVDbFolder::m_chansel
cool::ChannelSelection m_chansel
Definition: IOVDbFolder.h:288
IOVDbFolder::setTagOverride
void setTagOverride(const std::string &tag, const bool setFlag)
Definition: IOVDbFolder.cxx:172
IOVDbNamespace::PoolRef
@ PoolRef
Definition: FolderTypes.h:30
IOVDbConn::valid
bool valid() const
Definition: IOVDbConn.h:60
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
IOVDbFolder::p_tagInfoMgr
ITagInfoMgr * p_tagInfoMgr
Definition: IOVDbFolder.h:260
CondAttrListVec::minRange
IOVRange minRange() const
Definition: CondAttrListVec.h:232
IOVDbNamespace::makeEpochOrRunLumi
IOVTime makeEpochOrRunLumi(const cool::ValidityKey key, const bool timeIsEpoch)
Create an IOVTime in ns of epoch or run-lumi (determined by the bool) from a ValidityKey.
Definition: IOVDbCoolFunctions.cxx:87
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
AthenaAttributeList.h
IOVDbNamespace::IovStore::Iov_t
std::pair< cool::ValidityKey, cool::ValidityKey > Iov_t
Definition: IovStore.h:22
IOVDbFolder::setSharedSpec
void setSharedSpec(const coral::AttributeList &atrlist)
Definition: IOVDbFolder.cxx:1136
IOVDbNamespace::ReadFromFileMetaData::attributeList
AthenaAttributeList * attributeList()
Definition: ReadFromFileMetaData.cxx:102
IOVDbFolder::loadCache
bool loadCache(const cool::ValidityKey vkey, const unsigned int cacheDiv, const std::string &globalTag, const bool ignoreMissChan)
Definition: IOVDbFolder.cxx:221
IOVDbParser::named
bool named() const
Definition: IOVDbParser.cxx:174
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
CrestApi.h
Header file for CREST C++ Client Library.
IOVDbFolder::summary
void summary()
Definition: IOVDbFolder.cxx:814
IOVDbNamespace::replaceServiceType71
bool replaceServiceType71(std::string &addrHeader)
Definition: IOVDbStringFunctions.cxx:212
CoraCoolObject.h
cool
Definition: CoolTagInfo.h:12
IOVDbFolder::folderName
const std::string & folderName() const
Definition: IOVDbFolder.h:333
IOVDbConn::getFolderPtr
T getFolderPtr(const std::string &folderName)
Definition: IOVDbConn.h:43
IOVDbFolder::m_foldertype
IOVDbNamespace::FolderType m_foldertype
Definition: IOVDbFolder.h:282
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
IOVDbNamespace::Json2Cool
Produces cool objects from their JSON representation, storing them in a 'BasicFolder'.
Definition: Json2Cool.h:28
pool::DbPrintLvl::setLevel
void setLevel(MsgLevel l)
Definition: DbPrint.h:32
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
dq_defect_copy_defect_database.until
def until
Definition: dq_defect_copy_defect_database.py:55
IOVDbFolder::m_addrheader
std::string m_addrheader
Definition: IOVDbFolder.h:298
IOVDbStringFunctions.h
CoraCoolObject::const_iterator
AttrListVec::const_iterator const_iterator
Definition: CoraCoolObject.h:23
IOVDbJsonStringFunctions.h
IOVDbFolder::clid
CLID clid() const
Definition: IOVDbFolder.h:373
python.AthDsoLogger.delimiter
delimiter
Definition: AthDsoLogger.py:71
IOVDbFolder::m_readtime
float m_readtime
Definition: IOVDbFolder.h:305
IOVDbFolder::m_jotag
std::string m_jotag
Definition: IOVDbFolder.h:293
IOVDbFolder::m_iovoverride
cool::ValidityKey m_iovoverride
Definition: IOVDbFolder.h:281
CondAttrListVec.h
A CondAttrListVec is an Athena DataObject holding a vector of CORAL AttributeLists,...
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IOVDbFolder::addMetaAttrListColl
bool addMetaAttrListColl(const CondAttrListCollection *coll)
Definition: IOVDbFolder.cxx:1122
IOVDbFolder::preLoadFolder
std::unique_ptr< SG::TransientAddress > preLoadFolder(ITagInfoMgr *tagInfoMgr, const unsigned int cacheRun, const unsigned int cacheTime)
Definition: IOVDbFolder.cxx:890
python.AppMgr.iadd
def iadd(self, tool)
associator for public tools -------------------------------------------—
Definition: AppMgr.py:28
IOVDbFolder::p_clidSvc
IClassIDSvc * p_clidSvc
Definition: IOVDbFolder.h:261
CondAttrListVec
Definition: CondAttrListVec.h:31
lumiFormat.i
int i
Definition: lumiFormat.py:92
IOVDbNamespace::checkTagLock
std::optional< bool > checkTagLock(const cool::IFolderPtr &fptr, const std::string &tag)
Check whether a tag is locked on a folder, if possible.
Definition: TagFunctions.cxx:46
IOVDbNamespace::CrestFunctions
Definition: CrestFunctions.h:29
IOVDbFolder::~IOVDbFolder
~IOVDbFolder()
Definition: IOVDbFolder.cxx:157
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
IOVDbFolder::m_cachehint
int m_cachehint
Definition: IOVDbFolder.h:285
ReadFromFileMetaData.h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IOVDbFolder::m_clid
CLID m_clid
Definition: IOVDbFolder.h:299
IOVDbFolder::m_cachepar
std::string m_cachepar
Definition: IOVDbFolder.h:297
IOVDbFolder::m_channames
std::vector< std::string > m_channames
Definition: IOVDbFolder.h:310
Cool2Json.h
IOVDbParser::cache
std::string cache() const
Definition: IOVDbParser.cxx:163
AthenaAttrListAddress.h
This file contains the class definition for theAthenaAttrListAddress class.
calibdata.exception
exception
Definition: calibdata.py:496
IOVDbFolder::loadCacheIfDbChanged
bool loadCacheIfDbChanged(const cool::ValidityKey vkey, const std::string &globalTag, const cool::IDatabasePtr &dbPtr, const ServiceHandle< IIOVSvc > &iovSvc)
Definition: IOVDbFolder.cxx:506
IOVDbFolder::m_iovs
IOVDbNamespace::IovStore m_iovs
Definition: IOVDbFolder.h:322
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
IOVDbNamespace::IovStore::getCacheBounds
Iov_t getCacheBounds() const
Report the current cache bounds.
Definition: IovStore.cxx:31
IOVDbNamespace::CoolVector
@ CoolVector
Definition: FolderTypes.h:33
IOVDbFolder::m_iovoverridden
bool m_iovoverridden
Definition: IOVDbFolder.h:276
IOVDbNamespace::CoraCool
@ CoraCool
Definition: FolderTypes.h:32
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
IOVDbFolder::setIOVOverride
void setIOVOverride(const unsigned int run, const unsigned int lumiblock, const unsigned int time)
Definition: IOVDbFolder.cxx:187
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
IOVDbFolder::m_crest_tag
std::string m_crest_tag
Definition: IOVDbFolder.h:329
IOVDbFolder::m_autocache
bool m_autocache
Definition: IOVDbFolder.h:279
IOVDbFolder::printCache
void printCache()
Definition: IOVDbFolder.cxx:1157
run
Definition: run.py:1
IOVDbNamespace::channelList
std::pair< std::vector< cool::ChannelId >, std::vector< std::string > > channelList(IOVDbConn *pConnection, const std::string &folderName, const bool named)
Retrieve channel information.
Definition: IOVDbCoolFunctions.cxx:160
IIOVDbMetaDataTool
This is an interface to a tool used to manage the IOV Meta Data for a given object in the MetaData St...
Definition: IIOVDbMetaDataTool.h:44
IOVDbNamespace::BasicFolder::empty
bool empty() const
Definition: BasicFolder.cxx:31
IOVDbNamespace::IovStore::setCacheBounds
void setCacheBounds(const Iov_t &cacheBounds)
Set the cache bound variables.
Definition: IovStore.cxx:36
fptr
std::vector< TFile * > fptr
Definition: hcg.cxx:48
HLT::setFlag
void setFlag(TrigPassFlags *flags, const T *obj, const CONTAINER *container, const std::vector< bool > &flag)
Set the flag at index position.
Definition: TrigPassFlags.h:121
IOVDbFolder::m_folderDescription
std::string m_folderDescription
Definition: IOVDbFolder.h:266
IOVDbNamespace::AttrListColl
@ AttrListColl
Definition: FolderTypes.h:29
IOVDbFolder::m_source
const std::string m_source
Definition: IOVDbFolder.h:326
IIOVDbMetaDataTool::addPayload
virtual StatusCode addPayload(const std::string &folderName, CondAttrListCollection *payload) const =0
Add an IOV and Payload for a particular folder - replaces payloads if there is an IOV overlap.
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
IOVDbNamespace::ReadFromFileMetaData::folderType
IOVDbNamespace::FolderType folderType()
Definition: ReadFromFileMetaData.cxx:53
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
IOVDbParser::key
std::string key() const
Definition: IOVDbParser.cxx:138
CoraCoolFolderPtr
boost::shared_ptr< CoraCoolFolder > CoraCoolFolderPtr
Definition: CoraCoolTypes.h:15
IOVDbFolder::addMetaAttrList
bool addMetaAttrList(const coral::AttributeList &atrlist, const IOVRange &range)
Definition: IOVDbFolder.cxx:1110
IOVDbFolder::m_writemeta
bool m_writemeta
Definition: IOVDbFolder.h:271
IOVDbFolder::addIOVtoCache
void addIOVtoCache(cool::ValidityKey since, cool::ValidityKey until)
Definition: IOVDbFolder.cxx:1150
grepfile.ic
int ic
Definition: grepfile.py:33
Crest::CrestClient::storePayloadDump
void storePayloadDump(const std::string &tag, uint64_t since, const std::string &js)
Method to store a payload in the local file system.
Definition: CrestApi.cxx:2446
lumiFormat.array
array
Definition: lumiFormat.py:98
IOVDbFolder::dumpFile
void dumpFile(const std::string &dumpName, const cool::ValidityKey &vkey, IOVDbNamespace::Cool2Json *json, bool skipCoolIoV, IOVDbNamespace::BasicFolder *basicFolder, const std::string &crestNodeDescr, const std::string &specString) const
Definition: IOVDbFolder.cxx:1213
CoraCoolDatabasePtr
boost::shared_ptr< CoraCoolDatabase > CoraCoolDatabasePtr
Definition: CoraCoolTypes.h:12
CoraCoolFolder.h
IOVDbFolder::IOV2Index
std::pair< cool::ValidityKey, size_t > IOV2Index
Definition: IOVDbFolder.h:235
IOVDbNamespace::makeRange
IOVRange makeRange(const cool::ValidityKey since, const cool::ValidityKey until, const bool timeIsEpoch)
Make an IOVRange from two validity keys.
Definition: IOVDbCoolFunctions.cxx:113
IOVDbConn
Definition: IOVDbConn.h:18
IOVDbNamespace::IovStore::addIov
void addIov(const Iov_t &iov)
Add an iov to the store and update the span variables.
Definition: IovStore.cxx:16
IOVDbNamespace::BasicFolder
Definition: BasicFolder.h:21
IOVDbParser::getKey
bool getKey(const std::string &key, const std::string &devvalue, std::string &value) const
original 'getKey' method, now implemented using 'at'
Definition: IOVDbParser.cxx:108
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
IOVDbParser
Definition: IOVDbParser.h:19
IOVDbNamespace::sanitiseFilename
std::string sanitiseFilename(const std::string &fname)
Replace the '/' of a file path with '^'.
Definition: IOVDbStringFunctions.cxx:110
IOVDbFolder::m_chanrange
std::vector< ChanRange > m_chanrange
Definition: IOVDbFolder.h:290
IOVDbFolder::IOVDbFolder
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 bool crestToFile=false, const std::string &crestServer="", const std::string &crestTag="", const bool crestCoolToFile=false)
Definition: IOVDbFolder.cxx:70
IOVDbCoolFunctions.h
IOVDbNamespace::ReadFromFileMetaData::isValid
bool isValid()
Definition: ReadFromFileMetaData.cxx:47
IOVDbFolder::m_channums
std::vector< cool::ChannelId > m_channums
Definition: IOVDbFolder.h:309
IOVDbFolder::m_nobjread
unsigned int m_nobjread
Definition: IOVDbFolder.h:303
IOVDbFolder::key
const std::string & key() const
Definition: IOVDbFolder.h:334
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
IOVDbNamespace::typeSizeIsKnown
bool typeSizeIsKnown(const coral::Attribute &attribute)
Return a bool indicating whether the size of a given Attribute can be determined.
Definition: IOVDbCoolFunctions.cxx:67
IOVDbParser::timebaseIs_nsOfEpoch
bool timebaseIs_nsOfEpoch() const
Definition: IOVDbParser.cxx:158
IOVDbNamespace::CrestFunctions::getTagInfoElement
std::string getTagInfoElement(nlohmann::json tag_info, const std::string &key)
IOVDbNamespace::CrestFunctions::getTagInfo
nlohmann::json getTagInfo(const std::string &tag)
IOVDbFolder::cacheUpdateImplementation
unsigned int cacheUpdateImplementation(T &obj, const ServiceHandle< IIOVSvc > &iovSvc)
Definition: IOVDbFolder.h:175
IOVDbNamespace::resolveUsingTagInfo
std::string resolveUsingTagInfo(const std::string &tag, const ITagInfoMgr *tagInfoMgr)
Definition: TagFunctions.cxx:57
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:64
IOVDbFolder::m_cachespec
coral::AttributeListSpecification * m_cachespec
Definition: IOVDbFolder.h:317
IOVDbFolder::m_nchan
unsigned int m_nchan
Definition: IOVDbFolder.h:308
IOVDbNamespace::CrestFunctions::extractChannelListFromString
std::pair< std::vector< cool::ChannelId >, std::vector< std::string > > extractChannelListFromString(const std::string &chanString)
IOVDbParser::symLinks
std::vector< std::string > symLinks() const
Definition: IOVDbParser.cxx:211
IOVDbFolder::m_crestToFile
const bool m_crestToFile
Definition: IOVDbFolder.h:324
IOVDbNamespace::runLumiFromIovTime
std::pair< unsigned long long, unsigned long long > runLumiFromIovTime(const unsigned long long iovTime)
Return a [run,lumi] pair from an IOV time.
Definition: IOVDbCoolFunctions.cxx:108
IOVDbFolder::m_named
bool m_named
Definition: IOVDbFolder.h:275
lumiFormat.lumi
lumi
Definition: lumiFormat.py:113
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
IOVDbFolder::clearCache
void clearCache()
Definition: IOVDbFolder.cxx:1035
a
TList * a
Definition: liststreamerinfos.cxx:10
ITagInfoMgr
This is a Athena service which manages detector description tag information. It maintains a TagInfo o...
Definition: ITagInfoMgr.h:58
CoraCoolObjectIterPtr
boost::shared_ptr< CoraCoolObjectIter > CoraCoolObjectIterPtr
Definition: CoraCoolTypes.h:21
IOVDbNamespace::attributeListSize
unsigned int attributeListSize(const coral::AttributeList &atrlist)
return the size (in bytes) of an AttributeList
Definition: IOVDbCoolFunctions.cxx:72
IOVDbFolder::resolveTag
bool resolveTag(const cool::IFolderPtr &fptr, const std::string &globalTag)
Definition: IOVDbFolder.cxx:1045
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
IOVDbNamespace::folderMetadata
std::pair< bool, std::string > folderMetadata(IOVDbConn *pConnection, const std::string &folderName)
Retrieve (bool) multiversion flag and folder description
Definition: IOVDbCoolFunctions.cxx:136
IOVDbFolder::setCacheLength
void setCacheLength(const bool timeIs_nsOfEpoch, const unsigned int cacheRun, const unsigned int cacheTime)
Definition: IOVDbFolder.cxx:1007
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ref
const boost::regex ref(r_ef)
IOVDbConn::decUsage
void decUsage()
Definition: IOVDbConn.h:74
IOVDbNamespace::IovStore::extendCacheHi
bool extendCacheHi()
Extend upper cache bound to the minimum 'until' time; return whether this changes its value.
Definition: IovStore.cxx:96
DeMoScan.first
bool first
Definition: DeMoScan.py:534
CoraCoolObjectPtr
boost::shared_ptr< CoraCoolObject > CoraCoolObjectPtr
Definition: CoraCoolTypes.h:18
Crest::CrestClient::createTagMetaInfo
void createTagMetaInfo(nlohmann::json &js)
This method creates a tag meta info in the CREST database.
Definition: CrestApi.cxx:1998
IOVDbNamespace::AttrList
@ AttrList
Definition: FolderTypes.h:28
IOVDbFolder::overrideOptionsFromParsedDescription
bool overrideOptionsFromParsedDescription(const IOVDbParser &parsedDescription)
Definition: IOVDbFolder.cxx:829
Crest::CrestClient
Definition: CrestApi.h:62
IOVDbNamespace::SafeReadFromFileMetaData
Definition: ReadFromFileMetaData.h:74
CoraCoolDatabase.h
IOVDbNamespace::CrestFunctions::getIovsForTag
std::vector< IovHashPair > getIovsForTag(const std::string &tag, const bool testing=false)
IOVDbFolder::m_cachechan
std::vector< cool::ChannelId > m_cachechan
Definition: IOVDbFolder.h:318
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
IOVDbFolder::m_ndbread
unsigned int m_ndbread
Definition: IOVDbFolder.h:301
IOVDbNamespace::IovStore::at
Iov_t at(const unsigned int idx) const
'at' to read iov at specific index
Definition: IovStore.h:49
Example_ReadSampleNoise.globalTag
globalTag
Definition: Example_ReadSampleNoise.py:15
IOVDbNamespace::CrestFunctions::getPayloadForHash
std::string getPayloadForHash(const std::string &hash, const bool testing=false)
IOVDbNamespace::folderTypeName
std::string folderTypeName(const FolderType f)
Give a string name for the folder type.
Definition: FolderTypes.cxx:122
CoraCoolObjectIter.h
IOVDbNamespace::BasicFolder::setVectorPayloadFlag
void setVectorPayloadFlag(const bool flag)
Definition: BasicFolder.cxx:36
pvec
std::array< fp_t, 2 > pvec
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:9
IIOVDbMetaDataTool.h
This is an interface to a tool used to manage the IOV Meta Data for a given object in the MetaData St...
IOVDbParser::classId
CLID classId(MsgStream &msg) const
Definition: IOVDbParser.cxx:190
IOVDbNamespace::iovTimeFromRunLumi
unsigned long long iovTimeFromRunLumi(const unsigned long long run, const unsigned long long lumi)
Create a long long representing the IOV from run, lumi.
Definition: IOVDbCoolFunctions.cxx:103
IOVDbFolder::m_multiversion
bool m_multiversion
Definition: IOVDbFolder.h:267
IOVDbNamespace::determineFolderType
FolderType determineFolderType(const std::string &folderDescription, const std::string &spec, const std::vector< cool::ChannelId > &chans)
Determine folder type with optional check using clid service to check clid matches typename.
Definition: FolderTypes.cxx:16
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
IOVDbNamespace::IovStore::extendCacheLo
bool extendCacheLo()
Extend lower cache bound to the maximum 'since' time; return whether this changes its value.
Definition: IovStore.cxx:89
IOVDbFolder::m_nbytesread
unsigned long long m_nbytesread
Definition: IOVDbFolder.h:304
IOVDbNamespace::countSelectedChannels
int countSelectedChannels(const std::vector< cool::ChannelId > &channels, const cool::ChannelSelection &selected)
Count the number of selected channels in a vector of channels according to cool::Channel selection.
Definition: IOVDbCoolFunctions.cxx:81
IOVDbFolder::resetCache
void resetCache()
Definition: IOVDbFolder.cxx:623
IOVDbFolder::m_key
std::string m_key
Definition: IOVDbFolder.h:265
IOVDbNamespace::looksLikeMagicTag
bool looksLikeMagicTag(const std::string &candidateTag)
Looks like it should be magic.
Definition: IOVDbStringFunctions.cxx:151
CondAttrListVec::addSlice
void addSlice(const IOVRange &range, const unsigned int chan, const std::vector< coral::AttributeList > &data, const unsigned int datastart, const unsigned int dataend)
Definition: CondAttrListVec.h:268
IOVDbFolder::m_cacheccstart
std::vector< unsigned int > m_cacheccstart
Definition: IOVDbFolder.h:320
test_pyathena.counter
counter
Definition: test_pyathena.py:15
IOVDbConn::dropAndReconnect
bool dropAndReconnect()
Definition: IOVDbConn.cxx:79
python.PyAthena.obj
obj
Definition: PyAthena.py:135
IGeoModelSvc.h
IOVDbNamespace::BasicFolder::jsonPayload
std::string jsonPayload(const std::string &folderDescription, const std::string &spec)
Definition: BasicFolder.cxx:119
IOVDbParser::addressHeader
std::string addressHeader() const
Definition: IOVDbParser.cxx:206
CondAttrListCollection::add
bool add(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs.
Definition: CondAttrListCollection.h:452
StoreGateSvc.h
python.compressB64.c
def c
Definition: compressB64.py:93
IOVDbFolder::m_conn
IOVDbConn * m_conn
Definition: IOVDbFolder.h:263
IOVDbNamespace::IovStore::empty
bool empty() const
is the store empty?
Definition: IovStore.h:43
IOVDbNamespace::IovStore::setIovSpan
void setIovSpan(const Iov_t &span)
Set span.
Definition: IovStore.cxx:82
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
IOVDbConn::getCoraCoolDb
CoraCoolDatabasePtr getCoraCoolDb()
Definition: IOVDbConn.cxx:96
CondAttrListVecAddress.h
This file contains the class definition for the CondAttrListVecAddress class.
IOVDbFolder::m_typename
std::string m_typename
Definition: IOVDbFolder.h:295
IOVDbFolder::objectIteratorIsValid
bool objectIteratorIsValid(cool::IObjectIteratorPtr &objItr)
Definition: IOVDbFolder.h:216
CrestFunctions.h
Header for CrestFunctions utilities.
IOVDbFolder::m_timestamp
bool m_timestamp
Definition: IOVDbFolder.h:268
extractSporadic.myFile
myFile
Definition: extractSporadic.py:87
IOVDbFolder::m_cacheattr
std::vector< coral::AttributeList > m_cacheattr
Definition: IOVDbFolder.h:319
checkFileSG.ind
list ind
Definition: checkFileSG.py:118
CondAttrListCollection::addShared
void addShared(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs with shared data.
Definition: CondAttrListCollection.h:469
IOVDbFolder::setWriteMeta
void setWriteMeta()
Definition: IOVDbFolder.cxx:182
TagFunctions.h
IOVDbNamespace
Definition: Base64Codec.cxx:16
ServiceHandle< IIOVSvc >