ATLAS Offline Software
Loading...
Searching...
No Matches
SessionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "SessionTool.h"
6#include "DatabaseRegistry.h"
7#include "UserDatabase.h"
8#include "DatabaseHandler.h"
10
13
14
15SessionTool::SessionTool(const std::string& type,
16 const std::string& name,
17 const IInterface* parent)
18 : AthAlgTool(type, name, parent),
19 m_catalog(nullptr),
20 m_ageLimit(-1),
21 m_registry( std::make_unique<pool::DatabaseRegistry>() ),
22 m_transactionType(Io::INVALID)
23{
24}
25
26void
27SessionTool::setupFC( Gaudi::IFileCatalog& fileCatalog, int ageLimit )
28{
30 m_ageLimit = ageLimit;
31}
32
37
39{
40 // order is important
42 m_transactionType = Io::INVALID;
43 m_technologies.clear();
44}
45
47{
49 return AthAlgTool::finalize();
50}
51
52
53void*
54SessionTool::readObject( const Token& token, void* object )
55{
56 void* result {};
57 if( m_transactionType != Io::INVALID ) {
59 if ( db.openMode() == Io::INVALID ) {
60 db.setTechnology( token.technology() );
61 db.connectForRead();
62 }
63 result = db.readObject( token, object );
64 }
65 return result;
66}
67
68Token*
70 const void* object,
71 const RootType& type )
72{
73 if( m_transactionType != Io::WRITE && m_transactionType != Io::APPEND ) {
74 return 0;
75 }
77 if ( db.openMode() == Io::INVALID ) {
78 db.setTechnology( place.technology() );
79 db.connectForWrite();
80 }
81 return db.writeObject( place.containerName(), place.technology(), object, type );
82}
83
84
85bool
87{
88 bool ret = true;
89 for( auto& iManager : m_technologies ) {
90 if( !iManager.second->disconnectAll() ) ret = false;
91 }
92 return ret;
93}
94
95// MN: rename?
96bool
98{
99 if( m_transactionType != Io::INVALID ) return false;
101 return true;
102}
103
104
105bool
107{
108 if( m_transactionType != Io::INVALID ) {
109 bool OK = true;
110 for( auto db : *m_registry ) {
111 bool bCommit = db->commitTransaction(); // This has to be replaced with a two phase commit
112 if ( ! bCommit ) {
113 ATH_MSG_ERROR("Could not commit the transaction for the database with:" << endmsg
114 << "FID = " << db->fid() << endmsg << "PFN = " << db->pfn() );
115 }
116 OK = OK && bCommit;
117 }
118 m_transactionType = Io::INVALID;
119 return OK;
120 }
121 return false;
122}
123
124
125bool
127{
128 if( m_transactionType != Io::INVALID ) {
129 bool OK = true;
130 for( auto db : *m_registry ) {
131 bool bCommit = db->commitAndHoldTransaction(); // This has to be replaced with a two phase commit
132 if ( ! bCommit ) {
133 ATH_MSG_ERROR("Could not commit and hold the transaction for the database with:" << endmsg
134 << "FID = " << db->fid() << endmsg << "PFN = " << db->pfn() );
135 }
136 OK = OK && bCommit;
137 }
138 return OK;
139 }
140 return false;
141}
142
143
144
145std::unique_ptr<pool::IDatabase>
146SessionTool::databaseHandle( const std::string& dbName,
148{
149 if( m_transactionType != Io::INVALID ) {
150 return std::make_unique<pool::UserDatabase>( *this, dbName, dbNameType );
151 }
152 return nullptr;
153}
154
155Gaudi::IFileCatalog&
157{
158 return *m_catalog;
159}
160
161
163SessionTool::getStorageSvc( long technology )
164{
165 return microSessionManager( technology ).getStorageSvc();
166}
167
168
171{
172 pool::DbType dbType( technology );
173 long majorType = dbType.majorType();
174 auto iManager = m_technologies.find( majorType );
175 if ( iManager != m_technologies.end() ) {
176 iManager->second->connect( m_transactionType, m_ageLimit );
177 return *(iManager->second);
178 }
179 // Technology does not exist. Create the new session.
180 auto mgr = new pool::MicroSessionManager( *m_registry, majorType );
181 m_technologies.insert( std::make_pair( majorType, mgr ) );
182 mgr->connect( m_transactionType, m_ageLimit );
183 return *mgr;
184}
#define endmsg
#define ATH_MSG_ERROR(x,...)
This file contains the class definition for the Placement class (migrated from POOL).
TTypeAdapter RootType
Definition RootType.h:211
This file contains the class definition for the Token class (migrated from POOL).
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
constexpr void toString(std::span< char, StrLen > buf, bool uppercase=true) const noexcept
Automatic conversion to string representation.
This class holds all the necessary information to guide the writing of an object in a physical place.
Definition Placement.h:20
const std::string & containerName() const
Access container name.
Definition Placement.h:33
const std::string & fileName() const
Access file name.
Definition Placement.h:29
int technology() const
Access technology type.
Definition Placement.h:37
virtual bool commitAndHold() override final
Commits and holds the transaction.
Gaudi::IFileCatalog * m_catalog
virtual std::unique_ptr< pool::IDatabase > databaseHandle(const std::string &dbName, pool::DatabaseSpecification::NameType dbNameType) override final
Creates and returns a new database handle object.
virtual ~SessionTool()
Destructor.
SessionTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructors.
virtual void * readObject(const Token &token, void *object=0) override final
Retrieves an object from persistent store and return with type information The handle to the reflecti...
std::unique_ptr< pool::DatabaseRegistry > m_registry
StatusCode finalize() override final
virtual Gaudi::IFileCatalog & fileCatalog()
Returns the file catalog in use.
virtual Token * registerForWrite(const Placement &place, const void *object, const RootType &type) override final
registerForWrite registers an object for writing to the persistent medium higher level interactions w...
Io::IoFlag m_transactionType
std::map< long, std::unique_ptr< pool::MicroSessionManager > > m_technologies
virtual pool::IStorageSvc & getStorageSvc(long technology) override final
Return StorageSvc for a given technology used in this session.
virtual bool commit() override final
Commits the transaction.
pool::MicroSessionManager & microSessionManager(long technology) override final
Returns the technology given a technology type.
virtual bool disconnectAll() override final
Explicitly disconnects all the databases.
void closeSession() override final
virtual void setupFC(Gaudi::IFileCatalog &fileCatalog, int ageLimit) override final
Use this FileCatalog and DB ageing value for this session.
virtual bool start(Io::IoFlag type=Io::READ) override final
Starts a new transaction. Returns the success of the operation.
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:22
int technology() const
Access technology type.
Definition Token.h:78
const Guid & dbID() const
Access database identifier.
Definition Token.h:65
int majorType() const
Access to major type.
Definition DbType.h:67
The IStorageSvc interface is able to handle user request for.
Definition IStorageSvc.h:48
MicroSessionManager is a class taking care of starting sessions for a given major technology and mana...
IStorageSvc & getStorageSvc()
Return StorageSvc.
UserDatabase is an implementation of the IDatabase interface.
STL namespace.
NameType
Enumeration type specifying the database name field, wherever the latter is used in methods accessing...
Definition IDatabase.h:24
@ FID
Physical File Name.
Definition IDatabase.h:26