ATLAS Offline Software
AthReadAlg.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
3  */
12 #include "AthReadAlg.h"
14 
15 
20 {
21  // Initialize the output key.
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),
38  }
39  return StatusCode::SUCCESS;
40 }
41 
42 
47 StatusCode 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 __cplusplus >= 201709
91  if (a.ends_with ("_DELETED"))
92 #else
93  if (a.compare (a.size() - 8, 8, "_DELETED") == 0)
94 #endif
95  {
96  a.erase (a.size() - 8, 8);
97  if (!evtStore()->recordObject (dobj, a, false, true)) {
98  ATH_MSG_ERROR( "Can't make alias " << a << " for " <<
99  m_key.clid() << "/" << m_key.key());
100  return StatusCode::FAILURE;
101  }
102  }
103  }
104 
105  for (const std::string& a : extraAliases) {
106  if (!evtStore()->recordObject (dobj, a, false, true)) {
107  ATH_MSG_ERROR( "Can't make alias " << a << " for " <<
108  m_key.clid() << "/" << m_key.key());
109  return StatusCode::FAILURE;
110  }
111  }
112  }
113 
114  return StatusCode::SUCCESS;
115 }
116 
TypelessWriteHandle.h
Handle allowing writes to the event store with a configurable type.
AthReadAlg.h
Generic algorithm wrapping an input conversion.
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
SG::DataProxy::accessData
DataObject * accessData()
Access DataObject on-demand using conversion service.
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::TypelessWriteHandle
Handle allowing writes to the event store with a configurable type.
Definition: TypelessWriteHandle.h:35
AthReadAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Standard Algorithm execute method.
Definition: AthReadAlg.cxx:47
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
extractSporadic.h
list h
Definition: extractSporadic.py:97
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthReadAlg::m_aliases
Gaudi::Property< std::vector< std::string > > m_aliases
Definition: AthReadAlg.h:68
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthReadAlg::initialize
virtual StatusCode initialize() override
Standard initialize method.
Definition: AthReadAlg.cxx:19
AthReadAlg::m_sgkey
SG::sgkey_t m_sgkey
Cache sgkey of proxy corresponding to the original object.
Definition: AthReadAlg.h:71
SG::VarHandleKey::clid
CLID clid() const
Return the class ID for the referenced object.
Definition: StoreGate/src/VarHandleKey.cxx:177
a
TList * a
Definition: liststreamerinfos.cxx:10
h
LHEF::Writer
Pythia8::Writer Writer
Definition: Prophecy4fMerger.cxx:12
SG::DataObjectSharedPtr
Smart pointer to manage DataObject reference counts.
Definition: DataObjectSharedPtr.h:46
AthReadAlg::m_key
SG::TypelessWriteHandleKey m_key
Property: Output key.
Definition: AthReadAlg.h:65
SG::DataProxy
Definition: DataProxy.h:44