Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  // commented out line above, to keep decoration on key so can distinguish undeclared decorations from undeclared objects
112  // undeclared objects will be an error, undeclared decorations will just be a warning
113  // TODO: restore the above modification (and make all transient proxies an error in loadObj, not just non-decorations) when all decorations are declared
114  }
115  m_load.emplace (std::move(obj));
116  }
117  }
118 
119  // check if objects are not in EventStore
120  DataObjIDColl toLoad;
121  for (const DataObjID* obj : sortedDataObjIDColl (m_load)) {
122  // don't load anything that is in the ExtraOutputs list, which is used for objects created e.g. by the eventloopmgr
123  if( extraOutputDeps().count(*obj) ) {
124  ATH_MSG_DEBUG(obj->key() << " is in ExtraOutputs and will not be loaded");
125  continue;
126  } else if(std::string::size_type ppos = obj->key().find ('.'); ppos < obj->key().size()-1) {
127  // see if the object that the decoration is on is declared as extra output. Will assume the extra output
128  // will also provide such a decoration
129  DataObjID objcopy(*obj);
130  objcopy.updateKey(obj->key().substr (0, ppos));
131  if( extraOutputDeps().count(objcopy) ) {
132  ATH_MSG_DEBUG(obj->key() << "'s object/container is in ExtraOutputs and will not be loaded");
133  continue;
134  }
135  }
138  toLoad.emplace(*obj);
139  }
140  else if (StoreID::findStoreID(vhk.storeHandle().name()) == StoreID::CONDITION_STORE) {
141  ATH_MSG_ERROR("Unresolved conditions dependency: "
142  << *obj);
143  return StatusCode::FAILURE;
144  }
145  else {
146  ATH_MSG_DEBUG("Will not auto-load proxy for non-EventStore object: "
147  << *obj);
148  }
149  }
150  m_load = toLoad;
151 
152  m_first = false;
153  }
154 
155  bool b = loadObjs( m_load );
156 
157  if (m_dump.value()) {
158  ATH_MSG_DEBUG(evtStore()->dump());
159  }
160 
161  if (m_failEvt.value() && !b) {
162  ATH_MSG_ERROR("autoload of objects failed. aborting event processing");
163  sc = StatusCode::FAILURE;
164  }
165 
166  return sc;
167 }
168 
169 //---------------------------------------------------------------------------------
170 
171 void
172 SGInputLoader::loader(Gaudi::Details::PropertyBase& p ) {
173 
174  ATH_MSG_DEBUG("Adding to outputs: " << p.toString());
175 
176  DataObjIDColl toLoad;
177 
178  for (auto obj : m_load) {
179  // add an explicit storename as needed
181  obj.updateKey( vhk.objKey() );
182  toLoad.emplace(obj);
183  if(!outputDataObjs().count(obj)) { addDependency(obj,Gaudi::DataHandle::Writer); }
184  }
185  m_load = toLoad;
186 
187 }
188 
189 //---------------------------------------------------------------------------------
190 
191 bool
192 SGInputLoader::loadObjs(const DataObjIDColl& objs) const {
193 
194  bool ok = true;
195 
196  for (auto &obj: objs) {
197 
198  std::string::size_type ppos = obj.key().substr(0,obj.key().size()-1).find('.');
199 
200  // use the parsing built into the VarHandleKey to get the correct
201  // StoreGate key
202  SG::VarHandleKey vhk(obj.clid(),obj.key().substr(0,ppos),Gaudi::DataHandle::Reader);
203 
204  ATH_MSG_DEBUG("trying to load " << obj << " sgkey: " << vhk.key() );
205 
206  SG::DataProxy* dp = evtStore()->proxy(obj.clid(), vhk.key());
207  if (dp != 0) {
208  ATH_MSG_DEBUG(" found proxy for " << obj);
209  if (dp->provider() == 0 && extraOutputDeps().find(obj)==extraOutputDeps().end()) {
210  if(ppos==std::string::npos) {
211  ATH_MSG_ERROR(" obj " << obj << " has no provider, and is only Transient - indicative of a missing output declaration" );
212  ok =false;
213  } else { // just warning for now for potentially undeclared decorations, instead of error, because too many cases to fix
214  ATH_MSG_WARNING(" decoration " << obj << " has no provider, and is only Transient - indicative of a missing output declaration" );
215  }
216  }
217  } else {
218  ok = false;
219  if (m_failEvt.value()) {
220  ATH_MSG_ERROR("unable to find proxy for " << obj);
221  } else {
222  ATH_MSG_WARNING("unable to find proxy for " << obj);
223  }
224  }
225  }
226 
227  return ok;
228 
229 }
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
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
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:172
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
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
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
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
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
checkCorrelInHIST.objs
objs
Definition: checkCorrelInHIST.py:529
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
python.CaloAddPedShiftConfig.str
str
Definition: CaloAddPedShiftConfig.py:42
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:192
StoreID.h
SGInputLoader.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
errorcheck.h
Helpers for checking error return status codes and reporting errors.
columnar::operator()
decltype(auto) operator()(ObjectId< OT, CM > id) const noexcept
Definition: ColumnAccessor.h:175
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
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
AthAlgorithm::extraOutputDeps
virtual const DataObjIDColl & extraOutputDeps() const override
Return the list of extra output dependencies.
Definition: AthAlgorithm.cxx:50
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:45
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37