ATLAS Offline Software
PoolSvc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef POOLSVC_H
6 #define POOLSVC_H
7 
13 #include "PoolSvc/IPoolSvc.h"
14 #include "GaudiKernel/IIoComponent.h"
18 
19 #include <string>
20 #include <vector>
21 #include <map>
22 #include <mutex>
23 
24 // Forward declarations
25 namespace pool {
26  class IContainer;
27  class IDatabase;
28  class IPersistencySvc;
29 }
30 
31 
35 class PoolSvc : public extends<AthService, IPoolSvc, IIoComponent> {
36 
37 public: // Non-static members
39  virtual StatusCode initialize() override;
40  virtual StatusCode io_reinit() override;
42  virtual StatusCode start() override;
43  virtual StatusCode stop() override;
45  virtual StatusCode finalize() override;
46  virtual StatusCode io_finalize() override;
47 
52  virtual
53  Token* registerForWrite(const Placement* placement,
54  const void* obj,
55  const RootType& classDesc) override;
56 
60  virtual
61  void setObjPtr(void*& obj, const Token* token) override;
62 
65  virtual
66  unsigned int getOutputContext(const std::string& label) override;
67 
71  virtual
72  unsigned int getInputContext(const std::string& label,
73  unsigned int maxFile = 0) override;
74 
76  virtual
77  const std::map<std::string, unsigned int>& getInputContextMap() const override;
78 
80  virtual
81  const coral::Context* context() const override;
82 
85  virtual
86  void loadComponent(const std::string& compName) override;
87 
90  virtual
91  void setShareMode(bool shareCat) override;
92 
94  virtual
95  const pool::IFileCatalog* catalog() const override;
96 
101  virtual
102  void lookupBestPfn(const std::string& token, std::string& pfn, std::string& type) const override;
103 
107  virtual
108  void renamePfn(const std::string& pf, const std::string& newpf) override;
109 
115  virtual
116  pool::ICollection* createCollection(const std::string& collectionType,
117  const std::string& connection,
118  const std::string& collectionName,
119  unsigned int contextId = IPoolSvc::kInputStream) const override;
120 
125  virtual
126  Token* getToken(const std::string& connection,
127  const std::string& collection,
128  const unsigned long ientry) const override;
129 
131  virtual
133  unsigned int contextId = IPoolSvc::kInputStream) override;
134 
137  virtual
138  StatusCode commit(unsigned int contextId = IPoolSvc::kInputStream) const override;
139 
142  virtual
143  StatusCode commitAndHold(unsigned int contextId = IPoolSvc::kInputStream) const override;
144 
147  virtual
148  StatusCode disconnect(unsigned int contextId = IPoolSvc::kInputStream) const override;
149 
153  virtual
154  StatusCode disconnectDb(const std::string& connection,
155  unsigned int contextId = IPoolSvc::kInputStream) const override;
156 
158  virtual
159  long long int getFileSize(const std::string& dbName, long tech, unsigned int contextId) const override;
160 
162  virtual
163  StatusCode getAttribute(const std::string& optName,
164  std::string& data,
165  long tech,
166  unsigned int contextId = IPoolSvc::kInputStream) const override;
167 
169  virtual
170  StatusCode getAttribute(const std::string& optName,
171  std::string& data,
172  long tech,
173  const std::string& dbName,
174  const std::string& contName = "",
175  unsigned int contextId = IPoolSvc::kInputStream) const override;
176 
178  virtual
179  StatusCode setAttribute(const std::string& optName,
180  const std::string& data,
181  long tech,
182  unsigned int contextId = IPoolSvc::kOutputStream) const override;
183 
185  virtual
186  StatusCode setAttribute(const std::string& optName,
187  const std::string& data,
188  long tech,
189  const std::string& dbName,
190  const std::string& contName = "",
191  unsigned int contextId = IPoolSvc::kOutputStream) const override;
192 
194  virtual
195  StatusCode setFrontierCache(const std::string& conn) override;
196 
198  using base_class::base_class;
199 
201  virtual ~PoolSvc();
202 
203 private: // data
204  typedef std::recursive_mutex CallMutex;
205  // Lock Guard class to safely lock a mutex for a given contextId
206  class ContextLock {
207  std::unique_lock< CallMutex > m_lock;
208  public:
209  ContextLock(int contextId, CallMutex &glob_mtx, const std::vector<CallMutex*> &ctx_mutexes) {
210  // lock the global mutex to gain exclusive access to the context mutexes vector
211  std::lock_guard<CallMutex> temp_lock( glob_mtx );
212  // lock the mutex for the given context ID for the lifetime of this object
213  m_lock = std::unique_lock< CallMutex >{ *ctx_mutexes[contextId] };
214  }
215  ~ContextLock() { m_lock.unlock(); }
216  };
217 
219  coral::Context* m_context{nullptr};
220  bool m_shareCat{false};
222  std::vector<pool::IPersistencySvc*> m_persistencySvcVec;
223  std::vector<CallMutex*> m_pers_mut;
224  std::map<std::string, unsigned int> m_inputContextLabel;
225  std::map<std::string, unsigned int> m_outputContextLabel;
226  std::string m_mainOutputLabel{};
227  std::map<unsigned int, unsigned int> m_contextMaxFile;
228  // Cache for open file guids for each m_persistencySvcVec member, protected by m_pers_mut
229  mutable std::map<unsigned int, std::list<Guid> > m_guidLists ATLAS_THREAD_SAFE;
230 
231 private: // properties
233  StringProperty m_fileOpen{this,"FileOpen","overwrite"};
236  IntegerProperty m_dbAgeLimit{this,"MaxFilesOpen",0};
239  StringProperty m_writeCatalog{this,"WriteCatalog","xmlcatalog_file:PoolFileCatalog.xml"};
241  StringArrayProperty m_readCatalog{this,"ReadCatalog",{},"List of catalog files to read from","OrderedSet<std::string>"};
243  BooleanProperty m_useROOTIMT{this,"UseROOTImplicitMT",true};
245  BooleanProperty m_useROOTMaxTree{this,"UseROOTIncreaseVMaxTree",false};
246 
248  BooleanProperty m_attemptCatalogPatch{this,"AttemptCatalogPatch",true};
250  IntegerProperty m_retrialPeriod{this,"ConnectionRetrialPeriod",300};
252  IntegerProperty m_retrialTimeOut{this,"ConnectionRetrialTimeOut",3600};
254  IntegerProperty m_timeOut{this,"ConnectionTimeOut",5};
256  BooleanProperty m_connClean{this,"ConnectionCleanUp",false};
258  IntegerProperty m_frontierComp{this,"FrontierCompression",5};
259  StringArrayProperty m_frontierRefresh{this,"FrontierRefreshSchema",{}};
261  BooleanProperty m_sortReplicas{this,"SortReplicas",true};
262 
263 private: // internal helper functions
264  // delete all APR::Persistency Services, Catalog, Mutexes and Indexes
265  void clearState();
266 
268  void patchCatalog(const std::string& pfn, pool::IDatabase& dbH) const;
269 
270  // setup APR persistency
272 
274  std::unique_ptr<pool::IDatabase> getDbHandle(unsigned int contextId, const std::string& dbName) const;
276  std::unique_ptr<pool::IContainer> getContainerHandle(pool::IDatabase* dbH, const std::string& contName) const;
277 
279  std::string poolCondPath(const std::string& leaf);
280 };
281 #endif
PoolSvc::stop
virtual StatusCode stop() override
Definition: PoolSvc.cxx:230
PoolSvc::m_timeOut
IntegerProperty m_timeOut
ConnectionTimeOut, the time out for CORAL Connection Service: default = 5 seconds.
Definition: PoolSvc.h:254
IPoolSvc::kOutputStream
@ kOutputStream
Definition: IPoolSvc.h:39
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
AddEmptyComponent.compName
compName
Definition: AddEmptyComponent.py:32
Placement
This class holds all the necessary information to guide the writing of an object in a physical place.
Definition: Placement.h:19
PoolSvc::ATLAS_THREAD_SAFE
std::map< unsigned int, std::list< Guid > > m_guidLists ATLAS_THREAD_SAFE
Definition: PoolSvc.h:229
checkCorrelInHIST.conn
conn
Definition: checkCorrelInHIST.py:25
PoolSvc::getDbHandle
std::unique_ptr< pool::IDatabase > getDbHandle(unsigned int contextId, const std::string &dbName) const
Get Database handle.
Definition: PoolSvc.cxx:986
PoolSvc::m_retrialTimeOut
IntegerProperty m_retrialTimeOut
ConnectionRetrialTimeOut, the retrial time out for CORAL Connection Service: default = 300 seconds.
Definition: PoolSvc.h:252
PoolSvc::m_pool_mut
CallMutex m_pool_mut
Definition: PoolSvc.h:218
PoolSvc::m_fileOpen
StringProperty m_fileOpen
FileOpen, the open mode for the file ("append" or "overwrite").
Definition: PoolSvc.h:233
PoolSvc::m_frontierComp
IntegerProperty m_frontierComp
Frontier proprties, compression level and list of schemas to be refreshed: default = 5.
Definition: PoolSvc.h:258
PoolSvc::m_inputContextLabel
std::map< std::string, unsigned int > m_inputContextLabel
Definition: PoolSvc.h:224
PoolSvc::connect
virtual StatusCode connect(pool::ITransaction::Type type, unsigned int contextId=IPoolSvc::kInputStream) override
Connect to a logical database unit; PersistencySvc is chosen according to transaction type (accessmod...
Definition: PoolSvc.cxx:589
PoolSvc::commit
virtual StatusCode commit(unsigned int contextId=IPoolSvc::kInputStream) const override
Commit data for a given contextId and flush buffer.
Definition: PoolSvc.cxx:621
PoolSvc::m_attemptCatalogPatch
BooleanProperty m_attemptCatalogPatch
AttemptCatalogPatch, option to create catalog: default = false.
Definition: PoolSvc.h:248
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
pool
pool namespace
Definition: libname.h:15
PoolSvc::catalog
virtual const pool::IFileCatalog * catalog() const override
Definition: PoolSvc.cxx:399
PoolSvc::disconnect
virtual StatusCode disconnect(unsigned int contextId=IPoolSvc::kInputStream) const override
Disconnect PersistencySvc associated with a contextId.
Definition: PoolSvc.cxx:654
PoolSvc::m_frontierRefresh
StringArrayProperty m_frontierRefresh
Definition: PoolSvc.h:259
PoolSvc
This class provides the interface to the LCG POOL persistency software.
Definition: PoolSvc.h:35
PoolSvc::m_context
coral::Context * m_context
Definition: PoolSvc.h:219
PoolSvc::setAttribute
virtual StatusCode setAttribute(const std::string &optName, const std::string &data, long tech, unsigned int contextId=IPoolSvc::kOutputStream) const override
Set POOL attributes - domain.
Definition: PoolSvc.cxx:786
PoolSvc::getFileSize
virtual long long int getFileSize(const std::string &dbName, long tech, unsigned int contextId) const override
Get POOL FileSize attribute for database without logging a message.
Definition: PoolSvc.cxx:694
PoolSvc::m_writeCatalog
StringProperty m_writeCatalog
WriteCatalog, the file catalog to be used to register output files (also default input catalog): defa...
Definition: PoolSvc.h:239
PoolSvc::setObjPtr
virtual void setObjPtr(void *&obj, const Token *token) override
Definition: PoolSvc.cxx:303
PoolSvc::m_useROOTMaxTree
BooleanProperty m_useROOTMaxTree
Increase virtual TTree size to avoid backreads in multithreading, default = false.
Definition: PoolSvc.h:245
pool::ITransaction::Type
Type
Transaction type enumeration.
Definition: ITransaction.h:28
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition: Token.h:21
PoolSvc::renamePfn
virtual void renamePfn(const std::string &pf, const std::string &newpf) override
Definition: PoolSvc.cxx:421
PoolSvc::CallMutex
std::recursive_mutex CallMutex
Definition: PoolSvc.h:204
PoolSvc::m_pers_mut
std::vector< CallMutex * > m_pers_mut
Definition: PoolSvc.h:223
IPoolSvc::kInputStream
@ kInputStream
Definition: IPoolSvc.h:39
PoolSvc::m_mainOutputLabel
std::string m_mainOutputLabel
Definition: PoolSvc.h:226
pool::IFileCatalog
Definition: IFileCatalog.h:23
PoolSvc::context
virtual const coral::Context * context() const override
Definition: PoolSvc.cxx:387
PoolSvc::getOutputContext
virtual unsigned int getOutputContext(const std::string &label) override
Definition: PoolSvc.cxx:331
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PoolSvc::getContainerHandle
std::unique_ptr< pool::IContainer > getContainerHandle(pool::IDatabase *dbH, const std::string &contName) const
Get Container handle.
Definition: PoolSvc.cxx:1016
PixelModuleFeMask_create_db.dbName
string dbName
Definition: PixelModuleFeMask_create_db.py:21
PoolSvc::ContextLock::m_lock
std::unique_lock< CallMutex > m_lock
Definition: PoolSvc.h:207
PoolSvc::getToken
virtual Token * getToken(const std::string &connection, const std::string &collection, const unsigned long ientry) const override
Definition: PoolSvc.cxx:565
PoolSvc::disconnectDb
virtual StatusCode disconnectDb(const std::string &connection, unsigned int contextId=IPoolSvc::kInputStream) const override
Disconnect single Database.
Definition: PoolSvc.cxx:676
PoolSvc::ContextLock::ContextLock
ContextLock(int contextId, CallMutex &glob_mtx, const std::vector< CallMutex * > &ctx_mutexes)
Definition: PoolSvc.h:209
PoolSvc::ContextLock::~ContextLock
~ContextLock()
Definition: PoolSvc.h:215
PoolSvc::createCollection
virtual pool::ICollection * createCollection(const std::string &collectionType, const std::string &connection, const std::string &collectionName, unsigned int contextId=IPoolSvc::kInputStream) const override
Definition: PoolSvc.cxx:436
PoolSvc::commitAndHold
virtual StatusCode commitAndHold(unsigned int contextId=IPoolSvc::kInputStream) const override
Commit data for a given contextId and hold buffer.
Definition: PoolSvc.cxx:639
PoolSvc::m_sortReplicas
BooleanProperty m_sortReplicas
Use DBReplicaSvc to sort database connections, default = true.
Definition: PoolSvc.h:261
PoolSvc::setFrontierCache
virtual StatusCode setFrontierCache(const std::string &conn) override
Setup Frontier cache for given logical or physical connection name.
Definition: PoolSvc.cxx:882
PoolSvc::clearState
void clearState()
Definition: PoolSvc.cxx:243
PoolSvc::getAttribute
virtual StatusCode getAttribute(const std::string &optName, std::string &data, long tech, unsigned int contextId=IPoolSvc::kInputStream) const override
Get POOL attributes - domain.
Definition: PoolSvc.cxx:712
PoolSvc::m_catalog
pool::IFileCatalog * m_catalog
Definition: PoolSvc.h:221
PoolSvc::m_contextMaxFile
std::map< unsigned int, unsigned int > m_contextMaxFile
Definition: PoolSvc.h:227
pool::IDatabase
Definition: IDatabase.h:25
PoolSvc::m_readCatalog
StringArrayProperty m_readCatalog
ReadCatalog, the list of additional POOL input file catalogs to consult: default = empty vector.
Definition: PoolSvc.h:241
PoolSvc::m_dbAgeLimit
IntegerProperty m_dbAgeLimit
MaxFilesOpen, option to have PoolSvc limit the number of open Input Files: default = 0 (No files are ...
Definition: PoolSvc.h:236
PoolSvc::m_shareCat
bool m_shareCat
Definition: PoolSvc.h:220
PoolSvc::patchCatalog
void patchCatalog(const std::string &pfn, pool::IDatabase &dbH) const
Definition: PoolSvc.cxx:557
IPoolSvc.h
This file contains the class definition for the IPoolSvc interface class.
PoolSvc::loadComponent
virtual void loadComponent(const std::string &compName) override
Definition: PoolSvc.cxx:391
PoolSvc::getInputContextMap
virtual const std::map< std::string, unsigned int > & getInputContextMap() const override
Definition: PoolSvc.cxx:383
PoolSvc::poolCondPath
std::string poolCondPath(const std::string &leaf)
Resolve a file using ATLAS_POOLCOND_PATH.
Definition: PoolSvc.cxx:1033
PoolSvc::lookupBestPfn
virtual void lookupBestPfn(const std::string &token, std::string &pfn, std::string &type) const override
Definition: PoolSvc.cxx:403
PoolSvc::registerForWrite
virtual Token * registerForWrite(const Placement *placement, const void *obj, const RootType &classDesc) override
Definition: PoolSvc.cxx:279
PoolSvc::finalize
virtual StatusCode finalize() override
Required of all Gaudi services:
Definition: PoolSvc.cxx:262
PoolSvc::setShareMode
virtual void setShareMode(bool shareCat) override
Definition: PoolSvc.cxx:395
PoolSvc::start
virtual StatusCode start() override
Required of all Gaudi services:
Definition: PoolSvc.cxx:218
python.output.AtlRunQueryRoot.pf
pf
Definition: AtlRunQueryRoot.py:988
PoolSvc::initialize
virtual StatusCode initialize() override
Required of all Gaudi services:
Definition: PoolSvc.cxx:57
PoolSvc::m_persistencySvcVec
std::vector< pool::IPersistencySvc * > m_persistencySvcVec
Definition: PoolSvc.h:222
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
PoolSvc::setupPersistencySvc
StatusCode setupPersistencySvc()
Definition: PoolSvc.cxx:184
PoolSvc::ContextLock
Definition: PoolSvc.h:206
PoolSvc::~PoolSvc
virtual ~PoolSvc()
Destructor.
Definition: PoolSvc.cxx:983
AthService.h
PoolSvc::m_retrialPeriod
IntegerProperty m_retrialPeriod
ConnectionRetrialPeriod, retry period for CORAL Connection Service: default = 30 seconds.
Definition: PoolSvc.h:250
PoolSvc::createCatalog
pool::IFileCatalog * createCatalog()
Definition: PoolSvc.cxx:943
PoolSvc::io_reinit
virtual StatusCode io_reinit() override
Definition: PoolSvc.cxx:143
Guid.h
This file contains the class definition for the Guid class (migrated from POOL).
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
PoolSvc::getInputContext
virtual unsigned int getInputContext(const std::string &label, unsigned int maxFile=0) override
Definition: PoolSvc.cxx:358
PoolSvc::m_connClean
BooleanProperty m_connClean
ConnectionCleanUp - whether to use CORAL connection management thread: default = false.
Definition: PoolSvc.h:256
pool::ICollection
Definition: ICollection.h:24
PoolSvc::io_finalize
virtual StatusCode io_finalize() override
Definition: PoolSvc.cxx:267
PoolSvc::m_useROOTIMT
BooleanProperty m_useROOTIMT
Use ROOT Implicit MultiThreading, default = true.
Definition: PoolSvc.h:243
PoolSvc::m_outputContextLabel
std::map< std::string, unsigned int > m_outputContextLabel
Definition: PoolSvc.h:225
TScopeAdapter
Definition: RootType.h:119