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"
17
18// Framework
19#include "GaudiKernel/ClassID.h"
20#include "GaudiKernel/StatusCode.h"
21
23
24// Pool
26#include "StorageSvc/DbType.h"
27
28#include <vector>
29#include <list>
30
31//________________________________________________________________________________
32CondProxyProvider::CondProxyProvider(const std::string& name, ISvcLocator* pSvcLocator) :
33 base_class(name, pSvcLocator),
34 m_contextId(IPoolSvc::kInputStream)
35 {
36}
37//________________________________________________________________________________
40//________________________________________________________________________________
42 ATH_MSG_INFO("Initializing " << name());
43 // Check for input collection
44 if (m_inputCollectionsProp.value().size() == 0) {
45 return StatusCode::FAILURE;
46 }
47 // Retrieve AthenaPoolCnvSvc
48 ATH_CHECK( m_athenaPoolCnvSvc.retrieve() );
49
50 // Get PoolSvc and connect as "Conditions"
51 IPoolSvc *poolSvc = m_athenaPoolCnvSvc->getPoolSvc();
52 m_contextId = poolSvc->getInputContext("Conditions");
54
55 for( const auto &inp : m_inputCollectionsProp.value() ) {
56 ATH_MSG_INFO("Inputs: " << inp);
57 }
58 // Initialize
60 return StatusCode::SUCCESS;
61}
62//________________________________________________________________________________
65 if (storeID != StoreID::DETECTOR_STORE) {
66 return StatusCode::SUCCESS;
67 }
68 ServiceHandle<StoreGateSvc> detectorStoreSvc("DetectorStore", name());
69 // Retrieve DetectorStoreSvc
70 ATH_CHECK( detectorStoreSvc.retrieve() );
71
72 // Create an poolCollectionConverter to read the objects in
73 std::unique_ptr<PoolCollectionConverter> poolCollectionConverter = getCollectionCnv();
74 if (!poolCollectionConverter) {
75 return StatusCode::FAILURE;
76 }
77 // Create DataHeader iterators
78 pool::ICollectionCursor* headerIterator = &poolCollectionConverter->selectAll();
79
80 for (int verNumber = 0; verNumber < 100; verNumber++) {
81 if (!headerIterator->next()) {
82 poolCollectionConverter->disconnectDb().ignore();
83 poolCollectionConverter.reset();
86 // Create PoolCollectionConverter for input file
87 poolCollectionConverter = getCollectionCnv();
88 if (!poolCollectionConverter) {
89 return StatusCode::FAILURE;
90 }
91 // Get DataHeader iterator
92 headerIterator = &poolCollectionConverter->selectAll();
93 if (!headerIterator->next()) {
94 return StatusCode::FAILURE;
95 }
96 } else {
97 break;
98 }
99 }
100 SG::VersionedKey myVersKey(name(), verNumber);
101 auto token = std::make_unique<Token>();
102 token->fromString(headerIterator->eventRef().toString());
104 (new TokenAddress(pool::POOL_StorageType.type(), ClassID_traits<DataHeader>::ID(), "", myVersKey, m_contextId, std::move(token)));
105 if (!detectorStoreSvc->recordAddress(std::move(tokenAddr)).isSuccess()) {
106 ATH_MSG_ERROR("Cannot record DataHeader.");
107 return StatusCode::FAILURE;
108 }
109 }
110 std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
111 if (!detectorStoreSvc->retrieveAllVersions(allVersions, name()).isSuccess()) {
112 ATH_MSG_DEBUG("Cannot retrieve DataHeader from DetectorStore.");
113 return StatusCode::SUCCESS;
114 }
115 for (const auto& version : allVersions) {
116 SG::ReadHandle<DataHeader> dataHeader = version.dataObject;
117 ATH_MSG_DEBUG("The current File contains: " << dataHeader->size() << " objects");
118 for (const auto& element : *dataHeader) {
119 SG::TransientAddress* tadd = element.getAddress(pool::POOL_StorageType.type());
120 if (tadd->clID() == ClassID_traits<DataHeader>::ID()) {
121 delete tadd; tadd = 0;
122 } else {
123 ATH_MSG_DEBUG("preLoadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
124 tads.push_back(tadd);
125 }
126 EventSelectorAthenaPoolUtil::registerKeys(element, &*detectorStoreSvc);
127 }
128 }
129 return StatusCode::SUCCESS;
130}
131//________________________________________________________________________________
133 IAddressProvider::tadList& /*tads*/) {
134 return StatusCode::SUCCESS;
135}
136//________________________________________________________________________________
138 SG::TransientAddress* /*tad*/,
139 const EventContext& /*ctx*/) {
140 return StatusCode::FAILURE;
141}
142//__________________________________________________________________________
143std::unique_ptr<PoolCollectionConverter> CondProxyProvider::getCollectionCnv() {
144 ATH_MSG_DEBUG("Try item: \"" << *m_inputCollectionsIterator << "\" from the collection list.");
145 auto pCollCnv = std::make_unique<PoolCollectionConverter>("ImplicitCollection",
148 m_athenaPoolCnvSvc->getPoolSvc());
149 if (!pCollCnv->initialize().isSuccess()) {
150 // Close previous collection.
151 pCollCnv.reset();
152 ATH_MSG_ERROR("Unable to open: " << *m_inputCollectionsIterator);
153 }
154 return(pCollCnv);
155}
#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:36
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:84
Helper functions for registering hash keys with the SG service.