ATLAS Offline Software
Loading...
Searching...
No Matches
PoolCollectionConverter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9
11#include "PoolSvc/IPoolSvc.h"
12#include "PoolSvc/ISession.h"
14
15// Pool
19#include "StorageSvc/DbType.h"
20
21// Gaudi
22#include "GaudiKernel/StatusCode.h"
23
24#include <exception>
25#include <format>
26#include <mutex>
27#include <stdexcept>
28
29//______________________________________________________________________________
30PoolCollectionConverter::PoolCollectionConverter(const std::string& collectionType,
31 const std::string& inputCollection,
32 unsigned int contextId,
33 const IPoolSvc* svc) :
34 m_collectionType(collectionType),
35 m_inputCollection(inputCollection),
36 m_contextId(contextId),
37 m_poolSvc(svc),
38 m_poolCollection(nullptr) {
39}
40//______________________________________________________________________________
47//______________________________________________________________________________
49 // Check if already prefixed
50 if (!m_inputCollection.starts_with( "PFN:")
51 && !m_inputCollection.starts_with( "LFN:")
52 && !m_inputCollection.starts_with( "FID:")) {
53 // Prefix with PFN:
54 m_inputCollection = std::format("PFN:{}", m_inputCollection);
55 }
56 StatusCode sc = StatusCode::SUCCESS;
57 try {
58 if (m_collectionType == "RootCollection") {
59 sc = m_poolSvc->connectCollection(m_inputCollection, "Input", pool::ROOT_StorageType.type(), m_contextId);
61 }
62 if (m_poolCollection == nullptr) { // Open as ImplicitCollection if technologies fail, or none was specified
63 sc = m_poolSvc->connectCollection(m_inputCollection, "Input", pool::POOL_StorageType.type(), m_contextId);
65 }
66 } catch (std::exception &e) {
67 if (m_poolCollection == nullptr) return StatusCode::RECOVERABLE;
68 }
69 bool insertFile = false;
70 if (sc.isRecoverable()) {
71 insertFile = true;
72 } else if (sc.isFailure()) {
73 return StatusCode::FAILURE;
74 }
75 if (m_poolCollection == nullptr || insertFile) {
76 return m_poolSvc->checkCollection(m_inputCollection, m_contextId, m_poolCollection == nullptr);
77 }
78 return StatusCode::SUCCESS;
79}
80//______________________________________________________________________________
82 const std::string& collectionName,
83 const pool::DbType& collectionType,
84 unsigned int contextId) const {
85 // access to these variables is serial, since this is called by event selector only
87 pool::ICollection* collPtr ATLAS_THREAD_SAFE = nullptr;
88
89 // Try to open EventTags Collection in the input file
90 try {
91 collPtr = collSvc.open(collectionName, collectionType, connection, m_poolSvc->getInputContextSession(contextId));
92 } catch (std::exception &e) {
93 collPtr = nullptr;
94 }
95 return(collPtr);
96}
97//______________________________________________________________________________
99 if (m_poolCollection == nullptr) {
100 return StatusCode::SUCCESS;
101 }
102 return m_poolSvc->disconnectDb(m_inputCollection);
103}
104//______________________________________________________________________________
106 return m_poolCollection != nullptr ? StatusCode::SUCCESS : StatusCode::FAILURE;
107}
108//______________________________________________________________________________
109std::unique_ptr<pool::ICollectionCursor> PoolCollectionConverter::selectAll() {
110 if (m_poolCollection == nullptr)[[unlikely]] {
111 throw std::runtime_error("PoolCollectionConverter::selectAll: m_poolCollection is nullptr.");
112 }
113 return m_poolCollection->cursor();
114}
This file contains the class definition for the IPoolSvc interface class.
static Double_t sc
This file contains the class definition for the PoolCollectionConverter class.
This file contains the class definition for the Token class (migrated from POOL).
#define ATLAS_THREAD_SAFE
This class provides the interface to the APR persistency software.
Definition IPoolSvc.h:35
std::unique_ptr< pool::ICollectionCursor > selectAll()
StatusCode disconnectDb()
Disconnect Database.
pool::ICollection * m_poolCollection
StatusCode isValid() const
Check whether has valid pool::ICollection*.
PoolCollectionConverter(const std::string &collectionType, const std::string &inputCollection, unsigned int contextId, const IPoolSvc *svc)
Constructor.
pool::ICollection * createCollection(const std::string &connection, const std::string &collectionName, const pool::DbType &collectionType, unsigned int contextId) const
virtual ~PoolCollectionConverter()
Destructor.
StatusCode initialize()
Required by all Gaudi Services.
A service for creating, accessing and managing an ensemble of collections of event references.
An interface to a storage technology specific collection of event references and attributes.
Definition ICollection.h:24
static const DbType ROOT_StorageType
Definition DbType.h:85
static const DbType POOL_StorageType
Definition DbType.h:84
#define unlikely(x)