ATLAS Offline Software
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 
10 #include "CondProxyProvider.h"
12 #include "registerKeys.h"
13 
16 #include "PoolSvc/IPoolSvc.h"
17 #include "RootUtils/APRDefaults.h"
18 
19 // Framework
20 #include "GaudiKernel/ClassID.h"
21 #include "GaudiKernel/StatusCode.h"
22 
23 #include "StoreGate/StoreGateSvc.h"
24 
25 // Pool
27 
28 #include <vector>
29 #include <list>
30 
31 //________________________________________________________________________________
32 CondProxyProvider::CondProxyProvider(const std::string& name, ISvcLocator* pSvcLocator) :
33  base_class(name, pSvcLocator),
34  m_contextId(IPoolSvc::kInputStream)
35  {
36 }
37 //________________________________________________________________________________
39 }
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 //________________________________________________________________________________
64  // Release AthenaPoolCnvSvc
65  if (!m_athenaPoolCnvSvc.release().isSuccess()) {
66  ATH_MSG_WARNING("Cannot release AthenaPoolCnvSvc.");
67  }
68  return(StatusCode::SUCCESS);
69 }
70 //________________________________________________________________________________
73  if (storeID != StoreID::DETECTOR_STORE) {
74  return(StatusCode::SUCCESS);
75  }
76  ServiceHandle<StoreGateSvc> detectorStoreSvc("DetectorStore", name());
77  // Retrieve DetectorStoreSvc
78  ATH_CHECK( detectorStoreSvc.retrieve() );
79 
80  // Create an poolCollectionConverter to read the objects in
81  std::unique_ptr<PoolCollectionConverter> poolCollectionConverter = getCollectionCnv();
82  if (!poolCollectionConverter) {
83  return StatusCode::FAILURE;
84  }
85  // Create DataHeader iterators
86  pool::ICollectionCursor* headerIterator = &poolCollectionConverter->selectAll();
87 
88  for (int verNumber = 0; verNumber < 100; verNumber++) {
89  if (!headerIterator->next()) {
90  poolCollectionConverter->disconnectDb().ignore();
91  poolCollectionConverter.reset();
94  // Create PoolCollectionConverter for input file
95  poolCollectionConverter = getCollectionCnv();
96  if (!poolCollectionConverter) {
97  return(StatusCode::FAILURE);
98  }
99  // Get DataHeader iterator
100  headerIterator = &poolCollectionConverter->selectAll();
101  if (!headerIterator->next()) {
102  return(StatusCode::FAILURE);
103  }
104  } else {
105  break;
106  }
107  }
108  SG::VersionedKey myVersKey(name(), verNumber);
109  auto token = std::make_unique<Token>();
110  token->fromString(headerIterator->eventRef().toString());
111  TokenAddress* tokenAddr = new TokenAddress(POOL_StorageType, ClassID_traits<DataHeader>::ID(), "", myVersKey, m_contextId, std::move(token));
112  if (!detectorStoreSvc->recordAddress(tokenAddr).isSuccess()) {
113  delete tokenAddr;
114  ATH_MSG_ERROR("Cannot record DataHeader.");
115  return(StatusCode::FAILURE);
116  }
117  }
118  std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
119  if (!detectorStoreSvc->retrieveAllVersions(allVersions, name()).isSuccess()) {
120  ATH_MSG_DEBUG("Cannot retrieve DataHeader from DetectorStore.");
121  return(StatusCode::SUCCESS);
122  }
123  for (std::list<SG::ObjectWithVersion<DataHeader> >::iterator iter = allVersions.begin();
124  iter != allVersions.end(); ++iter) {
125  SG::ReadHandle<DataHeader> dataHeader = iter->dataObject;
126  ATH_MSG_DEBUG("The current File contains: " << dataHeader->size() << " objects");
127  for (const auto& element : *dataHeader) {
128  SG::TransientAddress* tadd = element.getAddress();
129  if (tadd->clID() == ClassID_traits<DataHeader>::ID()) {
130  delete tadd; tadd = 0;
131  } else {
132  ATH_MSG_DEBUG("preLoadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
133  tads.push_back(tadd);
134  }
135  EventSelectorAthenaPoolUtil::registerKeys(element, &*detectorStoreSvc);
136  }
137  }
138  return(StatusCode::SUCCESS);
139 }
140 //________________________________________________________________________________
142  IAddressProvider::tadList& /*tads*/) {
143  return(StatusCode::SUCCESS);
144 }
145 //________________________________________________________________________________
147  SG::TransientAddress* /*tad*/,
148  const EventContext& /*ctx*/) {
149  return(StatusCode::FAILURE);
150 }
151 //__________________________________________________________________________
152 std::unique_ptr<PoolCollectionConverter> CondProxyProvider::getCollectionCnv() {
153  ATH_MSG_DEBUG("Try item: \"" << *m_inputCollectionsIterator << "\" from the collection list.");
154  auto pCollCnv = std::make_unique<PoolCollectionConverter>(std::string("ImplicitCollection:") + APRDefaults::TTreeNames::DataHeader,
156  m_contextId,
157  m_athenaPoolCnvSvc->getPoolSvc());
158  if (!pCollCnv->initialize().isSuccess()) {
159  // Close previous collection.
160  pCollCnv.reset();
161  ATH_MSG_ERROR("Unable to open: " << *m_inputCollectionsIterator);
162  }
163  return(pCollCnv);
164 }
CondProxyProvider::getCollectionCnv
std::unique_ptr< PoolCollectionConverter > getCollectionCnv()
Return pointer to new PoolCollectionConverter.
Definition: CondProxyProvider.cxx:152
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CondProxyProvider::preLoadAddresses
virtual StatusCode preLoadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
Get all addresses from provider.
Definition: CondProxyProvider.cxx:71
registerKeys.h
Helper functions for registering hash keys with the SG service.
createLinkingScheme.iter
iter
Definition: createLinkingScheme.py:62
IPoolSvc
This class provides the interface to the LCG POOL persistency software.
Definition: IPoolSvc.h:35
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
PoolCollectionConverter.h
This file contains the class definition for the PoolCollectionConverter class.
ICollectionCursor.h
PoolCollectionConverter::selectAll
pool::ICollectionCursor & selectAll()
Definition: PoolCollectionConverter.cxx:109
SG::TransientAddress
Definition: TransientAddress.h:32
CondProxyProvider::updateAddress
virtual StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress *tad, const EventContext &ctx) override
Update a transient address.
Definition: CondProxyProvider.cxx:146
pool::ICollectionCursor::next
virtual bool next()=0
Advances the cursor to the next row of the query result set.
CondProxyProvider.h
This file contains the class definition for the CondProxyProvider class.
TokenAddress
This class provides a Generic Transient Address for POOL tokens.
Definition: TokenAddress.h:23
SG::TransientAddress::name
const std::string & name() const
Get the primary (hashed) SG key.
Definition: TransientAddress.h:217
EventSelectorAthenaPoolUtil::registerKeys
void registerKeys(const DataHeaderElement &dhe, StoreGateSvc *store)
Register all hash keys for one DH Element.
Definition: registerKeys.cxx:22
CondProxyProvider::m_contextId
unsigned int m_contextId
Definition: CondProxyProvider.h:59
APRDefaults.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DataHeader::size
int size() const
Definition: DataHeader.cxx:250
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CondProxyProvider::loadAddresses
virtual StatusCode loadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
Implementation of the loadAddresses function without any functionality.
Definition: CondProxyProvider.cxx:141
SG::VersionedKey
a StoreGateSvc key with a version number. Notice that StoreGate does not order multiple instances of ...
Definition: SGVersionedKey.h:31
SG::TransientAddress::clID
CLID clID() const
Retrieve string key:
Definition: TransientAddress.h:210
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:37
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CondProxyProvider::m_athenaPoolCnvSvc
ServiceHandle< IAthenaPoolCnvSvc > m_athenaPoolCnvSvc
Definition: CondProxyProvider.h:58
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CondProxyProvider::initialize
virtual StatusCode initialize() override
Required of all Gaudi Services.
Definition: CondProxyProvider.cxx:41
DataHeader.h
This file contains the class definition for the DataHeader and DataHeaderElement classes.
StoreID::DETECTOR_STORE
@ DETECTOR_STORE
Definition: StoreID.h:27
pool::ICollectionCursor
Definition: ICollectionCursor.h:22
APRDefaults::TTreeNames::DataHeader
static constexpr const char * DataHeader
Definition: APRDefaults.h:14
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
Token::toString
virtual const std::string toString() const
Retrieve the string representation of the token.
Definition: Token.cxx:129
LArConditionsTestConfig.poolSvc
poolSvc
Definition: LArConditionsTestConfig.py:80
IPoolSvc.h
This file contains the class definition for the IPoolSvc interface class.
TokenAddress.h
This file contains the class definition for the TokenAddress class.
PoolCollectionConverter::disconnectDb
StatusCode disconnectDb()
Disconnect Database.
Definition: PoolCollectionConverter.cxx:95
CondProxyProvider::finalize
virtual StatusCode finalize() override
Required of all Gaudi Services.
Definition: CondProxyProvider.cxx:63
StoreID::type
type
Definition: StoreID.h:24
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
pool::ITransaction::READ
@ READ
Definition: ITransaction.h:29
CondProxyProvider::~CondProxyProvider
virtual ~CondProxyProvider()
Destructor.
Definition: CondProxyProvider.cxx:38
CondProxyProvider::m_inputCollectionsProp
StringArrayProperty m_inputCollectionsProp
InputCollections, vector with names of the input collections.
Definition: CondProxyProvider.h:64
IAddressProvider::tadList
std::list< SG::TransientAddress * > tadList
Definition: IAddressProvider.h:32
CondProxyProvider::CondProxyProvider
CondProxyProvider(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
Definition: CondProxyProvider.cxx:32
pool::ICollectionCursor::eventRef
virtual const Token & eventRef() const =0
Returns the event reference Token for the current row.
SG::ObjectWithVersion
associate a data object with its VersionedKey The object is held by a ReadHandle to delay its retriev...
Definition: SGVersionedKey.h:17
StoreGateSvc.h
CondProxyProvider::m_inputCollectionsIterator
std::vector< std::string >::const_iterator m_inputCollectionsIterator
Definition: CondProxyProvider.h:65
ServiceHandle< StoreGateSvc >