Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 #include "RootUtils/APRDefaults.h"
19 
20 // Framework
21 #include "GaudiKernel/ClassID.h"
22 #include "GaudiKernel/StatusCode.h"
23 
24 #include "StoreGate/StoreGateSvc.h"
25 
26 // Pool
28 
29 #include <vector>
30 
31 //________________________________________________________________________________
32 CondProxyProvider::CondProxyProvider(const std::string& name, ISvcLocator* pSvcLocator) :
33  base_class(name, pSvcLocator),
34  m_athenaPoolCnvSvc("AthenaPoolCnvSvc", name),
35  m_poolCollectionConverter(0),
36  m_contextId(IPoolSvc::kInputStream)
37  {
38 }
39 //________________________________________________________________________________
41 }
42 //________________________________________________________________________________
44  ATH_MSG_INFO("Initializing " << name());
45  // Check for input collection
46  if (m_inputCollectionsProp.value().size() == 0) {
47  return(StatusCode::FAILURE);
48  }
49  // Retrieve AthenaPoolCnvSvc
50  ATH_CHECK( m_athenaPoolCnvSvc.retrieve() );
51 
52  // Get PoolSvc and connect as "Conditions"
53  IPoolSvc *poolSvc = m_athenaPoolCnvSvc->getPoolSvc();
54  m_contextId = poolSvc->getInputContext("Conditions");
56 
57  for( const auto &inp : m_inputCollectionsProp.value() ) {
58  ATH_MSG_INFO("Inputs: " << inp);
59  }
60  // Initialize
61  m_inputCollectionsIterator = m_inputCollectionsProp.value().begin();
62  // Create an m_poolCollectionConverter to read the objects in
63  m_poolCollectionConverter = getCollectionCnv();
64  if (m_poolCollectionConverter == 0) {
65  return(StatusCode::FAILURE);
66  }
67  return(StatusCode::SUCCESS);
68 }
69 //________________________________________________________________________________
71  if (m_poolCollectionConverter != 0) {
72  m_poolCollectionConverter->disconnectDb().ignore();
73  delete m_poolCollectionConverter; m_poolCollectionConverter = 0;
74  }
75  // Release AthenaPoolCnvSvc
76  if (!m_athenaPoolCnvSvc.release().isSuccess()) {
77  ATH_MSG_WARNING("Cannot release AthenaPoolCnvSvc.");
78  }
79  return(StatusCode::SUCCESS);
80 }
81 //________________________________________________________________________________
84  if (storeID != StoreID::DETECTOR_STORE) {
85  return(StatusCode::SUCCESS);
86  }
87  ServiceHandle<StoreGateSvc> detectorStoreSvc("DetectorStore", name());
88  // Retrieve DetectorStoreSvc
89  ATH_CHECK( detectorStoreSvc.retrieve() );
90 
91  if (m_poolCollectionConverter == nullptr) {
92  return StatusCode::FAILURE;
93  }
94 
95  // Create DataHeader iterators
96  pool::ICollectionCursor* headerIterator = &m_poolCollectionConverter->selectAll();
97  for (int verNumber = 0; verNumber < 100; verNumber++) {
98  if (!headerIterator->next()) {
99  m_poolCollectionConverter->disconnectDb().ignore();
100  delete m_poolCollectionConverter; m_poolCollectionConverter = 0;
101  ++m_inputCollectionsIterator;
102  if (m_inputCollectionsIterator != m_inputCollectionsProp.value().end()) {
103  // Create PoolCollectionConverter for input file
104  m_poolCollectionConverter = getCollectionCnv();
105  if (m_poolCollectionConverter == 0) {
106  return(StatusCode::FAILURE);
107  }
108  // Get DataHeader iterator
109  headerIterator = &m_poolCollectionConverter->selectAll();
110  if (!headerIterator->next()) {
111  return(StatusCode::FAILURE);
112  }
113  } else {
114  break;
115  }
116  }
117  SG::VersionedKey myVersKey(name(), verNumber);
118  auto token = std::make_unique<Token>();
119  token->fromString(headerIterator->eventRef().toString());
120  TokenAddress* tokenAddr = new TokenAddress(POOL_StorageType, ClassID_traits<DataHeader>::ID(), "", myVersKey, m_contextId, std::move(token));
121  if (!detectorStoreSvc->recordAddress(tokenAddr).isSuccess()) {
122  ATH_MSG_ERROR("Cannot record DataHeader.");
123  return(StatusCode::FAILURE);
124  }
125  }
126  std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
127  if (!detectorStoreSvc->retrieveAllVersions(allVersions, name()).isSuccess()) {
128  ATH_MSG_DEBUG("Cannot retrieve DataHeader from DetectorStore.");
129  return(StatusCode::SUCCESS);
130  }
131  for (std::list<SG::ObjectWithVersion<DataHeader> >::iterator iter = allVersions.begin();
132  iter != allVersions.end(); ++iter) {
133  SG::ReadHandle<DataHeader> dataHeader = iter->dataObject;
134  ATH_MSG_DEBUG("The current File contains: " << dataHeader->size() << " objects");
135  for (const auto& element : *dataHeader) {
136  SG::TransientAddress* tadd = element.getAddress();
137  if (tadd->clID() == ClassID_traits<DataHeader>::ID()) {
138  delete tadd; tadd = 0;
139  } else {
140  ATH_MSG_DEBUG("preLoadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
141  tads.push_back(tadd);
142  }
143  EventSelectorAthenaPoolUtil::registerKeys(element, &*detectorStoreSvc);
144  }
145  }
146 
147  return(StatusCode::SUCCESS);
148 }
149 //________________________________________________________________________________
151  IAddressProvider::tadList& /*tads*/) {
152  return(StatusCode::SUCCESS);
153 }
154 //________________________________________________________________________________
156  SG::TransientAddress* /*tad*/,
157  const EventContext& /*ctx*/) {
158  return(StatusCode::FAILURE);
159 }
160 //__________________________________________________________________________
162  ATH_MSG_DEBUG("Try item: \"" << *m_inputCollectionsIterator << "\" from the collection list.");
163  PoolCollectionConverter* pCollCnv = new PoolCollectionConverter(std::string("ImplicitROOT:") + APRDefaults::TTreeNames::DataHeader,
164  *m_inputCollectionsIterator,
165  m_contextId,
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:82
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:67
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:155
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:208
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:60
APRDefaults.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DataHeader::size
int size() const
Definition: DataHeader.cxx:232
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:150
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:37
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:43
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
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:79
CondProxyProvider::getCollectionCnv
PoolCollectionConverter * getCollectionCnv()
Return pointer to new PoolCollectionConverter.
Definition: CondProxyProvider.cxx:161
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:67
CondProxyProvider::finalize
virtual StatusCode finalize() override
Required of all Gaudi Services.
Definition: CondProxyProvider.cxx:70
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:40
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: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
ServiceHandle< StoreGateSvc >