ATLAS Offline Software
Loading...
Searching...
No Matches
AthReadAlg.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2024 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: " <<
53 m_key.clid() << "/" << m_key.key() << "_DELETED [" <<
54 m_sgkey << "]" );
55 return StatusCode::FAILURE;
56 }
57
58 // Read the object.
59 std::unique_ptr<DataObject> ptr (proxy->readData());
60 if (!ptr) {
61 ATH_MSG_ERROR( "Object read failed: " <<
62 m_key.clid() << "/" << m_key.key() << "_DELETED [" <<
63 m_sgkey << "]" );
64 return StatusCode::FAILURE;
65 }
66
67 // Record the result in the event store.
69 ATH_CHECK( h.typelessPut (std::move (ptr) ) );
70
71 // Any extra aliases?
72 std::vector<std::string> extraAliases;
73 for (const std::string& a : m_aliases) {
74 if (!proxy->hasAlias (a + "_DELETED")) {
75 extraAliases.push_back (a);
76 }
77 }
78
79 // Restore original aliases.
80 if (!proxy->alias().empty() || !extraAliases.empty()) {
81 SG::DataProxy* newprox = evtStore()->proxy (m_key.clid(), m_key.key());
82 if (!newprox) {
83 ATH_MSG_ERROR( "Can't find proxy for just-recorded object " <<
84 m_key.clid() << "/" << m_key.key());
85 return StatusCode::FAILURE;
86 }
88
89 for (std::string a : proxy->alias()) {
90 if (a.ends_with ("_DELETED")) {
91 a.erase (a.size() - 8, 8);
92 if (!evtStore()->recordObject (dobj, a, false, true)) {
93 ATH_MSG_ERROR( "Can't make alias " << a << " for " <<
94 m_key.clid() << "/" << m_key.key());
95 return StatusCode::FAILURE;
96 }
97 }
98 }
99
100 for (const std::string& a : extraAliases) {
101 if (!evtStore()->recordObject (dobj, a, false, true)) {
102 ATH_MSG_ERROR( "Can't make alias " << a << " for " <<
103 m_key.clid() << "/" << m_key.key());
104 return StatusCode::FAILURE;
105 }
106 }
107 }
108
109 return StatusCode::SUCCESS;
110}
111
#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.
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