ATLAS Offline Software
Loading...
Searching...
No Matches
CondProxyProvider.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include "CondProxyProvider.h"
12#include "registerKeys.h"
13
16#include "PoolSvc/IPoolSvc.h"
18
19// Framework
20#include "GaudiKernel/ClassID.h"
21#include "GaudiKernel/StatusCode.h"
22
24
25// Pool
27#include "StorageSvc/DbType.h"
28
29#include <vector>
30#include <list>
31
32//________________________________________________________________________________
33CondProxyProvider::CondProxyProvider(const std::string& name, ISvcLocator* pSvcLocator) :
34 base_class(name, pSvcLocator),
35 m_contextId(IPoolSvc::kInputStream)
36 {
37}
38//________________________________________________________________________________
41//________________________________________________________________________________
43 ATH_MSG_INFO("Initializing " << name());
44 // Check for input collection
45 if (m_inputCollectionsProp.value().size() == 0) {
46 return StatusCode::FAILURE;
47 }
48 // Retrieve AthenaPoolCnvSvc
49 ATH_CHECK( m_athenaPoolCnvSvc.retrieve() );
50
51 // Get PoolSvc and connect as "Conditions"
52 IPoolSvc *poolSvc = m_athenaPoolCnvSvc->getPoolSvc();
53 m_contextId = poolSvc->getInputContext("Conditions");
55
56 for( const auto &inp : m_inputCollectionsProp.value() ) {
57 ATH_MSG_INFO("Inputs: " << inp);
58 }
59 // Initialize
61 return StatusCode::SUCCESS;
62}
63//________________________________________________________________________________
66 if (storeID != StoreID::DETECTOR_STORE) {
67 return StatusCode::SUCCESS;
68 }
69 ServiceHandle<StoreGateSvc> detectorStoreSvc("DetectorStore", name());
70 // Retrieve DetectorStoreSvc
71 ATH_CHECK( detectorStoreSvc.retrieve() );
72
73 // Create an poolCollectionConverter to read the objects in
74 std::unique_ptr<PoolCollectionConverter> poolCollectionConverter = getCollectionCnv();
75 if (!poolCollectionConverter) {
76 return StatusCode::FAILURE;
77 }
78 // Create DataHeader iterators
79 pool::ICollectionCursor* headerIterator = &poolCollectionConverter->selectAll();
80
81 for (int verNumber = 0; verNumber < 100; verNumber++) {
82 if (!headerIterator->next()) {
83 poolCollectionConverter->disconnectDb().ignore();
84 poolCollectionConverter.reset();
87 // Create PoolCollectionConverter for input file
88 poolCollectionConverter = getCollectionCnv();
89 if (!poolCollectionConverter) {
90 return StatusCode::FAILURE;
91 }
92 // Get DataHeader iterator
93 headerIterator = &poolCollectionConverter->selectAll();
94 if (!headerIterator->next()) {
95 return StatusCode::FAILURE;
96 }
97 } else {
98 break;
99 }
100 }
101 SG::VersionedKey myVersKey(name(), verNumber);
102 auto token = std::make_unique<Token>();
103 token->fromString(headerIterator->eventRef().toString());
105 (new TokenAddress(pool::POOL_StorageType.type(), ClassID_traits<DataHeader>::ID(), "", myVersKey, m_contextId, std::move(token)));
106 if (!detectorStoreSvc->recordAddress(std::move(tokenAddr)).isSuccess()) {
107 ATH_MSG_ERROR("Cannot record DataHeader.");
108 return StatusCode::FAILURE;
109 }
110 }
111 std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
112 if (!detectorStoreSvc->retrieveAllVersions(allVersions, name()).isSuccess()) {
113 ATH_MSG_DEBUG("Cannot retrieve DataHeader from DetectorStore.");
114 return StatusCode::SUCCESS;
115 }
116 for (const auto& version : allVersions) {
117 SG::ReadHandle<DataHeader> dataHeader = version.dataObject;
118 ATH_MSG_DEBUG("The current File contains: " << dataHeader->size() << " objects");
119 for (const auto& element : *dataHeader) {
120 SG::TransientAddress* tadd = element.getAddress(pool::POOL_StorageType.type());
121 if (tadd->clID() == ClassID_traits<DataHeader>::ID()) {
122 delete tadd; tadd = 0;
123 } else {
124 ATH_MSG_DEBUG("preLoadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
125 tads.push_back(tadd);
126 }
127 EventSelectorAthenaPoolUtil::registerKeys(element, &*detectorStoreSvc);
128 }
129 }
130 return StatusCode::SUCCESS;
131}
132//________________________________________________________________________________
134 IAddressProvider::tadList& /*tads*/) {
135 return StatusCode::SUCCESS;
136}
137//________________________________________________________________________________
139 SG::TransientAddress* /*tad*/,
140 const EventContext& /*ctx*/) {
141 return StatusCode::FAILURE;
142}
143//__________________________________________________________________________
144std::unique_ptr<PoolCollectionConverter> CondProxyProvider::getCollectionCnv() {
145 ATH_MSG_DEBUG("Try item: \"" << *m_inputCollectionsIterator << "\" from the collection list.");
146 auto pCollCnv = std::make_unique<PoolCollectionConverter>(std::string("ImplicitCollection:") + APRDefaults::TTreeNames::DataHeader,
149 m_athenaPoolCnvSvc->getPoolSvc());
150 if (!pCollCnv->initialize().isSuccess()) {
151 // Close previous collection.
152 pCollCnv.reset();
153 ATH_MSG_ERROR("Unable to open: " << *m_inputCollectionsIterator);
154 }
155 return(pCollCnv);
156}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This file contains the class definition for the CondProxyProvider class.
This file contains the class definition for the DataHeader and DataHeaderElement classes.
This file contains the class definition for the IPoolSvc interface class.
This file contains the class definition for the PoolCollectionConverter class.
This file contains the class definition for the TokenAddress class.
unsigned int m_contextId
std::unique_ptr< PoolCollectionConverter > getCollectionCnv()
Return pointer to new PoolCollectionConverter.
virtual StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress *tad, const EventContext &ctx) override
Update a transient address.
virtual StatusCode initialize() override
Required of all Gaudi Services.
std::vector< std::string >::const_iterator m_inputCollectionsIterator
virtual StatusCode loadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
Implementation of the loadAddresses function without any functionality.
virtual ~CondProxyProvider()
Destructor.
ServiceHandle< IAthenaPoolCnvSvc > m_athenaPoolCnvSvc
CondProxyProvider(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
virtual StatusCode preLoadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
Get all addresses from provider.
Gaudi::Property< std::vector< std::string > > m_inputCollectionsProp
InputCollections, vector with names of the input collections.
Simple smart pointer for Gaudi-style refcounted objects.
std::list< SG::TransientAddress * > tadList
This class provides the interface to the LCG POOL persistency software.
Definition IPoolSvc.h:35
CLID clID() const
Retrieve string key:
const std::string & name() const
Get the primary (hashed) SG key.
a StoreGateSvc key with a version number.
@ DETECTOR_STORE
Definition StoreID.h:27
This class provides a Generic Transient Address for POOL tokens.
virtual const std::string toString() const
Retrieve the string representation of the token.
Definition Token.cxx:134
An interface used to navigate the result of a query on a collection.
virtual bool next()=0
Advances the cursor to the next row of the query result set.
virtual const Token & eventRef() const =0
Returns the event reference Token for the current row.
void registerKeys(const DataHeaderElement &dhe, StoreGateSvc *store)
Register all hash keys for one DH Element.
static const DbType POOL_StorageType
Definition DbType.h:98
Helper functions for registering hash keys with the SG service.
static constexpr const char * DataHeader
Definition APRDefaults.h:14