ATLAS Offline Software
Loading...
Searching...
No Matches
PoolSvc.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef POOLSVC_H
6#define POOLSVC_H
7
12
13#include "PoolSvc/IPoolSvc.h"
14#include "GaudiKernel/IIoComponent.h"
18
19#include <string>
20#include <vector>
21#include <map>
22#include <mutex>
23#include <memory>
24
25// Forward declarations
26namespace pool {
27 class IContainer;
28 class IDatabase;
29 class IPersistencySvc;
30}
31
32
36class PoolSvc : public extends<AthService, IPoolSvc, IIoComponent> {
37
38public: // Non-static members
40 virtual StatusCode initialize() override;
41 virtual StatusCode io_reinit() override;
43 virtual StatusCode start() override;
44 virtual StatusCode stop() override;
46 virtual StatusCode finalize() override;
47 virtual StatusCode io_finalize() override;
48
53 virtual
54 Token* registerForWrite(const Placement* placement,
55 const void* obj,
56 const RootType& classDesc) override;
57
61 virtual
62 void setObjPtr(void*& obj, const Token* token) override;
63
66 virtual
67 unsigned int getOutputContext(const std::string& label) override;
68
72 virtual
73 unsigned int getInputContext(const std::string& label,
74 unsigned int maxFile = 0) override;
75
77 virtual
78 std::map<std::string, unsigned int> getInputContextMap() const override;
79
81 virtual
82 unsigned int getInputContextMapSize() const override;
83
85 virtual
86 const coral::Context* context() const override;
87
90 virtual
91 void loadComponent(const std::string& compName) override;
92
95 virtual
96 void setShareMode(bool shareCat) override;
97
99 virtual
100 const pool::IFileCatalog* catalog() const override;
101
106 virtual
107 void lookupBestPfn(const std::string& token, std::string& pfn, std::string& type) const override;
108
112 virtual
113 void renamePfn(const std::string& pf, const std::string& newpf) override;
114
120 virtual
121 pool::ICollection* createCollection(const std::string& collectionType,
122 const std::string& connection,
123 const std::string& collectionName,
124 unsigned int contextId = IPoolSvc::kInputStream) const override;
125
130 virtual
131 Token* getToken(const std::string& connection,
132 const std::string& collection,
133 const unsigned long ientry) const override;
134
136 virtual
138 unsigned int contextId = IPoolSvc::kInputStream) override;
139
142 virtual
143 StatusCode commit(unsigned int contextId = IPoolSvc::kInputStream) const override;
144
147 virtual
148 StatusCode commitAndHold(unsigned int contextId = IPoolSvc::kInputStream) const override;
149
152 virtual
153 StatusCode disconnect(unsigned int contextId = IPoolSvc::kInputStream) const override;
154
158 virtual
159 StatusCode disconnectDb(const std::string& connection,
160 unsigned int contextId = IPoolSvc::kInputStream) const override;
161
163 virtual
164 long long int getFileSize(const std::string& dbName, long tech, unsigned int contextId) const override;
165
167 virtual
168 StatusCode getAttribute(const std::string& optName,
169 std::string& data,
170 long tech,
171 unsigned int contextId = IPoolSvc::kInputStream) const override;
172
174 virtual
175 StatusCode getAttribute(const std::string& optName,
176 std::string& data,
177 long tech,
178 const std::string& dbName,
179 const std::string& contName = "",
180 unsigned int contextId = IPoolSvc::kInputStream) const override;
181
183 virtual
184 StatusCode setAttribute(const std::string& optName,
185 const std::string& data,
186 long tech,
187 unsigned int contextId = IPoolSvc::kOutputStream) const override;
188
190 virtual
191 StatusCode setAttribute(const std::string& optName,
192 const std::string& data,
193 long tech,
194 const std::string& dbName,
195 const std::string& contName = "",
196 unsigned int contextId = IPoolSvc::kOutputStream) const override;
197
199 virtual
200 StatusCode setFrontierCache(const std::string& conn) override;
201
203 using base_class::base_class;
204
206 virtual ~PoolSvc();
207
208private: // data
209 typedef std::recursive_mutex CallMutex;
210 // Lock Guard class to safely lock a mutex for a given contextId
212 std::unique_lock< CallMutex > m_lock;
213 public:
214 ContextLock(int contextId, CallMutex &glob_mtx, const std::vector<CallMutex*> &ctx_mutexes) {
215 // lock the global mutex to gain exclusive access to the context mutexes vector
216 std::lock_guard<CallMutex> temp_lock( glob_mtx );
217 // lock the mutex for the given context ID for the lifetime of this object
218 m_lock = std::unique_lock< CallMutex >{ *ctx_mutexes[contextId] };
219 }
220 ~ContextLock() { m_lock.unlock(); }
221 };
222
224 coral::Context* m_context{nullptr};
225 bool m_shareCat{false};
227 std::vector<pool::IPersistencySvc*> m_persistencySvcVec;
228 std::vector<CallMutex*> m_pers_mut;
229 std::map<std::string, unsigned int> m_inputContextLabel;
230 std::map<std::string, unsigned int> m_outputContextLabel;
231 std::string m_mainOutputLabel{};
232 std::map<unsigned int, unsigned int> m_contextMaxFile;
233 // Cache for open file guids for each m_persistencySvcVec member, protected by m_pers_mut
234 mutable std::map<unsigned int, std::list<Guid> > m_guidLists ATLAS_THREAD_SAFE;
235
236private: // properties
238 Gaudi::Property<std::string> m_fileOpen{this,"FileOpen","overwrite"};
241 Gaudi::Property<int> m_dbAgeLimit{this,"MaxFilesOpen",0};
244 Gaudi::Property<std::string> m_writeCatalog{this,"WriteCatalog","xmlcatalog_file:PoolFileCatalog.xml"};
246 Gaudi::Property<std::vector<std::string>> m_readCatalog{this,"ReadCatalog",{},"List of catalog files to read from","OrderedSet<std::string>"};
248 Gaudi::Property<bool> m_useROOTIMT{this,"UseROOTImplicitMT",true};
250 Gaudi::Property<bool> m_useROOTMaxTree{this,"UseROOTIncreaseVMaxTree",false};
251
253 Gaudi::Property<bool> m_attemptCatalogPatch{this,"AttemptCatalogPatch",true};
255 Gaudi::Property<int> m_retrialPeriod{this,"ConnectionRetrialPeriod",300};
257 Gaudi::Property<int> m_retrialTimeOut{this,"ConnectionRetrialTimeOut",3600};
259 Gaudi::Property<int> m_timeOut{this,"ConnectionTimeOut",5};
261 Gaudi::Property<bool> m_connClean{this,"ConnectionCleanUp",false};
263 Gaudi::Property<int> m_frontierComp{this,"FrontierCompression",5};
264 Gaudi::Property<std::vector<std::string>> m_frontierRefresh{this,"FrontierRefreshSchema",{}};
266 Gaudi::Property<bool> m_sortReplicas{this,"SortReplicas",true};
268 Gaudi::Property<std::string> m_defaultROOTContainerType{this, "DefaultContainerType", "ROOTTREEINDEX"};
269
270private: // internal helper functions
271 // delete all APR::Persistency Services, Catalog, Mutexes and Indexes
272 void clearState();
273
275 void patchCatalog(const std::string& pfn, pool::IDatabase& dbH) const;
276
277 // setup APR persistency
278 StatusCode setupPersistencySvc();
279
281 std::unique_ptr<pool::IDatabase> getDbHandle(unsigned int contextId, const std::string& dbName) const;
283 std::unique_ptr<pool::IContainer> getContainerHandle(pool::IDatabase* dbH, const std::string& contName) const;
284
286 std::string poolCondPath(const std::string& leaf);
287};
288#endif
This file contains the class definition for the Guid class (migrated from POOL).
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
This file contains the class definition for the IPoolSvc interface class.
TTypeAdapter RootType
Definition RootType.h:211
Define macros for attributes used to control the static checker.
@ kOutputStream
Definition IPoolSvc.h:39
@ kInputStream
Definition IPoolSvc.h:39
This class holds all the necessary information to guide the writing of an object in a physical place.
Definition Placement.h:19
ContextLock(int contextId, CallMutex &glob_mtx, const std::vector< CallMutex * > &ctx_mutexes)
Definition PoolSvc.h:214
std::unique_lock< CallMutex > m_lock
Definition PoolSvc.h:212
This class provides the interface to the LCG POOL persistency software.
Definition PoolSvc.h:36
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:668
virtual StatusCode io_reinit() override
Definition PoolSvc.cxx:134
pool::IFileCatalog * createCatalog()
Definition PoolSvc.cxx:915
virtual Token * registerForWrite(const Placement *placement, const void *obj, const RootType &classDesc) override
Definition PoolSvc.cxx:276
virtual ~PoolSvc()
Destructor.
Definition PoolSvc.cxx:955
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:563
Gaudi::Property< int > m_retrialTimeOut
ConnectionRetrialTimeOut, the retrial time out for CORAL Connection Service: default = 300 seconds.
Definition PoolSvc.h:257
Gaudi::Property< int > m_timeOut
ConnectionTimeOut, the time out for CORAL Connection Service: default = 5 seconds.
Definition PoolSvc.h:259
virtual void renamePfn(const std::string &pf, const std::string &newpf) override
Definition PoolSvc.cxx:428
Gaudi::Property< int > m_retrialPeriod
ConnectionRetrialPeriod, retry period for CORAL Connection Service: default = 30 seconds.
Definition PoolSvc.h:255
virtual const coral::Context * context() const override
Definition PoolSvc.cxx:394
pool::IFileCatalog * m_catalog
Definition PoolSvc.h:226
Gaudi::Property< std::vector< std::string > > m_frontierRefresh
Definition PoolSvc.h:264
std::string poolCondPath(const std::string &leaf)
Resolve a file using ATLAS_POOLCOND_PATH.
Definition PoolSvc.cxx:1002
virtual unsigned int getInputContextMapSize() const override
Definition PoolSvc.cxx:389
void patchCatalog(const std::string &pfn, pool::IDatabase &dbH) const
Definition PoolSvc.cxx:531
CallMutex m_pool_mut
Definition PoolSvc.h:223
virtual unsigned int getInputContext(const std::string &label, unsigned int maxFile=0) override
Definition PoolSvc.cxx:359
Gaudi::Property< bool > m_sortReplicas
Use DBReplicaSvc to sort database connections, default = true.
Definition PoolSvc.h:266
std::recursive_mutex CallMutex
Definition PoolSvc.h:209
Gaudi::Property< std::string > m_defaultROOTContainerType
Default ROOT container type.
Definition PoolSvc.h:268
virtual void lookupBestPfn(const std::string &token, std::string &pfn, std::string &type) const override
Definition PoolSvc.cxx:410
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:760
Gaudi::Property< bool > m_connClean
ConnectionCleanUp - whether to use CORAL connection management thread: default = false.
Definition PoolSvc.h:261
Gaudi::Property< bool > m_useROOTIMT
Use ROOT Implicit MultiThreading, default = true.
Definition PoolSvc.h:248
virtual StatusCode commit(unsigned int contextId=IPoolSvc::kInputStream) const override
Commit data for a given contextId and flush buffer.
Definition PoolSvc.cxx:595
std::unique_ptr< pool::IContainer > getContainerHandle(pool::IDatabase *dbH, const std::string &contName) const
Get Container handle.
Definition PoolSvc.cxx:985
virtual Token * getToken(const std::string &connection, const std::string &collection, const unsigned long ientry) const override
Definition PoolSvc.cxx:539
virtual StatusCode start() override
Required of all Gaudi services:
Definition PoolSvc.cxx:214
Gaudi::Property< int > m_frontierComp
Frontier proprties, compression level and list of schemas to be refreshed: default = 5.
Definition PoolSvc.h:263
StatusCode setupPersistencySvc()
Definition PoolSvc.cxx:175
virtual StatusCode io_finalize() override
Definition PoolSvc.cxx:264
Gaudi::Property< int > m_dbAgeLimit
MaxFilesOpen, option to have PoolSvc limit the number of open Input Files: default = 0 (No files are ...
Definition PoolSvc.h:241
Gaudi::Property< bool > m_useROOTMaxTree
Increase virtual TTree size to avoid backreads in multithreading, default = false.
Definition PoolSvc.h:250
std::map< std::string, unsigned int > m_outputContextLabel
Definition PoolSvc.h:230
std::vector< pool::IPersistencySvc * > m_persistencySvcVec
Definition PoolSvc.h:227
virtual StatusCode disconnectDb(const std::string &connection, unsigned int contextId=IPoolSvc::kInputStream) const override
Disconnect single Database.
Definition PoolSvc.cxx:650
std::vector< CallMutex * > m_pers_mut
Definition PoolSvc.h:228
std::map< std::string, unsigned int > m_inputContextLabel
Definition PoolSvc.h:229
virtual void setObjPtr(void *&obj, const Token *token) override
Definition PoolSvc.cxx:300
virtual void loadComponent(const std::string &compName) override
Definition PoolSvc.cxx:398
Gaudi::Property< std::vector< std::string > > m_readCatalog
ReadCatalog, the list of additional POOL input file catalogs to consult: default = empty vector.
Definition PoolSvc.h:246
std::string m_mainOutputLabel
Definition PoolSvc.h:231
virtual const pool::IFileCatalog * catalog() const override
Definition PoolSvc.cxx:406
void clearState()
Definition PoolSvc.cxx:239
std::map< unsigned int, unsigned int > m_contextMaxFile
Definition PoolSvc.h:232
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:443
virtual void setShareMode(bool shareCat) override
Definition PoolSvc.cxx:402
std::unique_ptr< pool::IDatabase > getDbHandle(unsigned int contextId, const std::string &dbName) const
Get Database handle.
Definition PoolSvc.cxx:958
coral::Context * m_context
Definition PoolSvc.h:224
virtual StatusCode commitAndHold(unsigned int contextId=IPoolSvc::kInputStream) const override
Commit data for a given contextId and hold buffer.
Definition PoolSvc.cxx:613
virtual StatusCode disconnect(unsigned int contextId=IPoolSvc::kInputStream) const override
Disconnect PersistencySvc associated with a contextId.
Definition PoolSvc.cxx:628
virtual StatusCode finalize() override
Required of all Gaudi services:
Definition PoolSvc.cxx:259
virtual StatusCode initialize() override
Required of all Gaudi services:
Definition PoolSvc.cxx:57
virtual StatusCode setFrontierCache(const std::string &conn) override
Setup Frontier cache for given logical or physical connection name.
Definition PoolSvc.cxx:856
virtual std::map< std::string, unsigned int > getInputContextMap() const override
Definition PoolSvc.cxx:384
virtual unsigned int getOutputContext(const std::string &label) override
Definition PoolSvc.cxx:328
Gaudi::Property< std::string > m_writeCatalog
WriteCatalog, the file catalog to be used to register output files (also default input catalog): defa...
Definition PoolSvc.h:244
virtual StatusCode stop() override
Definition PoolSvc.cxx:226
Gaudi::Property< bool > m_attemptCatalogPatch
AttemptCatalogPatch, option to create catalog: default = false.
Definition PoolSvc.h:253
std::map< unsigned int, std::list< Guid > > m_guidLists ATLAS_THREAD_SAFE
Definition PoolSvc.h:234
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:686
bool m_shareCat
Definition PoolSvc.h:225
Gaudi::Property< std::string > m_fileOpen
FileOpen, the open mode for the file ("append" or "overwrite").
Definition PoolSvc.h:238
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:21
An interface to a storage technology specific collection of event references and attributes.
Definition ICollection.h:23
IContainer is the base class for container objects.
Definition IContainer.h:23
IDatabase is the base class for database objects.
Definition IDatabase.h:25
IPersistencySvc is the abstract interface for all services which execute the conversion between trans...
Type
Transaction type enumeration.
std::string label(const std::string &format, int i)
Definition label.h:19
pool namespace
Definition libname.h:15