ATLAS Offline Software
CondProxyProvider.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "CondProxyProvider.h"
12 #include "registerKeys.h"
13 
17 #include "PoolSvc/IPoolSvc.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 
30 //________________________________________________________________________________
31 CondProxyProvider::CondProxyProvider(const std::string& name, ISvcLocator* pSvcLocator) :
32  base_class(name, pSvcLocator),
33  m_athenaPoolCnvSvc("AthenaPoolCnvSvc", name),
34  m_poolCollectionConverter(0),
35  m_contextId(IPoolSvc::kInputStream)
36  {
37 }
38 //________________________________________________________________________________
40 }
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
60  m_inputCollectionsIterator = m_inputCollectionsProp.value().begin();
61  // Create an m_poolCollectionConverter to read the objects in
62  m_poolCollectionConverter = getCollectionCnv();
63  if (m_poolCollectionConverter == 0) {
64  return(StatusCode::FAILURE);
65  }
66  return(StatusCode::SUCCESS);
67 }
68 //________________________________________________________________________________
70  if (m_poolCollectionConverter != 0) {
71  m_poolCollectionConverter->disconnectDb().ignore();
72  delete m_poolCollectionConverter; m_poolCollectionConverter = 0;
73  }
74  // Release AthenaPoolCnvSvc
75  if (!m_athenaPoolCnvSvc.release().isSuccess()) {
76  ATH_MSG_WARNING("Cannot release AthenaPoolCnvSvc.");
77  }
78  return(StatusCode::SUCCESS);
79 }
80 //________________________________________________________________________________
83  if (storeID != StoreID::DETECTOR_STORE) {
84  return(StatusCode::SUCCESS);
85  }
86  ServiceHandle<StoreGateSvc> detectorStoreSvc("DetectorStore", name());
87  // Retrieve DetectorStoreSvc
88  ATH_CHECK( detectorStoreSvc.retrieve() );
89 
90  if (m_poolCollectionConverter == nullptr) {
91  return StatusCode::FAILURE;
92  }
93 
94  // Create DataHeader iterators
95  pool::ICollectionCursor* headerIterator = &m_poolCollectionConverter->executeQuery();
96  for (int verNumber = 0; verNumber < 100; verNumber++) {
97  if (!headerIterator->next()) {
98  m_poolCollectionConverter->disconnectDb().ignore();
99  delete m_poolCollectionConverter; m_poolCollectionConverter = 0;
100  ++m_inputCollectionsIterator;
101  if (m_inputCollectionsIterator != m_inputCollectionsProp.value().end()) {
102  // Create PoolCollectionConverter for input file
103  m_poolCollectionConverter = getCollectionCnv();
104  if (m_poolCollectionConverter == 0) {
105  return(StatusCode::FAILURE);
106  }
107  // Get DataHeader iterator
108  headerIterator = &m_poolCollectionConverter->executeQuery();
109  if (!headerIterator->next()) {
110  return(StatusCode::FAILURE);
111  }
112  } else {
113  break;
114  }
115  }
116  SG::VersionedKey myVersKey(name(), verNumber);
117  Token* token = new Token;
118  token->fromString(headerIterator->eventRef().toString());
119  TokenAddress* tokenAddr = new TokenAddress(POOL_StorageType, ClassID_traits<DataHeader>::ID(), "", myVersKey, m_contextId, token);
120  if (!detectorStoreSvc->recordAddress(tokenAddr).isSuccess()) {
121  ATH_MSG_ERROR("Cannot record DataHeader.");
122  return(StatusCode::FAILURE);
123  }
124  }
125  std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
126  if (!detectorStoreSvc->retrieveAllVersions(allVersions, name()).isSuccess()) {
127  ATH_MSG_DEBUG("Cannot retrieve DataHeader from DetectorStore.");
128  return(StatusCode::SUCCESS);
129  }
130  for (std::list<SG::ObjectWithVersion<DataHeader> >::iterator iter = allVersions.begin();
131  iter != allVersions.end(); ++iter) {
132  SG::ReadHandle<DataHeader> dataHeader = iter->dataObject;
133  ATH_MSG_DEBUG("The current File contains: " << dataHeader->size() << " objects");
134  for (const auto& element : *dataHeader) {
135  SG::TransientAddress* tadd = element.getAddress();
136  if (tadd->clID() == ClassID_traits<DataHeader>::ID()) {
137  delete tadd; tadd = 0;
138  } else {
139  ATH_MSG_DEBUG("preLoadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
140  tads.push_back(tadd);
141  }
142  EventSelectorAthenaPoolUtil::registerKeys(element, &*detectorStoreSvc);
143  }
144  }
145 
146  return(StatusCode::SUCCESS);
147 }
148 //________________________________________________________________________________
150  IAddressProvider::tadList& /*tads*/) {
151  return(StatusCode::SUCCESS);
152 }
153 //________________________________________________________________________________
155  SG::TransientAddress* /*tad*/,
156  const EventContext& /*ctx*/) {
157  return(StatusCode::FAILURE);
158 }
159 //__________________________________________________________________________
161  ATH_MSG_DEBUG("Try item: \"" << *m_inputCollectionsIterator << "\" from the collection list.");
162  PoolCollectionConverter* pCollCnv = new PoolCollectionConverter("ImplicitROOT",
163  *m_inputCollectionsIterator,
164  m_contextId,
165  "",
166  m_athenaPoolCnvSvc->getPoolSvc());
167  if (!pCollCnv->initialize().isSuccess()) {
168  // Close previous collection.
169  delete pCollCnv; pCollCnv = 0;
170  ATH_MSG_ERROR("Unable to open: " << *m_inputCollectionsIterator);
171  }
172  return(pCollCnv);
173 }
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:81
registerKeys.h
Helper functions for registering hash keys with the SG service.
IPoolSvc
This class provides the interface to the LCG POOL persistency software.
Definition: IPoolSvc.h:35
IAthenaPoolCnvSvc.h
This file contains the class definition for the IAthenaPoolCnvSvc interface class.
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PoolCollectionConverter
This class provides an interface to POOL collections.
Definition: PoolCollectionConverter.h:27
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
PoolCollectionConverter.h
This file contains the class definition for the PoolCollectionConverter class.
ICollectionCursor.h
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:154
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.
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition: Token.h:21
TokenAddress
This class provides a Generic Transient Address for POOL tokens.
Definition: TokenAddress.h:21
SG::TransientAddress::name
const std::string & name() const
Get the primary (hashed) SG key.
Definition: TransientAddress.h:208
EventSelectorAthenaPoolUtil::registerKeys
void registerKeys(const DataHeaderElement &dhe, StoreGateSvc *store)
Register all hash keys for one DH Element.
Definition: registerKeys.cxx:22
Token::fromString
Token & fromString(const std::string &from)
Build from the string representation of a token.
Definition: Token.cxx:133
CondProxyProvider::m_contextId
unsigned int m_contextId
Definition: CondProxyProvider.h:60
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DataHeader::size
int size() const
Definition: DataHeader.cxx:251
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:149
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:201
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CondProxyProvider::m_athenaPoolCnvSvc
ServiceHandle< IAthenaPoolCnvSvc > m_athenaPoolCnvSvc
Definition: CondProxyProvider.h:57
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CondProxyProvider::initialize
virtual StatusCode initialize() override
Required of all Gaudi Services.
Definition: CondProxyProvider.cxx:42
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:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Token::toString
virtual const std::string toString() const
Retrieve the string representation of the token.
Definition: Token.cxx:114
LArConditionsTestConfig.poolSvc
poolSvc
Definition: LArConditionsTestConfig.py:79
CondProxyProvider::getCollectionCnv
PoolCollectionConverter * getCollectionCnv()
Return pointer to new PoolCollectionConverter.
Definition: CondProxyProvider.cxx:160
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::initialize
StatusCode initialize()
Required by all Gaudi Services.
Definition: PoolCollectionConverter.cxx:69
CondProxyProvider::finalize
virtual StatusCode finalize() override
Required of all Gaudi Services.
Definition: CondProxyProvider.cxx:69
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:39
CondProxyProvider::m_inputCollectionsProp
StringArrayProperty m_inputCollectionsProp
InputCollections, vector with names of the input collections.
Definition: CondProxyProvider.h:65
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:31
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
ServiceHandle< StoreGateSvc >