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

This class provides the interface to the LCG POOL persistency software. More...

#include <PoolSvc.h>

Inheritance diagram for PoolSvc:
Collaboration diagram for PoolSvc:

Classes

class  ContextLock

Public Member Functions

virtual StatusCode initialize () override
 Required of all Gaudi services:
virtual StatusCode io_reinit () override
virtual StatusCode start () override
 Required of all Gaudi services:
virtual StatusCode stop () override
virtual StatusCode finalize () override
 Required of all Gaudi services:
virtual StatusCode io_finalize () override
virtual Token * registerForWrite (const Placement *placement, const void *obj, const RootType &classDesc) override
virtual void setObjPtr (void *&obj, const Token *token) override
virtual unsigned int getOutputContext (const std::string &label) override
virtual unsigned int getInputContext (const std::string &label, unsigned int maxFile=0) override
virtual std::map< std::string, unsigned int > getInputContextMap () const override
virtual unsigned int getInputContextMapSize () const override
virtual FileDescriptor getInputFileDescriptor (unsigned int contextId, const std::string &connection) override
virtual void setShareMode (bool shareCat) override
virtual void startCatalog () override
virtual void commitCatalog () override
virtual void lookupBestPfn (const std::string &dbID, std::string &pfn, std::string &type) const override
virtual StatusCode connectCollection (const std::string &connection, const std::string &collectionName, unsigned int contextId=IPoolSvc::kInputStream) override
virtual StatusCode checkCollection (const std::string &connection, unsigned int contextId, bool noContainer) override
virtual Token * getToken (const std::string &connection, const std::string &collection, const unsigned long ientry) override
virtual StatusCode connect (Io::IoFlag type, unsigned int contextId=IPoolSvc::kInputStream) override
 Connect to a logical database unit; PersistencySvc is chosen according to transaction type (accessmode).
virtual StatusCode commit (unsigned int contextId=IPoolSvc::kInputStream) override
 Commit data for a given contextId and flush buffer.
virtual StatusCode commitAndHold (unsigned int contextId=IPoolSvc::kInputStream) override
 Commit data for a given contextId and hold buffer.
virtual StatusCode disconnect (unsigned int contextId=IPoolSvc::kInputStream) override
 Disconnect PersistencySvc associated with a contextId.
virtual StatusCode disconnectDb (const std::string &connection, unsigned int contextId=IPoolSvc::kInputStream) override
 Disconnect single Database.
virtual StatusCode getAttribute (const std::string &optName, std::string &data, long tech, unsigned int contextId=IPoolSvc::kInputStream) override
 Get POOL attributes - domain.
virtual StatusCode getAttribute (const std::string &optName, std::string &data, long tech, const std::string &dbName, const std::string &contName="", unsigned int contextId=IPoolSvc::kInputStream) override
 Get POOL attributes - db/file, container/collection.
virtual StatusCode setAttribute (const std::string &optName, const std::string &data, long tech, unsigned int contextId=IPoolSvc::kOutputStream) override
 Set POOL attributes - domain.
virtual StatusCode setAttribute (const std::string &optName, const std::string &data, long tech, const std::string &dbName, const std::string &contName="", unsigned int contextId=IPoolSvc::kOutputStream) override
 Set POOL attributes - db/file, container/collection.
StatusCode createSession (const std::string &sessionName, int ageLimit=-1)
 Create a new session for a given session name and age limit.
virtual ~PoolSvc ()
 Destructor.

Private Types

using CallMutex = std::recursive_mutex

Private Member Functions

void clearState ()
bool createCatalog ()
void patchCatalog (const std::string &pfn, Database &dbH) const
StatusCode setupPersistencySvc ()
std::unique_ptr< Database > getDbHandle (unsigned int contextId, const std::string &dbName)
 Get Database handle.
std::unique_ptr< Container > getContainerHandle (Database *dbH, const std::string &contName)
 Get Container handle.
std::string poolCondPath (const std::string &leaf)
 Resolve a file using ATLAS_POOLCOND_PATH.

Private Attributes

CallMutex m_pool_mut
bool m_shareCat {false}
SmartIF< Gaudi::IFileCatalogMgr > m_catalogMgr
SmartIF< Gaudi::IFileCatalog > m_catalog
std::vector< ToolHandle< SessionTool > > m_dbSessionVec
std::vector< CallMutex * > m_pers_mut
std::map< std::string, unsigned int > m_inputContextLabel
std::map< std::string, unsigned int > m_outputContextLabel
std::string m_mainOutputLabel {}
std::map< unsigned int, unsigned int > m_contextMaxFile
std::map< unsigned int, std::list< Guid > > m_guidLists ATLAS_THREAD_SAFE
Gaudi::Property< int > m_dbAgeLimit {this,"MaxFilesOpen",0}
 MaxFilesOpen, option to have PoolSvc limit the number of open Input Files: default = 0 (No files are closed automatically).
Gaudi::Property< std::string > m_writeCatalog {this,"WriteCatalog","xmlcatalog_file:PoolFileCatalog.xml"}
 WriteCatalog, the file catalog to be used to register output files (also default input catalog): default = "" (use POOL default).
Gaudi::Property< std::vector< std::string > > m_readCatalog {this,"ReadCatalog",{},"List of catalog files to read from","OrderedSet<std::string>"}
 ReadCatalog, the list of additional POOL input file catalogs to consult: default = empty vector.
Gaudi::Property< bool > m_useROOTIMT {this,"UseROOTImplicitMT",true}
 Use ROOT Implicit MultiThreading, default = true.
Gaudi::Property< bool > m_useROOTMaxTree {this,"UseROOTIncreaseVMaxTree",false}
 Increase virtual TTree size to avoid backreads in multithreading, default = false.
Gaudi::Property< bool > m_attemptCatalogPatch {this,"AttemptCatalogPatch",true}
 AttemptCatalogPatch, option to create catalog: default = false.

Detailed Description

This class provides the interface to the LCG POOL persistency software.

Definition at line 35 of file PoolSvc.h.

Member Typedef Documentation

◆ CallMutex

using PoolSvc::CallMutex = std::recursive_mutex
private

Definition at line 204 of file PoolSvc.h.

Constructor & Destructor Documentation

◆ ~PoolSvc()

PoolSvc::~PoolSvc ( )
virtual

Destructor.

Definition at line 814 of file PoolSvc.cxx.

814 {
815}

Member Function Documentation

◆ checkCollection()

StatusCode PoolSvc::checkCollection ( const std::string & connection,
unsigned int contextId,
bool noContainer )
overridevirtual
Returns
status of check
Parameters
connection[IN] string containing the connection.
contextId[IN] id for PoolSvc persistency service to use for input.
noContainer[IN] if no collection was found check whether file exists or had no events

Definition at line 438 of file PoolSvc.cxx.

440 {
442 std::unique_ptr<Database> dbH = getDbHandle(contextId, connection);
443 if (dbH != nullptr && !dbH->fid().empty()) {
444 if (noContainer) {
445 return(StatusCode::SUCCESS); // no events
446 }
447 if (m_attemptCatalogPatch.value()) {
448 patchCatalog(connection.substr(4), *dbH);
449 }
450 return(StatusCode::SUCCESS);
451 }
452 return(StatusCode::FAILURE);
453}
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
void patchCatalog(const std::string &pfn, Database &dbH) const
Definition PoolSvc.cxx:455
CallMutex m_pool_mut
Definition PoolSvc.h:218
std::unique_ptr< Database > getDbHandle(unsigned int contextId, const std::string &dbName)
Get Database handle.
Definition PoolSvc.cxx:817
std::vector< CallMutex * > m_pers_mut
Definition PoolSvc.h:225
Gaudi::Property< bool > m_attemptCatalogPatch
AttemptCatalogPatch, option to create catalog: default = false.
Definition PoolSvc.h:248

◆ clearState()

void PoolSvc::clearState ( )
private

Definition at line 180 of file PoolSvc.cxx.

180 {
181 std::lock_guard<CallMutex> lock(m_pool_mut);
182 // Cleanup persistency service
183 // Tools are kept forever, hopefully closing sessions will be enough
184 for( auto& session : m_dbSessionVec ) {
185 session->closeSession();
186 }
187 m_dbSessionVec.clear();
188 for (const auto& persistencyMutex : m_pers_mut) {
189 delete persistencyMutex;
190 }
191 m_mainOutputLabel.clear();
192 m_inputContextLabel.clear();
193 m_outputContextLabel.clear();
194 m_pers_mut.clear();
195 if (m_catalog.isValid()) {
196 m_catalog->commit();
197 m_catalog = SmartIF<Gaudi::IFileCatalog>();
198 m_catalogMgr = SmartIF<Gaudi::IFileCatalogMgr>();
199 }
200}
std::vector< ToolHandle< SessionTool > > m_dbSessionVec
Definition PoolSvc.h:223
SmartIF< Gaudi::IFileCatalog > m_catalog
Definition PoolSvc.h:222
SmartIF< Gaudi::IFileCatalogMgr > m_catalogMgr
Definition PoolSvc.h:221
std::map< std::string, unsigned int > m_outputContextLabel
Definition PoolSvc.h:227
std::map< std::string, unsigned int > m_inputContextLabel
Definition PoolSvc.h:226
std::string m_mainOutputLabel
Definition PoolSvc.h:228

◆ commit()

StatusCode PoolSvc::commit ( unsigned int contextId = IPoolSvc::kInputStream)
overridevirtual

Commit data for a given contextId and flush buffer.

Parameters
contextId[IN] poolStream to be commited.

Definition at line 511 of file PoolSvc.cxx.

511 {
512 if (contextId >= m_dbSessionVec.size()) {
513 return StatusCode::FAILURE;
514 }
516 auto& session = m_dbSessionVec[contextId];
517 if( session->openMode() != Io::INVALID && !session->commit() ) {
518 ATH_MSG_ERROR("POOL commit failed " << session);
519 return StatusCode::FAILURE;
520 }
521 if (session->openMode() == Io::READ) {
522 session->disconnectAll();
523 }
524 return StatusCode::SUCCESS;
525}
#define ATH_MSG_ERROR(x,...)

◆ commitAndHold()

StatusCode PoolSvc::commitAndHold ( unsigned int contextId = IPoolSvc::kInputStream)
overridevirtual

Commit data for a given contextId and hold buffer.

Parameters
contextId[IN] poolStream to be commited.

Definition at line 527 of file PoolSvc.cxx.

527 {
528 if (contextId >= m_dbSessionVec.size()) {
529 return StatusCode::FAILURE;
530 }
532 auto& session = m_dbSessionVec[contextId];
533 if( session->openMode() != Io::INVALID && !session->commitAndHold() ) {
534 ATH_MSG_ERROR("POOL commitAndHold failed " << session);
535 return StatusCode::FAILURE;
536 }
537 return StatusCode::SUCCESS;
538}

◆ commitCatalog()

void PoolSvc::commitCatalog ( )
overridevirtual
Returns
void

Definition at line 370 of file PoolSvc.cxx.

370 {
371 if (m_catalog.isValid()) {
372 m_catalog->commit();
373 }
374}

◆ connect()

StatusCode PoolSvc::connect ( Io::IoFlag type,
unsigned int contextId = IPoolSvc::kInputStream )
overridevirtual

Connect to a logical database unit; PersistencySvc is chosen according to transaction type (accessmode).

Definition at line 483 of file PoolSvc.cxx.

483 {
484 if (type != Io::READ) {
485 if (contextId >= m_dbSessionVec.size()) {
486 ATH_MSG_WARNING("connect: Using default output Stream instead of id = " << contextId);
487 contextId = IPoolSvc::kOutputStream;
488 }
489 } else {
490 if (contextId > m_dbSessionVec.size()) {
491 ATH_MSG_WARNING("connect: Using default input Stream instead of id = " << contextId);
492 contextId = IPoolSvc::kInputStream;
493 } else if (contextId == m_dbSessionVec.size()) {
494 ATH_MSG_INFO("Connecting to InputStream for: " << contextId);
495 contextId = this->getInputContext("");
496 }
497 }
498 if (contextId >= m_dbSessionVec.size()) {
499 return StatusCode::FAILURE;
500 }
502 auto& session = m_dbSessionVec[contextId];
503 // Connect to a logical database using the pre-defined technology and dbID
504 if( session->openMode() == Io::INVALID && !session->startTransaction(type) ) {
505 ATH_MSG_ERROR("connect failed session = " << session << " type = " << type);
506 return StatusCode::FAILURE;
507 }
508 return StatusCode::SUCCESS;
509}
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
@ kOutputStream
Definition IPoolSvc.h:34
@ kInputStream
Definition IPoolSvc.h:34
virtual unsigned int getInputContext(const std::string &label, unsigned int maxFile=0) override
Definition PoolSvc.cxx:300

◆ connectCollection()

StatusCode PoolSvc::connectCollection ( const std::string & connection,
const std::string & collectionName,
unsigned int contextId = IPoolSvc::kInputStream )
overridevirtual
Returns
status of connect
Parameters
connection[IN] string containing the connection.
collectionName[IN] string containing the persistent name of the collection.
contextId[IN] id for PoolSvc persistency service to use for input.

Definition at line 380 of file PoolSvc.cxx.

383{
384 ATH_MSG_DEBUG("connectCollection() connection=" << connection
385 << ", name=" << collectionName << ", contextID=" << contextId);
386 if (contextId >= m_dbSessionVec.size()) {
387 ATH_MSG_WARNING("connectCollection: Using default input Stream instead of id = " << contextId);
388 contextId = IPoolSvc::kInputStream;
389 }
390
392 // Check POOL FileCatalog entry.
393 bool insertFile = false;
394 if (connection.starts_with("PFN:")) {
395 std::string fid, fileType;
396 FileCatalogUtils::lookupFileByPFN(*m_catalog, connection.substr(4), fid, fileType);
397 if (fid.empty()) { // No entry in file catalog
398 insertFile = true;
399 ATH_MSG_INFO("File is not in Catalog! Attempt to open it anyway.");
400 }
401 }
402
403 // Check whether Collection Container exists.
404 std::unique_ptr<Database> dbH = getDbHandle(contextId, connection);
405 if( !dbH ) {
406 ATH_MSG_INFO("connectCollection(): Failed to get Database Handle for: " << connection);
407 return StatusCode::FAILURE;
408 }
409 try {
410 if (dbH->openMode() == Io::INVALID) {
411 dbH->connectForRead();
412 }
413 std::map<unsigned int, unsigned int>::const_iterator maxFileIter = m_contextMaxFile.find(contextId);
414 if (maxFileIter != m_contextMaxFile.end() && maxFileIter->second > 0 && !dbH->fid().empty()) {
415 const Guid guid(dbH->fid());
416 m_guidLists[contextId].remove(guid);
417 m_guidLists[contextId].push_back(guid);
418 while (m_guidLists[contextId].size() > maxFileIter->second + 1) {
419 this->disconnectDb("FID:" + m_guidLists[contextId].begin()->toString(), contextId).ignore();
420 }
421 }
422 } catch (std::exception& e) {
423 ATH_MSG_INFO("connectCollection() failed to open '" << connection << "' - trying.");
424 }
425 // For multithreaded processing (with multiple events in flight),
426 // increase virtual tree size to accomodate back reads
427 if (m_useROOTMaxTree && contextId == IPoolSvc::kInputStream && Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents() > 1) {
428 ATH_MSG_DEBUG("connectCollection(): Increasing virtual TTree size for: " << connection);
429 if (!this->setAttribute("TREE_MAX_VIRTUAL_SIZE", "-1", pool::ROOT_StorageType.type(), connection.substr(4), "CollectionTree", contextId).isSuccess()) {
430 ATH_MSG_DEBUG("Failed to increase maximum virtual TTree size.");
431 }
432 }
433 if (insertFile) return(StatusCode::RECOVERABLE);
434
435 return(StatusCode::SUCCESS);
436}
#define ATH_MSG_DEBUG(x,...)
std::string toString(const float number)
Pipe a number to a string.
size_t size() const
Number of registered mappings.
virtual StatusCode disconnectDb(const std::string &connection, unsigned int contextId=IPoolSvc::kInputStream) override
Disconnect single Database.
Definition PoolSvc.cxx:562
Gaudi::Property< bool > m_useROOTMaxTree
Increase virtual TTree size to avoid backreads in multithreading, default = false.
Definition PoolSvc.h:245
std::map< unsigned int, unsigned int > m_contextMaxFile
Definition PoolSvc.h:229
virtual StatusCode setAttribute(const std::string &optName, const std::string &data, long tech, unsigned int contextId=IPoolSvc::kOutputStream) override
Set POOL attributes - domain.
Definition PoolSvc.cxx:664
void lookupFileByPFN(const Gaudi::IFileCatalog &fc, const std::string &pfn, std::string &fid, std::string &tech)
Get FID and filetype for a given PFN.
static const DbType ROOT_StorageType
Definition DbType.h:72

◆ createCatalog()

bool PoolSvc::createCatalog ( )
private

Definition at line 768 of file PoolSvc.cxx.

768 {
769 m_catalogMgr = Gaudi::svcLocator()->service<Gaudi::IFileCatalogMgr>("Gaudi::MultiFileCatalog");
770 m_catalog = SmartIF<Gaudi::IFileCatalog>(m_catalogMgr);
771 if (!m_catalogMgr.isValid() || !m_catalog.isValid()) {
772 return false;
773 }
774 // set the output level of the XMLCatalog component - works only if the Gaudi AppMgr was initialized
775 Gaudi::svcLocator()->service<IMessageSvc>("MessageSvc")
776 ->setOutputLevel("XMLCatalog", DbPrint::getOutputLvl());
777 m_catalogMgr->removeCatalog("*");
778 for (auto& catalog : m_readCatalog.value()) {
779 ATH_MSG_DEBUG("POOL ReadCatalog is " << catalog);
780 if (catalog.starts_with("apcfile:") || catalog.starts_with("prfile:")) {
781 std::string::size_type cpos = catalog.find(':');
782 // check for file accessed via ATLAS_POOLCOND_PATH
783 std::string file = poolCondPath(catalog.substr(cpos + 1));
784 if (!file.empty()) {
785 ATH_MSG_INFO("Resolved path (via ATLAS_POOLCOND_PATH) is " << file);
787 } else {
788 // As backup, check for file accessed via PathResolver
789 file = PathResolver::find_file(catalog.substr(cpos + 1), "DATAPATH");
790 if (!file.empty()) {
791 ATH_MSG_INFO("Resolved path (via DATAPATH) is " << file);
793 } else {
794 ATH_MSG_INFO("Unable find catalog "
795 << catalog
796 << " in $ATLAS_POOLCOND_PATH and $DATAPATH");
797 }
798 }
799 } else {
801 }
802 }
803 try {
804 ATH_MSG_INFO("POOL WriteCatalog is " << m_writeCatalog.value());
806 } catch(std::exception& e) {
807 ATH_MSG_ERROR("setWriteCatalog - caught exception: " << e.what());
808 return false; // This catalog is not setup properly!
809 }
810 return true;
811}
static MSG::Level getOutputLvl()
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
std::string poolCondPath(const std::string &leaf)
Resolve a file using ATLAS_POOLCOND_PATH.
Definition PoolSvc.cxx:859
Gaudi::Property< std::vector< std::string > > m_readCatalog
ReadCatalog, the list of additional POOL input file catalogs to consult: default = empty vector.
Definition PoolSvc.h:241
Gaudi::Property< std::string > m_writeCatalog
WriteCatalog, the file catalog to be used to register output files (also default input catalog): defa...
Definition PoolSvc.h:239
void setOutputLevel(IMessageSvc *ims, const std::string &source, int level)
std::string addCatalog(Gaudi::IFileCatalogMgr &mgr, const std::string &connect, bool forWriting=false)
Add new catalog, identified by name, to the existing ones, optionally as the write catalog.
TFile * file

◆ createSession()

StatusCode PoolSvc::createSession ( const std::string & sessionName,
int ageLimit = -1 )

Create a new session for a given session name and age limit.

make a new session tool and add it to the list of session tools

Definition at line 878 of file PoolSvc.cxx.

879{
880 ToolHandle<SessionTool> session_tool = ToolHandle<SessionTool>("SessionTool/" + sessionName, this);
881 ATH_CHECK(session_tool.retrieve());
882 session_tool->setupFC( *m_catalog, dbAgeLimit );
883 m_dbSessionVec.push_back(session_tool);
884 return StatusCode::SUCCESS;
885}
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ disconnect()

StatusCode PoolSvc::disconnect ( unsigned int contextId = IPoolSvc::kInputStream)
overridevirtual

Disconnect PersistencySvc associated with a contextId.

Parameters
contextId[IN] poolStream to be disconnected.

Definition at line 540 of file PoolSvc.cxx.

540 {
541 ATH_MSG_DEBUG("Disconnect request for contextId=" << contextId);
542 if (contextId >= m_dbSessionVec.size()) {
543 return StatusCode::SUCCESS;
544 }
546 auto& session = m_dbSessionVec[contextId];
547 if( session->openMode() != Io::INVALID ) {
548 if( !commit(contextId).isSuccess() ) {
549 ATH_MSG_ERROR("disconnect failed to commit " << session);
550 return StatusCode::FAILURE;
551 }
552 if( session->disconnectAll() ) {
553 ATH_MSG_DEBUG("Disconnected PersistencySvc session");
554 } else {
555 ATH_MSG_ERROR("disconnect failed to diconnect PersistencySvc");
556 return StatusCode::FAILURE;
557 }
558 }
559 return StatusCode::SUCCESS;
560}
virtual StatusCode commit(unsigned int contextId=IPoolSvc::kInputStream) override
Commit data for a given contextId and flush buffer.
Definition PoolSvc.cxx:511

◆ disconnectDb()

StatusCode PoolSvc::disconnectDb ( const std::string & connection,
unsigned int contextId = IPoolSvc::kInputStream )
overridevirtual

Disconnect single Database.

Parameters
connection[IN] connection string for Database to be disconnected.
contextId[IN] context id of database to be disconnected.

Definition at line 562 of file PoolSvc.cxx.

562 {
563 if (contextId >= m_dbSessionVec.size()) {
564 return (StatusCode::SUCCESS);
565 }
567 std::unique_ptr<Database> dbH = getDbHandle(contextId, connection);
568 if (dbH == nullptr) {
569 ATH_MSG_ERROR("Failed to get Session/DatabaseHandle.");
570 return(StatusCode::FAILURE);
571 }
572 std::map<unsigned int, unsigned int>::const_iterator maxFileIter = m_contextMaxFile.find(contextId);
573 if (maxFileIter != m_contextMaxFile.end() && maxFileIter->second > 0) {
574 m_guidLists[contextId].remove(Guid(dbH->fid()));
575 }
576 dbH->disconnect();
577 return(StatusCode::SUCCESS);
578}

◆ finalize()

StatusCode PoolSvc::finalize ( )
overridevirtual

Required of all Gaudi services:

Definition at line 202 of file PoolSvc.cxx.

202 {
203 clearState();
204 return(::AthService::finalize());
205}
void clearState()
Definition PoolSvc.cxx:180

◆ getAttribute() [1/2]

StatusCode PoolSvc::getAttribute ( const std::string & optName,
std::string & data,
long tech,
const std::string & dbName,
const std::string & contName = "",
unsigned int contextId = IPoolSvc::kInputStream )
overridevirtual

Get POOL attributes - db/file, container/collection.

Definition at line 606 of file PoolSvc.cxx.

611 {
613 std::unique_ptr<Database> dbH = getDbHandle(contextId, dbName);
614 if (dbH == nullptr) {
615 ATH_MSG_DEBUG("getAttribute: Failed to get Session/DatabaseHandle to get POOL property.");
616 return(StatusCode::FAILURE);
617 }
618 if (dbH->openMode() == Io::INVALID) {
619 if (m_dbSessionVec[contextId]->openMode() == Io::WRITE || m_dbSessionVec[contextId]->openMode() == Io::APPEND) {
620 dbH->setTechnology(tech);
621 dbH->connectForWrite();
622 } else {
623 dbH->connectForRead();
624 }
625 }
626 std::ostringstream oss;
627 if (contName.empty()) {
628 if (data == "DbLonglong") {
629 long long int attr_data;
630 oss << std::dec << dbH->attributeOfType(optName, static_cast<void*>(&attr_data), typeid(long long int), "");
631 } else if (data == "double") {
632 double attr_data;
633 oss << std::dec << dbH->attributeOfType(optName, static_cast<void*>(&attr_data), typeid(double), "");
634 } else if (data == "string") {
635 char* attr_data;
636 oss << std::dec << dbH->attributeOfType(optName, static_cast<void*>(&attr_data), typeid(char*), "");
637 } else {
638 int attr_data;
639 oss << std::dec << dbH->attributeOfType(optName, static_cast<void*>(&attr_data), typeid(int), "");
640 }
641 ATH_MSG_INFO("Database (" << dbH->pfn() << ") attribute [" << optName << "]" << ": " << oss.str());
642 } else {
643 std::unique_ptr<Container> contH = getContainerHandle(dbH.get(), contName);
644 if (contH == nullptr) {
645 ATH_MSG_DEBUG("Failed to get ContainerHandle to get POOL property.");
646 return(StatusCode::FAILURE);
647 }
648 if (data == "DbLonglong") {
649 long long int attr_data;
650 oss << std::dec << contH->attributeOfType(optName, static_cast<void*>(&attr_data), typeid(long long int), "");
651 } else if (data == "double") {
652 double attr_data;
653 oss << std::dec << contH->attributeOfType(optName, static_cast<void*>(&attr_data), typeid(double), "");
654 } else {
655 int attr_data;
656 oss << std::dec << contH->attributeOfType(optName, static_cast<void*>(&attr_data), typeid(int), "");
657 }
658 ATH_MSG_INFO("Container attribute [" << contName << "." << optName << "]: " << oss.str());
659 }
660 data = oss.str();
661 return(StatusCode::SUCCESS);
662}
std::unique_ptr< Container > getContainerHandle(Database *dbH, const std::string &contName)
Get Container handle.
Definition PoolSvc.cxx:845

◆ getAttribute() [2/2]

StatusCode PoolSvc::getAttribute ( const std::string & optName,
std::string & data,
long tech,
unsigned int contextId = IPoolSvc::kInputStream )
overridevirtual

Get POOL attributes - domain.

Definition at line 580 of file PoolSvc.cxx.

583 {
584 if (contextId >= m_dbSessionVec.size()) {
585 ATH_MSG_WARNING("getAttribute: Using default input Stream instead of id = " << contextId);
586 contextId = IPoolSvc::kInputStream;
587 }
589 auto& sesH = m_dbSessionVec[contextId];
590 std::ostringstream oss;
591 if (data == "DbLonglong") {
592 long long int attr_data;
593 oss << std::dec << sesH->attributeOfType(tech, optName, static_cast<void*>(&attr_data), typeid(long long int), "");
594 } else if (data == "double") {
595 double attr_data;
596 oss << std::dec << sesH->attributeOfType(tech, optName, static_cast<void*>(&attr_data), typeid(double), "");
597 } else {
598 int attr_data;
599 oss << std::dec << sesH->attributeOfType(tech, optName, static_cast<void*>(&attr_data), typeid(int), "");
600 }
601 data = oss.str();
602 ATH_MSG_INFO("Domain attribute [" << optName << "]" << ": " << data);
603 return(StatusCode::SUCCESS);
604}

◆ getContainerHandle()

std::unique_ptr< Container > PoolSvc::getContainerHandle ( Database * dbH,
const std::string & contName )
private

Get Container handle.

Definition at line 845 of file PoolSvc.cxx.

845 {
846 Container* contH = nullptr;
847 if (dbH == nullptr) {
848 ATH_MSG_DEBUG("No DatabaseHandle to get Container.");
849 return(nullptr);
850 }
851 if (contName.find("DataHeader") != std::string::npos) {
852 contH = dbH->containerHandle(contName.substr(0, contName.find("_p")));
853 } else {
854 contH = dbH->containerHandle(contName);
855 }
856 return(std::unique_ptr<Container>(contH));
857}
Container * containerHandle(const std::string &name)
Returns a pointer to a container object. The user acquires ownership of that object.

◆ getDbHandle()

std::unique_ptr< Database > PoolSvc::getDbHandle ( unsigned int contextId,
const std::string & dbName )
private

Get Database handle.

Definition at line 817 of file PoolSvc.cxx.

817 {
818 if (contextId >= m_dbSessionVec.size()) {
819 ATH_MSG_WARNING("getDbHandle: Using default input Stream instead of id = " << contextId);
820 contextId = IPoolSvc::kInputStream;
821 }
822 auto& sesH = m_dbSessionVec[contextId];
823 if (!sesH){
824 ATH_MSG_ERROR("Session pointer is null.");
825 return nullptr;
826 }
827 if (sesH->openMode() == Io::INVALID) {
828 Io::IoFlag transMode = Io::READ;
829 ATH_MSG_DEBUG("Start transaction, type = " << transMode);
830 if (!sesH->startTransaction(transMode)) {
831 ATH_MSG_WARNING("Failed to start transaction, type = " << transMode);
832 return nullptr;
833 }
834 }
835 if (dbName.starts_with("PFN:")) {
836 return sesH->databaseHandle(dbName.substr(4), Database::Specification::PFN);
837 } else if (dbName.starts_with("LFN:")) {
838 return sesH->databaseHandle(dbName.substr(4), Database::Specification::LFN);
839 } else if (dbName.starts_with("FID:")) {
840 return sesH->databaseHandle(dbName.substr(4), Database::Specification::FID);
841 }
842 return sesH->databaseHandle(dbName, Database::Specification::PFN);
843}

◆ getInputContext()

unsigned int PoolSvc::getInputContext ( const std::string & label,
unsigned int maxFile = 0 )
overridevirtual
Returns
an Id for an input context (POOL persistency service) and create it if needed.
Parameters
label[IN] string label to name new context and allow sharing (returns existing contextId)
maxFile[IN] maximum number of open input files.

Definition at line 300 of file PoolSvc.cxx.

300 {
301 std::lock_guard<CallMutex> lock(m_pool_mut);
302 if (!label.empty()) {
303 std::map<std::string, unsigned int>::const_iterator contextIter = m_inputContextLabel.find(label);
304 if (contextIter != m_inputContextLabel.end()) {
305 if (maxFile > 0) {
306 m_contextMaxFile[contextIter->second] = maxFile;
307 }
308 return(contextIter->second);
309 }
310 }
311 const unsigned int id = m_dbSessionVec.size();
312 if( !createSession(label, maxFile).isSuccess() ) {
313 ATH_MSG_WARNING("getInputContext: Failed to create new input Stream id = " << id << ". Using default input Stream instead.");
315 }
316 m_pers_mut.push_back(new CallMutex);
317 if (!connect(Io::READ, id).isSuccess()) {
318 ATH_MSG_WARNING("Failed to connect Input PersistencySvc: " << id);
320 }
321 if (!label.empty()) {
322 m_inputContextLabel.try_emplace(label, id);
323 }
324 m_contextMaxFile.try_emplace(id, maxFile);
325 return(id);
326}
StatusCode createSession(const std::string &sessionName, int ageLimit=-1)
Create a new session for a given session name and age limit.
Definition PoolSvc.cxx:878
virtual StatusCode connect(Io::IoFlag type, unsigned int contextId=IPoolSvc::kInputStream) override
Connect to a logical database unit; PersistencySvc is chosen according to transaction type (accessmod...
Definition PoolSvc.cxx:483
std::recursive_mutex CallMutex
Definition PoolSvc.h:204
std::string label(const std::string &format, int i)
Definition label.h:19

◆ getInputContextMap()

std::map< std::string, unsigned int > PoolSvc::getInputContextMap ( ) const
overridevirtual
Returns
copy of the map of all labelled input contexts.

Definition at line 328 of file PoolSvc.cxx.

328 {
329 std::lock_guard<CallMutex> lock(m_pool_mut);
330 return(m_inputContextLabel);
331}

◆ getInputContextMapSize()

unsigned int PoolSvc::getInputContextMapSize ( ) const
overridevirtual
Returns
size of the map of all labelled input contexts.

Definition at line 333 of file PoolSvc.cxx.

333 {
334 std::lock_guard<CallMutex> lock(m_pool_mut);
335 return(m_inputContextLabel.size());
336}

◆ getInputFileDescriptor()

FileDescriptor PoolSvc::getInputFileDescriptor ( unsigned int contextId,
const std::string & connection )
overridevirtual
Returns
size of the map of all labelled input contexts.

Definition at line 338 of file PoolSvc.cxx.

339 {
340 if (contextId == m_dbSessionVec.size()) {
341 ATH_MSG_DEBUG("getInputFileDescriptor: On-demand creating new input Stream id = " << contextId);
342 contextId = this->getInputContext("");
343 }
344 if (contextId >= m_dbSessionVec.size()) {
345 ATH_MSG_WARNING("getInputFileDescriptor: Using default input Stream instead of id = " << contextId);
346 contextId = IPoolSvc::kInputStream;
347 }
349 std::unique_ptr<Database> dbH = getDbHandle(contextId, connection);
350 if (!dbH) {
351 throw std::runtime_error("Could not retrieve a database handle to '" + connection + "'");
352 }
353 FileDescriptor* fd = dbH->fileDescriptor();
354 if (!fd) {
355 throw std::runtime_error("Could not retrieve connection info from DB '" + connection + "'");
356 }
357 return *fd;
358}

◆ getOutputContext()

unsigned int PoolSvc::getOutputContext ( const std::string & label)
overridevirtual
Returns
an Id for an output context (POOL persistency service) and create it if needed.
Parameters
label[IN] string label to name new context and allow sharing (returns existing contextId)

Definition at line 277 of file PoolSvc.cxx.

277 {
278 std::lock_guard<CallMutex> lock(m_pool_mut);
279 if (m_mainOutputLabel.empty()) {
282 }
283 if (label == m_mainOutputLabel || label.empty()) {
285 }
286 std::map<std::string, unsigned int>::const_iterator contextIter = m_outputContextLabel.find(label);
287 if (contextIter != m_outputContextLabel.end()) {
288 return(contextIter->second);
289 }
290 const unsigned int id = m_dbSessionVec.size();
291 if( !createSession(label).isSuccess() ) {
292 ATH_MSG_WARNING("getOutputContext: Failed to create new output Stream id = " << id << ". Using default output Stream instead.");
294 }
295 m_pers_mut.push_back(new CallMutex);
296 m_outputContextLabel.try_emplace(label, id);
297 return(id);
298}

◆ getToken()

Token * PoolSvc::getToken ( const std::string & connection,
const std::string & collection,
const unsigned long ientry )
overridevirtual
Returns
a token for a container entry.
Parameters
connection[IN] string containing the connection/file name.
collection[IN] string containing the persistent name of the collection.
ientry[IN] entry number for the token to be returned

Definition at line 463 of file PoolSvc.cxx.

465 {
466 std::lock_guard<CallMutex> lock(*m_pers_mut[IPoolSvc::kInputStream]);
467 std::unique_ptr<Database> dbH = getDbHandle(IPoolSvc::kInputStream, connection);
468 if (dbH == nullptr) {
469 return(nullptr);
470 }
471 if (dbH->openMode() == Io::INVALID) {
472 dbH->connectForRead();
473 }
474 std::unique_ptr<Container> contH = getContainerHandle(dbH.get(), collection);
475 if (contH == nullptr) {
476 return(nullptr);
477 }
478 auto tokenIter = std::unique_ptr<TokenIterator>(contH->tokens());
479 // the Token returned by the iterator has the refCount already increased
480 return tokenIter->seek(ientry)? tokenIter->next() : nullptr;
481}

◆ initialize()

StatusCode PoolSvc::initialize ( )
overridevirtual

Required of all Gaudi services:

Definition at line 46 of file PoolSvc.cxx.

46 {
47 ATH_CHECK(::AthService::initialize());
48
49 // Register this service for 'I/O' events
50 ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
51 ATH_CHECK(iomgr.retrieve());
52 ATH_CHECK(iomgr->io_register(this));
53 // Register input file's names with the I/O manager, unless in SharedWrite mode, set by AthenaPoolCnvSvc
54 bool allGood = true;
55 for (const auto& catalog : m_readCatalog.value()) {
56 if (catalog.starts_with("xmlcatalog_file:")) {
57 const std::string fileName = catalog.substr(16);
58 if (!iomgr->io_register(this, IIoComponentMgr::IoMode::READ, fileName, fileName).isSuccess()) {
59 ATH_MSG_FATAL("could not register [" << catalog << "] for input !");
60 allGood = false;
61 } else {
62 ATH_MSG_INFO("io_register[" << this->name() << "](" << catalog << ") [ok]");
63 }
64 }
65 }
66 if (m_writeCatalog.value().starts_with("xmlcatalog_file:")) {
67 const std::string fileName = m_writeCatalog.value().substr(16);
68 if (!iomgr->io_register(this, IIoComponentMgr::IoMode::WRITE, fileName, fileName).isSuccess()) {
69 ATH_MSG_FATAL("could not register [" << m_writeCatalog.value() << "] for input !");
70 allGood = false;
71 } else {
72 ATH_MSG_INFO("io_register[" << this->name() << "](" << m_writeCatalog.value() << ") [ok]");
73 }
74 }
75 if (!allGood) {
76 return(StatusCode::FAILURE);
77 }
78
79 MSG::Level athLvl = msg().level();
80 ATH_MSG_DEBUG("OutputLevel is " << (int)athLvl);
82 return(setupPersistencySvc());
83}
#define ATH_MSG_FATAL(x,...)
StatusCode setupPersistencySvc()
Definition PoolSvc.cxx:127
bool allGood
Loop over the SDOs & Digits.
static void setLevel(MSG::Level l)
Definition DbPrint.h:13
MsgStream & msg
Definition testRead.cxx:32

◆ io_finalize()

StatusCode PoolSvc::io_finalize ( )
overridevirtual

Definition at line 207 of file PoolSvc.cxx.

207 {
208 ATH_MSG_INFO("I/O finalization...");
209 for (size_t i = 0; i < m_dbSessionVec.size(); i++) {
210 if ((m_dbSessionVec[i]->openMode() == Io::WRITE || m_dbSessionVec[i]->openMode() == Io::APPEND) &&
211 !disconnect(i).isSuccess()) {
212 ATH_MSG_WARNING("Cannot disconnect output Stream " << i);
213 }
214 }
215 clearState();
216 return(StatusCode::SUCCESS);
217}
virtual StatusCode disconnect(unsigned int contextId=IPoolSvc::kInputStream) override
Disconnect PersistencySvc associated with a contextId.
Definition PoolSvc.cxx:540

◆ io_reinit()

StatusCode PoolSvc::io_reinit ( )
overridevirtual

Definition at line 86 of file PoolSvc.cxx.

86 {
87 ATH_MSG_INFO("I/O reinitialization...");
88 ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", name());
89 if (!iomgr.retrieve().isSuccess()) {
90 ATH_MSG_FATAL("Could not retrieve IoComponentMgr !");
91 return(StatusCode::FAILURE);
92 }
93 if (!iomgr->io_hasitem(this)) {
94 ATH_MSG_FATAL("IoComponentMgr does not know about myself !");
95 return(StatusCode::FAILURE);
96 }
97 std::vector<std::string> readcat = m_readCatalog.value();
98 for (std::size_t icat = 0, imax = readcat.size(); icat < imax; icat++) {
99 if (readcat[icat].starts_with("xmlcatalog_file:")) {
100 std::string fileName = readcat[icat].substr(16);
101 if (iomgr->io_contains(this, fileName)) {
102 if (!iomgr->io_retrieve(this, fileName).isSuccess()) {
103 ATH_MSG_FATAL("Could not retrieve new value for [" << fileName << "] !");
104 return(StatusCode::FAILURE);
105 }
106 readcat[icat] = "xmlcatalog_file:" + fileName;
107 }
108 }
109 }
110 // all good... copy over.
111 m_readCatalog = readcat;
112 if (m_writeCatalog.value().starts_with("xmlcatalog_file:")) {
113 std::string fileName = m_writeCatalog.value().substr(16);
114 if (iomgr->io_contains(this, fileName)) {
115 if (!iomgr->io_retrieve(this, fileName).isSuccess()) {
116 ATH_MSG_FATAL("Could not retrieve new value for [" << fileName << "] !");
117 return(StatusCode::FAILURE);
118 }
119 if (!m_shareCat) {
120 m_writeCatalog.setValue("xmlcatalog_file:" + fileName);
121 }
122 }
123 }
124 return(setupPersistencySvc());
125}
int imax(int i, int j)
bool m_shareCat
Definition PoolSvc.h:220

◆ lookupBestPfn()

void PoolSvc::lookupBestPfn ( const std::string & dbID,
std::string & pfn,
std::string & type ) const
overridevirtual
Returns
void
Parameters
dbID[IN] database ID to be translated
pfn[OUT] string PFN of database
type[OUT] string filetype of database

Definition at line 376 of file PoolSvc.cxx.

376 {
377 FileCatalogUtils::getFirstPFN(*m_catalog, dbID, pfn, type); // FID -> best PFN
378}
void getFirstPFN(const Gaudi::IFileCatalog &fc, const std::string &fid, std::string &pfn, std::string &tech)
Get the first PFN + filetype for the given FID.

◆ patchCatalog()

void PoolSvc::patchCatalog ( const std::string & pfn,
Database & dbH ) const
private

Definition at line 455 of file PoolSvc.cxx.

455 {
456 std::scoped_lock lock(m_pool_mut);
458 std::string fid = dbH.fid();
459 Gaudi::IFileCatalog* catalog_locked ATLAS_THREAD_SAFE = m_catalog.get();
460 FileCatalogUtils::registerPFN(*catalog_locked, pfn, "ROOT_All", fid);
461}
const std::string & fid()
Returns the file identifier of this database.
bool setTechnology(long technology)
Sets the technology identifier for this database.
std::map< unsigned int, std::list< Guid > > m_guidLists ATLAS_THREAD_SAFE
Definition PoolSvc.h:231
void registerPFN(Gaudi::IFileCatalog &fc, const std::string &pfn, const std::string &ftype, std::string &fid)
Register PFN, assign new FID if not given. Throws if the PFN is already registered.

◆ poolCondPath()

std::string PoolSvc::poolCondPath ( const std::string & leaf)
private

Resolve a file using ATLAS_POOLCOND_PATH.

Definition at line 859 of file PoolSvc.cxx.

859 {
860 // look for files at $ATLAS_POOLCOND_PATH/<leaf>
861 // return full filename if exists, or empty string if not
862 const char* cpath = std::getenv("ATLAS_POOLCOND_PATH");
863 if (cpath && strcmp(cpath, "") != 0) {
864 const std::string testpath = std::string(cpath) + "/" + leaf;
865
866 // Try to open file for reading. Note that a simple stat call may return
867 // a wrong result if the file is residing on an auto-mounted FS (ATR-28801).
868 if (FILE* fp = std::fopen(testpath.c_str(), "r")) {
869 std::fclose(fp);
870 return testpath;
871 }
872 }
873 return {};
874}

◆ registerForWrite()

Token * PoolSvc::registerForWrite ( const Placement * placement,
const void * obj,
const RootType & classDesc )
overridevirtual
Returns
a token to a Data Object written to Pool.
Parameters
placement[IN] pointer to the placement hint.
obj[IN] pointer to the Data Object to be written to Pool.
classDesc[IN] pointer to the Seal class description for the Data Object.

Definition at line 219 of file PoolSvc.cxx.

221 {
222 unsigned int contextId = IPoolSvc::kOutputStream;
223 const std::string& auxString = placement->auxString();
224 if (!auxString.empty()) {
225 if (auxString.starts_with("[CTXT=")) {
226 ::sscanf(auxString.c_str(), "[CTXT=%08X]", &contextId);
227 } else if (auxString.starts_with("[CLABEL=")) {
228 contextId = this->getOutputContext(auxString);
229 }
230 if (contextId >= m_dbSessionVec.size()) {
231 ATH_MSG_WARNING("registerForWrite: Using default output Stream instead of id = " << contextId);
232 contextId = IPoolSvc::kOutputStream;
233 }
234 }
235 std::lock_guard<CallMutex> lock(*m_pers_mut[contextId]);
236 Token* token = m_dbSessionVec[contextId]->registerForWrite(*placement, obj, classDesc);
237 if (token == nullptr) {
238 ATH_MSG_WARNING("Cannot write object: " << placement->containerName());
239 }
240 return(token);
241}
const std::string & auxString() const
Access auxiliary string.
Definition Placement.h:41
const std::string & containerName() const
Access container name.
Definition Placement.h:33
virtual unsigned int getOutputContext(const std::string &label) override
Definition PoolSvc.cxx:277

◆ setAttribute() [1/2]

StatusCode PoolSvc::setAttribute ( const std::string & optName,
const std::string & data,
long tech,
const std::string & dbName,
const std::string & contName = "",
unsigned int contextId = IPoolSvc::kOutputStream )
overridevirtual

Set POOL attributes - db/file, container/collection.

Definition at line 690 of file PoolSvc.cxx.

695 {
696 if (contextId >= m_dbSessionVec.size()) {
697 ATH_MSG_WARNING("setAttribute: Using default output Stream instead of id = " << contextId);
698 contextId = IPoolSvc::kOutputStream;
699 }
701 std::unique_ptr<Database> dbH = getDbHandle(contextId, dbName);
702 if (dbH == nullptr) {
703 ATH_MSG_DEBUG("Failed to get Session/DatabaseHandle to set POOL property.");
704 return(StatusCode::FAILURE);
705 }
706 if (dbH->openMode() == Io::INVALID) {
707 if (m_dbSessionVec[contextId]->openMode() == Io::WRITE || m_dbSessionVec[contextId]->openMode() == Io::APPEND) {
708 dbH->setTechnology(tech);
709 dbH->connectForWrite();
710 } else {
711 dbH->connectForRead();
712 }
713 }
714 bool retError = false;
715 std::string objName;
716 bool hasTTreeName = contName.starts_with("TTree=");
717 if (contName.empty() || hasTTreeName || m_dbSessionVec[contextId]->openMode() == Io::READ) {
718 objName = hasTTreeName ? contName.substr(6) : contName;
719 if( !isNumber(data) ) {
720 const char* atttibuteValue = data.c_str();
721 retError = dbH->setAttributeOfType(optName, static_cast<const void*>(&atttibuteValue), typeid(char*), objName);
722 } else if( data[data.size() - 1] == 'L' ) {
723 const long long int& atttibuteValue = atoll(data.c_str());
724 retError = dbH->setAttributeOfType(optName, static_cast<const void*>(&atttibuteValue), typeid(long long int), objName);
725 } else {
726 const int& atttibuteValue = atoi(data.c_str());
727 retError = dbH->setAttributeOfType(optName, static_cast<const void*>(&atttibuteValue), typeid(int), objName);
728 }
729 if (!retError) {
730 ATH_MSG_DEBUG("Failed to set POOL property, " << optName << " to " << data);
731 return(StatusCode::FAILURE);
732 }
733 } else {
734 std::unique_ptr<Container> contH = getContainerHandle(dbH.get(), contName);
735 if (contH == nullptr) {
736 ATH_MSG_DEBUG("Failed to get ContainerHandle to set POOL property.");
737 return(StatusCode::FAILURE);
738 }
739 if (auto p = contName.find('('); p != std::string::npos) {
740 objName = contName.substr(p + 1); // Get BranchName between parenthesis
741 objName.erase(objName.find(')'));
742 } else if (auto p = contName.find("::"); p != std::string::npos) {
743 objName = contName.substr(p + 2); // Split off Tree name
744 } else if (auto p = contName.find('_'); p != std::string::npos) {
745 objName = contName.substr(p + 1); // Split off "POOLContainer"
746 objName.erase(objName.find('/')); // Split off key
747 }
748 std::string::size_type off = 0;
749 while ((off = objName.find_first_of("<>/")) != std::string::npos) {
750 objName[off] = '_'; // Replace special chars (e.g. templates)
751 }
752 if (data[data.size() - 1] == 'L') {
753 const long long int& atttibuteValue = atoll(data.c_str());
754 retError = contH->setAttributeOfType(optName, static_cast<const void*>(&atttibuteValue), typeid(long long int), objName);
755 } else {
756 const int& atttibuteValue = atoi(data.c_str());
757 retError = contH->setAttributeOfType(optName, static_cast<const void*>(&atttibuteValue), typeid(int), objName);
758 }
759 if (!retError) {
760 ATH_MSG_DEBUG("Failed to set POOL container property, " << optName << " for " << contName << " : " << objName << " to " << data);
761 return(StatusCode::FAILURE);
762 }
763 }
764 return(StatusCode::SUCCESS);
765}
bool isNumber(const std::string &s)
Definition PoolSvc.cxx:41
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...

◆ setAttribute() [2/2]

StatusCode PoolSvc::setAttribute ( const std::string & optName,
const std::string & data,
long tech,
unsigned int contextId = IPoolSvc::kOutputStream )
overridevirtual

Set POOL attributes - domain.

Definition at line 664 of file PoolSvc.cxx.

667 {
668 if (contextId >= m_dbSessionVec.size()) {
669 ATH_MSG_WARNING("setAttribute: Using default output Stream instead of id = " << contextId);
670 contextId = IPoolSvc::kOutputStream;
671 }
673 auto& sesH = m_dbSessionVec[contextId];
674 if (data[data.size() - 1] == 'L') {
675 const long long int& atttibuteValue = atoll(data.c_str());
676 if (!sesH->setAttributeOfType(tech, optName, static_cast<const void*>(&atttibuteValue), typeid(long long int), "")) {
677 ATH_MSG_DEBUG("Failed to set POOL property, " << optName << " to " << data);
678 return(StatusCode::FAILURE);
679 }
680 } else {
681 const int& atttibuteValue = atoi(data.c_str());
682 if (!sesH->setAttributeOfType(tech, optName, static_cast<const void*>(&atttibuteValue), typeid(int), "")) {
683 ATH_MSG_DEBUG("Failed to set POOL property, " << optName << " to " << data);
684 return(StatusCode::FAILURE);
685 }
686 }
687 return(StatusCode::SUCCESS);
688}

◆ setObjPtr()

void PoolSvc::setObjPtr ( void *& obj,
const Token * token )
overridevirtual
Returns
void
Parameters
obj[OUT] pointer to the Data Object.
token[IN] token of the Data Object for which a Pool Ref is filled.

Definition at line 243 of file PoolSvc.cxx.

243 {
244 unsigned int contextId = IPoolSvc::kInputStream;
245 const std::string& auxString = token->auxString();
246 bool allowAging = true;
247 if (!auxString.empty()) {
248 if (auxString.starts_with("[CTXT=")) {
249 ::sscanf(auxString.c_str(), "[CTXT=%08X]", &contextId);
250 if (contextId == m_dbSessionVec.size()) {
251 ATH_MSG_DEBUG("setObjPtr: On-demand creating new input Stream id = " << contextId);
252 contextId = this->getInputContext("");
253 }
254 } else if (auxString.starts_with("[CLABEL=")) {
255 contextId = this->getInputContext(auxString);
256 }
257 if (contextId >= m_dbSessionVec.size()) {
258 ATH_MSG_WARNING("setObjPtr: Using default input Stream instead of id = " << contextId);
259 contextId = IPoolSvc::kInputStream;
260 allowAging = false;
261 }
262 }
263 ATH_MSG_VERBOSE("setObjPtr: token=" << token->toString() << ", auxString=" << auxString << ", contextID=" << contextId);
264 // Get Context ID/label from Token
265 std::lock_guard<CallMutex> lock(*m_pers_mut[contextId]);
266 obj = m_dbSessionVec[contextId]->readObject(*token, obj);
267 std::map<unsigned int, unsigned int>::const_iterator maxFileIter = m_contextMaxFile.find(contextId);
268 if (allowAging && maxFileIter != m_contextMaxFile.end() && maxFileIter->second > 0) {
269 m_guidLists[contextId].remove(token->dbID());
270 m_guidLists[contextId].push_back(token->dbID());
271 while (m_guidLists[contextId].size() > maxFileIter->second) {
272 this->disconnectDb("FID:" + m_guidLists[contextId].begin()->toString(), contextId).ignore();
273 }
274 }
275}
#define ATH_MSG_VERBOSE(x,...)
const std::string & auxString() const
Access auxiliary string.
Definition Token.h:92
std::string toString() const
Retrieve the string representation of the token.
Definition Token.cxx:136
const Guid & dbID() const
Access database identifier.
Definition Token.h:65

◆ setShareMode()

void PoolSvc::setShareMode ( bool shareCat)
overridevirtual
Returns
void
Parameters
shareCat[IN] bool to share the file catalog.

Definition at line 360 of file PoolSvc.cxx.

360 {
361 m_shareCat = shareCat;
362}

◆ setupPersistencySvc()

StatusCode PoolSvc::setupPersistencySvc ( )
private

Definition at line 127 of file PoolSvc.cxx.

127 {
128 clearState();
129 ATH_MSG_INFO("Setting up FileCatalog and Streams");
130 if (!createCatalog()) {
131 ATH_MSG_FATAL("Failed to setup POOL File Catalog.");
132 return(StatusCode::FAILURE);
133 }
134 m_catalog->init();
135 // Setup a persistency services
136 ATH_CHECK( createSession("ReadSession") ); // Add Read Session
137 m_pers_mut.push_back(new CallMutex);
138 const bool& atttibuteValue = true;
139 if (!m_dbSessionVec[IPoolSvc::kInputStream]->setAttributeOfType(pool::ROOT_StorageType.type(), "ENABLE_THREADSAFETY", static_cast<const void*>(&atttibuteValue), typeid(bool), "")) {
140 ATH_MSG_FATAL("Failed to enable thread safety in ROOT via PersistencySvc.");
141 return(StatusCode::FAILURE);
142 }
144 if (!connect(Io::READ, IPoolSvc::kInputStream).isSuccess()) {
145 ATH_MSG_FATAL("Failed to connect Input PersistencySvc.");
146 return(StatusCode::FAILURE);
147 }
148 ATH_CHECK( createSession("WriteSession") ); // Add Write Session
149 m_pers_mut.push_back(new CallMutex);
150
151 return(StatusCode::SUCCESS);
152}
bool createCatalog()
Definition PoolSvc.cxx:768
Gaudi::Property< int > m_dbAgeLimit
MaxFilesOpen, option to have PoolSvc limit the number of open Input Files: default = 0 (No files are ...
Definition PoolSvc.h:236

◆ start()

StatusCode PoolSvc::start ( )
overridevirtual

Required of all Gaudi services:

Definition at line 154 of file PoolSvc.cxx.

154 {
155 // Switiching on ROOT implicit multi threading for AthenaMT
156 if (m_useROOTIMT && Gaudi::Concurrency::ConcurrencyFlags::numThreads() > 1) {
157 const int& atttibuteValue = Gaudi::Concurrency::ConcurrencyFlags::numThreads() - 1;
158 if (!m_dbSessionVec[IPoolSvc::kInputStream]->setAttributeOfType(pool::ROOT_StorageType.type(), "ENABLE_IMPLICITMT", static_cast<const void*>(&atttibuteValue), typeid(int), "")) {
159 ATH_MSG_FATAL("Failed to enable implicit multithreading in ROOT via PersistencySvc.");
160 return(StatusCode::FAILURE);
161 }
162 ATH_MSG_INFO("Enabled implicit multithreading in ROOT via PersistencySvc to: " << Gaudi::Concurrency::ConcurrencyFlags::numThreads() - 1);
163 }
164 return(StatusCode::SUCCESS);
165}
Gaudi::Property< bool > m_useROOTIMT
Use ROOT Implicit MultiThreading, default = true.
Definition PoolSvc.h:243

◆ startCatalog()

void PoolSvc::startCatalog ( )
overridevirtual
Returns
void

Definition at line 364 of file PoolSvc.cxx.

364 {
365 if (m_catalog.isValid()) {
366 m_catalog->init();
367 }
368}

◆ stop()

StatusCode PoolSvc::stop ( )
overridevirtual

Definition at line 167 of file PoolSvc.cxx.

167 {
168 ATH_MSG_VERBOSE("stop()");
169 bool retError = false;
170 for (unsigned int contextId = 0, imax = m_dbSessionVec.size(); contextId < imax; contextId++) {
171 if (!disconnect(contextId).isSuccess()) {
172 ATH_MSG_FATAL("Cannot disconnect Stream: " << contextId);
173 retError = true;
174 }
175 }
176 return(retError ? StatusCode::FAILURE : StatusCode::SUCCESS);
177}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::map<unsigned int, std::list<Guid> > m_guidLists PoolSvc::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 231 of file PoolSvc.h.

◆ m_attemptCatalogPatch

Gaudi::Property<bool> PoolSvc::m_attemptCatalogPatch {this,"AttemptCatalogPatch",true}
private

AttemptCatalogPatch, option to create catalog: default = false.

Definition at line 248 of file PoolSvc.h.

248{this,"AttemptCatalogPatch",true};

◆ m_catalog

SmartIF<Gaudi::IFileCatalog> PoolSvc::m_catalog
private

Definition at line 222 of file PoolSvc.h.

◆ m_catalogMgr

SmartIF<Gaudi::IFileCatalogMgr> PoolSvc::m_catalogMgr
private

Definition at line 221 of file PoolSvc.h.

◆ m_contextMaxFile

std::map<unsigned int, unsigned int> PoolSvc::m_contextMaxFile
private

Definition at line 229 of file PoolSvc.h.

◆ m_dbAgeLimit

Gaudi::Property<int> PoolSvc::m_dbAgeLimit {this,"MaxFilesOpen",0}
private

MaxFilesOpen, option to have PoolSvc limit the number of open Input Files: default = 0 (No files are closed automatically).

Definition at line 236 of file PoolSvc.h.

236{this,"MaxFilesOpen",0};

◆ m_dbSessionVec

std::vector<ToolHandle<SessionTool> > PoolSvc::m_dbSessionVec
private

Definition at line 223 of file PoolSvc.h.

◆ m_inputContextLabel

std::map<std::string, unsigned int> PoolSvc::m_inputContextLabel
private

Definition at line 226 of file PoolSvc.h.

◆ m_mainOutputLabel

std::string PoolSvc::m_mainOutputLabel {}
private

Definition at line 228 of file PoolSvc.h.

228{};

◆ m_outputContextLabel

std::map<std::string, unsigned int> PoolSvc::m_outputContextLabel
private

Definition at line 227 of file PoolSvc.h.

◆ m_pers_mut

std::vector<CallMutex*> PoolSvc::m_pers_mut
private

Definition at line 225 of file PoolSvc.h.

◆ m_pool_mut

CallMutex PoolSvc::m_pool_mut
mutableprivate

Definition at line 218 of file PoolSvc.h.

◆ m_readCatalog

Gaudi::Property<std::vector<std::string> > PoolSvc::m_readCatalog {this,"ReadCatalog",{},"List of catalog files to read from","OrderedSet<std::string>"}
private

ReadCatalog, the list of additional POOL input file catalogs to consult: default = empty vector.

Definition at line 241 of file PoolSvc.h.

241{this,"ReadCatalog",{},"List of catalog files to read from","OrderedSet<std::string>"};

◆ m_shareCat

bool PoolSvc::m_shareCat {false}
private

Definition at line 220 of file PoolSvc.h.

220{false};

◆ m_useROOTIMT

Gaudi::Property<bool> PoolSvc::m_useROOTIMT {this,"UseROOTImplicitMT",true}
private

Use ROOT Implicit MultiThreading, default = true.

Definition at line 243 of file PoolSvc.h.

243{this,"UseROOTImplicitMT",true};

◆ m_useROOTMaxTree

Gaudi::Property<bool> PoolSvc::m_useROOTMaxTree {this,"UseROOTIncreaseVMaxTree",false}
private

Increase virtual TTree size to avoid backreads in multithreading, default = false.

Definition at line 245 of file PoolSvc.h.

245{this,"UseROOTIncreaseVMaxTree",false};

◆ m_writeCatalog

Gaudi::Property<std::string> PoolSvc::m_writeCatalog {this,"WriteCatalog","xmlcatalog_file:PoolFileCatalog.xml"}
private

WriteCatalog, the file catalog to be used to register output files (also default input catalog): default = "" (use POOL default).

Definition at line 239 of file PoolSvc.h.

239{this,"WriteCatalog","xmlcatalog_file:PoolFileCatalog.xml"};

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