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 const std::map<std::string, unsigned int>& getInputContextMap() const override;
79
81 virtual
82 const coral::Context* context() const override;
83
86 virtual
87 void loadComponent(const std::string& compName) override;
88
91 virtual
92 void setShareMode(bool shareCat) override;
93
95 virtual
96 const pool::IFileCatalog* catalog() const override;
97
102 virtual
103 void lookupBestPfn(const std::string& token, std::string& pfn, std::string& type) const override;
104
108 virtual
109 void renamePfn(const std::string& pf, const std::string& newpf) override;
110
116 virtual
117 pool::ICollection* createCollection(const std::string& collectionType,
118 const std::string& connection,
119 const std::string& collectionName,
120 unsigned int contextId = IPoolSvc::kInputStream) const override;
121
126 virtual
127 Token* getToken(const std::string& connection,
128 const std::string& collection,
129 const unsigned long ientry) const override;
130
132 virtual
134 unsigned int contextId = IPoolSvc::kInputStream) override;
135
138 virtual
139 StatusCode commit(unsigned int contextId = IPoolSvc::kInputStream) const override;
140
143 virtual
144 StatusCode commitAndHold(unsigned int contextId = IPoolSvc::kInputStream) const override;
145
148 virtual
149 StatusCode disconnect(unsigned int contextId = IPoolSvc::kInputStream) const override;
150
154 virtual
155 StatusCode disconnectDb(const std::string& connection,
156 unsigned int contextId = IPoolSvc::kInputStream) const override;
157
159 virtual
160 long long int getFileSize(const std::string& dbName, long tech, unsigned int contextId) const override;
161
163 virtual
164 StatusCode getAttribute(const std::string& optName,
165 std::string& data,
166 long tech,
167 unsigned int contextId = IPoolSvc::kInputStream) const override;
168
170 virtual
171 StatusCode getAttribute(const std::string& optName,
172 std::string& data,
173 long tech,
174 const std::string& dbName,
175 const std::string& contName = "",
176 unsigned int contextId = IPoolSvc::kInputStream) const override;
177
179 virtual
180 StatusCode setAttribute(const std::string& optName,
181 const std::string& data,
182 long tech,
183 unsigned int contextId = IPoolSvc::kOutputStream) const override;
184
186 virtual
187 StatusCode setAttribute(const std::string& optName,
188 const std::string& data,
189 long tech,
190 const std::string& dbName,
191 const std::string& contName = "",
192 unsigned int contextId = IPoolSvc::kOutputStream) const override;
193
195 virtual
196 StatusCode setFrontierCache(const std::string& conn) override;
197
199 using base_class::base_class;
200
202 virtual ~PoolSvc();
203
204private: // data
205 typedef std::recursive_mutex CallMutex;
206 // Lock Guard class to safely lock a mutex for a given contextId
208 std::unique_lock< CallMutex > m_lock;
209 public:
210 ContextLock(int contextId, CallMutex &glob_mtx, const std::vector<CallMutex*> &ctx_mutexes) {
211 // lock the global mutex to gain exclusive access to the context mutexes vector
212 std::lock_guard<CallMutex> temp_lock( glob_mtx );
213 // lock the mutex for the given context ID for the lifetime of this object
214 m_lock = std::unique_lock< CallMutex >{ *ctx_mutexes[contextId] };
215 }
216 ~ContextLock() { m_lock.unlock(); }
217 };
218
220 coral::Context* m_context{nullptr};
221 bool m_shareCat{false};
223 std::vector<pool::IPersistencySvc*> m_persistencySvcVec;
224 std::vector<CallMutex*> m_pers_mut;
225 std::map<std::string, unsigned int> m_inputContextLabel;
226 std::map<std::string, unsigned int> m_outputContextLabel;
227 std::string m_mainOutputLabel{};
228 std::map<unsigned int, unsigned int> m_contextMaxFile;
229 // Cache for open file guids for each m_persistencySvcVec member, protected by m_pers_mut
230 mutable std::map<unsigned int, std::list<Guid> > m_guidLists ATLAS_THREAD_SAFE;
231
232private: // properties
234 Gaudi::Property<std::string> m_fileOpen{this,"FileOpen","overwrite"};
237 Gaudi::Property<int> m_dbAgeLimit{this,"MaxFilesOpen",0};
240 Gaudi::Property<std::string> m_writeCatalog{this,"WriteCatalog","xmlcatalog_file:PoolFileCatalog.xml"};
242 Gaudi::Property<std::vector<std::string>> m_readCatalog{this,"ReadCatalog",{},"List of catalog files to read from","OrderedSet<std::string>"};
244 Gaudi::Property<bool> m_useROOTIMT{this,"UseROOTImplicitMT",true};
246 Gaudi::Property<bool> m_useROOTMaxTree{this,"UseROOTIncreaseVMaxTree",false};
247
249 Gaudi::Property<bool> m_attemptCatalogPatch{this,"AttemptCatalogPatch",true};
251 Gaudi::Property<int> m_retrialPeriod{this,"ConnectionRetrialPeriod",300};
253 Gaudi::Property<int> m_retrialTimeOut{this,"ConnectionRetrialTimeOut",3600};
255 Gaudi::Property<int> m_timeOut{this,"ConnectionTimeOut",5};
257 Gaudi::Property<bool> m_connClean{this,"ConnectionCleanUp",false};
259 Gaudi::Property<int> m_frontierComp{this,"FrontierCompression",5};
260 Gaudi::Property<std::vector<std::string>> m_frontierRefresh{this,"FrontierRefreshSchema",{}};
262 Gaudi::Property<bool> m_sortReplicas{this,"SortReplicas",true};
264 Gaudi::Property<std::string> m_defaultROOTContainerType{this, "DefaultContainerType", "ROOTTREEINDEX"};
265
266private: // internal helper functions
267 // delete all APR::Persistency Services, Catalog, Mutexes and Indexes
268 void clearState();
269
271 void patchCatalog(const std::string& pfn, pool::IDatabase& dbH) const;
272
273 // setup APR persistency
274 StatusCode setupPersistencySvc();
275
277 std::unique_ptr<pool::IDatabase> getDbHandle(unsigned int contextId, const std::string& dbName) const;
279 std::unique_ptr<pool::IContainer> getContainerHandle(pool::IDatabase* dbH, const std::string& contName) const;
280
282 std::string poolCondPath(const std::string& leaf);
283};
284#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:210
std::unique_lock< CallMutex > m_lock
Definition PoolSvc.h:208
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:692
virtual StatusCode io_reinit() override
Definition PoolSvc.cxx:134
pool::IFileCatalog * createCatalog()
Definition PoolSvc.cxx:939
virtual Token * registerForWrite(const Placement *placement, const void *obj, const RootType &classDesc) override
Definition PoolSvc.cxx:276
virtual ~PoolSvc()
Destructor.
Definition PoolSvc.cxx:979
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:587
Gaudi::Property< int > m_retrialTimeOut
ConnectionRetrialTimeOut, the retrial time out for CORAL Connection Service: default = 300 seconds.
Definition PoolSvc.h:253
Gaudi::Property< int > m_timeOut
ConnectionTimeOut, the time out for CORAL Connection Service: default = 5 seconds.
Definition PoolSvc.h:255
virtual void renamePfn(const std::string &pf, const std::string &newpf) override
Definition PoolSvc.cxx:422
Gaudi::Property< int > m_retrialPeriod
ConnectionRetrialPeriod, retry period for CORAL Connection Service: default = 30 seconds.
Definition PoolSvc.h:251
virtual const coral::Context * context() const override
Definition PoolSvc.cxx:388
pool::IFileCatalog * m_catalog
Definition PoolSvc.h:222
Gaudi::Property< std::vector< std::string > > m_frontierRefresh
Definition PoolSvc.h:260
std::string poolCondPath(const std::string &leaf)
Resolve a file using ATLAS_POOLCOND_PATH.
Definition PoolSvc.cxx:1026
void patchCatalog(const std::string &pfn, pool::IDatabase &dbH) const
Definition PoolSvc.cxx:555
CallMutex m_pool_mut
Definition PoolSvc.h:219
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:262
std::recursive_mutex CallMutex
Definition PoolSvc.h:205
Gaudi::Property< std::string > m_defaultROOTContainerType
Default ROOT container type.
Definition PoolSvc.h:264
virtual void lookupBestPfn(const std::string &token, std::string &pfn, std::string &type) const override
Definition PoolSvc.cxx:404
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:784
Gaudi::Property< bool > m_connClean
ConnectionCleanUp - whether to use CORAL connection management thread: default = false.
Definition PoolSvc.h:257
Gaudi::Property< bool > m_useROOTIMT
Use ROOT Implicit MultiThreading, default = true.
Definition PoolSvc.h:244
virtual StatusCode commit(unsigned int contextId=IPoolSvc::kInputStream) const override
Commit data for a given contextId and flush buffer.
Definition PoolSvc.cxx:619
std::unique_ptr< pool::IContainer > getContainerHandle(pool::IDatabase *dbH, const std::string &contName) const
Get Container handle.
Definition PoolSvc.cxx:1009
virtual Token * getToken(const std::string &connection, const std::string &collection, const unsigned long ientry) const override
Definition PoolSvc.cxx:563
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:259
StatusCode setupPersistencySvc()
Definition PoolSvc.cxx:175
virtual const std::map< std::string, unsigned int > & getInputContextMap() const override
Definition PoolSvc.cxx:384
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:237
Gaudi::Property< bool > m_useROOTMaxTree
Increase virtual TTree size to avoid backreads in multithreading, default = false.
Definition PoolSvc.h:246
std::map< std::string, unsigned int > m_outputContextLabel
Definition PoolSvc.h:226
std::vector< pool::IPersistencySvc * > m_persistencySvcVec
Definition PoolSvc.h:223
virtual StatusCode disconnectDb(const std::string &connection, unsigned int contextId=IPoolSvc::kInputStream) const override
Disconnect single Database.
Definition PoolSvc.cxx:674
std::vector< CallMutex * > m_pers_mut
Definition PoolSvc.h:224
std::map< std::string, unsigned int > m_inputContextLabel
Definition PoolSvc.h:225
virtual void setObjPtr(void *&obj, const Token *token) override
Definition PoolSvc.cxx:300
virtual void loadComponent(const std::string &compName) override
Definition PoolSvc.cxx:392
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:242
std::string m_mainOutputLabel
Definition PoolSvc.h:227
virtual const pool::IFileCatalog * catalog() const override
Definition PoolSvc.cxx:400
void clearState()
Definition PoolSvc.cxx:239
std::map< unsigned int, unsigned int > m_contextMaxFile
Definition PoolSvc.h:228
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:437
virtual void setShareMode(bool shareCat) override
Definition PoolSvc.cxx:396
std::unique_ptr< pool::IDatabase > getDbHandle(unsigned int contextId, const std::string &dbName) const
Get Database handle.
Definition PoolSvc.cxx:982
coral::Context * m_context
Definition PoolSvc.h:220
virtual StatusCode commitAndHold(unsigned int contextId=IPoolSvc::kInputStream) const override
Commit data for a given contextId and hold buffer.
Definition PoolSvc.cxx:637
virtual StatusCode disconnect(unsigned int contextId=IPoolSvc::kInputStream) const override
Disconnect PersistencySvc associated with a contextId.
Definition PoolSvc.cxx:652
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:880
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:240
virtual StatusCode stop() override
Definition PoolSvc.cxx:226
Gaudi::Property< bool > m_attemptCatalogPatch
AttemptCatalogPatch, option to create catalog: default = false.
Definition PoolSvc.h:249
std::map< unsigned int, std::list< Guid > > m_guidLists ATLAS_THREAD_SAFE
Definition PoolSvc.h:230
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:710
bool m_shareCat
Definition PoolSvc.h:221
Gaudi::Property< std::string > m_fileOpen
FileOpen, the open mode for the file ("append" or "overwrite").
Definition PoolSvc.h:234
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