ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaPoolAddressProviderSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9
12#include "registerKeys.h"
13
17
18// Framework
19#include "GaudiKernel/IClassIDSvc.h"
20#include "GaudiKernel/GenericAddress.h"
21#include "GaudiKernel/StatusCode.h"
22
26#include "StorageSvc/DbType.h"
27
28#include <vector>
29
30//________________________________________________________________________________
31AthenaPoolAddressProviderSvc::AthenaPoolAddressProviderSvc(const std::string& name, ISvcLocator* pSvcLocator) :
32 base_class(name, pSvcLocator),
33 m_metaDataStore("StoreGateSvc/MetaDataStore", name),
34 m_clidSvc("ClassIDSvc", name),
35 m_guid() {
36}
37//________________________________________________________________________________
40//________________________________________________________________________________
44//________________________________________________________________________________
46
47 ATH_CHECK( m_metaDataStore.retrieve() );
48 ATH_CHECK( m_clidSvc.retrieve() );
49
50 return StatusCode::SUCCESS;
51}
52//________________________________________________________________________________
55 if (storeID != StoreID::DETECTOR_STORE) {
56 return StatusCode::SUCCESS;
57 }
58 ServiceHandle<StoreGateSvc> detectorStoreSvc("DetectorStore", name());
59 ATH_CHECK( detectorStoreSvc.retrieve() );
60
61 SG::ReadHandle<DataHeader> dataHeader("CondProxyProvider", detectorStoreSvc->name());
62 if (!dataHeader.isValid()) {
63 ATH_MSG_DEBUG("Cannot retrieve DataHeader from DetectorStore.");
64 return StatusCode::SUCCESS;
65 }
66 ATH_MSG_DEBUG("The current File contains: " << dataHeader->size() << " objects");
67 for (const auto& element : *dataHeader) {
68 SG::TransientAddress* tadd = element.getAddress(pool::POOL_StorageType.type());
69 if (tadd->clID() == ClassID_traits<DataHeader>::ID()) {
70 delete tadd; tadd = nullptr;
71 } else {
72 ATH_MSG_DEBUG("preLoadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
73 tads.push_back(tadd);
74 }
75 EventSelectorAthenaPoolUtil::registerKeys(element, &*detectorStoreSvc);
76 }
77
78 return StatusCode::SUCCESS;
79}
80//________________________________________________________________________________
83 if (storeID != StoreID::EVENT_STORE && storeID != StoreID::PILEUP_STORE) {
84 return StatusCode::SUCCESS;
85 }
86
87 Guid thisFile = Guid::null();
88 const DataHeader* dataHeader = nullptr;
89 if (dataHeader == nullptr) { // New file (or reading DataHeader)
90 SG::ReadHandle<DataHeader> eventDataHeader(m_dataHeaderKey.value(), eventStore()->name());
91 if (!eventDataHeader.isValid()) {
92 ATH_MSG_ERROR("Cannot retrieve DataHeader from StoreGate: " << m_dataHeaderKey);
93 return StatusCode::FAILURE;
94 }
95 dataHeader = eventDataHeader.cptr();
96 }
97 // second data header
98 if (m_attrListKey.value() != "") {
99 const AthenaAttributeList* attrList = nullptr;
100 std::string tokenStr;
101 if (eventStore()->retrieve(attrList, m_attrListKey.value()).isSuccess()) {
102 try {
103 tokenStr = (*attrList)["eventRef_secondary"].data<std::string>();
104 ATH_MSG_DEBUG("found AthenaAttribute, name = eventRef_secondary = " << tokenStr);
105 } catch (std::exception &e) {
106 ATH_MSG_ERROR(e.what());
107 return StatusCode::FAILURE;
108 }
109 } else {
110 ATH_MSG_ERROR("Cannot find AthenaAttribute, key = " << m_attrListKey.value());
111 return StatusCode::FAILURE;
112 }
113 IOpaqueAddress* iop = new GenericAddress(pool::POOL_StorageType.type(), ClassID_traits<DataHeader>::ID(), tokenStr, "SecondaryEventSelector");
114 if (!eventStore()->recordAddress(iop).isSuccess()) {
115 ATH_MSG_ERROR("Cannot record address to StoreGate with token string: " << tokenStr);
116 return StatusCode::FAILURE;
117 }
118 ATH_MSG_DEBUG("Created dataHeader SecondaryEventSelector");
119 }
121 bool doRegister = dataHeader->dhFormToken().empty() ||
122 m_dhFormKeys.emplace (dataHeader->dhFormToken()).second;
123 ATH_MSG_DEBUG("The current Event contains: " << dataHeader->size() << " objects");
124 for (const auto& element : *dataHeader) {
125 if (doRegister) {
127 }
128 SG::TransientAddress* tadd = element.getAddress(pool::POOL_StorageType.type());
129 if (tadd->clID() == ClassID_traits<DataHeader>::ID()) { // self reference
130 delete tadd; tadd = nullptr;
131 } else {
132 ATH_MSG_DEBUG("loadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
133 tadd->setProvider(this, storeID);
134 tads.push_back(tadd);
135 }
136 }
137 m_guid = thisFile;
138 return StatusCode::SUCCESS;
139}
140//________________________________________________________________________________
142 SG::TransientAddress* /*tad*/,
143 const EventContext& /*ctx*/) {
144 return StatusCode::FAILURE;
145}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(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.
Hold a pointer to the current event store.
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:98
Helper functions for registering hash keys with the SG service.