ATLAS Offline Software
Loading...
Searching...
No Matches
SGInputLoader.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2025 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"
18
19//---------------------------------------------------------------------------------
20
21
22namespace
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
42SGInputLoader::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
58
59//---------------------------------------------------------------------------------
60
61StatusCode
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
86StatusCode
88{
89 ATH_MSG_INFO ("Finalizing " << name() << "...");
90
91 return StatusCode::SUCCESS;
92}
93
94//---------------------------------------------------------------------------------
95
96StatusCode
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 }
136 SG::VarHandleKey vhk(obj->clid(),obj->key(),Gaudi::DataHandle::Writer);
138 toLoad.emplace(*obj);
139 }
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 = std::move(toLoad);
151
152 m_first = false;
153 }
154
155 bool b = loadObjs( m_load );
156
157 if (m_dump.value()) {
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
171void
172SGInputLoader::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
180 SG::VarHandleKey vhk(obj.clid(),obj.key(),Gaudi::DataHandle::Writer);
181 obj.updateKey( vhk.objKey() );
182 toLoad.emplace(obj);
183 if(!outputDataObjs().count(obj)) { addDependency(obj,Gaudi::DataHandle::Writer); }
184 }
185 m_load = std::move(toLoad);
186
187}
188
189//---------------------------------------------------------------------------------
190
191bool
192SGInputLoader::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 - either a decoration output declaration is missing, or a ReadDecorHandleKey is being used to read a non-decoration" );
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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
static Double_t a
static Double_t sc
A property holding a SG store/key/clid from which a VarHandle is made.
virtual const DataObjIDColl & extraOutputDeps() const override
Return the list of extra output dependencies.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
SGInputLoader()
Default constructor:
virtual ~SGInputLoader()
Gaudi::Property< bool > m_failEvt
void loader(Gaudi::Details::PropertyBase &)
bool loadObjs(const DataObjIDColl &objs) const
Gaudi::Property< bool > m_dump
virtual StatusCode execute() override
Gaudi::Property< bool > m_loadProxies
DataObjIDColl m_load
Properties.
virtual StatusCode finalize() override
virtual StatusCode initialize() override
A property holding a SG store/key/clid from which a VarHandle is made.
const std::string & key() const
Return the StoreGate ID for the referenced object.
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.
@ EVENT_STORE
Definition StoreID.h:26
@ CONDITION_STORE
Definition StoreID.h:28
static StoreID::type findStoreID(const std::string &storeName)
Definition StoreID.cxx:21
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
-event-from-file
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.