ATLAS Offline Software
Loading...
Searching...
No Matches
pool::UserSession Class Reference

UserSession is an implementation of the ISession interface. More...

#include <UserSession.h>

Inheritance diagram for pool::UserSession:
Collaboration diagram for pool::UserSession:

Public Member Functions

 UserSession (IFileCatalog &fileCatalog, int ageLimit)
 Constructor.
virtual ~UserSession ()
 Destructor.
 UserSession (const UserSession &)=delete
UserSessionoperator= (const UserSession &)=delete
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 reflection class is necessary to later delete the object.
virtual TokenregisterForWrite (const Placement &place, const void *object, const RootType &type) override
 registerForWrite registers an object for writing to the persistent medium higher level interactions with the framework are necessary.
DatabaseRegistryregistry ()
virtual bool disconnectAll () override final
 Explicitly disconnects all the databases.
virtual bool start (Io::IoFlag type=Io::READ) override final
 Starts a new transaction. Returns the success of the operation.
virtual bool commit () override final
 Commits the transaction.
virtual bool commitAndHold () override final
 Commits and holds the transaction.
virtual Io::IoFlag type () const override final
 Returns the transaction type.
virtual std::unique_ptr< IDatabasedatabaseHandle (const std::string &dbName, DatabaseSpecification::NameType dbNameType) override final
 Creates and returns a new database handle object.
virtual IFileCatalogfileCatalog ()
 Returns the file catalog in use.
virtual ITechnologySpecificAttributestechnologySpecificAttributes (long technology) override final
 Returns the object holding the technology specific attributes for a given technology domain.
MicroSessionManagermicroSessionManager (long technology)
 Returns the technology given a technology type.
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

IFileCatalogm_catalog
int m_ageLimit
DatabaseRegistrym_registry
Io::IoFlag m_transactionType
std::map< long, std::unique_ptr< MicroSessionManager > > m_technologies
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging).

Detailed Description

UserSession is an implementation of the ISession interface.

Definition at line 26 of file UserSession.h.

Constructor & Destructor Documentation

◆ UserSession() [1/2]

pool::UserSession::UserSession ( pool::IFileCatalog & fileCatalog,
int ageLimit )
explicit

Constructor.

Definition at line 22 of file UserSession.cxx.

22 :
23 APRMessaging( "APR Session" ),
25 m_ageLimit( ageLimit ),
26 m_registry( 0 ),
27 m_transactionType( Io::INVALID )
28{
29 m_registry = new pool::DatabaseRegistry();
30}
APRMessaging(const std::string &name)
IFileCatalog * m_catalog
DatabaseRegistry * m_registry
virtual IFileCatalog & fileCatalog()
Returns the file catalog in use.
Io::IoFlag m_transactionType

◆ ~UserSession()

pool::UserSession::~UserSession ( )
virtual

Destructor.

Definition at line 32 of file UserSession.cxx.

33{
34 // order is important
35 m_technologies.clear();
36 delete m_registry;
37}
std::map< long, std::unique_ptr< MicroSessionManager > > m_technologies

◆ UserSession() [2/2]

pool::UserSession::UserSession ( const UserSession & )
delete

Member Function Documentation

◆ commit()

bool pool::UserSession::commit ( )
finaloverridevirtual

Commits the transaction.

Implements pool::ISession.

Definition at line 100 of file UserSession.cxx.

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}
#define endmsg
#define ATH_MSG_ERROR(x,...)

◆ commitAndHold()

bool pool::UserSession::commitAndHold ( )
finaloverridevirtual

Commits and holds the transaction.

Implements pool::ISession.

Definition at line 120 of file UserSession.cxx.

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}

◆ databaseHandle()

std::unique_ptr< pool::IDatabase > pool::UserSession::databaseHandle ( const std::string & dbName,
DatabaseSpecification::NameType dbNameType )
finaloverridevirtual

Creates and returns a new database handle object.

Implements pool::ISession.

Definition at line 140 of file UserSession.cxx.

142{
143 if( m_transactionType != Io::INVALID ) {
144 return std::make_unique<UserDatabase>( *this, dbName, dbNameType );
145 }
146 return nullptr;
147}

◆ disconnectAll()

bool pool::UserSession::disconnectAll ( )
finaloverridevirtual

Explicitly disconnects all the databases.

If a transaction is active, then all the changes since the last commit are aborted.

Implements pool::ISession.

Definition at line 80 of file UserSession.cxx.

81{
82 bool ret = true;
83 for( auto& iManager : m_technologies ) {
84 if( !iManager.second->disconnectAll() ) ret = false;
85 }
86 return ret;
87}

◆ fileCatalog()

pool::IFileCatalog & pool::UserSession::fileCatalog ( )
virtual

Returns the file catalog in use.

Definition at line 150 of file UserSession.cxx.

151{
152 return *m_catalog;
153}

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)
int outputLevel(const IMessageSvc *ims, const std::string &source)

◆ microSessionManager()

pool::MicroSessionManager & pool::UserSession::microSessionManager ( long technology)

Returns the technology given a technology type.

Definition at line 156 of file UserSession.cxx.

157{
158 pool::DbType dbType( technology );
159 long majorType = dbType.majorType();
160 auto iManager = m_technologies.find( majorType );
161 if ( iManager != m_technologies.end() ) {
162 return *(iManager->second);
163 }
164 // Technology does not exist. Create the new session.
165 auto mgr = new pool::MicroSessionManager( *m_registry, majorType );
166 m_technologies.insert( std::make_pair( majorType, mgr ) );
167 mgr->connect( m_transactionType, m_ageLimit );
168 return *mgr;
169}

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 167 of file AthMessaging.h.

168{
169 MsgStream* ms = m_msg_tls.get();
170 if (!ms) {
171 if (!m_initialized.test_and_set()) initMessaging();
172 ms = new MsgStream(m_imsg,m_nm);
173 m_msg_tls.reset( ms );
174 }
175
176 ms->setLevel (m_lvl);
177 return *ms;
178}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels).
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 182 of file AthMessaging.h.

183{ return msg() << lvl; }
MsgStream & msg() const
The standard message stream.

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 // If user did not set explicit message level we have to initialize
154 // the messaging and retrieve the default via the MessageSvc.
155 if (m_lvl==MSG::NIL && !m_initialized.test_and_set()) initMessaging();
156
157 if (m_lvl <= lvl) {
158 msg() << lvl;
159 return true;
160 } else {
161 return false;
162 }
163}

◆ operator=()

UserSession & pool::UserSession::operator= ( const UserSession & )
delete

◆ readObject()

void * pool::UserSession::readObject ( const Token & token,
void * object = 0 )
overridevirtual

Retrieves an object from persistent store and return with type information The handle to the reflection class is necessary to later delete the object.

The Guid of the transient class is assumed to be the classID of the token

Parameters
token[IN] reference to the token for the object
object[IN] pointer to memory for the object (created if 0)
Returns
void* The data.

In case of failure zero is returned.

Implements pool::ISession.

Definition at line 41 of file UserSession.cxx.

42{
43 void* result {};
44 if( m_transactionType != Io::INVALID ) {
45 UserDatabase db( *this, token.dbID().toString(), pool::DatabaseSpecification::FID );
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}
constexpr void toString(std::span< char, StrLen > buf, bool uppercase=true) const noexcept
Automatic conversion to string representation.
int technology() const
Access technology type.
Definition Token.h:78
const Guid & dbID() const
Access database identifier.
Definition Token.h:65
@ FID
Physical File Name.
Definition IDatabase.h:26

◆ registerForWrite()

Token * pool::UserSession::registerForWrite ( const Placement & place,
const void * object,
const RootType & type )
overridevirtual

registerForWrite registers an object for writing to the persistent medium higher level interactions with the framework are necessary.

Parameters
place[IN] the placement hint
object[IN] pointer to transient object which will be written
type[IN] reflection class description with the layout of transient object
Returns
Token* the token address of the persistent object. I case of failure 0 is returned.

Implements pool::ISession.

Definition at line 56 of file UserSession.cxx.

59{
60 if( m_transactionType != Io::WRITE && m_transactionType != Io::APPEND ) {
61 return 0;
62 }
63 UserDatabase db( *this, place.fileName(), pool::DatabaseSpecification::PFN );
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}
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 Io::IoFlag type() const override final
Returns the transaction type.
Definition UserSession.h:83

◆ registry()

pool::DatabaseRegistry & pool::UserSession::registry ( )

Definition at line 73 of file UserSession.cxx.

74{
75 return *m_registry;
76}

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

◆ start()

bool pool::UserSession::start ( Io::IoFlag type = Io::READ)
finaloverridevirtual

Starts a new transaction. Returns the success of the operation.

Implements pool::ISession.

Definition at line 91 of file UserSession.cxx.

92{
93 if( m_transactionType != Io::INVALID ) return false;
95 return true;
96}

◆ technologySpecificAttributes()

pool::ITechnologySpecificAttributes & pool::UserSession::technologySpecificAttributes ( long technology)
finaloverridevirtual

Returns the object holding the technology specific attributes for a given technology domain.

Implements pool::ISession.

Definition at line 172 of file UserSession.cxx.

173{
174 pool::MicroSessionManager& mgr = microSessionManager( technology );
175 mgr.connect( m_transactionType, m_ageLimit );
176 return mgr;
177}
MicroSessionManager & microSessionManager(long technology)
Returns the technology given a technology type.

◆ type()

virtual Io::IoFlag pool::UserSession::type ( ) const
inlinefinaloverridevirtual

Returns the transaction type.

Implements pool::ISession.

Definition at line 83 of file UserSession.h.

83{ return m_transactionType; }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging).

Definition at line 141 of file AthMessaging.h.

◆ m_ageLimit

int pool::UserSession::m_ageLimit
private

Definition at line 101 of file UserSession.h.

◆ m_catalog

IFileCatalog* pool::UserSession::m_catalog
private

Definition at line 100 of file UserSession.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels).

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_registry

DatabaseRegistry* pool::UserSession::m_registry
private

Definition at line 102 of file UserSession.h.

◆ m_technologies

std::map< long, std::unique_ptr<MicroSessionManager> > pool::UserSession::m_technologies
private

Definition at line 104 of file UserSession.h.

◆ m_transactionType

Io::IoFlag pool::UserSession::m_transactionType
private

Definition at line 103 of file UserSession.h.


The documentation for this class was generated from the following files: