ATLAS Offline Software
Loading...
Searching...
No Matches
PoolSvc.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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"
15#include "GaudiKernel/IIoComponent.h"
16#include "GaudiKernel/SmartIF.h"
20
21#include <string>
22#include <vector>
23#include <map>
24#include <mutex>
25#include <memory>
26
27// Forward declarations
28class SessionTool;
29class Database;
30class Container;
31
35class PoolSvc : public extends<AthService, IPoolSvc, IIoComponent> {
36
37public: // 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 std::map<std::string, unsigned int> getInputContextMap() const override;
78
80 virtual
81 unsigned int getInputContextMapSize() const override;
82
84 virtual
85 FileDescriptor getInputFileDescriptor(unsigned int contextId,
86 const std::string& connection) override;
87
90 virtual
91 void setShareMode(bool shareCat) override;
92
94 virtual
95 void startCatalog() override;
96
98 virtual
99 void commitCatalog() override;
100
105 virtual
106 void lookupBestPfn(const std::string& dbID, std::string& pfn, std::string& type) const override;
107
112 virtual
113 StatusCode connectCollection(const std::string& connection,
114 const std::string& collectionName,
115 unsigned int contextId = IPoolSvc::kInputStream) override;
116
121 virtual
122 StatusCode checkCollection(const std::string& connection,
123 unsigned int contextId,
124 bool noContainer) override;
125
130 virtual
131 Token* getToken(const std::string& connection,
132 const std::string& collection,
133 const unsigned long ientry) override;
134
136 virtual
137 StatusCode connect(Io::IoFlag type,
138 unsigned int contextId = IPoolSvc::kInputStream) override;
139
142 virtual
143 StatusCode commit(unsigned int contextId = IPoolSvc::kInputStream) override;
144
147 virtual
148 StatusCode commitAndHold(unsigned int contextId = IPoolSvc::kInputStream) override;
149
152 virtual
153 StatusCode disconnect(unsigned int contextId = IPoolSvc::kInputStream) override;
154
158 virtual
159 StatusCode disconnectDb(const std::string& connection,
160 unsigned int contextId = IPoolSvc::kInputStream) override;
161
163 virtual
164 StatusCode getAttribute(const std::string& optName,
165 std::string& data,
166 long tech,
167 unsigned int contextId = IPoolSvc::kInputStream) 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) 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) 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) override;
193
195 StatusCode createSession( const std::string& sessionName, int ageLimit = -1 );
196
198 using base_class::base_class;
199
201 virtual ~PoolSvc();
202
203private: // data
204 using CallMutex = std::recursive_mutex;
205 // Lock Guard class to safely lock a mutex for a given contextId
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
220 bool m_shareCat{false};
221 SmartIF<Gaudi::IFileCatalogMgr> m_catalogMgr;
222 SmartIF<Gaudi::IFileCatalog> m_catalog;
223 std::vector<ToolHandle<SessionTool>> m_dbSessionVec;
224
225 std::vector<CallMutex*> m_pers_mut;
226 std::map<std::string, unsigned int> m_inputContextLabel;
227 std::map<std::string, unsigned int> m_outputContextLabel;
228 std::string m_mainOutputLabel{};
229 std::map<unsigned int, unsigned int> m_contextMaxFile;
230 // Cache for open file guids for each m_dbsessionVec member, protected by m_pers_mut
231 mutable std::map<unsigned int, std::list<Guid> > m_guidLists ATLAS_THREAD_SAFE;
232
233private: // properties
236 Gaudi::Property<int> m_dbAgeLimit{this,"MaxFilesOpen",0};
239 Gaudi::Property<std::string> m_writeCatalog{this,"WriteCatalog","xmlcatalog_file:PoolFileCatalog.xml"};
241 Gaudi::Property<std::vector<std::string>> m_readCatalog{this,"ReadCatalog",{},"List of catalog files to read from","OrderedSet<std::string>"};
243 Gaudi::Property<bool> m_useROOTIMT{this,"UseROOTImplicitMT",true};
245 Gaudi::Property<bool> m_useROOTMaxTree{this,"UseROOTIncreaseVMaxTree",false};
246
248 Gaudi::Property<bool> m_attemptCatalogPatch{this,"AttemptCatalogPatch",true};
249
250
251private: // internal helper functions
252 // delete all Persistency Services, Catalog, Mutexes and Indexes
253 void clearState();
254
255 // Set up m_catalogMgr/m_catalog. Returns false on failure.
256 bool createCatalog();
257 void patchCatalog(const std::string& pfn, Database& dbH) const;
258
259 // setup persistency
260 StatusCode setupPersistencySvc();
261
263 std::unique_ptr<Database> getDbHandle(unsigned int contextId, const std::string& dbName);
265 std::unique_ptr<Container> getContainerHandle(Database* dbH, const std::string& contName);
266
268 std::string poolCondPath(const std::string& leaf);
269};
270#endif
This file contains the class definition for the Guid class (migrated from POOL).
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.
Description:
@ kOutputStream
Definition IPoolSvc.h:34
@ kInputStream
Definition IPoolSvc.h:34
This class holds all the necessary information to guide the writing of an object in a physical place.
Definition Placement.h:20
ContextLock(int contextId, CallMutex &glob_mtx, const std::vector< CallMutex * > &ctx_mutexes)
Definition PoolSvc.h:209
std::unique_lock< CallMutex > m_lock
Definition PoolSvc.h:207
This class provides the interface to the LCG POOL persistency software.
Definition PoolSvc.h:35
virtual StatusCode io_reinit() override
Definition PoolSvc.cxx:86
bool createCatalog()
Definition PoolSvc.cxx:768
virtual Token * registerForWrite(const Placement *placement, const void *obj, const RootType &classDesc) override
Definition PoolSvc.cxx:219
std::vector< ToolHandle< SessionTool > > m_dbSessionVec
Definition PoolSvc.h:223
virtual ~PoolSvc()
Destructor.
Definition PoolSvc.cxx:814
virtual void startCatalog() override
Definition PoolSvc.cxx:364
StatusCode createSession(const std::string &sessionName, int ageLimit=-1)
Create a new session for a given session name and age limit.
Definition PoolSvc.cxx:878
SmartIF< Gaudi::IFileCatalog > m_catalog
Definition PoolSvc.h:222
void patchCatalog(const std::string &pfn, Database &dbH) const
Definition PoolSvc.cxx:455
virtual StatusCode connect(Io::IoFlag type, unsigned int contextId=IPoolSvc::kInputStream) override
Connect to a logical database unit; PersistencySvc is chosen according to transaction type (accessmod...
Definition PoolSvc.cxx:483
std::string poolCondPath(const std::string &leaf)
Resolve a file using ATLAS_POOLCOND_PATH.
Definition PoolSvc.cxx:859
virtual unsigned int getInputContextMapSize() const override
Definition PoolSvc.cxx:333
CallMutex m_pool_mut
Definition PoolSvc.h:218
virtual unsigned int getInputContext(const std::string &label, unsigned int maxFile=0) override
Definition PoolSvc.cxx:300
virtual StatusCode disconnectDb(const std::string &connection, unsigned int contextId=IPoolSvc::kInputStream) override
Disconnect single Database.
Definition PoolSvc.cxx:562
SmartIF< Gaudi::IFileCatalogMgr > m_catalogMgr
Definition PoolSvc.h:221
virtual StatusCode checkCollection(const std::string &connection, unsigned int contextId, bool noContainer) override
Definition PoolSvc.cxx:438
std::unique_ptr< Database > getDbHandle(unsigned int contextId, const std::string &dbName)
Get Database handle.
Definition PoolSvc.cxx:817
Gaudi::Property< bool > m_useROOTIMT
Use ROOT Implicit MultiThreading, default = true.
Definition PoolSvc.h:243
virtual StatusCode start() override
Required of all Gaudi services:
Definition PoolSvc.cxx:154
StatusCode setupPersistencySvc()
Definition PoolSvc.cxx:127
virtual StatusCode commit(unsigned int contextId=IPoolSvc::kInputStream) override
Commit data for a given contextId and flush buffer.
Definition PoolSvc.cxx:511
virtual StatusCode io_finalize() override
Definition PoolSvc.cxx:207
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:236
virtual void lookupBestPfn(const std::string &dbID, std::string &pfn, std::string &type) const override
Definition PoolSvc.cxx:376
virtual Token * getToken(const std::string &connection, const std::string &collection, const unsigned long ientry) override
Definition PoolSvc.cxx:463
Gaudi::Property< bool > m_useROOTMaxTree
Increase virtual TTree size to avoid backreads in multithreading, default = false.
Definition PoolSvc.h:245
std::map< std::string, unsigned int > m_outputContextLabel
Definition PoolSvc.h:227
std::recursive_mutex CallMutex
Definition PoolSvc.h:204
virtual void commitCatalog() override
Definition PoolSvc.cxx:370
std::unique_ptr< Container > getContainerHandle(Database *dbH, const std::string &contName)
Get Container handle.
Definition PoolSvc.cxx:845
std::vector< CallMutex * > m_pers_mut
Definition PoolSvc.h:225
std::map< std::string, unsigned int > m_inputContextLabel
Definition PoolSvc.h:226
virtual void setObjPtr(void *&obj, const Token *token) override
Definition PoolSvc.cxx:243
virtual StatusCode connectCollection(const std::string &connection, const std::string &collectionName, unsigned int contextId=IPoolSvc::kInputStream) override
Definition PoolSvc.cxx:380
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:241
std::string m_mainOutputLabel
Definition PoolSvc.h:228
void clearState()
Definition PoolSvc.cxx:180
std::map< unsigned int, unsigned int > m_contextMaxFile
Definition PoolSvc.h:229
virtual void setShareMode(bool shareCat) override
Definition PoolSvc.cxx:360
virtual FileDescriptor getInputFileDescriptor(unsigned int contextId, const std::string &connection) override
Definition PoolSvc.cxx:338
virtual StatusCode finalize() override
Required of all Gaudi services:
Definition PoolSvc.cxx:202
virtual StatusCode initialize() override
Required of all Gaudi services:
Definition PoolSvc.cxx:46
virtual StatusCode getAttribute(const std::string &optName, std::string &data, long tech, unsigned int contextId=IPoolSvc::kInputStream) override
Get POOL attributes - domain.
Definition PoolSvc.cxx:580
virtual StatusCode setAttribute(const std::string &optName, const std::string &data, long tech, unsigned int contextId=IPoolSvc::kOutputStream) override
Set POOL attributes - domain.
Definition PoolSvc.cxx:664
virtual StatusCode commitAndHold(unsigned int contextId=IPoolSvc::kInputStream) override
Commit data for a given contextId and hold buffer.
Definition PoolSvc.cxx:527
virtual std::map< std::string, unsigned int > getInputContextMap() const override
Definition PoolSvc.cxx:328
virtual unsigned int getOutputContext(const std::string &label) override
Definition PoolSvc.cxx:277
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:239
virtual StatusCode stop() override
Definition PoolSvc.cxx:167
Gaudi::Property< bool > m_attemptCatalogPatch
AttemptCatalogPatch, option to create catalog: default = false.
Definition PoolSvc.h:248
std::map< unsigned int, std::list< Guid > > m_guidLists ATLAS_THREAD_SAFE
Definition PoolSvc.h:231
bool m_shareCat
Definition PoolSvc.h:220
virtual StatusCode disconnect(unsigned int contextId=IPoolSvc::kInputStream) override
Disconnect PersistencySvc associated with a contextId.
Definition PoolSvc.cxx:540
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:22
std::string label(const std::string &format, int i)
Definition label.h:19