ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaPoolAddressProviderSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9
11#include "registerKeys.h"
12
16
17// Framework
18#include "GaudiKernel/IClassIDSvc.h"
19#include "GaudiKernel/GenericAddress.h"
20#include "GaudiKernel/StatusCode.h"
21
25#include "StorageSvc/DbType.h"
26
27#include <vector>
28
29//________________________________________________________________________________
30AthenaPoolAddressProviderSvc::AthenaPoolAddressProviderSvc(const std::string& name, ISvcLocator* pSvcLocator) :
31 base_class(name, pSvcLocator),
32 m_metaDataStore("StoreGateSvc/MetaDataStore", name),
33 m_clidSvc("ClassIDSvc", name),
34 m_guid() {
35}
36//________________________________________________________________________________
39//________________________________________________________________________________
43//________________________________________________________________________________
45
46 ATH_CHECK( m_metaDataStore.retrieve() );
47 ATH_CHECK( m_clidSvc.retrieve() );
48
49 return StatusCode::SUCCESS;
50}
51//________________________________________________________________________________
54 if (storeID != StoreID::DETECTOR_STORE) {
55 return StatusCode::SUCCESS;
56 }
57 ServiceHandle<StoreGateSvc> detectorStoreSvc("DetectorStore", name());
58 ATH_CHECK( detectorStoreSvc.retrieve() );
59
60 SG::ReadHandle<DataHeader> dataHeader("CondProxyProvider", detectorStoreSvc.get());
61 if (!dataHeader.isValid()) {
62 ATH_MSG_DEBUG("Cannot retrieve DataHeader from DetectorStore.");
63 return StatusCode::SUCCESS;
64 }
65 ATH_MSG_DEBUG("The current File contains: " << dataHeader->size() << " objects");
66 for (const auto& element : *dataHeader) {
67 SG::TransientAddress* tadd = element.getAddress(pool::POOL_StorageType.type());
68 if (tadd->clID() == ClassID_traits<DataHeader>::ID()) {
69 delete tadd; tadd = nullptr;
70 } else {
71 ATH_MSG_DEBUG("preLoadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
72 tads.push_back(tadd);
73 }
74 EventSelectorAthenaPoolUtil::registerKeys(element, &*detectorStoreSvc);
75 }
76
77 return StatusCode::SUCCESS;
78}
79//________________________________________________________________________________
82 if (storeID != StoreID::EVENT_STORE && storeID != StoreID::PILEUP_STORE) {
83 return StatusCode::SUCCESS;
84 }
85
86 Guid thisFile = Guid::null();
87 const DataHeader* dataHeader = nullptr;
88 if (dataHeader == nullptr) { // New file (or reading DataHeader)
89 SG::ReadHandle<DataHeader> eventDataHeader(m_dataHeaderKey.value(), eventStore());
90 if (!eventDataHeader.isValid()) {
91 ATH_MSG_ERROR("Cannot retrieve DataHeader from StoreGate: " << m_dataHeaderKey);
92 return StatusCode::FAILURE;
93 }
94 dataHeader = eventDataHeader.cptr();
95 }
96 // second data header
97 if (m_attrListKey.value() != "") {
98 const AthenaAttributeList* attrList = nullptr;
99 std::string tokenStr;
100 if (eventStore()->retrieve(attrList, m_attrListKey.value()).isSuccess()) {
101 try {
102 tokenStr = (*attrList)["eventRef_secondary"].data<std::string>();
103 ATH_MSG_DEBUG("found AthenaAttribute, name = eventRef_secondary = " << tokenStr);
104 } catch (std::exception &e) {
105 ATH_MSG_ERROR(e.what());
106 return StatusCode::FAILURE;
107 }
108 } else {
109 ATH_MSG_ERROR("Cannot find AthenaAttribute, key = " << m_attrListKey.value());
110 return StatusCode::FAILURE;
111 }
112 IOpaqueAddress* iop = new GenericAddress(pool::POOL_StorageType.type(), ClassID_traits<DataHeader>::ID(), tokenStr, "SecondaryEventSelector");
113 if (!eventStore()->recordAddress(iop).isSuccess()) {
114 ATH_MSG_ERROR("Cannot record address to StoreGate with token string: " << tokenStr);
115 return StatusCode::FAILURE;
116 }
117 ATH_MSG_DEBUG("Created dataHeader SecondaryEventSelector");
118 }
120 bool doRegister = dataHeader->dhFormToken().empty() ||
121 m_dhFormKeys.emplace (dataHeader->dhFormToken()).second;
122 ATH_MSG_DEBUG("The current Event contains: " << dataHeader->size() << " objects");
123 for (const auto& element : *dataHeader) {
124 if (doRegister) {
126 }
127 SG::TransientAddress* tadd = element.getAddress(pool::POOL_StorageType.type());
128 if (tadd->clID() == ClassID_traits<DataHeader>::ID()) { // self reference
129 delete tadd; tadd = nullptr;
130 } else {
131 ATH_MSG_DEBUG("loadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
132 tadd->setProvider(this, storeID);
133 tads.push_back(tadd);
134 }
135 }
136 m_guid = thisFile;
137 return StatusCode::SUCCESS;
138}
139//________________________________________________________________________________
141 SG::TransientAddress* /*tad*/,
142 const EventContext& /*ctx*/) {
143 return StatusCode::FAILURE;
144}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
This file contains the class definition for the AthenaPoolAddressProviderSvc class.
This file contains the class definition for the DataHeader and DataHeaderElement classes.
An AttributeList represents a logical row of attributes in a metadata table.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
This file contains the class definition for the TokenAddress class.
An AttributeList represents a logical row of attributes in a metadata table.
ServiceHandle< StoreGateSvc > m_metaDataStore
StoreGateSvc * eventStore() const
Return pointer to active event SG.
std::unordered_set< std::string > m_dhFormKeys
Set of DataHeader form keys for which we've already done registerKeys.
ServiceHandle< IClassIDSvc > m_clidSvc
AthenaPoolAddressProviderSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
virtual StatusCode initialize() override
Required of all Gaudi Services.
virtual StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress *tad, const EventContext &ctx) override
Update a transient address.
virtual StatusCode loadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
Get all addresses for this event from provider.
Gaudi::Property< std::string > m_attrListKey
virtual StatusCode preLoadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
Get all addresses from provider.
Gaudi::Property< std::string > m_dataHeaderKey
This class provides the layout for summary information stored for data written to POOL.
Definition DataHeader.h:123
const std::string & dhFormToken() const
Form token, to be able to tell when the form changes.
int size() const
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition Guid.h:25
static const Guid & null() noexcept
NULL-Guid: static class method.
Definition Guid.cxx:14
std::list< SG::TransientAddress * > tadList
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
CLID clID() const
Retrieve string key:
const std::string & name() const
Get the primary (hashed) SG key.
void setProvider(IAddressProvider *provider, StoreID::type storeID)
The Athena Transient Store API.
static StoreGateSvc * currentStoreGate()
get current StoreGate
@ EVENT_STORE
Definition StoreID.h:26
@ DETECTOR_STORE
Definition StoreID.h:27
@ PILEUP_STORE
Definition StoreID.h:31
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.