ATLAS Offline Software
SGInputLoader.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // SGInputLoader.cxx
8 // Implementation file for class SGInputLoader
10 
11 #include "SGInputLoader.h"
12 
13 // FrameWork includes
14 #include "Gaudi/Property.h"
16 #include "StoreGate/VarHandleKey.h"
17 #include "AthenaKernel/StoreID.h"
18 
19 //---------------------------------------------------------------------------------
20 
21 
22 namespace
23 {
24  struct DataObjIDSorter {
25  bool operator()( const DataObjID* a, const DataObjID* b ) { return a->fullKey() < b->fullKey(); }
26  };
27 
28  // Sort a DataObjIDColl in a well-defined, reproducible manner.
29  // Used for making debugging dumps.
30  std::vector<const DataObjID*> sortedDataObjIDColl( const DataObjIDColl& coll )
31  {
32  std::vector<const DataObjID*> v;
33  v.reserve( coll.size() );
34  for ( const DataObjID& id : coll ) v.push_back( &id );
35  std::sort( v.begin(), v.end(), DataObjIDSorter() );
36  return v;
37  }
38 }
39 
40 //---------------------------------------------------------------------------------
41 
42 SGInputLoader::SGInputLoader( const std::string& name,
43  ISvcLocator* pSvcLocator ) :
44  ::AthAlgorithm( name, pSvcLocator )
45 {
46  //
47  // Property declaration
48  //
49  declareProperty( "Load", m_load, "create Output data dependencies for these objects")
50  ->declareUpdateHandler(&SGInputLoader::loader, this);
51 
52 }
53 
54 //---------------------------------------------------------------------------------
55 
57 {}
58 
59 //---------------------------------------------------------------------------------
60 
63 {
64  ATH_MSG_VERBOSE ("Initializing " << name() << "...");
65 
66  StatusCode sc(StatusCode::SUCCESS);
67 
68  if (m_load.size() > 0) {
69  std::ostringstream str;
70  str << "Will explicitly preload the following DataObjects:";
71  for (auto &e : m_load) {
72  str << "\n + " << e;
73  if (e.key().empty()) {
74  sc = StatusCode::FAILURE;
75  str << " ERROR: empty key is not allowed!";
76  }
77  }
78  ATH_MSG_INFO(str.str());
79  }
80 
81  return sc;
82 }
83 
84 //---------------------------------------------------------------------------------
85 
88 {
89  ATH_MSG_INFO ("Finalizing " << name() << "...");
90 
91  return StatusCode::SUCCESS;
92 }
93 
94 //---------------------------------------------------------------------------------
95 
98 {
99  StatusCode sc(StatusCode::SUCCESS);
100 
101  ATH_MSG_DEBUG ("Executing " << name() << "...");
102 
103  // add objects automatically added by the Scheduler
104  if (m_first) {
105  if (m_loadProxies.value()) {
106  for (DataObjID obj : outputDataObjs() ) {
107  // Strip any decoration name.
108  std::string::size_type ppos = obj.key().find ('.');
109  if (ppos < obj.key().size()-1) {
110  obj.updateKey (obj.key().substr (0, ppos));
111  }
112  m_load.emplace (std::move(obj));
113  }
114  }
115 
116  // check if objects are not in EventStore
117  DataObjIDColl toLoad;
118  for (const DataObjID* obj : sortedDataObjIDColl (m_load)) {
121  toLoad.emplace(*obj);
122  }
123  else if (StoreID::findStoreID(vhk.storeHandle().name()) == StoreID::CONDITION_STORE) {
124  ATH_MSG_ERROR("Unresolved conditions dependency: "
125  << *obj);
126  return StatusCode::FAILURE;
127  }
128  else {
129  ATH_MSG_DEBUG("Will not auto-load proxy for non-EventStore object: "
130  << *obj);
131  }
132  }
133  m_load = toLoad;
134 
135  m_first = false;
136  }
137 
138  bool b = loadObjs( m_load );
139 
140  if (m_dump.value()) {
141  ATH_MSG_DEBUG(evtStore()->dump());
142  }
143 
144  if (m_failEvt.value() && !b) {
145  ATH_MSG_ERROR("autoload of objects failed. aborting event processing");
146  sc = StatusCode::FAILURE;
147  }
148 
149  return sc;
150 }
151 
152 //---------------------------------------------------------------------------------
153 
154 void
155 SGInputLoader::loader(Gaudi::Details::PropertyBase& p ) {
156 
157  ATH_MSG_DEBUG("setting prop ExtraOutputs to " << p.toString());
158 
159  DataObjIDColl toLoad;
160 
161  for (auto obj : m_load) {
162  // add an explicit storename as needed
164  obj.updateKey( vhk.objKey() );
165  toLoad.emplace(obj);
166  }
167  m_load = toLoad;
168 
169  if (!setProperty("ExtraOutputs", p).isSuccess()) {
170  ATH_MSG_WARNING("failed setting property ExtraOutputs");
171  }
172 }
173 
174 //---------------------------------------------------------------------------------
175 
176 bool
177 SGInputLoader::loadObjs(const DataObjIDColl& objs) const {
178 
179  bool ok = true;
180 
181  for (auto &obj: objs) {
182 
183  // use the parsing built into the VarHandleKey to get the correct
184  // StoreGate key
186 
187  ATH_MSG_DEBUG("trying to load " << obj << " sgkey: " << vhk.key() );
188 
189  SG::DataProxy* dp = evtStore()->proxy(obj.clid(), vhk.key());
190  if (dp != 0) {
191  ATH_MSG_DEBUG(" found proxy for " << obj);
192  if (dp->provider() == 0) {
193  ATH_MSG_DEBUG(" obj " << obj << " has no provider, and is only Transient" );
194  }
195  } else {
196  ok = false;
197  if (m_failEvt.value()) {
198  ATH_MSG_ERROR("unable to find proxy for " << obj);
199  } else {
200  ATH_MSG_WARNING("unable to find proxy for " << obj);
201  }
202  }
203  }
204 
205  return ok;
206 
207 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:840
VarHandleKey.h
A property holding a SG store/key/clid from which a VarHandle is made.
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SGInputLoader::finalize
virtual StatusCode finalize() override
Definition: SGInputLoader.cxx:87
SGInputLoader::~SGInputLoader
virtual ~SGInputLoader()
Definition: SGInputLoader.cxx:56
SG::VarHandleKey::storeHandle
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SGInputLoader::loader
void loader(Gaudi::Details::PropertyBase &)
Definition: SGInputLoader.cxx:155
SGInputLoader::m_loadProxies
Gaudi::Property< bool > m_loadProxies
Definition: SGInputLoader.h:54
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
run_Egamma1_LArStrip_Fex.dump
dump
Definition: run_Egamma1_LArStrip_Fex.py:88
SGInputLoader::initialize
virtual StatusCode initialize() override
Definition: SGInputLoader.cxx:62
SGInputLoader::m_dump
Gaudi::Property< bool > m_dump
Definition: SGInputLoader.h:48
StoreID::CONDITION_STORE
@ CONDITION_STORE
Definition: StoreID.h:28
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SGInputLoader::m_failEvt
Gaudi::Property< bool > m_failEvt
Definition: SGInputLoader.h:51
SGInputLoader::m_first
bool m_first
Definition: SGInputLoader.h:58
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
checkFileSG.objs
list objs
Definition: checkFileSG.py:93
LHEF::Reader
Pythia8::Reader Reader
Definition: Prophecy4fMerger.cxx:11
SGInputLoader::m_load
DataObjIDColl m_load
Properties.
Definition: SGInputLoader.h:46
SGInputLoader::execute
virtual StatusCode execute() override
Definition: SGInputLoader.cxx:97
AthAlgorithm
Definition: AthAlgorithm.h:47
SGInputLoader::loadObjs
bool loadObjs(const DataObjIDColl &objs) const
Definition: SGInputLoader.cxx:177
StoreID.h
SGInputLoader.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
errorcheck.h
Helpers for checking error return status codes and reporting errors.
SG::VarHandleKey
A property holding a SG store/key/clid from which a VarHandle is made.
Definition: StoreGate/StoreGate/VarHandleKey.h:62
python.PyAthena.v
v
Definition: PyAthena.py:154
a
TList * a
Definition: liststreamerinfos.cxx:10
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SGInputLoader::SGInputLoader
SGInputLoader()
Default constructor:
StoreID::findStoreID
static StoreID::type findStoreID(const std::string &storeName)
Definition: StoreID.cxx:21
str
Definition: BTagTrackIpAccessor.cxx:11
LHEF::Writer
Pythia8::Writer Writer
Definition: Prophecy4fMerger.cxx:12
StoreID::EVENT_STORE
@ EVENT_STORE
Definition: StoreID.h:26
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::DataProxy
Definition: DataProxy.h:44