ATLAS Offline Software
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 
12 #include "registerKeys.h"
13 
17 
18 // Framework
19 #include "GaudiKernel/IClassIDSvc.h"
20 #include "GaudiKernel/GenericAddress.h"
21 #include "GaudiKernel/StatusCode.h"
22 
23 #include "StoreGate/StoreGateSvc.h"
24 #include "StoreGate/ReadHandle.h"
25 #include "StoreGate/WriteHandle.h"
26 #include "StorageSvc/DbType.h"
27 
28 #include <vector>
29 
30 //________________________________________________________________________________
31 AthenaPoolAddressProviderSvc::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 //________________________________________________________________________________
39 }
40 //________________________________________________________________________________
43 }
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
AthenaPoolAddressProviderSvc::loadAddresses
virtual StatusCode loadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
Get all addresses for this event from provider.
Definition: AthenaPoolAddressProviderSvc.cxx:81
CurrentEventStore.h
Hold a pointer to the current event store.
registerKeys.h
Helper functions for registering hash keys with the SG service.
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
SG::TransientAddress
Definition: TransientAddress.h:34
AthenaPoolAddressProviderSvc::m_guid
Guid m_guid
Definition: AthenaPoolAddressProviderSvc.h:57
AthenaPoolAddressProviderSvc::m_clidSvc
ServiceHandle< IClassIDSvc > m_clidSvc
Definition: AthenaPoolAddressProviderSvc.h:56
DbType.h
AthenaPoolAddressProviderSvc::m_metaDataStore
ServiceHandle< StoreGateSvc > m_metaDataStore
Definition: AthenaPoolAddressProviderSvc.h:55
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
AthenaPoolAddressProviderSvc::updateAddress
virtual StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress *tad, const EventContext &ctx) override
Update a transient address.
Definition: AthenaPoolAddressProviderSvc.cxx:141
SG::TransientAddress::name
const std::string & name() const
Get the primary (hashed) SG key.
Definition: TransientAddress.h:214
AthenaPoolAddressProviderSvc::m_dataHeaderKey
Gaudi::Property< std::string > m_dataHeaderKey
Definition: AthenaPoolAddressProviderSvc.h:62
EventSelectorAthenaPoolUtil::registerKeys
void registerKeys(const DataHeaderElement &dhe, StoreGateSvc *store)
Register all hash keys for one DH Element.
Definition: registerKeys.cxx:22
WriteHandle.h
Handle class for recording to StoreGate.
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:122
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
StoreID::PILEUP_STORE
@ PILEUP_STORE
Definition: StoreID.h:31
DataHeader
This class provides the layout for summary information stored for data written to POOL.
Definition: DataHeader.h:123
DataHeader::size
int size() const
Definition: DataHeader.cxx:245
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
SG::TransientAddress::clID
CLID clID() const
Retrieve string key:
Definition: TransientAddress.h:207
StoreGateSvc::currentStoreGate
static StoreGateSvc * currentStoreGate()
get current StoreGate
Definition: StoreGateSvc.cxx:51
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:37
calibdata.exception
exception
Definition: calibdata.py:495
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
DataHeader.h
This file contains the class definition for the DataHeader and DataHeaderElement classes.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AthenaPoolAddressProviderSvc::m_attrListKey
Gaudi::Property< std::string > m_attrListKey
Definition: AthenaPoolAddressProviderSvc.h:65
StoreID::DETECTOR_STORE
@ DETECTOR_STORE
Definition: StoreID.h:27
SG::TransientAddress::setProvider
void setProvider(IAddressProvider *provider, StoreID::type storeID)
Definition: TransientAddress.h:337
AthenaPoolAddressProviderSvc::m_dhFormKeys
std::unordered_set< std::string > m_dhFormKeys
Set of DataHeader form keys for which we've already done registerKeys.
Definition: AthenaPoolAddressProviderSvc.h:59
AthenaPoolAddressProviderSvc::~AthenaPoolAddressProviderSvc
virtual ~AthenaPoolAddressProviderSvc()
Destructor.
Definition: AthenaPoolAddressProviderSvc.cxx:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
AthenaAttributeList.h
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
AthenaPoolAddressProviderSvc.h
This file contains the class definition for the AthenaPoolAddressProviderSvc class.
Guid::null
static const Guid & null() noexcept
NULL-Guid: static class method.
Definition: Guid.cxx:14
TokenAddress.h
This file contains the class definition for the TokenAddress class.
Guid
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition: Guid.h:25
StoreID::type
type
Definition: StoreID.h:24
AthenaPoolAddressProviderSvc::AthenaPoolAddressProviderSvc
AthenaPoolAddressProviderSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
Definition: AthenaPoolAddressProviderSvc.cxx:31
AthenaPoolAddressProviderSvc::preLoadAddresses
virtual StatusCode preLoadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
Get all addresses from provider.
Definition: AthenaPoolAddressProviderSvc.cxx:53
IAddressProvider::tadList
std::list< SG::TransientAddress * > tadList
Definition: IAddressProvider.h:32
StoreID::EVENT_STORE
@ EVENT_STORE
Definition: StoreID.h:26
ReadHandle.h
Handle class for reading from StoreGate.
AthenaPoolAddressProviderSvc::initialize
virtual StatusCode initialize() override
Required of all Gaudi Services.
Definition: AthenaPoolAddressProviderSvc.cxx:45
AthenaPoolAddressProviderSvc::eventStore
StoreGateSvc * eventStore() const
Return pointer to active event SG.
Definition: AthenaPoolAddressProviderSvc.cxx:41
StoreGateSvc.h
DataHeader::dhFormToken
const std::string & dhFormToken() const
Form token, to be able to tell when the form changes.
Definition: DataHeader.cxx:302
ServiceHandle< StoreGateSvc >