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( IFileCatalog& catalog , int ageLimit )
17{
18 return std::unique_ptr<ISession>( new pool::UserSession(catalog, ageLimit) );
19}
20
21
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( isActive() ) {
46 if ( db.openMode() == Io::INVALID ) {
47 db.setTechnology( token.technology() );
48 db.connectForRead();
49 }
50 result = db.databaseHandler().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.databaseHandler().writeObject( place.containerName(),
69 place.technology(),
70 object,
71 type );
72}
73
74
80
81
82bool
84{
85 bool ret = true;
86 for( auto& iManager : m_technologies ) {
87 if( !iManager.second->disconnectAll() ) ret = false;
88 }
89 return ret;
90}
91
92
93bool
95{
96 if( isActive() ) return false;
98 return true;
99}
100
101
102bool
104{
105 if( isActive() ) {
106 bool OK = true;
107 for( auto db : *m_registry ) {
108 bool bCommit = db->commitTransaction(); // This has to be replaced with a two phase commit
109 if ( ! bCommit ) {
110 ATH_MSG_ERROR("Could not commit the transaction for the database with:" << endmsg
111 << "FID = " << db->fid() << endmsg << "PFN = " << db->pfn() );
112 }
113 OK = OK && bCommit;
114 }
115 m_transactionType = Io::INVALID;
116 return OK;
117 }
118 return false;
119}
120
121
122bool
124{
125 if( isActive() ) {
126 bool OK = true;
127 for( auto db : *m_registry ) {
128 bool bCommit = db->commitAndHoldTransaction(); // This has to be replaced with a two phase commit
129 if ( ! bCommit ) {
130 ATH_MSG_ERROR("Could not commit and hold the transaction for the database with:" << endmsg
131 << "FID = " << db->fid() << endmsg << "PFN = " << db->pfn() );
132 }
133 OK = OK && bCommit;
134 }
135 return OK;
136 }
137 return false;
138}
139
140
141
142std::unique_ptr<pool::IDatabase>
143pool::UserSession::databaseHandle( const std::string& dbName,
145{
146 if( isActive() ) {
147 return std::make_unique<UserDatabase>( *this, dbName, dbNameType );
148 }
149 return nullptr;
150}
151
157
158void
163
164
167{
168 pool::DbType dbType( technology );
169 long majorType = dbType.majorType();
170 auto iManager = m_technologies.find( majorType );
171 if ( iManager != m_technologies.end() ) {
172 return *(iManager->second);
173 }
174 // Technology does not exist. Create the new session.
175 auto mgr = new pool::MicroSessionManager( *m_registry, majorType );
176 m_technologies.insert( std::make_pair( majorType, mgr ) );
177 mgr->connect( m_transactionType, m_ageLimit );
178 return *mgr;
179}
180
183{
185 mgr.connect( m_transactionType, m_ageLimit );
186 return mgr;
187}
#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
ITechnologySpecificAttributes is the interface for an object holding technology-specific attributes.
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
IFileCatalog * m_catalog
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...
MicroSessionManager & microSessionManager(long technology)
Returns the technology given a technology type.
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
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:90
virtual bool commitAndHold() override final
Commits and holds the transaction.
std::map< long, std::unique_ptr< MicroSessionManager > > m_technologies
virtual IFileCatalog & fileCatalog() override final
Returns the file catalog in use.
virtual bool commit() override final
Commits the transaction.
Io::IoFlag m_transactionType
void setFileCatalog(IFileCatalog &catalog)
Set the file catalog to be used.
virtual bool isActive() const override final
Checks if the transaction is active.
Definition UserSession.h:87
UserSession(IFileCatalog &fileCatalog, int ageLimit)
Constructor.
virtual ITechnologySpecificAttributes & technologySpecificAttributes(long technology) override final
Returns the object holding the technology specific attributes for a given technology domain.
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 ~UserSession()
Destructor.
static const long long int INVALID
std::unique_ptr< ISession > createSession(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