ATLAS Offline Software
Loading...
Searching...
No Matches
SessionTool Class Reference

More...

#include <SessionTool.h>

Inheritance diagram for SessionTool:
Collaboration diagram for SessionTool:

Public Member Functions

 SessionTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructors.
virtual ~SessionTool ()
 Destructor.
 SessionTool (const SessionTool &)=delete
SessionTool & operator= (const SessionTool &)=delete
virtual void setupFC (Gaudi::IFileCatalog &fileCatalog, int ageLimit) override final
 Use this FileCatalog and DB ageing value for this session.
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 reflection class is necessary to later delete the object.
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 with the framework are necessary.
pool::DatabaseRegistry & registry ()
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 openMode () const override final
 Returns the transaction type.
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 Gaudi::IFileCatalog & fileCatalog ()
 Returns the file catalog in use.
virtual pool::IStorageSvc & getStorageSvc (long technology) override final
 Return StorageSvc for a given technology used in this session.
pool::MicroSessionManager & microSessionManager (long technology) override final
 Returns the technology given a technology type.
void closeSession () override final
StatusCode finalize () override final
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Attributes

Gaudi::IFileCatalog * m_catalog
int m_ageLimit
std::unique_ptr< pool::DatabaseRegistry > m_registry
Io::IoFlag m_transactionType
std::map< long, std::unique_ptr< pool::MicroSessionManager > > m_technologies

Detailed Description

Definition at line 19 of file SessionTool.h.

Constructor & Destructor Documentation

◆ SessionTool() [1/2]

SessionTool::SessionTool ( const std::string & type,
const std::string & name,
const IInterface * parent )
explicit

Constructors.

Definition at line 15 of file SessionTool.cxx.

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}
AthAlgTool()
Default constructor:
Gaudi::IFileCatalog * m_catalog
std::unique_ptr< pool::DatabaseRegistry > m_registry
Io::IoFlag m_transactionType

◆ ~SessionTool()

SessionTool::~SessionTool ( )
virtual

Destructor.

Definition at line 33 of file SessionTool.cxx.

34{
36}
void closeSession() override final

◆ SessionTool() [2/2]

SessionTool::SessionTool ( const SessionTool & )
delete

Member Function Documentation

◆ closeSession()

void SessionTool::closeSession ( )
finaloverridevirtual

Implements ISessionTool.

Definition at line 38 of file SessionTool.cxx.

39{
40 // order is important
42 m_transactionType = Io::INVALID;
43 m_technologies.clear();
44}
std::map< long, std::unique_ptr< pool::MicroSessionManager > > m_technologies
virtual bool disconnectAll() override final
Explicitly disconnects all the databases.

◆ commit()

bool SessionTool::commit ( )
finaloverridevirtual

Commits the transaction.

Implements ISessionTool.

Definition at line 106 of file SessionTool.cxx.

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

◆ commitAndHold()

bool SessionTool::commitAndHold ( )
finaloverridevirtual

Commits and holds the transaction.

Implements ISessionTool.

Definition at line 126 of file SessionTool.cxx.

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}

◆ databaseHandle()

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

Creates and returns a new database handle object.

Implements ISessionTool.

Definition at line 146 of file SessionTool.cxx.

148{
149 if( m_transactionType != Io::INVALID ) {
150 return std::make_unique<pool::UserDatabase>( *this, dbName, dbNameType );
151 }
152 return nullptr;
153}

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ disconnectAll()

bool SessionTool::disconnectAll ( )
finaloverridevirtual

Explicitly disconnects all the databases.

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

Implements ISessionTool.

Definition at line 86 of file SessionTool.cxx.

87{
88 bool ret = true;
89 for( auto& iManager : m_technologies ) {
90 if( !iManager.second->disconnectAll() ) ret = false;
91 }
92 return ret;
93}

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ fileCatalog()

Gaudi::IFileCatalog & SessionTool::fileCatalog ( )
virtual

Returns the file catalog in use.

Definition at line 156 of file SessionTool.cxx.

157{
158 return *m_catalog;
159}

◆ finalize()

StatusCode SessionTool::finalize ( )
finaloverride

Definition at line 46 of file SessionTool.cxx.

47{
49 return AthAlgTool::finalize();
50}

◆ getStorageSvc()

pool::IStorageSvc & SessionTool::getStorageSvc ( long technology)
finaloverridevirtual

Return StorageSvc for a given technology used in this session.

Implements ISessionTool.

Definition at line 163 of file SessionTool.cxx.

164{
165 return microSessionManager( technology ).getStorageSvc();
166}
pool::MicroSessionManager & microSessionManager(long technology) override final
Returns the technology given a technology type.
IStorageSvc & getStorageSvc()
Return StorageSvc.

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ microSessionManager()

pool::MicroSessionManager & SessionTool::microSessionManager ( long technology)
finaloverridevirtual

Returns the technology given a technology type.

Implements ISessionTool.

Definition at line 170 of file SessionTool.cxx.

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}

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ openMode()

virtual Io::IoFlag SessionTool::openMode ( ) const
inlinefinaloverridevirtual

Returns the transaction type.

Implements ISessionTool.

Definition at line 81 of file SessionTool.h.

81{ return m_transactionType; }

◆ operator=()

SessionTool & SessionTool::operator= ( const SessionTool & )
delete

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ readObject()

void * SessionTool::readObject ( const Token & token,
void * object = 0 )
finaloverridevirtual

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 ISessionTool.

Definition at line 54 of file SessionTool.cxx.

55{
56 void* result {};
57 if( m_transactionType != Io::INVALID ) {
58 pool::UserDatabase db( *this, token.dbID().toString(), pool::DatabaseSpecification::FID );
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}
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 * SessionTool::registerForWrite ( const Placement & place,
const void * object,
const RootType & type )
finaloverridevirtual

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 ISessionTool.

Definition at line 69 of file SessionTool.cxx.

72{
73 if( m_transactionType != Io::WRITE && m_transactionType != Io::APPEND ) {
74 return 0;
75 }
76 pool::UserDatabase db( *this, place.fileName(), pool::DatabaseSpecification::PFN );
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}
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

◆ registry()

pool::DatabaseRegistry & SessionTool::registry ( )
inline

Definition at line 64 of file SessionTool.h.

64{return *m_registry; }

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 368 of file AthCommonDataStore.h.

369 {
370 h.renounce();
372 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 352 of file AthCommonDataStore.h.

352 {
354 }

◆ setupFC()

void SessionTool::setupFC ( Gaudi::IFileCatalog & fileCatalog,
int ageLimit )
finaloverridevirtual

Use this FileCatalog and DB ageing value for this session.

Implements ISessionTool.

Definition at line 27 of file SessionTool.cxx.

28{
30 m_ageLimit = ageLimit;
31}
virtual Gaudi::IFileCatalog & fileCatalog()
Returns the file catalog in use.

◆ start()

bool SessionTool::start ( Io::IoFlag type = Io::READ)
finaloverridevirtual

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

Implements ISessionTool.

Definition at line 97 of file SessionTool.cxx.

98{
99 if( m_transactionType != Io::INVALID ) return false;
101 return true;
102}

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, and AthCheckedComponent<::AthAlgTool >.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 298 of file AthCommonDataStore.h.

298 {
299 for (auto &a : m_vhka) {
301 for (auto k : keys) {
302 k->setOwner(this);
303 }
304 }
305 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_ageLimit

int SessionTool::m_ageLimit
private

Definition at line 101 of file SessionTool.h.

◆ m_catalog

Gaudi::IFileCatalog* SessionTool::m_catalog
private

Definition at line 100 of file SessionTool.h.

◆ m_registry

std::unique_ptr<pool::DatabaseRegistry> SessionTool::m_registry
private

Definition at line 102 of file SessionTool.h.

◆ m_technologies

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

Definition at line 104 of file SessionTool.h.

◆ m_transactionType

Io::IoFlag SessionTool::m_transactionType
private

Definition at line 103 of file SessionTool.h.


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