ATLAS Offline Software
Loading...
Searching...
No Matches
UserSession.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 "UserSession.h"
6#include "DatabaseRegistry.h"
7#include "UserDatabase.h"
8#include "DatabaseHandler.h"
10
13
14
15std::unique_ptr< pool::ISession >
16pool::createSession( Gaudi::IFileCatalog& catalog , int ageLimit )
17{
18 return std::unique_ptr<ISession>( new pool::UserSession(catalog, ageLimit) );
19}
20
21
22pool::UserSession::UserSession( Gaudi::IFileCatalog& fileCatalog, int ageLimit ):
23 APRMessaging( "APR Session" ),
25 m_ageLimit( ageLimit ),
26 m_registry( 0 ),
28{
30}
31
33{
34 // order is important
35 m_technologies.clear();
36 delete m_registry;
37}
38
39
40void*
41pool::UserSession::readObject( const Token& token, void* object )
42{
43 void* result {};
44 if( m_transactionType != Io::INVALID ) {
46 if ( db.openMode() == Io::INVALID ) {
47 db.setTechnology( token.technology() );
48 db.connectForRead();
49 }
50 result = db.readObject( token, object );
51 }
52 return result;
53}
54
55Token*
57 const void* object,
58 const RootType& type )
59{
60 if( m_transactionType != Io::WRITE && m_transactionType != Io::APPEND ) {
61 return 0;
62 }
64 if ( db.openMode() == Io::INVALID ) {
65 db.setTechnology( place.technology() );
66 db.connectForWrite();
67 }
68 return db.writeObject( place.containerName(), place.technology(), object, type );
69}
70
71
77
78
79bool
81{
82 bool ret = true;
83 for( auto& iManager : m_technologies ) {
84 if( !iManager.second->disconnectAll() ) ret = false;
85 }
86 return ret;
87}
88
89
90bool
92{
93 if( m_transactionType != Io::INVALID ) return false;
95 return true;
96}
97
98
99bool
101{
102 if( m_transactionType != Io::INVALID ) {
103 bool OK = true;
104 for( auto db : *m_registry ) {
105 bool bCommit = db->commitTransaction(); // This has to be replaced with a two phase commit
106 if ( ! bCommit ) {
107 ATH_MSG_ERROR("Could not commit the transaction for the database with:" << endmsg
108 << "FID = " << db->fid() << endmsg << "PFN = " << db->pfn() );
109 }
110 OK = OK && bCommit;
111 }
112 m_transactionType = Io::INVALID;
113 return OK;
114 }
115 return false;
116}
117
118
119bool
121{
122 if( m_transactionType != Io::INVALID ) {
123 bool OK = true;
124 for( auto db : *m_registry ) {
125 bool bCommit = db->commitAndHoldTransaction(); // This has to be replaced with a two phase commit
126 if ( ! bCommit ) {
127 ATH_MSG_ERROR("Could not commit and hold the transaction for the database with:" << endmsg
128 << "FID = " << db->fid() << endmsg << "PFN = " << db->pfn() );
129 }
130 OK = OK && bCommit;
131 }
132 return OK;
133 }
134 return false;
135}
136
137
138
139std::unique_ptr<pool::IDatabase>
140pool::UserSession::databaseHandle( const std::string& dbName,
142{
143 if( m_transactionType != Io::INVALID ) {
144 return std::make_unique<UserDatabase>( *this, dbName, dbNameType );
145 }
146 return nullptr;
147}
148
149Gaudi::IFileCatalog&
154
155
158{
159 return microSessionManager( technology ).getStorageSvc();
160}
161
162
165{
166 pool::DbType dbType( technology );
167 long majorType = dbType.majorType();
168 auto iManager = m_technologies.find( majorType );
169 if ( iManager != m_technologies.end() ) {
170 iManager->second->connect( m_transactionType, m_ageLimit );
171 return *(iManager->second);
172 }
173 // Technology does not exist. Create the new session.
174 auto mgr = new pool::MicroSessionManager( *m_registry, majorType );
175 m_technologies.insert( std::make_pair( majorType, mgr ) );
176 mgr->connect( m_transactionType, m_ageLimit );
177 return *mgr;
178}
#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).
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
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
APRMessaging(const std::string &name)
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...
UserDatabase is an implementation of the IDatabase interface.
UserSession is an implementation of the ISession interface.
Definition UserSession.h:27
DatabaseRegistry & registry()
virtual Token * registerForWrite(const Placement &place, const void *object, const RootType &type) override
registerForWrite registers an object for writing to the persistent medium higher level interactions w...
UserSession(Gaudi::IFileCatalog &fileCatalog, int ageLimit)
Constructor.
virtual void * readObject(const Token &token, void *object=0) override
Retrieves an object from persistent store and return with type information The handle to the reflecti...
DatabaseRegistry * m_registry
MicroSessionManager & microSessionManager(long technology) override final
Returns the technology given a technology type.
virtual bool start(Io::IoFlag type=Io::READ) override final
Starts a new transaction. Returns the success of the operation.
virtual Io::IoFlag type() const override final
Returns the transaction type.
Definition UserSession.h:83
virtual bool commitAndHold() override final
Commits and holds the transaction.
std::map< long, std::unique_ptr< MicroSessionManager > > m_technologies
virtual bool commit() override final
Commits the transaction.
Io::IoFlag m_transactionType
virtual Gaudi::IFileCatalog & fileCatalog()
Returns the file catalog in use.
virtual std::unique_ptr< IDatabase > databaseHandle(const std::string &dbName, DatabaseSpecification::NameType dbNameType) override final
Creates and returns a new database handle object.
virtual bool disconnectAll() override final
Explicitly disconnects all the databases.
virtual IStorageSvc & getStorageSvc(long technology) override final
Return StorageSvc for a given technology used in this session.
virtual ~UserSession()
Destructor.
Gaudi::IFileCatalog * m_catalog
Definition UserSession.h:99
static const long long int INVALID
std::unique_ptr< ISession > createSession(Gaudi::IFileCatalog &catalog, int ageLimit=-1)
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