ATLAS Offline Software
Loading...
Searching...
No Matches
AthReadAlg.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
12#include "AthReadAlg.h"
14
15
20{
21 // Initialize the output key.
22 ATH_CHECK( m_key.initialize() );
23
24 // AddressRemappingSvc will rename the proxy for the original object
25 // so that it ends with _DELETED. Cache the sgkey for this proxy.
26 m_sgkey = evtStore()->stringToKey (m_key.key() + "_DELETED",
27 m_key.clid());
28
29 std::string storename;
30 const std::string& objkey = m_key.objKey();
31 std::string::size_type ppos = objkey.find ('+');
32 if (ppos != std::string::npos) {
33 storename = objkey.substr (0, ppos+1);
34 }
35 for (const std::string& a : m_aliases) {
36 this->addDependency (DataObjID (m_key.clid(), storename + a),
37 Gaudi::DataHandle::Writer);
38 }
39 return StatusCode::SUCCESS;
40}
41
42
47StatusCode AthReadAlg::execute (const EventContext& ctx) const
48{
49 // Look up the proxy for the original object.
50 SG::DataProxy* proxy = evtStore()->proxy_exact (m_sgkey);
51 if (!proxy) {
52 ATH_MSG_ERROR( "Cannot find proxy for original object: {}/{}_DELETED [{}]",
53 m_key.clid(), m_key.key(), m_sgkey);
54 return StatusCode::FAILURE;
55 }
56
57 // Read the object.
58 std::unique_ptr<DataObject> ptr (proxy->readData());
59 if (!ptr) {
60 ATH_MSG_ERROR( "Object read failed: {}/{}_DELETED [{}]",
61 m_key.clid(), m_key.key(), m_sgkey);
62 return StatusCode::FAILURE;
63 }
64
65 // Record the result in the event store.
67 ATH_CHECK( h.typelessPut (std::move (ptr) ) );
68
69 // Any extra aliases?
70 std::vector<std::string> extraAliases;
71 for (const std::string& a : m_aliases) {
72 if (!proxy->hasAlias (a + "_DELETED")) {
73 extraAliases.push_back (a);
74 }
75 }
76
77 // Restore original aliases.
78 if (!proxy->alias().empty() || !extraAliases.empty()) {
79 SG::DataProxy* newprox = evtStore()->proxy (m_key.clid(), m_key.key());
80 if (!newprox) {
81 ATH_MSG_ERROR( "Can't find proxy for just-recorded object {}/{}",
82 m_key.clid(), m_key.key());
83 return StatusCode::FAILURE;
84 }
86
87 for (std::string a : proxy->alias()) {
88 if (a.ends_with ("_DELETED")) {
89 a.erase (a.size() - 8, 8);
90 if (!evtStore()->recordObject (dobj, a, false, true)) {
91 ATH_MSG_ERROR( "Can't make alias {} for {}/{}",
92 a, m_key.clid(), m_key.key());
93 return StatusCode::FAILURE;
94 }
95 }
96 }
97
98 for (const std::string& a : extraAliases) {
99 if (!evtStore()->recordObject (dobj, a, false, true)) {
100 ATH_MSG_ERROR( "Can't make alias {} for {}/{}",
101 a, m_key.clid(), m_key.key());
102 return StatusCode::FAILURE;
103 }
104 }
105 }
106
107 return StatusCode::SUCCESS;
108}
109
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
Generic algorithm wrapping an input conversion.
static Double_t a
Handle allowing writes to the event store with a configurable type.
ServiceHandle< StoreGateSvc > & evtStore()
Header file for AthHistogramAlgorithm.
virtual StatusCode execute(const EventContext &ctx) const override
Standard Algorithm execute method.
SG::sgkey_t m_sgkey
Cache sgkey of proxy corresponding to the original object.
Definition AthReadAlg.h:71
SG::TypelessWriteHandleKey m_key
Property: Output key.
Definition AthReadAlg.h:65
Gaudi::Property< std::vector< std::string > > m_aliases
Definition AthReadAlg.h:68
virtual StatusCode initialize() override
Standard initialize method.
DataObject * accessData()
Access DataObject on-demand using conversion service.
Handle allowing writes to the event store with a configurable type.
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr