ATLAS Offline Software
AthenaPoolAddressProviderSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
27 #include <vector>
28 
29 //________________________________________________________________________________
30 AthenaPoolAddressProviderSvc::AthenaPoolAddressProviderSvc(const std::string& name, ISvcLocator* pSvcLocator) :
31  base_class(name, pSvcLocator),
32  m_metaDataStore("MetaDataStore", name),
33  m_clidSvc("ClassIDSvc", name),
34  m_guid() {
35 }
36 //________________________________________________________________________________
38 }
39 //________________________________________________________________________________
42 }
43 //________________________________________________________________________________
45 
46  ATH_CHECK( m_metaDataStore.retrieve() );
47  ATH_CHECK( m_clidSvc.retrieve() );
48 
49  return(StatusCode::SUCCESS);
50 }
51 //________________________________________________________________________________
53  // Release ClassIDSvc
54  if (!m_clidSvc.release().isSuccess()) {
55  ATH_MSG_WARNING("Cannot release ClassIDSvc.");
56  }
57  // Release MetaDataStore
58  if (!m_metaDataStore.release().isSuccess()) {
59  ATH_MSG_WARNING("Cannot release MetaDataStore.");
60  }
61 
62  return(StatusCode::SUCCESS);
63 }
64 //________________________________________________________________________________
67  if (storeID != StoreID::DETECTOR_STORE) {
68  return(StatusCode::SUCCESS);
69  }
70  ServiceHandle<StoreGateSvc> detectorStoreSvc("DetectorStore", name());
71  ATH_CHECK( detectorStoreSvc.retrieve() );
72 
73  SG::ReadHandle<DataHeader> dataHeader("CondProxyProvider", detectorStoreSvc->name());
74  if (!dataHeader.isValid()) {
75  ATH_MSG_DEBUG("Cannot retrieve DataHeader from DetectorStore.");
76  return(StatusCode::SUCCESS);
77  }
78  ATH_MSG_DEBUG("The current File contains: " << dataHeader->size() << " objects");
79  for (const auto& element : *dataHeader) {
80  SG::TransientAddress* tadd = element.getAddress();
81  if (tadd->clID() == ClassID_traits<DataHeader>::ID()) {
82  delete tadd; tadd = nullptr;
83  } else {
84  ATH_MSG_DEBUG("preLoadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
85  tads.push_back(tadd);
86  }
87  EventSelectorAthenaPoolUtil::registerKeys(element, &*detectorStoreSvc);
88  }
89 
90  return(StatusCode::SUCCESS);
91 }
92 //________________________________________________________________________________
95  if (storeID != StoreID::EVENT_STORE && storeID != StoreID::PILEUP_STORE) {
96  return(StatusCode::SUCCESS);
97  }
98 
99  Guid thisFile = Guid::null();
100  const DataHeader* dataHeader = nullptr;
101  if (dataHeader == nullptr) { // New file (or reading DataHeader)
102  SG::ReadHandle<DataHeader> eventDataHeader(m_dataHeaderKey.value(), eventStore()->name());
103  if (!eventDataHeader.isValid()) {
104  ATH_MSG_ERROR("Cannot retrieve DataHeader from StoreGate: " << m_dataHeaderKey);
105  return(StatusCode::FAILURE);
106  }
107  dataHeader = eventDataHeader.cptr();
108  }
109  // second data header
110  if (m_attrListKey.value() != "") {
111  const AthenaAttributeList* attrList = nullptr;
112  std::string tokenStr;
113  if (eventStore()->retrieve(attrList, m_attrListKey.value()).isSuccess()) {
114  try {
115  tokenStr = (*attrList)["eventRef_secondary"].data<std::string>();
116  ATH_MSG_DEBUG("found AthenaAttribute, name = eventRef_secondary = " << tokenStr);
117  } catch (std::exception &e) {
118  ATH_MSG_ERROR(e.what());
119  return (StatusCode::FAILURE);
120  }
121  } else {
122  ATH_MSG_ERROR("Cannot find AthenaAttribute, key = " << m_attrListKey.value());
123  return (StatusCode::FAILURE);
124  }
125  IOpaqueAddress* iop = new GenericAddress(POOL_StorageType, ClassID_traits<DataHeader>::ID(), tokenStr, "SecondaryEventSelector");
126  if (!eventStore()->recordAddress(iop).isSuccess()) {
127  ATH_MSG_ERROR("Cannot record address to StoreGate with token string: " << tokenStr);
128  return(StatusCode::FAILURE);
129  }
130  ATH_MSG_DEBUG("Created dataHeader SecondaryEventSelector");
131  }
132  ATH_MSG_DEBUG("The current Event contains: " << dataHeader->size() << " objects");
133  for (const auto& element : *dataHeader) {
134  SG::TransientAddress* tadd = element.getAddress();
135  if (tadd->clID() == ClassID_traits<DataHeader>::ID()) { // self reference
136  delete tadd; tadd = nullptr;
137  } else {
138  ATH_MSG_DEBUG("loadAddresses: DataObject address, clid = " << tadd->clID() << ", name = " << tadd->name());
139  tadd->setProvider(this, storeID);
140  tads.push_back(tadd);
141  }
143  }
144  m_guid = thisFile;
145  return(StatusCode::SUCCESS);
146 }
147 //________________________________________________________________________________
149  SG::TransientAddress* /*tad*/,
150  const EventContext& /*ctx*/) {
151  return(StatusCode::FAILURE);
152 }
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:93
CurrentEventStore.h
Hold a pointer to the current event store.
registerKeys.h
Helper functions for registering hash keys with the SG service.
Guid::null
static const Guid & null()
NULL-Guid: static class method.
Definition: Guid.cxx:18
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::TransientAddress
Definition: TransientAddress.h:32
AthenaPoolAddressProviderSvc::m_guid
Guid m_guid
Definition: AthenaPoolAddressProviderSvc.h:58
AthenaPoolAddressProviderSvc::m_clidSvc
ServiceHandle< IClassIDSvc > m_clidSvc
Definition: AthenaPoolAddressProviderSvc.h:57
AthenaPoolAddressProviderSvc::m_metaDataStore
ServiceHandle< StoreGateSvc > m_metaDataStore
Definition: AthenaPoolAddressProviderSvc.h:56
AthenaPoolAddressProviderSvc::updateAddress
virtual StatusCode updateAddress(StoreID::type storeID, SG::TransientAddress *tad, const EventContext &ctx) override
Update a transient address.
Definition: AthenaPoolAddressProviderSvc.cxx:148
SG::TransientAddress::name
const std::string & name() const
Get the primary (hashed) SG key.
Definition: TransientAddress.h:208
AthenaPoolAddressProviderSvc::m_dataHeaderKey
Gaudi::Property< std::string > m_dataHeaderKey
Definition: AthenaPoolAddressProviderSvc.h:61
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:125
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:124
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
SG::TransientAddress::clID
CLID clID() const
Retrieve string key:
Definition: TransientAddress.h:201
StoreGateSvc::currentStoreGate
static StoreGateSvc * currentStoreGate()
get current StoreGate
Definition: StoreGateSvc.cxx:69
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
calibdata.exception
exception
Definition: calibdata.py:496
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:64
StoreID::DETECTOR_STORE
@ DETECTOR_STORE
Definition: StoreID.h:27
SG::TransientAddress::setProvider
void setProvider(IAddressProvider *provider, StoreID::type storeID)
Definition: TransientAddress.h:317
AthenaPoolAddressProviderSvc::~AthenaPoolAddressProviderSvc
virtual ~AthenaPoolAddressProviderSvc()
Destructor.
Definition: AthenaPoolAddressProviderSvc.cxx:37
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AthenaPoolAddressProviderSvc::finalize
virtual StatusCode finalize() override
Required of all Gaudi Services.
Definition: AthenaPoolAddressProviderSvc.cxx:52
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.
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:20
StoreID::type
type
Definition: StoreID.h:24
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthenaPoolAddressProviderSvc::AthenaPoolAddressProviderSvc
AthenaPoolAddressProviderSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
Definition: AthenaPoolAddressProviderSvc.cxx:30
AthenaPoolAddressProviderSvc::preLoadAddresses
virtual StatusCode preLoadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
Get all addresses from provider.
Definition: AthenaPoolAddressProviderSvc.cxx:65
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:44
AthenaPoolAddressProviderSvc::eventStore
StoreGateSvc * eventStore() const
Return pointer to active event SG.
Definition: AthenaPoolAddressProviderSvc.cxx:40
StoreGateSvc.h
ServiceHandle< StoreGateSvc >