ATLAS Offline Software
CondProxyProvider.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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  ::AthService(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  if (!::AthService::initialize().isSuccess()) {
45  ATH_MSG_FATAL("Cannot initialize AthService base class.");
46  return(StatusCode::FAILURE);
47  }
48  // Check for input collection
49  if (m_inputCollectionsProp.value().size() == 0) {
50  return(StatusCode::FAILURE);
51  }
52  // Retrieve AthenaPoolCnvSvc
53  if (!m_athenaPoolCnvSvc.retrieve().isSuccess()) {
54  ATH_MSG_FATAL("Cannot get AthenaPoolCnvSvc.");
55  return(StatusCode::FAILURE);
56  }
57  // Get PoolSvc and connect as "Conditions"
58  IPoolSvc *poolSvc = m_athenaPoolCnvSvc->getPoolSvc();
59  m_contextId = poolSvc->getInputContext("Conditions");
61  if (!status.isSuccess()) {
62  ATH_MSG_FATAL("Cannot connect to Database.");
63  return(StatusCode::FAILURE);
64  }
65  for( const auto &inp : m_inputCollectionsProp.value() ) {
66  ATH_MSG_INFO("Inputs: " << inp);
67  }
68  // Initialize
69  m_inputCollectionsIterator = m_inputCollectionsProp.value().begin();
70  // Create an m_poolCollectionConverter to read the objects in
71  m_poolCollectionConverter = getCollectionCnv();
72  if (m_poolCollectionConverter == 0) {
73  return(StatusCode::FAILURE);
74  }
75  return(StatusCode::SUCCESS);
76 }
77 //________________________________________________________________________________
79  if (m_poolCollectionConverter != 0) {
80  m_poolCollectionConverter->disconnectDb().ignore();
81  delete m_poolCollectionConverter; m_poolCollectionConverter = 0;
82  }
83  // Release AthenaPoolCnvSvc
84  if (!m_athenaPoolCnvSvc.release().isSuccess()) {
85  ATH_MSG_WARNING("Cannot release AthenaPoolCnvSvc.");
86  }
87  return(::AthService::finalize());
88 }
89 //________________________________________________________________________________
90 StatusCode CondProxyProvider::queryInterface(const InterfaceID& riid, void** ppvInterface) {
91  return(::AthService::queryInterface(riid, ppvInterface));
92 }
93 //________________________________________________________________________________
96  if (storeID != StoreID::DETECTOR_STORE) {
97  return(StatusCode::SUCCESS);
98  }
99  ServiceHandle<StoreGateSvc> detectorStoreSvc("DetectorStore", name());
100  // Retrieve DetectorStoreSvc
101  if (!detectorStoreSvc.retrieve().isSuccess()) {
102  ATH_MSG_FATAL("Cannot get DetectorStoreSvc.");
103  return(StatusCode::FAILURE);
104  }
105 
106  if (m_poolCollectionConverter == nullptr) {
107  return StatusCode::FAILURE;
108  }
109 
110  // Create DataHeader iterators
111  pool::ICollectionCursor* headerIterator = &m_poolCollectionConverter->executeQuery();
112  for (int verNumber = 0; verNumber < 100; verNumber++) {
113  if (!headerIterator->next()) {
114  m_poolCollectionConverter->disconnectDb().ignore();
115  delete m_poolCollectionConverter; m_poolCollectionConverter = 0;
116  ++m_inputCollectionsIterator;
117  if (m_inputCollectionsIterator != m_inputCollectionsProp.value().end()) {
118  // Create PoolCollectionConverter for input file
119  m_poolCollectionConverter = getCollectionCnv();
120  if (m_poolCollectionConverter == 0) {
121  return(StatusCode::FAILURE);
122  }
123  // Get DataHeader iterator
124  headerIterator = &m_poolCollectionConverter->executeQuery();
125  if (!headerIterator->next()) {
126  return(StatusCode::FAILURE);
127  }
128  } else {
129  break;
130  }
131  }
132  SG::VersionedKey myVersKey(name(), verNumber);
133  Token* token = new Token;
134  token->fromString(headerIterator->eventRef().toString());
135  TokenAddress* tokenAddr = new TokenAddress(POOL_StorageType, ClassID_traits<DataHeader>::ID(), "", myVersKey, m_contextId, token);
136  if (!detectorStoreSvc->recordAddress(tokenAddr).isSuccess()) {
137  ATH_MSG_ERROR("Cannot record DataHeader.");
138  return(StatusCode::FAILURE);
139  }
140  }
141  std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
142  if (!detectorStoreSvc->retrieveAllVersions(allVersions, name()).isSuccess()) {
143  ATH_MSG_DEBUG("Cannot retrieve DataHeader from DetectorStore.");
144  return(StatusCode::SUCCESS);
145  }
146  for (std::list<SG::ObjectWithVersion<DataHeader> >::iterator iter = allVersions.begin();
147  iter != allVersions.end(); ++iter) {
148  SG::ReadHandle<DataHeader> dataHeader = iter->dataObject;
149  ATH_MSG_DEBUG("The current File contains: " << dataHeader->size() << " objects");
150  for (const auto& element : *dataHeader) {
151  SG::TransientAddress* tadd = element.getAddress();
152  if (tadd->clID() == ClassID_traits<DataHeader>::ID()) {
153  delete tadd; tadd = 0;
154  } else {
155  ATH_MSG_DEBUG("preLoadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
156  tads.push_back(tadd);
157  }
158  EventSelectorAthenaPoolUtil::registerKeys(element, &*detectorStoreSvc);
159  }
160  }
161  if (!detectorStoreSvc.release().isSuccess()) {
162  ATH_MSG_WARNING("Cannot release DetectorStoreSvc.");
163  }
164  return(StatusCode::SUCCESS);
165 }
166 //________________________________________________________________________________
168  IAddressProvider::tadList& /*tads*/) {
169  return(StatusCode::SUCCESS);
170 }
171 //________________________________________________________________________________
173  SG::TransientAddress* /*tad*/,
174  const EventContext& /*ctx*/) {
175  return(StatusCode::FAILURE);
176 }
177 //__________________________________________________________________________
179  ATH_MSG_DEBUG("Try item: \"" << *m_inputCollectionsIterator << "\" from the collection list.");
180  PoolCollectionConverter* pCollCnv = new PoolCollectionConverter("ImplicitROOT",
181  *m_inputCollectionsIterator,
182  m_contextId,
183  "",
184  m_athenaPoolCnvSvc->getPoolSvc());
185  if (!pCollCnv->initialize().isSuccess()) {
186  // Close previous collection.
187  delete pCollCnv; pCollCnv = 0;
188  ATH_MSG_ERROR("Unable to open: " << *m_inputCollectionsIterator);
189  }
190  return(pCollCnv);
191 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CondProxyProvider::finalize
virtual StatusCode finalize()
Required of all Gaudi Services.
Definition: CondProxyProvider.cxx:78
registerKeys.h
Helper functions for registering hash keys with the SG service.
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
IPoolSvc
This class provides the interface to the LCG POOL persistency software.
Definition: IPoolSvc.h:36
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.
initialize
void initialize()
Definition: run_EoverP.cxx:894
ICollectionCursor.h
SG::TransientAddress
Definition: TransientAddress.h:32
pool::ICollectionCursor::next
virtual bool next()=0
Advances the cursor to the next row of the query result set.
CondProxyProvider::preLoadAddresses
virtual StatusCode preLoadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads)
Get all addresses from provider.
Definition: CondProxyProvider.cxx:94
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:62
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
AthService
Definition: AthService.h:32
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
CondProxyProvider::m_athenaPoolCnvSvc
ServiceHandle< IAthenaPoolCnvSvc > m_athenaPoolCnvSvc
Definition: CondProxyProvider.h:59
CondProxyProvider::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Does this object satisfy a given interface? See Gaudi documentation for details.
Definition: CondProxyProvider.cxx:90
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
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:195
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:178
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
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:67
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
merge.status
status
Definition: merge.py:17
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::loadAddresses
virtual StatusCode loadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads)
Implementation of the loadAddresses function without any functionality.
Definition: CondProxyProvider.cxx:167
CondProxyProvider::initialize
virtual StatusCode initialize()
Required of all Gaudi Services.
Definition: CondProxyProvider.cxx:42
CondProxyProvider::updateAddress
virtual StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress *tad, const EventContext &ctx)
Update a transient address.
Definition: CondProxyProvider.cxx:172
ServiceHandle< StoreGateSvc >