Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
IOVDbSvc.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 // IOVDbSvc.cxx
6 // Re-implementation of Athena IOVDbSvc
7 // Richard Hawkijngs, started 23/11/08
8 // based on earlier code by RD Schaffer, Antoine Perus and RH
9 
10 #include "StoreGate/StoreGateSvc.h"
12 #include "Gaudi/Interfaces/IOptionsSvc.h"
13 #include "GaudiKernel/IIncidentSvc.h"
14 #include "GaudiKernel/Guards.h"
15 #include "GaudiKernel/IOpaqueAddress.h"
16 #include "GaudiKernel/IProperty.h"
17 #include "GaudiKernel/IIoComponentMgr.h"
18 #include "AthenaKernel/IOVRange.h"
23 #include "DBLock/DBLock.h"
25 
26 #include "IOVDbParser.h"
27 #include "IOVDbFolder.h"
28 #include "IOVDbSvc.h"
29 #include "CoralCrestManager.h"
30 
31 #include <algorithm>
32 #include <list>
33 #include <utility>
34 
35 // helper function for getting jobopt properties
36 namespace {
37  bool
38  refersToConditionsFolder(const ITagInfoMgr::NameTagPair & thisPair){
39  return thisPair.first.front() == '/';
40  }
41 
42 
43 // Wrap a cool IDatabase with a DBLock.
44 class LockedDatabase
45  : public cool::IDatabase
46 {
47 public:
48  LockedDatabase (cool::IDatabasePtr dbptr,
49  const Athena::DBLock& dblock);
50  virtual ~LockedDatabase();
51 
52  virtual const cool::DatabaseId& databaseId() const override
53  { return m_dbptr->databaseId(); }
54 
55  virtual const cool::IRecord& databaseAttributes() const override
56  { return m_dbptr->databaseAttributes(); }
57 
58  virtual cool::IFolderSetPtr createFolderSet
59  ( const std::string& fullPath,
60  const std::string& description = "",
61  bool createParents = false ) override
62  { return m_dbptr->createFolderSet (fullPath, description, createParents); }
63 
64  virtual bool existsFolderSet( const std::string& folderSetName ) override
65  { return m_dbptr->existsFolderSet (folderSetName); }
66 
67  virtual cool::IFolderSetPtr getFolderSet( const std::string& fullPath ) override
68  { return m_dbptr->getFolderSet (fullPath); }
69 
70  virtual cool::IFolderPtr createFolder
71  ( const std::string& fullPath,
72  const cool::IFolderSpecification& folderSpec,
73  const std::string& description = "",
74  bool createParents = false ) override
75  { return m_dbptr->createFolder (fullPath, folderSpec, description, createParents); }
76 
77  virtual bool existsFolder( const std::string& fullPath ) override
78  { return m_dbptr->existsFolder (fullPath); }
79 
80  virtual cool::IFolderPtr getFolder( const std::string& fullPath ) override
81  { return m_dbptr->getFolder (fullPath); }
82 
83  virtual const std::vector<std::string> listAllNodes( bool ascending = true ) override
84  { return m_dbptr->listAllNodes (ascending); }
85 
86  virtual bool dropNode( const std::string& fullPath ) override
87  { return m_dbptr->dropNode (fullPath); }
88 
89  virtual bool existsTag( const std::string& tagName ) const override
90  { return m_dbptr->existsTag (tagName); }
91 
92  virtual cool::IHvsNode::Type tagNameScope( const std::string& tagName ) const override
93  { return m_dbptr->tagNameScope (tagName); }
94 
95  virtual const std::vector<std::string>
96  taggedNodes( const std::string& tagName ) const override
97  { return m_dbptr->taggedNodes (tagName); }
98 
99  virtual bool isOpen() const override
100  { return m_dbptr->isOpen(); }
101 
102  virtual void openDatabase() override
103  { return m_dbptr->openDatabase(); }
104 
105  virtual void closeDatabase() override
106  { return m_dbptr->closeDatabase(); }
107 
108  virtual const std::string& databaseName() const override
109  { return m_dbptr->databaseName(); }
110 
111 #ifdef COOL400TX
112  virtual ITransactionPtr startTransaction() override
114  { return m_dbptr->startTransaction(); }
115 #endif
116 
117 
118 private:
119  cool::IDatabasePtr m_dbptr;
120  Athena::DBLock m_dblock;
121 };
122 
123 
124 LockedDatabase::LockedDatabase (cool::IDatabasePtr dbptr,
125  const Athena::DBLock& dblock)
126  : m_dbptr (std::move(dbptr)),
127  m_dblock (dblock)
128 {
129 }
130 
131 
132 LockedDatabase::~LockedDatabase()
133 = default;
134 
135 
136 } // anonymous namespace
137 
138 
139 IOVDbSvc::~IOVDbSvc() = default;
140 
142 {
143  if( m_poolSvcContext < 0 ) {
144  // Get context for POOL conditions files, and created an initial connection
146  m_poolSvcContext=m_h_poolSvc->getInputContext("Conditions", m_par_maxNumPoolFiles);
147  } else {
148  m_poolSvcContext=m_h_poolSvc->getInputContext("Conditions");
149  }
150  if( m_h_poolSvc->connect(pool::ITransaction::READ, m_poolSvcContext).isSuccess() ) {
151  ATH_MSG_INFO( "Opened read transaction for POOL PersistencySvc");
152  } else {
153  // We only emit info for failure to connect (for the moment? RDS 01/2008)
154  ATH_MSG_INFO( "Cannot connect to POOL PersistencySvc" );
155  }
156  }
157  return m_poolSvcContext;
158 }
159 
161  if (StatusCode::SUCCESS!=AthService::initialize()) return StatusCode::FAILURE;
162  // subscribe to events
163  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc",name());
164  if (StatusCode::SUCCESS!=incSvc.retrieve()) {
165  ATH_MSG_ERROR( "Unable to get the IncidentSvc" );
166  return StatusCode::FAILURE;
167  }
168  long int pri=100;
169  incSvc->addListener( this, "BeginEvent", pri );
170  incSvc->addListener( this, "StoreCleared", pri ); // for SP Athena
171  incSvc->addListener( this, IncidentType::EndProcessing, pri ); // for MT Athena
172 
173  // Register this service for 'I/O' events
174  ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
175  if (!iomgr.retrieve().isSuccess()) {
176  ATH_MSG_FATAL("Could not retrieve IoComponentMgr !");
177  return(StatusCode::FAILURE);
178  }
179  if (!iomgr->io_register(this).isSuccess()) {
180  ATH_MSG_FATAL("Could not register myself with the IoComponentMgr !");
181  return(StatusCode::FAILURE);
182  }
183  // print warnings/info depending on state of job options
185  ATH_MSG_INFO( "COOL connection management disabled - connections kept open throughout job" );
187  ATH_MSG_INFO( "POOL file connection management disabled - files kept open throught job" );
188  if (m_par_maxNumPoolFiles.value() > 0)
189  ATH_MSG_INFO( "Only " << m_par_maxNumPoolFiles.value() << " POOL conditions files will be open at once" );
190  if (m_par_forceRunNumber.value() > 0 || m_par_forceLumiblockNumber.value() > 0)
191  ATH_MSG_WARNING( "Global run/LB number forced to be [" <<
192  m_par_forceRunNumber.value() << "," << m_par_forceLumiblockNumber.value() << "]" );
193  if (m_par_forceTimestamp.value() > 0)
194  ATH_MSG_WARNING( "Global timestamp forced to be " <<
195  m_par_forceTimestamp.value() );
196  if (m_par_cacheRun.value() > 0)
197  ATH_MSG_INFO( "Run-LB data will be cached in groups of " <<
198  m_par_cacheRun.value() << " runs" );
199  if (m_par_cacheTime.value() > 0)
200  ATH_MSG_INFO( "Timestamp data will be cached in groups of " << m_par_cacheTime.value() << " seconds" );
201  if (m_par_cacheAlign > 0)
202  ATH_MSG_INFO( "Cache alignment will be done in " << m_par_cacheAlign.value() << " slices" );
203  if (m_par_onlineMode)
204  ATH_MSG_INFO( "Online mode ignoring potential missing channels outside cache" );
205  if (m_par_checklock)
206  ATH_MSG_INFO( "Tags will be required to be locked");
207 
208  // make sure iovTime is undefined
209  m_iovTime.reset();
210 
211  // extract information from EventSelector for run/LB/time overrides
212  if (StatusCode::SUCCESS!=checkEventSel()) return StatusCode::FAILURE;
213 
214  // initialise default connection
215  if (!m_par_defaultConnection.empty()) {
216  // default connection is readonly if no : in name (i.e. logical conn)
217  bool readonly=(m_par_defaultConnection.value().find(':')==std::string::npos);
218  m_connections.push_back(new IOVDbConn(m_par_defaultConnection,readonly,msg()));
219  }
220 
221  // set time of timestampslop in nanoseconds
222  m_iovslop=static_cast<cool::ValidityKey>(m_par_timeStampSlop*1.E9);
223 
224  // check for global tag in jobopt, which will override anything in input file
225  if (!m_par_globalTag.empty()) {
227  ATH_MSG_INFO( "Global tag: " << m_par_globalTag.value() << " set from joboptions" );
228  }
229 
230  // setup folders and process tag overrides
231  if (StatusCode::SUCCESS!=setupFolders()) return StatusCode::FAILURE;
232 
233  // Set state to initialize
235  ATH_MSG_INFO( "Initialised with " << m_connections.size() <<
236  " connections and " << m_foldermap.size() << " folders" );
237  if (m_outputToFile.value()) ATH_MSG_INFO("Db dump to file activated");
238  if (m_crestToFile.value()) ATH_MSG_INFO("Crest dump to file activated");
239  if (m_crestCoolToFile.value())ATH_MSG_INFO("Crest or Cool dump to file activated");
240  ATH_MSG_INFO( "Service IOVDbSvc initialised successfully" );
241 
243  return StatusCode::SUCCESS;
244 }
245 
246 
248  ATH_MSG_DEBUG("I/O reinitialization...");
249  // PoolSvc clears all connections on IO_reinit - forget the stored contextId
250  m_poolSvcContext = -1;
251  return(StatusCode::SUCCESS);
252 }
253 
255  ATH_MSG_DEBUG("I/O finalization...");
256  return(StatusCode::SUCCESS);
257 }
258 
260  // summarise and delete folders, adding total read from COOL
261  float readtime=0.;
262  // accumulate a map of readtime by connection
263  typedef std::map<IOVDbConn*,float> CTMap;
264  CTMap ctmap;
265  for (const auto & namePtrPair : m_foldermap) {
266  IOVDbFolder* folder=namePtrPair.second;
267  folder->summary();
268  const float& fread=folder->readTime();
269  readtime+=fread;
270  IOVDbConn* cptr=folder->conn();
271  CTMap::iterator citr=ctmap.find(cptr);
272  if (citr!=ctmap.end()) {
273  (citr->second)+=fread;
274  } else {
275  ctmap.insert(CTMap::value_type(cptr,fread));
276  }
277  delete folder;
278  }
279  ATH_MSG_INFO( " bytes in (( " << std::fixed << std::setw(9) << std::setprecision(2) <<
280  readtime << " ))s" );
281 
282  // close and delete connections, printing time in each one
283  for (auto & pThisConnection : m_connections) {
284  float fread=0;
285  CTMap::iterator citr=ctmap.find(pThisConnection);
286  if (citr!=ctmap.end()) fread=citr->second;
287  pThisConnection->setInactive();
288  pThisConnection->summary(fread);
289  delete pThisConnection;
290  }
291  // finally remove the msg svc
292  //delete m_log;
293  return AthService::finalize();
294 }
295 
296 cool::IDatabasePtr IOVDbSvc::getDatabase(bool readOnly) {
297  // get default database connection
298  cool::IDatabasePtr dbconn;
299  if (m_par_defaultConnection.empty() || m_connections.empty()) {
300  ATH_MSG_INFO( "No default COOL database connection is available");
301  dbconn.reset();
302  } else {
303  Athena::DBLock dblock;
304  if (m_connections[0]->isReadOnly()!=readOnly) {
305  ATH_MSG_INFO("Changing state of default connection to readonly=" << readOnly );
306  m_connections[0]->setReadOnly(readOnly);
307  }
308  dbconn = std::make_shared<LockedDatabase> (m_connections[0]->getCoolDb(),
309  dblock);
310  }
311  return dbconn;
312 }
313 
315  // Read information for folders and setup TADs
316  if (storeID!=StoreID::DETECTOR_STORE) return StatusCode::SUCCESS;
317  // Preloading of addresses should be done ONLY for detector store
318  ATH_MSG_DEBUG( "preLoadAddress: storeID -> " << storeID );
319 
320  Athena::DBLock dblock;
321 
322  // check File Level Meta Data of input, see if any requested folders are available there
325  if (StatusCode::SUCCESS==m_h_metaDataStore->retrieve(cont,contEnd)) {
326  unsigned int ncontainers=0;
327  unsigned int nused=0;
328  for (;cont!=contEnd; ++cont) {
329  ++ncontainers;
330  const std::string& fname=cont->folderName();
331  // check if this folder is in list requested by IOVDbSvc
332  for (const auto & thisNamePtrPair : m_foldermap) {
333  // take data from FLMD only if tag override is NOT set
334  if (thisNamePtrPair.second->folderName()==fname && !(thisNamePtrPair.second->tagOverride())) {
335  ATH_MSG_INFO( "Folder " << fname << " will be taken from file metadata" );
336  thisNamePtrPair.second->useFileMetaData();
337  thisNamePtrPair.second->setFolderDescription( cont->folderDescription() );
338  ++nused;
339  break;
340  }
341  }
342  }
343  ATH_MSG_INFO( "Found " << ncontainers << " metadata containers in input file, " << nused << " will be used");
344  } else {
345  ATH_MSG_DEBUG( "Could not retrieve IOVMetaDataContainer objects from MetaDataStore" );
346  }
347 
348  // Remove folders which should only be read from file meta data, but
349  // were not found in the MetaDataStore
350 
351  // Note: we cannot iterate and perform erase within the iteration
352  // because the iterator becomes invalid. So first collect the keys
353  // to erase in a first pass and then erase them.
354  std::vector<std::string> keysToDelete;
355  for (const auto & thisNamePtrPair : m_foldermap) {
356  if (thisNamePtrPair.second->fromMetaDataOnly() && !thisNamePtrPair.second->readMeta()) {
357  ATH_MSG_INFO( "preLoadAddresses: Removing folder " << thisNamePtrPair.second->folderName() <<
358  ". It should only be in the file meta data and was not found." );
359  keysToDelete.push_back(thisNamePtrPair.first);
360  }
361  }
362 
363  for (auto & thisKey : keysToDelete) {
364  FolderMap::iterator fitr=m_foldermap.find(thisKey);
365  if (fitr != m_foldermap.end()) {
366  fitr->second->conn()->decUsage();
367  delete (fitr->second);
368  m_foldermap.erase(fitr);
369  } else {
370  ATH_MSG_ERROR( "preLoadAddresses: Could not find folder " << thisKey << " for removal" );
371  }
372  }
373 
374 
375  // loop over all folders, grouped by connection
376  // do metadata folders on first connection (default connection)
377  bool doMeta=true;
378  // do not close COOL connection until next one has been opened, this enables
379  // connection sharing in CORAL, so all COOL connections will use the same
380  // CORAL one (althugh they will each be given a separate session)
381  IOVDbConn* oldconn=nullptr;
382  for (const auto & pThisConnection : m_connections) {
383  if (pThisConnection->nFolders()>0 || doMeta) {
384  // loop over all folders using this connection
385  for (const auto & thisNamePtrPair : m_foldermap) {
386  IOVDbFolder* folder=thisNamePtrPair.second;
387  if (folder->conn()==pThisConnection || (folder->conn()==nullptr && doMeta)) {
388  std::unique_ptr<SG::TransientAddress> tad =
389  folder->preLoadFolder( &(*m_h_tagInfoMgr), m_par_cacheRun.value(),
390  m_par_cacheTime.value());
391  if (oldconn!=pThisConnection) {
392  // close old connection if appropriate
393  if (m_par_manageConnections && oldconn!=nullptr) oldconn->setInactive();
394  oldconn=pThisConnection;
395  }
396  if (tad==nullptr) {
397  ATH_MSG_ERROR( "preLoadFolder failed for folder " << folder->folderName() );
398  return StatusCode::FAILURE;
399  }
400  // for write-metadata folder, request data preload
401  if (folder->writeMeta()) {
402  if (StatusCode::SUCCESS!=m_h_IOVSvc->preLoadDataTAD(tad.get(),folder->eventStore())) {
403  ATH_MSG_ERROR( "Could not request IOVSvc to preload metadata for " << folder->folderName() );
404  return StatusCode::FAILURE;
405  }
406  } else {
407  // for other folders, just preload TAD (not data)
408  if (StatusCode::SUCCESS!=m_h_IOVSvc->preLoadTAD(tad.get(), folder->eventStore())) {
409  ATH_MSG_ERROR( "Could not request IOVSvc to preload metadata for " << folder->folderName() );
410  return StatusCode::FAILURE;
411  }
412  }
413  // Add TAD to Storegate
414  tlist.push_back(tad.release());
415  // check for IOV override
416  folder->setIOVOverride(m_par_forceRunNumber.value(),
418  }
419  }
420  }
421  doMeta=false;
422  }
423  // close last connection
424  if (oldconn!=nullptr and m_par_manageConnections) oldconn->setInactive();
425 
426  // some folder keys may have changed during preloadFolder due to use of
427  // <key> specification in folder description string
428  // build a new foldermap with the updated keys
429  FolderMap newmap;
430  for (const auto & thisNamePtrPair : m_foldermap) {
431  newmap[thisNamePtrPair.second->key()]=thisNamePtrPair.second;
432  }
433  m_foldermap=newmap;
434  // fill global and explicit folder tags into TagInfo
435  if (StatusCode::SUCCESS!=fillTagInfo())
436  ATH_MSG_ERROR("Could not fill TagInfo object from preLoadAddresses" );
437  return StatusCode::SUCCESS;
438 }
439 
441  // this method does nothing
442  return StatusCode::SUCCESS;
443 }
444 
445 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
447  const EventContext& /*ctx*/)
448 {
449  // Provide TAD and associated range, actually reading the conditions data
450 
451  // Read information for folders and setup TADs
452  if (storeID!=StoreID::DETECTOR_STORE) return StatusCode::FAILURE;
453  Gaudi::Guards::AuditorGuard auditor(std::string("UpdateAddr::")+(tad->name().empty() ? "anonymous" : tad->name()),
454  auditorSvc(), "preLoadProxy");
455 
456  IOVTime iovTime{m_iovTime};
457  IOVRange range;
458  std::unique_ptr<IOpaqueAddress> address;
459 
460  // first check if this key is managed by IOVDbSvc
461  // return FAILURE if not - this allows other AddressProviders to be
462  // asked for the TAD
463  const std::string& key=tad->name();
464  FolderMap::const_iterator fitr=m_foldermap.find(key);
465  if (fitr==m_foldermap.end()) {
467  "updateAddress cannot find description for TAD " << key );
468  return StatusCode::FAILURE;
469  }
470  IOVDbFolder* folder=fitr->second;
471  if (folder->clid()!=tad->clID()) {
472  ATH_MSG_VERBOSE( "CLID for TAD " << key << " is " << tad->clID()
473  << " but expecting " << folder->clid() );
474 
475  return StatusCode::FAILURE;
476  }
477 
478  // IOVDbSvc will satisfy the request, using already found folder
479  // now determine the current IOVTime
481  ATH_MSG_DEBUG( "updateAddress: in initialisation phase and no iovTime defined" );
482  return::StatusCode::SUCCESS;
483  }
485  // determine iovTime from eventID in the event context
486  const EventIDBase* evid = EventIDFromStore( m_h_sgSvc );
487  if( evid ) {
488  iovTime.setRunEvent( evid->run_number(), evid->lumi_block()) ;
489  // save both seconds and ns offset for timestamp
490  uint64_t nsTime = evid->time_stamp() *1000000000LL;
491  nsTime += evid->time_stamp_ns_offset();
492  iovTime.setTimestamp(nsTime);
493  m_iovTime = iovTime;
494  ATH_MSG_DEBUG( "updateAddress - using iovTime from EventInfo: " << iovTime);
495  } else {
496  // failed to get event info - just return success
497  ATH_MSG_DEBUG( "Could not get event - initialise phase");
498  return StatusCode::SUCCESS;
499  }
500  } else {
501  ATH_MSG_DEBUG("updateAddress: using iovTime from init/beginRun: " << iovTime);
502  }
503 
504 
505 
506  // obtain the validity key for this folder (includes overrides)
507  cool::ValidityKey vkey=folder->iovTime(iovTime);
508  {
509  // The dblock is currently abused to also protect the cache in the IOVDbFolders.
510  // This global lock may give rise to deadlocks between the dblock and the internal lock
511  // of the SGImplSvc. The deadlock may arise if the order of the initial call to IOVDbSvc
512  // and SGImplSvc are different, because the two services call each other.
513  // A problem was observed when SG::DataProxy::isValidAddress first called IOVDbSvc::updateAddress
514  // which called IOVSvc::setRange then SGImplSvc::proxy, and at the same time
515  // StoreGateSvc::contains called first SGImplSvc::proxy which then called IOVDbSvc::updateAddress.
516  // This problem is mitigated by limiting the scope of the dblock here.
517  Athena::DBLock dblock;
518  ATH_MSG_DEBUG("Validity key "<<vkey);
519  if (!folder->readMeta() && !folder->cacheValid(vkey)) {
520  // mark this folder as not-dropped so cache-read will succeed
521  folder->setDropped(false);
522  // reload cache for this folder (and all others sharing this DB connection)
523  ATH_MSG_DEBUG( "Triggering cache load for folder " << folder->folderName());
524  if (StatusCode::SUCCESS!=loadCaches(folder->conn())) {
525  ATH_MSG_ERROR( "Cache load failed for at least one folder from " << folder->conn()->name()
526  << ". You may see errors from other folders sharing the same connection." );
527  return StatusCode::FAILURE;
528  }
529  }
530 
531  // data should now be in cache
532  // setup address and range
533  {
534  Gaudi::Guards::AuditorGuard auditor(std::string("FldrSetup:")+(tad->name().empty() ? "anonymous" : tad->name()),
535  auditorSvc(), "preLoadProxy");
536  if (!folder->getAddress(vkey,&(*m_h_persSvc),poolSvcContext(),address,
538  ATH_MSG_ERROR( "getAddress failed for folder " << folder->folderName() );
539  return StatusCode::FAILURE;
540  }
541  }
542  // reduce minimum IOV of timestamp folders to avoid 'thrashing'
543  // due to events slightly out of order in HLT
544  if (folder->timeStamp()) {
545  cool::ValidityKey start=range.start().timestamp();
547  range=IOVRange(IOVTime(start),range.stop());
548  }
549  }
550 
551  // Pass range onto IOVSvc
552  if (StatusCode::SUCCESS!=m_h_IOVSvc->setRange(tad->clID(),tad->name(),
553  range,folder->eventStore())) {
554  ATH_MSG_ERROR( "setRange failed for folder " << folder->folderName() );
555  return StatusCode::FAILURE;
556  }
557  tad->setAddress(address.release());
558  return StatusCode::SUCCESS;
559 }
560 
561 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
562 
564  const std::string& dbKey,
565  const IOVTime& time,
566  IOVRange& range,
567  std::string& tag,
568  std::unique_ptr<IOpaqueAddress>& address) {
569 
570  Athena::DBLock dblock;
571 
572  ATH_MSG_DEBUG( "getRange clid: " << clid << " key: \""<< dbKey << "\" t: " << time );
573  const std::string& key=dbKey;
574  FolderMap::const_iterator fitr=m_foldermap.find(key);
575  if (fitr==m_foldermap.end()) {
576  ATH_MSG_VERBOSE("getRange cannot find description for dbKey " << key );
577  return StatusCode::FAILURE;
578  }
579  IOVDbFolder* folder=fitr->second;
580  if (folder->clid()!=clid) {
581  ATH_MSG_VERBOSE( "supplied CLID for " << key << " is "
582  << clid
583  << " but expecting " << folder->clid() );
584 
585  return StatusCode::FAILURE;
586  }
587 
588  tag = folder->key();
589 
590  // obtain the validity key for this folder (includes overrides)
591  cool::ValidityKey vkey=folder->iovTime(time);
592  if (!folder->readMeta() && !folder->cacheValid(vkey)) {
593  // mark this folder as not-dropped so cache-read will succeed
594  folder->setDropped(false);
595  // reload cache for this folder (and all others sharing this DB connection)
596  ATH_MSG_DEBUG( "Triggering cache load for folder " << folder->folderName() );
597  if (StatusCode::SUCCESS!=loadCaches(folder->conn(),&time)) {
598  ATH_MSG_ERROR( "Cache load failed for at least one folder from " << folder->conn()->name()
599  << ". You may see errors from other folders sharing the same connection." );
600  return StatusCode::FAILURE;
601  }
602  }
603 
604  // data should now be in cache
605  address.reset();
606  // setup address and range
607  {
608  Gaudi::Guards::AuditorGuard auditor(std::string("FldrSetup:")+(key.empty() ? "anonymous" : key),
609  auditorSvc(), "preLoadProxy");
610  if (!folder->getAddress(vkey,&(*m_h_persSvc),poolSvcContext(),address,
612  ATH_MSG_ERROR("getAddress failed for folder " <<folder->folderName() );
613  return StatusCode::FAILURE;
614  }
615  }
616 
617  // Special handling for extensible folders:
618  if (folder->extensible()) {
619  // Set the end time to just past the current event or lumiblock.
620  IOVTime extStop = range.stop();
621  if (folder->timeStamp()) {
622  extStop.setTimestamp (time.timestamp() + 1);
623  }
624  else {
625  extStop.setRETime (time.re_time() + 1);
626  }
627  range = IOVRange (range.start(), extStop);
628  }
629 
630  // Special handling for IOV override: set the infinite validity range
631  if (folder->iovOverridden()) {
632  if (folder->timeStamp()) {
635  }
636  else {
639  }
640  }
641 
642  return StatusCode::SUCCESS;
643 }
644 
645 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
646 
648  const std::string& /*dbKey*/,
649  const IOVRange& /*range*/,
650  const std::string& /*storeName*/ ) {
651  // this method does nothing
652  return StatusCode::SUCCESS;
653 }
654 
656  const EventContext& ctx)
657 {
658  Athena::DBLock dblock;
659 
660  // Begin run - set state and save time for later use
662  // Is this a different run compared to the previous call?
663  bool newRun = m_iovTime.isValid() && (m_iovTime.run() != beginRunTime.run());
664  m_iovTime=beginRunTime;
665  // For a MC event, the run number we need to use to look up the conditions
666  // may be different from that of the event itself. Override the run
667  // number with the conditions run number from the event context,
668  // if it is defined.
669  EventIDBase::number_type conditionsRun =
671  if (conditionsRun != EventIDBase::UNDEFNUM) {
672  m_iovTime.setRunEvent (conditionsRun, m_iovTime.event());
673  }
674 
675  ATH_MSG_DEBUG( "signalBeginRun> begin run time " << m_iovTime);
676  if (!m_par_onlineMode) {
677  return StatusCode::SUCCESS;
678  }
679 
680  // ONLINE mode: allow adding of new calibration constants between runs
681  if (!newRun) {
682  ATH_MSG_DEBUG( "Same run as previous signalBeginRun call. Skipping re-loading of folders..." );
683  return StatusCode::SUCCESS;
684  }
685 
686  // all other stuff is event based so happens after this.
687  // this is before first event of each run
688  ATH_MSG_DEBUG( "In online mode will recheck ... " );
689  ATH_MSG_DEBUG( "First reload PoolCataloge ... " );
690 
691  pool::IFileCatalog* catalog ATLAS_THREAD_SAFE = // we are not within the event loop yet
692  const_cast<pool::IFileCatalog*>(m_h_poolSvc->catalog());
693  catalog->commit();
694  catalog->start();
695 
696  for (const auto & pThisConnection : m_connections){
697  // only access connections which are actually in use - avoids waking up
698  // the default DB connection if it is not being used
699  if (pThisConnection->nFolders()>0) {
700  //request for database activates connection
701  cool::IDatabasePtr dbconn=pThisConnection->getCoolDb();
702  if (dbconn.get()==nullptr) {
703  ATH_MSG_FATAL( "Conditions database connection " << pThisConnection->name() << " cannot be opened - STOP" );
704  return StatusCode::FAILURE;
705  }
706  for (const auto & thisNamePtrPair: m_foldermap) {
707  IOVDbFolder* folder=thisNamePtrPair.second;
708  if (folder->conn()!=pThisConnection) continue;
709  folder->printCache();
710  cool::ValidityKey vkey=folder->iovTime(m_iovTime);
711  {
712  Gaudi::Guards::AuditorGuard auditor(std::string("FldrCache:")+folder->folderName(), auditorSvc(), "preLoadProxy");
713  if (!folder->loadCacheIfDbChanged(vkey, m_globalTag, dbconn, m_h_IOVSvc)) {
714  ATH_MSG_ERROR( "Problem RELOADING: " << folder->folderName());
715  return StatusCode::FAILURE;
716  }
717  }
718  folder->printCache();
719  }
720  }
721  if (m_par_manageConnections) pThisConnection->setInactive();
722  }
723  return StatusCode::SUCCESS;
724 }
725 
727  // this method does nothing
728 }
729 
731  // Close any open POOL files after loding Conditions
732  ATH_MSG_DEBUG( "postConditionsLoad: m_par_managePoolConnections=" << m_par_managePoolConnections
733  << " m_poolPayloadRequested=" << m_poolPayloadRequested );
734 
736  // reset POOL connection to close all open conditions POOL files
737  m_par_managePoolConnections.set(false);
739  if( m_poolSvcContext ) {
740  if (StatusCode::SUCCESS==m_h_poolSvc->disconnect(m_poolSvcContext)) {
741  ATH_MSG_DEBUG( "Successfully closed input POOL connections");
742  } else {
743  ATH_MSG_WARNING( "Unable to close input POOL connections" );
744  }
745  // reopen transaction
746  if (StatusCode::SUCCESS==m_h_poolSvc->connect(pool::ITransaction::READ, m_poolSvcContext)) {
747  ATH_MSG_DEBUG("Reopend read transaction for POOL conditions input files" );
748  } else {
749  ATH_MSG_WARNING("Cannot reopen read transaction for POOL conditions input files");
750  }
751  }
752  }
753 }
754 
755 void IOVDbSvc::handle( const Incident& inc) {
756  // Handle incidents:
757  // BeginEvent to set IOVDbSvc state to EVENT_LOOP
758  // StoreCleared/EndProcessing to close any open POOL files
759  ATH_MSG_VERBOSE( "entering handle(), incident type " << inc.type() << " from " << inc.source() );
760  if (inc.type()=="BeginEvent") {
762  } else {
763  Athena::DBLock dblock;
764 
765  const StoreClearedIncident* sinc = dynamic_cast<const StoreClearedIncident*>(&inc);
766  if( (inc.type()=="StoreCleared" && sinc!=nullptr && sinc->store()==&*m_h_sgSvc)
767  or inc.type()==IncidentType::EndProcessing )
768  {
771  }
772  }
773 }
774 
776  // Processing of taginfo
777  // Set GlobalTag and any folder-specific overrides if given
778 
779  // dump out contents of TagInfo
780  ATH_MSG_DEBUG( "Tags from input TagInfo:");
781  if( msg().level()>=MSG::DEBUG ) m_h_tagInfoMgr->printTags(msg());
782 
783  // check IOVDbSvc GlobalTag, if not already set
784  if (m_globalTag.empty()) {
785  m_globalTag = m_h_tagInfoMgr->findTag("IOVDbGlobalTag");
786  if (!m_globalTag.empty()) ATH_MSG_INFO( "Global tag: " << m_globalTag<< " set from input file" );
788  }
789 
790  // now check for tag overrides for specific folders
791  const ITagInfoMgr::NameTagPairVec nameTagPairs = m_h_tagInfoMgr->getInputTags();
792  for (const auto & thisNameTagPair: nameTagPairs) {
793  // assume tags relating to conditions folders start with /
794  if (not refersToConditionsFolder(thisNameTagPair)) continue;
795  // check for folder(s) with this name in (key, ptr) pair
796  for (const auto & thisKeyPtrPair: m_foldermap) {
797  IOVDbFolder* folder=thisKeyPtrPair.second;
798  const std::string& ifname=folder->folderName();
799  if (ifname!=thisNameTagPair.first) continue;
800  // use an override from TagInfo only if there is not an explicit jo tag,
801  // and folder meta-data is not used, and there is no <noover/> spec,
802  // and no global tag set in job options
803  const auto & theTag{thisNameTagPair.second};
804  if (folder->joTag().empty() && !folder->readMeta() && !folder->noOverride() && m_par_globalTag.empty()) {
805  folder->setTagOverride(theTag,false);
806  ATH_MSG_INFO( "TagInfo override for tag " << theTag << " in folder " << ifname );
807  } else if (folder->joTag()!=theTag) {
808  const std::string_view tagTypeString=(folder->joTag().empty()) ? "hierarchical" : "jobOption";
809  ATH_MSG_INFO( "Ignoring inputfile TagInfo request for tag " << theTag << " in folder " << ifname<<" in favour of "<<tagTypeString);
810  }
811  }
812  }
813  return StatusCode::SUCCESS;
814 }
815 
816 std::vector<std::string>
818  // return a list of all the StoreGate keys being managed by IOVDbSvc
819  std::vector<std::string> keys;
820  keys.reserve(m_foldermap.size());
821  std::for_each(m_foldermap.begin(),m_foldermap.end(), [&keys](const auto &i){keys.emplace_back(i.first);});
822  return keys;
823 }
824 
825 bool IOVDbSvc::getKeyInfo(const std::string& key, IIOVDbSvc::KeyInfo& info) {
826  // return information about given SG key
827  // first attempt to find the folder object for this key
828  FolderMap::const_iterator itr = m_foldermap.find(key);
829  if (itr!=m_foldermap.end()) {
830  const IOVDbFolder* f=itr->second;
831  info.folderName = f->folderName();
832  info.tag = f->resolvedTag();
833  info.range = f->currentRange();
834  info.retrieved = f->retrieved();
835  info.bytesRead = f->bytesRead();
836  info.readTime = f->readTime();
837  info.extensible = f->extensible();
838  return true;
839  } else {
840  info.retrieved = false;
841  return false;
842  }
843 }
844 
845 bool IOVDbSvc::dropObject(const std::string& key, const bool resetCache) {
846  // find the folder corresponding to this object
847  FolderMap::const_iterator itr=m_foldermap.find(key);
848  if (itr!=m_foldermap.end()) {
849  IOVDbFolder* folder=itr->second;
850  CLID clid=folder->clid();
851  SG::DataProxy* proxy=m_h_detStore->proxy(clid,key);
852  if (proxy!=nullptr) {
853  m_h_detStore->clearProxyPayload(proxy);
854  ATH_MSG_DEBUG("Dropped payload for key " << key );
855  folder->setDropped(true);
856  if (resetCache) {
857  folder->resetCache();
858  ATH_MSG_DEBUG( "Cache reset done for folder " << folder->folderName() );
859  }
860  return true;
861  } else {
862  return false;
863  }
864  } else {
865  return false;
866  }
867 }
868 
869 
870 /************************/
871 // private methods of IOVDbSvc
872 
874  // check if EventSelector is being used to override run numbers
875  // if so, we can set IOV time already to allow conditons retrieval
876  // in the initialise phase, needed for setting up simulation
877 
878  ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc",name());
879  ATH_CHECK( joSvc.retrieve() );
880 
881  if (!joSvc->has("EventSelector.OverrideRunNumber")) {
882  // do not return FAILURE if the EventSelector cannot be found, or it has
883  // no override property, can e.g. happen in online running
884  ATH_MSG_DEBUG( "No EventSelector.OverrideRunNumber property found" );
885  return StatusCode::SUCCESS;
886  }
887 
888  BooleanProperty bprop("OverrideRunNumber",false);
889  ATH_CHECK( bprop.fromString(joSvc->get("EventSelector.OverrideRunNumber")) );
890  if (bprop.value()) {
891  // if flag is set, extract Run,LB and time
892  ATH_MSG_INFO( "Setting run/LB/time from EventSelector override in initialize" );
893  uint32_t run,lumib;
894  uint64_t time;
895  bool allGood=true;
896  if (m_par_forceRunNumber.value()!=0 ||
897  m_par_forceLumiblockNumber.value()!=0)
898  ATH_MSG_WARNING( "forceRunNumber property also set" );
899  IntegerProperty iprop1("RunNumber",0);
900  if (iprop1.fromString(joSvc->get("EventSelector.RunNumber","INVALID"))) {
901  run=iprop1.value();
902  } else {
903  ATH_MSG_ERROR( "Unable to get RunNumber from EventSelector");
904  allGood=false;
905  }
906  IntegerProperty iprop2("FirstLB",0);
907  if (iprop2.fromString(joSvc->get("EventSelector.FirstLB","INVALID"))) {
908  lumib=iprop2.value();
909  } else {
910  ATH_MSG_ERROR( "Unable to get FirstLB from EventSelector");
911  allGood=false;
912  }
913  IntegerProperty iprop3("InitialTimeStamp",0);
914  if (iprop3.fromString(joSvc->get("EventSelector.InitialTimeStamp","INVALID"))) {
915  time=iprop3.value();
916  } else {
917  ATH_MSG_ERROR("Unable to get InitialTimeStamp from EventSelector" );
918  allGood=false;
919  }
920  if (allGood) {
921  m_iovTime.setRunEvent(run,lumib);
922  uint64_t nsTime=time*1000000000LL;
923  m_iovTime.setTimestamp(nsTime);
924  ATH_MSG_INFO( "run/LB/time set to [" << run << "," << lumib << " : " << nsTime << "]" );
925  } else {
926  ATH_MSG_ERROR( "run/LB/Time NOT changed" );
927  }
928  }
929 
930  return StatusCode::SUCCESS;
931 }
932 
934  // read the Folders joboptions and setup the folder list
935  // no wildcards are allowed
936 
937  // getting the pairs: folder name - CREST tag name:
938  if (m_par_source == "CREST"){
939  m_cresttagmap.clear();
941  }
942 
943  //1. Loop through folders
944  std::list<IOVDbParser> allFolderdata;
945  for (const auto & thisFolder : m_par_folders.value()) {
946  ATH_MSG_DEBUG( "Setup folder " << thisFolder );
947  IOVDbParser folderdata(thisFolder,msg());
948  if (!folderdata.isValid()) {
949  ATH_MSG_FATAL("setupFolders: Folder setup string is invalid: " <<thisFolder);
950  return StatusCode::FAILURE;
951  }
952 
953  allFolderdata.push_back(folderdata);
954  }
955 
956  //2. Loop through overwrites:
957  // syntax for entries is <prefix>folderpath</prefix> <tag>value</tag>
958  // folderpath matches from left of folderName
959  // but if partial match, next character must be / so override for /Fred/Ji
960  // matches /Fred/Ji/A and /Fred/Ji but not /Fred/Jim
961 
962  for (const auto & thisOverrideTag : m_par_overrideTags) {
963  IOVDbParser keys(thisOverrideTag,msg());
964  if (not keys.isValid()){
965  ATH_MSG_ERROR("An override tag was invalid: " << thisOverrideTag);
966  return StatusCode::FAILURE;
967  }
968  std::string prefix;
969  if (!keys.getKey("prefix","",prefix)) { // || !keys.getKey("tag","",tag)) {
970  ATH_MSG_ERROR( "Problem in overrideTag specification " <<thisOverrideTag );
971  return StatusCode::FAILURE;
972  }
973 
974  for (auto& folderdata : allFolderdata) {
975  const std::string& ifname=folderdata.folderName();
976  if (ifname.compare(0,prefix.size(), prefix)==0 &&
977  (ifname.size()==prefix.size() || ifname[prefix.size()]=='/')) {
978  //Match!
979  folderdata.applyOverrides(keys,msg());
980  }// end if
981  }// end loop over allFolderdata
982  }// end loop over overrides
983 
984  //3. Remove any duplicates:
985  std::list<IOVDbParser>::iterator it1=allFolderdata.begin();
986  std::list<IOVDbParser>::iterator it_e=allFolderdata.end();
987  for (;it1!=it_e;++it1) {
988  const IOVDbParser& folder1=*it1;
990  ++it2;
991  while(it2!=it_e) {
992  const IOVDbParser& folder2=*it2;
993  if (folder1==folder2) {
994  it2=allFolderdata.erase(it2); //FIXME: Smarter distinction/reporting about same folder but different keys.
995  ATH_MSG_DEBUG( "Removing duplicate folder " << folder1.folderName());
996  } else {
997  ++it2;
998  //Catch suspicous cases:
999  if (folder1.folderName()==folder2.folderName()) {
1000  ATH_MSG_WARNING( "Folder name appears twice: " << folder1.folderName() );
1001  ATH_MSG_WARNING( folder1 << " vs " << folder2 );
1002  }
1003  }
1004  }//end inner loop
1005  }//end outer loop
1006 
1007  //4.Set up folder map with cleaned folder list
1008 
1009  bool hasError=false;
1010  for (const auto& folderdata : allFolderdata) {
1011  // find the connection specification first - db or dbConnection
1012  // default is to use the 'default' connection
1013  IOVDbConn* conn=nullptr;
1014  std::string connstr;
1015  if (folderdata.getKey("db","",connstr) ||
1016  folderdata.getKey("dbConnection","",connstr)) {
1017  // an explicit database name is specified
1018  // check if it is already present in the existing connections
1019  for (const auto & pThisConnection : m_connections) {
1020  if (pThisConnection->name()==connstr) {
1021  // found existing connection - use that
1022  conn=pThisConnection;
1023  break;
1024  }
1025  }
1026  if (conn==nullptr) {
1027  // create new read-onlyconnection
1028  conn=new IOVDbConn(connstr,true,msg());
1029  m_connections.push_back(conn);
1030  }
1031  } else {
1032  // no connection specified - use default if available
1033  if (!m_par_defaultConnection.empty()) {
1034  conn=m_connections[0];
1035  } else {
1036  ATH_MSG_FATAL( "Folder request " << folderdata.folderName() <<
1037  " gives no DB connection information and no default set" );
1038  return StatusCode::FAILURE;
1039  }
1040  }
1041 
1042  // create the new folder, but only if a folder for this SG key has not
1043  // already been requested
1044 
1045  std::string crestTag = "";
1046  if (m_par_source == "CREST"){
1047  crestTag = m_cresttagmap[folderdata.folderName()];
1048  if(crestTag.size()==0 && folderdata.folderName().compare("/TagInfo")!=0){
1049  ATH_MSG_FATAL( "Global Tag "<<m_par_globalTag<<" hasn't folder: " << folderdata.folderName() <<
1050  " in Global Tag Map." );
1051  hasError=true;
1052  continue;
1053  }
1054  }
1055 
1056  IOVDbFolder* folder=new IOVDbFolder(conn,folderdata,msg(),&(*m_h_clidSvc), &(*m_h_metaDataTool),
1058  const std::string& key=folder->key();
1059  if (m_foldermap.find(key)==m_foldermap.end()) { //This check is too weak. For POOL-based folders, the SG key is in the folder description (not known at this point).
1061  conn->incUsage();
1062  } else {
1063  ATH_MSG_ERROR( "Duplicate request for folder " <<
1064  folder->folderName() <<
1065  " associated to already requested Storegate key " << key );
1066  // clean up this duplicate request
1067  delete folder;
1068  }
1069  }// end loop over folders
1070  // check for folders to be written to metadata
1071  if(hasError)
1072  return StatusCode::FAILURE;
1073  for (const auto & folderToWrite : m_par_foldersToWrite) {
1074  // match wildcard * at end of string only (i.e. /A/* matches /A/B, /A/C/D)
1075  std::string_view match=folderToWrite;
1076  std::string::size_type idx=folderToWrite.find('*');
1077  if (idx!=std::string::npos) {
1078  match=std::string_view(folderToWrite).substr(0,idx);
1079  }
1080  for (const auto & thisFolder : m_foldermap) {
1081  IOVDbFolder* fptr=thisFolder.second;
1082  if ((fptr->folderName()).compare(0,match.size(), match)==0) {
1083  fptr->setWriteMeta();
1084  ATH_MSG_INFO( "Folder " << fptr->folderName() << " will be written to file metadata" );
1085  }
1086  }//end loop over FolderMap
1087  }//end loop over m_par_foldersToWrite
1088  return StatusCode::SUCCESS;
1089 }
1090 
1092  if (!m_par_globalTag.empty()) {
1093  ATH_MSG_DEBUG( "Adding GlobalTag " << m_par_globalTag << " into TagInfo" );
1094  if (StatusCode::SUCCESS!=m_h_tagInfoMgr->addTag("IOVDbGlobalTag",m_par_globalTag))
1095  return StatusCode::FAILURE;
1096  }
1097  // add all explicit tags specified in folders
1098  // can be from Folders or tagOverrides properties
1099  for (const auto & thisFolder : m_foldermap) {
1100  const IOVDbFolder* folder=thisFolder.second;
1101  if (!folder->joTag().empty()) {
1102  ATH_MSG_DEBUG( "Adding folder " << folder->folderName() <<" tag " << folder->joTag() << " into TagInfo" );
1103  if (StatusCode::SUCCESS!=m_h_tagInfoMgr->addTag(folder->folderName(),folder->joTag()))
1104  return StatusCode::FAILURE;
1105  }
1106  // check to see if any input TagInfo folder overrides should be removed
1107  // this anticipates the decisions which will be made in processTagInfo
1108  // Here we do not have access to the TagInfo object, but can put remove
1109  // requests in for all folders if the global tag is set, or if there is
1110  // an explict joboption tag, nooverride spec, or data comes from metadata
1111  if (!m_par_globalTag.empty() || !folder->joTag().empty() || folder->noOverride() ||
1112  folder->readMeta()) {
1113  if (StatusCode::SUCCESS!=
1114  m_h_tagInfoMgr->removeTagFromInput(folder->folderName())) {
1115  ATH_MSG_WARNING( "Could not add TagInfo remove request for "
1116  << folder->folderName() );
1117  } else {
1118  ATH_MSG_INFO( "Added taginfo remove for " <<
1119  folder->folderName() );
1120  }
1121  }
1122  }
1123  return StatusCode::SUCCESS;
1124 }
1125 
1127  // load the caches for all folders using the given connection
1128  // so connection use is optimised
1129 
1130  Gaudi::Guards::AuditorGuard auditor(std::string("loadCachesOverhead:")+conn->name(), auditorSvc(), "preLoadProxy");
1131 
1132  ATH_MSG_DEBUG( "loadCaches: Begin for connection " << conn->name());
1133  // if global abort already set, load nothing
1134  if (m_abort) return StatusCode::FAILURE;
1135  bool access=false;
1136  StatusCode sc=StatusCode::SUCCESS;
1137  for (const auto & thisNamePtrPair : m_foldermap) {
1138  IOVDbFolder* folder=thisNamePtrPair.second;
1139  if (folder->conn()!=conn) continue;
1140  cool::ValidityKey vkey=folder->iovTime(time==nullptr ? m_iovTime : *time);
1141  // protect against out of range times (timestamp -1 happened in FDR2)
1142  if (vkey>cool::ValidityKeyMax) {
1143  ATH_MSG_WARNING( "Requested validity key " << vkey << " is out of range, reset to 0" );
1144  vkey=0;
1145  }
1146  if (!folder->cacheValid(vkey) && !folder->dropped()) {
1147  access=true;
1148  {
1149  Gaudi::Guards::AuditorGuard auditor(std::string("FldrCache:")+folder->folderName(), auditorSvc(), "preLoadProxy");
1150  if (!folder->loadCache(vkey,m_par_cacheAlign,m_globalTag,m_par_onlineMode)) {
1151  ATH_MSG_ERROR( "Cache load (prefetch) failed for folder " << folder->folderName() );
1152  // remember the failure, but also load other folders on this connection
1153  // while it is open
1154  sc=StatusCode::FAILURE;
1155  }
1156  }
1157  }
1158  }
1159  // disconnect from database if we connected
1160  if (access && m_par_manageConnections) conn->setInactive();
1161  // if connection aborted, set overall abort so we do not waste time trying
1162  // to read data from other schema
1163  if (conn->aborted()) {
1164  ATH_MSG_FATAL( "Connection " << conn->name() << " was aborted, set global abort" );
1165  m_abort=true;
1166  ATH_MSG_FATAL( "loadCache: impossible to load cache!" );
1167  throw std::exception();
1168  }
1169  return sc;
1170 }
1171 
1173 // check consistency of global tag and database instance, if set
1174  // catch most common user misconfigurations
1175  // this is only done here as need global tag to be set even if read from file
1176  // @TODO should this not be done during initialize
1177  if (!m_par_dbinst.empty() && !m_globalTag.empty() and (m_par_source!="CREST")) {
1178  const std::string_view tagstub=std::string_view(m_globalTag).substr(0,7);
1179  ATH_MSG_DEBUG( "Checking " << m_par_dbinst << " against " <<tagstub );
1180  if (((m_par_dbinst=="COMP200" || m_par_dbinst=="CONDBR2") &&
1181  (tagstub!="COMCOND" && tagstub!="CONDBR2")) ||
1182  (m_par_dbinst=="OFLP200" && (tagstub!="OFLCOND" && tagstub!="CMCCOND"))) {
1183  ATH_MSG_FATAL( "Likely incorrect conditions DB configuration! "
1184  << "Attached to database instance " << m_par_dbinst <<
1185  " but global tag begins " << tagstub );
1186  ATH_MSG_FATAL( "See Atlas/CoolTroubles wiki for details," <<
1187  " or set IOVDbSvc.DBInstance=\"\" to disable check" );
1188  return StatusCode::FAILURE;
1189  }
1190  }
1191  return StatusCode::SUCCESS;
1192 }
IOVDbSvc::postConditionsLoad
virtual void postConditionsLoad() override
May be called once conditions are loaded to let IOVDbSvc release resources.
Definition: IOVDbSvc.cxx:730
grepfile.info
info
Definition: grepfile.py:38
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
IOVDbSvc::initialize
virtual StatusCode initialize() override
Service init.
Definition: IOVDbSvc.cxx:160
IOVDbFolder.h
IOVDbSvc::INITIALIZATION
@ INITIALIZATION
Definition: IOVDbSvc.h:262
IOVDbSvc::preLoadAddresses
virtual StatusCode preLoadAddresses(StoreID::type storeID, tadList &list) override
Get all addresses that the provider wants to preload in SG maps.
Definition: IOVDbSvc.cxx:314
IOVDbSvc::getKeyInfo
virtual bool getKeyInfo(const std::string &key, IIOVDbSvc::KeyInfo &info) override
Return information about SG key return false if this key is not known to IOVDbSvc.
Definition: IOVDbSvc.cxx:825
EventIDFromStore.h
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
checkCorrelInHIST.conn
conn
Definition: checkCorrelInHIST.py:25
IOVRange
Validity Range object. Holds two IOVTimes (start and stop)
Definition: IOVRange.h:30
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:402
IOVTime::MAXRUN
static constexpr uint32_t MAXRUN
Definition: IOVTime.h:48
IOVDbSvc::m_crestCoolToFile
BooleanProperty m_crestCoolToFile
Definition: IOVDbSvc.h:233
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
IOVRange.h
Validity Range object. Holds two IOVTime instances (start and stop)
IOVDbSvc::m_abort
bool m_abort
Definition: IOVDbSvc.h:285
IOVTime::event
uint32_t event() const noexcept
Definition: IOVTime.h:106
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
Atlas::ExtendedEventContext::conditionsRun
EventIDBase::number_type conditionsRun() const
Definition: ExtendedEventContext.h:38
IOVDbSvc::fillTagInfo
StatusCode fillTagInfo()
Definition: IOVDbSvc.cxx:1091
IOVDbSvc::getDatabase
virtual cool::IDatabasePtr getDatabase(bool readOnly) override
Access to COOL database for a given folder.
Definition: IOVDbSvc.cxx:296
initialize
void initialize()
Definition: run_EoverP.cxx:894
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
CscCalibQuery.fullPath
string fullPath
Definition: CscCalibQuery.py:360
IFileCatalog.h
query_example.tlist
tlist
Definition: query_example.py:25
IOVDbSvc::m_par_maxNumPoolFiles
IntegerProperty m_par_maxNumPoolFiles
Definition: IOVDbSvc.h:208
SG::TransientAddress
Definition: TransientAddress.h:32
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
IOVDbSvc::poolSvcContext
int poolSvcContext()
Definition: IOVDbSvc.cxx:141
IOVDbSvc::signalEndProxyPreload
virtual void signalEndProxyPreload() override
Signal that callback has been fired.
Definition: IOVDbSvc.cxx:726
IOVDbSvc::m_foldermap
FolderMap m_foldermap
Definition: IOVDbSvc.h:283
AtlasMcWeight::number_type
unsigned int number_type
Definition: AtlasMcWeight.h:20
IOVDbSvc::m_h_poolSvc
ServiceHandle< IPoolSvc > m_h_poolSvc
Definition: IOVDbSvc.h:242
pool::IFileCatalog::commit
void commit()
Save catalog to file.
Definition: IFileCatalog.h:49
IOVDbSvc::m_par_timeStampSlop
FloatProperty m_par_timeStampSlop
Definition: IOVDbSvc.h:210
IOVDbSvc::dropObject
virtual bool dropObject(const std::string &key, const bool resetCache=false) override
Definition: IOVDbSvc.cxx:845
IOVDbSvc::io_reinit
StatusCode io_reinit() override final
Definition: IOVDbSvc.cxx:247
IOVDbSvc::tadList
IAddressProvider::tadList tadList
Definition: IOVDbSvc.h:103
IOVDbSvc::m_par_manageConnections
BooleanProperty m_par_manageConnections
Definition: IOVDbSvc.h:198
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ReadCellNoiseFromCoolCompare.folder2
folder2
Definition: ReadCellNoiseFromCoolCompare.py:296
IOVTime::isValid
bool isValid() const noexcept
Definition: IOVTime.cxx:117
CaloTime_fillDB.folderSpec
folderSpec
Definition: CaloTime_fillDB.py:92
IOVDbFolder
Definition: IOVDbFolder.h:52
IOVDbSvc::m_crestToFile
BooleanProperty m_crestToFile
Definition: IOVDbSvc.h:232
IOVDbSvc::FINALIZE_ALG
@ FINALIZE_ALG
Definition: IOVDbSvc.h:265
IOVDbSvc::m_h_metaDataStore
ServiceHandle< StoreGateSvc > m_h_metaDataStore
Definition: IOVDbSvc.h:239
CoralCrestManager::getGlobalTagMap
static std::map< std::string, std::string > getGlobalTagMap(const std::string &crest_path, const std::string &globaltag)
Definition: CoralCrestManager.cxx:29
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
IOVDbSvc::m_h_clidSvc
ServiceHandle< IClassIDSvc > m_h_clidSvc
Definition: IOVDbSvc.h:241
IOVTime::MINRUN
static constexpr uint32_t MINRUN
Definition: IOVTime.h:44
Atlas::getExtendedEventContext
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Definition: ExtendedEventContext.cxx:32
SG::TransientAddress::name
const std::string & name() const
Get the primary (hashed) SG key.
Definition: TransientAddress.h:217
IOVDbSvc::m_par_forceRunNumber
IntegerProperty m_par_forceRunNumber
Definition: IOVDbSvc.h:202
Type
RootType Type
Definition: TrigTSerializer.h:30
IOVTime
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
Definition: IOVTime.h:33
IOVDbSvc.h
Athena service for Interval Of Validity database.
pool::IFileCatalog
Definition: IFileCatalog.h:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IOVDbSvc::setRange
virtual StatusCode setRange(const CLID &clid, const std::string &dbKey, const IOVRange &range, const std::string &tag) override
Set range for a particular data object.
Definition: IOVDbSvc.cxx:647
IOVDbSvc::m_par_forceLumiblockNumber
IntegerProperty m_par_forceLumiblockNumber
Definition: IOVDbSvc.h:204
lumiFormat.i
int i
Definition: lumiFormat.py:85
IOVDbSvc::BEGIN_RUN
@ BEGIN_RUN
Definition: IOVDbSvc.h:263
IOVDbSvc::processTagInfo
virtual StatusCode processTagInfo() override
Process TagInfo.
Definition: IOVDbSvc.cxx:775
ITagInfoMgr::NameTagPairVec
std::vector< NameTagPair > NameTagPairVec
Definition: ITagInfoMgr.h:66
Athena::DBLock
Common database lock.
Definition: DBLock.h:46
DetDescrDictionaryDict::it1
std::vector< HWIdentifier >::iterator it1
Definition: DetDescrDictionaryDict.h:17
IOVDbParser::isValid
bool isValid() const
Definition: IOVDbParser.h:67
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IOVDbSvc::updateAddress
virtual StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress *tad, const EventContext &ctx) override
Update a transient Address.
Definition: IOVDbSvc.cxx:446
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IOVDbSvc::m_par_cacheAlign
UnsignedIntegerProperty m_par_cacheAlign
Definition: IOVDbSvc.h:217
IOVDbSvc::m_par_crestServer
StringProperty m_par_crestServer
Definition: IOVDbSvc.h:225
IOVTime::reset
void reset() noexcept
Definition: IOVTime.cxx:108
SG::TransientAddress::clID
CLID clID() const
Retrieve string key:
Definition: TransientAddress.h:210
IOVDbSvc::m_poolSvcContext
int m_poolSvcContext
Definition: IOVDbSvc.h:253
IOVDbParser.h
calibdata.exception
exception
Definition: calibdata.py:496
IOVDbSvc::checkEventSel
StatusCode checkEventSel()
Definition: IOVDbSvc.cxx:873
ITagInfoMgr::NameTagPair
std::pair< std::string, std::string > NameTagPair
Definition: ITagInfoMgr.h:65
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
IOVTime::MAXTIMESTAMP
static constexpr uint64_t MAXTIMESTAMP
Definition: IOVTime.h:58
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
IOVDbSvc::m_cresttagmap
std::map< std::string, std::string > m_cresttagmap
Definition: IOVDbSvc.h:227
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IOVDbSvc::m_par_managePoolConnections
BooleanProperty m_par_managePoolConnections
Definition: IOVDbSvc.h:200
IOVDbSvc::m_par_defaultConnection
Gaudi::Property< std::string > m_par_defaultConnection
Definition: IOVDbSvc.h:186
hist_file_dump.f
f
Definition: hist_file_dump.py:141
IOVTime::setRETime
void setRETime(uint64_t time) noexcept
Definition: IOVTime.cxx:84
IOVDbSvc::getKeyList
virtual std::vector< std::string > getKeyList() override
Definition: IOVDbSvc.cxx:817
run
Definition: run.py:1
python.TriggerAPI.TriggerAPISession.ascending
ascending
Definition: TriggerAPISession.py:435
ReadCoolUPD4.openDatabase
def openDatabase(dbstring)
Definition: ReadCoolUPD4.py:21
fptr
std::vector< TFile * > fptr
Definition: hcg.cxx:48
IOVTime::setTimestamp
void setTimestamp(uint64_t timestamp) noexcept
Definition: IOVTime.cxx:72
IOVDbSvc::m_h_tagInfoMgr
ServiceHandle< ITagInfoMgr > m_h_tagInfoMgr
Definition: IOVDbSvc.h:244
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
python.dummyaccess.access
def access(filename, mode)
Definition: dummyaccess.py:18
checkRpcDigits.allGood
bool allGood
Loop over the SDOs & Digits.
Definition: checkRpcDigits.py:171
IOVDbSvc::m_par_onlineMode
BooleanProperty m_par_onlineMode
Definition: IOVDbSvc.h:219
IOVDbSvc::m_iovTime
IOVTime m_iovTime
Definition: IOVDbSvc.h:270
StoreID::DETECTOR_STORE
@ DETECTOR_STORE
Definition: StoreID.h:27
IOVDbConn::setInactive
void setInactive()
Definition: IOVDbConn.cxx:114
IOVDbSvc::m_connections
ConnVec m_connections
Definition: IOVDbSvc.h:280
IOVTime::MAXEVENT
static constexpr uint32_t MAXEVENT
Definition: IOVTime.h:51
IOVDbSvc::FolderMap
std::map< std::string, IOVDbFolder * > FolderMap
Definition: IOVDbSvc.h:282
IOVMetaDataContainer.h
This class is a container for conditions data. It is intended to be used to store conditions data fro...
IOVDbSvc::m_par_checklock
BooleanProperty m_par_checklock
Definition: IOVDbSvc.h:221
IOVDbSvc::handle
virtual void handle(const Incident &incident) override
Incident service handle for EndEvent.
Definition: IOVDbSvc.cxx:755
IOVDbConn
Definition: IOVDbConn.h:18
dumpBeamSpot.dbconn
dbconn
Definition: dumpBeamSpot.py:27
IOVDbSvc::io_finalize
StatusCode io_finalize() override final
Definition: IOVDbSvc.cxx:254
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
IOVDbParser
Definition: IOVDbParser.h:19
IOVTime::run
uint32_t run() const noexcept
Definition: IOVTime.h:105
StoreClearedIncident::store
const StoreGateSvc * store() const
Return the store that was cleared.
Definition: StoreClearedIncident.cxx:33
IOVDbSvc::m_par_overrideTags
Gaudi::Property< std::vector< std::string > > m_par_overrideTags
Definition: IOVDbSvc.h:194
IOVDbSvc::m_outputToFile
BooleanProperty m_outputToFile
Definition: IOVDbSvc.h:231
IOVDbSvc::m_state
IOVDbSvc_state m_state
Definition: IOVDbSvc.h:267
StoreClearedIncident.h
Incident sent after a store is cleared.
python.checkUPD1.connstr
connstr
Definition: checkUPD1.py:78
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
IOVDbSvc::m_h_persSvc
ServiceHandle< IAddressCreator > m_h_persSvc
Definition: IOVDbSvc.h:240
IOVTime::MINEVENT
static constexpr uint32_t MINEVENT
Definition: IOVTime.h:50
IOVDbSvc::m_par_cacheRun
IntegerProperty m_par_cacheRun
Definition: IOVDbSvc.h:212
SG::TransientAddress::setAddress
void setAddress(IOpaqueAddress *pAddress)
Retrieve primary clid.
Definition: TransientAddress.cxx:192
fillPileUpNoiseLumi.createFolder
def createFolder(db, name)
Definition: fillPileUpNoiseLumi.py:6
IOVDbSvc::EVENT_LOOP
@ EVENT_LOOP
Definition: IOVDbSvc.h:264
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
IOVDbSvc::m_par_globalTag
Gaudi::Property< std::string > m_par_globalTag
Definition: IOVDbSvc.h:188
IOVDbSvc::m_par_dbinst
Gaudi::Property< std::string > m_par_dbinst
Definition: IOVDbSvc.h:190
CoralCrestManager.h
Header for CoralCrestManager class.
IOVDbSvc::m_poolPayloadRequested
bool m_poolPayloadRequested
Definition: IOVDbSvc.h:249
IOVDbSvc::getRange
virtual StatusCode getRange(const CLID &clid, const std::string &dbKey, const IOVTime &time, IOVRange &range, std::string &tag, std::unique_ptr< IOpaqueAddress > &ioa) override
Get range for a particular data object identified by its clid and key and a requested IOVTime.
Definition: IOVDbSvc.cxx:563
IOVDbSvc::~IOVDbSvc
virtual ~IOVDbSvc()
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
StoreID::type
type
Definition: StoreID.h:24
ReadNoiseFromCool.folder1
folder1
Definition: ReadNoiseFromCool.py:91
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
pool::ITransaction::READ
@ READ
Definition: ITransaction.h:29
IOVDbSvc::m_par_folders
Gaudi::Property< std::vector< std::string > > m_par_folders
Definition: IOVDbSvc.h:192
IOVDbSvc::finalize
virtual StatusCode finalize() override
Service finalize.
Definition: IOVDbSvc.cxx:259
DEBUG
#define DEBUG
Definition: page_access.h:11
IOVTime::setRunEvent
void setRunEvent(uint32_t run, uint32_t event) noexcept
Definition: IOVTime.cxx:96
EventIDFromStore
const EventIDBase * EventIDFromStore(IProxyDict *store)
Retrieve the EventID from EventContext saved in store STORE.
Definition: EventIDFromStore.cxx:15
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
DBLock.h
Common database lock.
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
IIOVDbSvc::KeyInfo
Filled by IIOVDbSvc::getKeyInfo.
Definition: IIOVDbSvc.h:44
IAddressProvider.h
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
IOVTime::MINTIMESTAMP
static constexpr uint64_t MINTIMESTAMP
Definition: IOVTime.h:56
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
makeDTCalibBlob_pickPhase.theTag
def theTag
Definition: makeDTCalibBlob_pickPhase.py:384
IOVDbSvc::m_h_detStore
ServiceHandle< StoreGateSvc > m_h_detStore
Definition: IOVDbSvc.h:238
IOVDbSvc::m_iovslop
cool::ValidityKey m_iovslop
Definition: IOVDbSvc.h:276
IOVDbSvc::loadCaches
StatusCode loadCaches(IOVDbConn *conn, const IOVTime *time=nullptr)
Definition: IOVDbSvc.cxx:1126
checker_macros.h
Define macros for attributes used to control the static checker.
SG::DataProxy
Definition: DataProxy.h:45
IOVDbSvc::setupFolders
StatusCode setupFolders()
Definition: IOVDbSvc.cxx:933
IOVDbSvc::m_h_IOVSvc
ServiceHandle< IIOVSvc > m_h_IOVSvc
Definition: IOVDbSvc.h:236
StoreGateSvc.h
SG::ConstIterator
Definition: SGIterator.h:164
IOVDbSvc::signalBeginRun
virtual StatusCode signalBeginRun(const IOVTime &beginRunTime, const EventContext &ctx) override
Set time for begin run.
Definition: IOVDbSvc.cxx:655
IOVDbSvc::m_par_source
StringProperty m_par_source
Definition: IOVDbSvc.h:223
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
IOVDbSvc::m_h_sgSvc
ServiceHandle< StoreGateSvc > m_h_sgSvc
Definition: IOVDbSvc.h:237
IOVDbSvc::m_par_foldersToWrite
Gaudi::Property< std::vector< std::string > > m_par_foldersToWrite
Definition: IOVDbSvc.h:196
IOVDbSvc::m_globalTag
std::string m_globalTag
Definition: IOVDbSvc.h:273
IOVDbSvc::loadAddresses
virtual StatusCode loadAddresses(StoreID::type storeID, tadList &list) override
Get all new addresses from Provider for this Event.
Definition: IOVDbSvc.cxx:440
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
IOVDbSvc::m_h_metaDataTool
PublicToolHandle< IIOVDbMetaDataTool > m_h_metaDataTool
Definition: IOVDbSvc.h:243
IOVDbSvc::m_par_forceTimestamp
IntegerProperty m_par_forceTimestamp
Definition: IOVDbSvc.h:206
IOVDbSvc::checkConfigConsistency
StatusCode checkConfigConsistency() const
Definition: IOVDbSvc.cxx:1172
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88
ServiceHandle< IIncidentSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
IOVDbSvc::m_par_cacheTime
IntegerProperty m_par_cacheTime
Definition: IOVDbSvc.h:214
StoreClearedIncident
Incident sent after a store is cleared.
Definition: StoreClearedIncident.h:30