ATLAS Offline Software
Loading...
Searching...
No Matches
ExpressionParsing::SGxAODProxyLoader Class Reference

Auxiliary class to access content of xAOD objects referred to by variables of an expressions handled by an instance of the ExpressionParser. More...

#include <SGxAODProxyLoader.h>

Inheritance diagram for ExpressionParsing::SGxAODProxyLoader:
Collaboration diagram for ExpressionParsing::SGxAODProxyLoader:

Classes

class  IParentHelper
 Interface of an auxiliary class to pass the parent, e.g. More...
class  ParentHelper
 Template of an auxiliary class to declare the new handles in the parent AthAlgTool, AthAlgorithm etc. More...
class  ReadHandleMapTmpl
 Particular map which is used to associate names to read handles of AuxElements or AuxVectorBase. More...

Public Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t
using VariableType = IAccessor::VariableType

Public Member Functions

 SGxAODProxyLoader (StoreGateSvc_t &evtStore, bool verbose=false)
virtual ~SGxAODProxyLoader ()
virtual void reset () override
virtual VariableType variableType (const std::string &var_name) const override
virtual std::pair< IProxyLoader::VariableType, const IAccessor & > getAccessorFromString (const EventContext &ctx, const std::string &varname) const override
virtual int loadInt (const EventContext &ctx, const std::string &varname) const override
virtual double loadDouble (const EventContext &ctx, const std::string &varname) const override
virtual std::vector< int > loadVecInt (const EventContext &ctx, const std::string &varname) const override
virtual std::vector< double > loadVec (const EventContext &ctx, const std::string &varname) const override
bool updateDataDependencies (SGxAODProxyLoader::IParentHelper &parent, const std::vector< std::string > &var_names, const std::vector< std::string > &renounce, const std::vector< const DataObjID * > &input_data_in, const std::vector< const DataObjID * > &output_data_in, std::vector< Gaudi::DataHandle * > &new_input_handles, std::vector< Gaudi::DataHandle * > &new_output_handles)
 Create extra data dependencies arising eventually from the given variables.

Static Public Member Functions

template<class T>
static ParentHelper< T > wrapParent (T *parent)
 auxiliary method to create the auxiliary class to declare new data handles with the calling AthAlgTool, AthAlgorithm etc.

Private Types

using ReadHandleMap
using ReadDecorHandleMap

Private Member Functions

void splitVarnameIntoContainerAndMethod (const std::string &varname, std::string &containerName, std::string &methodName) const
IAccessorcomputeClassForVarname (const EventContext &ctx, std::unordered_map< std::string, CxxUtils::CachedUniquePtrT< IAccessor > >::const_iterator accessor_iter, const std::string &varname) const
 Auxiliary method to create an xAOD object content accessor for the given variable name.
std::pair< RootUtils::TSMethodCall, TVirtualCollectionProxy * > getMethodCallAccessor (const std::string &method_name, const std::type_info &info) const
 Auxiliary method to create a TMethodCall and eventually also a collection proxy to call the given method of the specified container type.
IAccessorgetAccessor (const EventContext &ctx, const std::string &varname) const
 Get an existing or create a new accessor for the given variable name.
template<class T_Aux>
std::unique_ptr< IAccessorcreateAccessor (const EventContext &ctx, const SG::ReadHandleKey< T_Aux > &key, const SG::ReadDecorHandleKey< T_Aux > *decor_key, SG::auxid_t method_id, const std::string &method_name) const
 Auxiliary method to create an accessor for the given method_name.

Private Attributes

StoreGateSvc_t m_evtStore
ReadHandleMap m_readKeys
ReadDecorHandleMap m_decorKeys
std::unordered_map< std::string, CxxUtils::CachedUniquePtrT< IAccessor > > m_accessor
 Association of variable names to accessors for corresponding xAOD object content.
std::unique_ptr< IAccessorm_emptyVectorAccessor
 Special accessor to handle empty vectors Accessor are constructed at time of first evaluation.
bool m_verbose = false

Detailed Description

Auxiliary class to access content of xAOD objects referred to by variables of an expressions handled by an instance of the ExpressionParser.

Definition at line 47 of file SGxAODProxyLoader.h.

Member Typedef Documentation

◆ ReadDecorHandleMap

Initial value:
Particular map which is used to associate names to read handles of AuxElements or AuxVectorBase.
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.

Definition at line 203 of file SGxAODProxyLoader.h.

◆ ReadHandleMap

Initial value:

Definition at line 201 of file SGxAODProxyLoader.h.

◆ StoreGateSvc_t

◆ VariableType

Constructor & Destructor Documentation

◆ SGxAODProxyLoader()

ExpressionParsing::SGxAODProxyLoader::SGxAODProxyLoader ( StoreGateSvc_t & evtStore,
bool verbose = false )

Definition at line 43 of file SGxAODProxyLoader.cxx.

43: m_evtStore(evtStore), m_emptyVectorAccessor(std::make_unique<EmptyVectorAccessor>()),m_verbose(verbose) { }
std::unique_ptr< IAccessor > m_emptyVectorAccessor
Special accessor to handle empty vectors Accessor are constructed at time of first evaluation.
bool verbose
Definition hcg.cxx:73

◆ ~SGxAODProxyLoader()

ExpressionParsing::SGxAODProxyLoader::~SGxAODProxyLoader ( )
virtual

Definition at line 45 of file SGxAODProxyLoader.cxx.

46 {}

Member Function Documentation

◆ computeClassForVarname()

IAccessor & ExpressionParsing::SGxAODProxyLoader::computeClassForVarname ( const EventContext & ctx,
std::unordered_map< std::string, CxxUtils::CachedUniquePtrT< IAccessor > >::const_iterator accessor_iter,
const std::string & varname ) const
private

Auxiliary method to create an xAOD object content accessor for the given variable name.

Parameters
ctxthe current event context
accessor_iterlocation where the newly created accessor will be stored.
varnamethe variable name which defines the xAOD container and the content.

Definition at line 130 of file SGxAODProxyLoader.cxx.

133 {
134 const IProxyDict *proxy = Atlas::getExtendedEventContext( ctx ).proxy();
135 (void) proxy;
136 std::string container_name;
137 std::string method_name;
138 splitVarnameIntoContainerAndMethod(varname,container_name, method_name);
139 ReadHandleMap::const_iterator key_iter = m_readKeys.find(container_name);
140 if (key_iter == m_readKeys.end()) {
141 std::stringstream msg;
142 msg << "No read handle key for " << container_name;
143 throw std::runtime_error(msg.str());
144 }
145 SG::auxid_t method_id = SG::null_auxid;
146 ReadDecorHandleMap::const_iterator decor_key_iter = m_decorKeys.end();
147 if (ReadHandleMap::isVector(key_iter->second) || ReadHandleMap::isElement(key_iter->second)) {
148 method_id = SG::AuxTypeRegistry::instance().findAuxID(method_name,"");
149 if (method_id != SG::null_auxid) {
150 decor_key_iter=m_decorKeys.find(varname);
151 }
152 }
153 std::unique_ptr<IAccessor> accessor;
154 if (ReadHandleMap::isVector(key_iter->second)) {
155 if (m_verbose) { std::cout << "DEBUG SGxAODProxyLoader::computeClassForVarname is Vector: " << varname << std::endl; }
157 ReadHandleMap::vectorKey(key_iter->second),
158 (decor_key_iter != m_decorKeys.end() ? &ReadDecorHandleMap::vectorKey(decor_key_iter->second) : nullptr),
159 method_id,
160 method_name);
161 }
162 else if (ReadHandleMap::isElement(key_iter->second)) {
163 if (m_verbose) { std::cout << "DEBUG SGxAODProxyLoader::computeClassForVarname is element: " << varname << std::endl; }
165 ReadHandleMap::elementKey(key_iter->second),
166 (decor_key_iter != m_decorKeys.end() ? &ReadDecorHandleMap::elementKey(decor_key_iter->second) : nullptr),
167 method_id,
168 method_name);
169 }
170 else {
171 if (m_verbose) { std::cout << "DEBUG SGxAODProxyLoader::computeClassForVarname try to create plain type accessor for " << varname << std::endl; }
173 }
174 if (!accessor) {
175 return *m_emptyVectorAccessor;
176 }
177 IAccessor* accessorPlainPtr = accessor.get();//avoid Wpotentially-evaluated-expression from typeid
178 if (m_verbose) {
179 std::cout << "DEBUG SGxAODProxyLoader use accessor "
180 << typeid(*accessorPlainPtr).name() << " for " << varname
181 << std::endl;
182 }
183 accessor_iter->second.set(std::move(accessor));
184 return *(accessor_iter->second);
185 }
std::unique_ptr< IAccessor > createAccessor(const std::any &handle_key) const
void splitVarnameIntoContainerAndMethod(const std::string &varname, std::string &containerName, std::string &methodName) const
std::unique_ptr< IAccessor > createAccessor(const EventContext &ctx, const SG::ReadHandleKey< T_Aux > &key, const SG::ReadDecorHandleKey< T_Aux > *decor_key, SG::auxid_t method_id, const std::string &method_name) const
Auxiliary method to create an accessor for the given method_name.
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
MsgStream & msg
Definition testRead.cxx:32

◆ createAccessor()

template<class T_Aux>
std::unique_ptr< IAccessor > ExpressionParsing::SGxAODProxyLoader::createAccessor ( const EventContext & ctx,
const SG::ReadHandleKey< T_Aux > & key,
const SG::ReadDecorHandleKey< T_Aux > * decor_key,
SG::auxid_t method_id,
const std::string & method_name ) const
private

Auxiliary method to create an accessor for the given method_name.

Parameters
ctxthe current event context.
keya valid read handle key to retrieve the corresponding container.
decor_keya valid read handle key or nullptr to create a decoration handle for the given method
method_idthe xAOD ID of the given method
thename of the method.
Returns
returns an accessor for the xAOD content.

Definition at line 105 of file SGxAODProxyLoader.cxx.

110 {
111 SG::ReadHandle<T_Aux> handle(key, ctx);
112 if (!handle.isValid()) {
113 std::stringstream amsg;
114 amsg << "Failed to get " << key.key();
115 throw std::runtime_error(amsg.str());
116 }
117 if (getContainerSize(*handle)==0) {
118 return std::unique_ptr<IAccessor>();
119 }
120 if (!isAvailable(*handle,method_id)) {
121 auto [method_wrapper, proxy]
122 = details::getMethodCallAccessor(method_name, typeid(*handle), m_verbose);
123 return MethodAccessorFactory::instance().create( key, std::move(method_wrapper), proxy);
124 }
125 else {
126 return ExpressionParsing::AccessorFactory::instance().create( key, method_id , decor_key );
127 }
128 }
std::unique_ptr< IAccessor > create(const SG::ReadHandleKey< SG::AuxElement > &key, SG::auxid_t auxid, const SG::ReadDecorHandleKey< SG::AuxElement > *decor_key=nullptr) const
create an accessor for the specified content of an AuxElement.
std::unique_ptr< IAccessor > create(const SG::ReadHandleKey< SG::AuxElement > &key, RootUtils::ClingCallWrapperUncheckedReturnValue<> &&method_wrapper, TVirtualCollectionProxy *proxy=nullptr) const
Create an accessor which calls the specified method of an AuxElement.
std::pair< RootUtils::ClingCallWrapperUncheckedReturnValue<>, TVirtualCollectionProxy * > getMethodCallAccessor(const std::string &method_name, const std::type_info &info, bool verbose)
bool isAvailable(const T_Aux &cont, SG::auxid_t auxid)

◆ getAccessor()

IAccessor & ExpressionParsing::SGxAODProxyLoader::getAccessor ( const EventContext & ctx,
const std::string & varname ) const
inlineprivate

Get an existing or create a new accessor for the given variable name.

Parameters
ctxthe current event context
varnamethe name of the variable for which an accessor will be returned. The event context is needed if a new accessor has to be created to gather information about the type which the variable refers to.

Definition at line 142 of file SGxAODProxyLoader.h.

142 {
143 std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> >::const_iterator
144 accessor_iter = m_accessor.find(varname);
145 if (accessor_iter == m_accessor.end()) {
146 std::stringstream msg;
147 msg << "No accessor stub was created for " << varname << " i.e. variable is unknown.";
148 throw std::runtime_error(msg.str());
149 }
150 if (accessor_iter->second) return *(accessor_iter->second);
151 return computeClassForVarname(ctx,accessor_iter, varname);
152 }
std::unordered_map< std::string, CxxUtils::CachedUniquePtrT< IAccessor > > m_accessor
Association of variable names to accessors for corresponding xAOD object content.
IAccessor & computeClassForVarname(const EventContext &ctx, std::unordered_map< std::string, CxxUtils::CachedUniquePtrT< IAccessor > >::const_iterator accessor_iter, const std::string &varname) const
Auxiliary method to create an xAOD object content accessor for the given variable name.

◆ getAccessorFromString()

std::pair< IProxyLoader::VariableType, const IAccessor & > ExpressionParsing::SGxAODProxyLoader::getAccessorFromString ( const EventContext & ctx,
const std::string & varname ) const
overridevirtual

Implements ExpressionParsing::IProxyLoader.

Definition at line 200 of file SGxAODProxyLoader.cxx.

200 {
201 const IAccessor &accessor = getAccessor(ctx, varname);
202 return {accessor.variableType(varname), accessor};
203 }
IAccessor & getAccessor(const EventContext &ctx, const std::string &varname) const
Get an existing or create a new accessor for the given variable name.

◆ getMethodCallAccessor()

std::pair< RootUtils::TSMethodCall, TVirtualCollectionProxy * > ExpressionParsing::SGxAODProxyLoader::getMethodCallAccessor ( const std::string & method_name,
const std::type_info & info ) const
private

Auxiliary method to create a TMethodCall and eventually also a collection proxy to call the given method of the specified container type.

Parameters
method_namethe name of the method to be called.
infothe type_info of the container whose method is to be called.
Returns
a TMethodCall object and optionally collection proxy which is owned by ROOT(?)

◆ loadDouble()

double ExpressionParsing::SGxAODProxyLoader::loadDouble ( const EventContext & ctx,
const std::string & varname ) const
overridevirtual

Implements ExpressionParsing::IAccessor.

Definition at line 228 of file SGxAODProxyLoader.cxx.

229 {
230 return dump(varname,getAccessor(ctx, varname).loadDouble(ctx,varname));
231 }
virtual double loadDouble(const EventContext &ctx, const std::string &varname) const override
std::ostream & dump(std::ostream &out, const I4MomIter iBeg, const I4MomIter iEnd)
Helper to stream out a range of I4Momentum objects.
Definition P4Dumper.h:24

◆ loadInt()

int ExpressionParsing::SGxAODProxyLoader::loadInt ( const EventContext & ctx,
const std::string & varname ) const
overridevirtual

Implements ExpressionParsing::IAccessor.

Definition at line 223 of file SGxAODProxyLoader.cxx.

224 {
225 return dump(varname,getAccessor(ctx, varname).loadInt(ctx,varname));
226 }
virtual int loadInt(const EventContext &ctx, const std::string &varname) const override

◆ loadVec()

std::vector< double > ExpressionParsing::SGxAODProxyLoader::loadVec ( const EventContext & ctx,
const std::string & varname ) const
overridevirtual

Implements ExpressionParsing::IAccessor.

Definition at line 238 of file SGxAODProxyLoader.cxx.

239 {
240 return dump(varname,getAccessor(ctx, varname).loadVec(ctx,varname));
241 }
virtual std::vector< double > loadVec(const EventContext &ctx, const std::string &varname) const override

◆ loadVecInt()

std::vector< int > ExpressionParsing::SGxAODProxyLoader::loadVecInt ( const EventContext & ctx,
const std::string & varname ) const
overridevirtual

Implements ExpressionParsing::IAccessor.

Definition at line 233 of file SGxAODProxyLoader.cxx.

234 {
235 return dump(varname,getAccessor(ctx, varname).loadVecInt(ctx,varname));
236 }
virtual std::vector< int > loadVecInt(const EventContext &ctx, const std::string &varname) const override

◆ reset()

void ExpressionParsing::SGxAODProxyLoader::reset ( )
overridevirtual

Implements ExpressionParsing::IProxyLoader.

Definition at line 48 of file SGxAODProxyLoader.cxx.

48 {
49 m_decorKeys.clear();
50 m_readKeys.clear();
51 m_accessor.clear();
52 }

◆ splitVarnameIntoContainerAndMethod()

void ExpressionParsing::SGxAODProxyLoader::splitVarnameIntoContainerAndMethod ( const std::string & varname,
std::string & containerName,
std::string & methodName ) const
private

Definition at line 54 of file SGxAODProxyLoader.cxx.

55 {
56 size_t dotPosition = varname.find('.');
57 containerName = varname.substr(0, dotPosition);
58 methodName = varname.substr(dotPosition + 1);
59 }

◆ updateDataDependencies()

bool ExpressionParsing::SGxAODProxyLoader::updateDataDependencies ( SGxAODProxyLoader::IParentHelper & parent,
const std::vector< std::string > & var_names,
const std::vector< std::string > & renounce,
const std::vector< const DataObjID * > & input_data_in,
const std::vector< const DataObjID * > & output_data_in,
std::vector< Gaudi::DataHandle * > & new_input_handles,
std::vector< Gaudi::DataHandle * > & new_output_handles )

Create extra data dependencies arising eventually from the given variables.

Parameters
parentauxiliary class to declare new data handles with the calling parent
var_namesthe variables for which data dependencies might be created.
renouncea list of output data keys, which should be renounced from the new_input_handles list.
input_data_inread data object IDs declared by all algorithms and tools
output_data_inwrite data object IDs declared by all algorithms and tools
new_input_handleswill be filled with read data handles newly created by this loader
new_output_handleswill be filled with write data handles newly created by this loader (unused).
Returns
true if new handles have been declared.

Definition at line 243 of file SGxAODProxyLoader.cxx.

250 {
251 (void) new_output_handles;
252 std::size_t initial_size=m_decorKeys.size()+m_readKeys.size();
253 for (const std::string &var_name : var_names) {
254 if ( m_decorKeys.find(var_name)!= m_decorKeys.end()) continue;
255 std::string container_name;
256 std::string method_name;
257 splitVarnameIntoContainerAndMethod(var_name,container_name, method_name);
258 if (m_verbose) {
259 std::cout << "DEBUG SGxAODProxyLoader::updateDataDependencies var " << var_name << " -> " << container_name << " . " << method_name
260 << " i:" << input_data_in.size() << " o:" << output_data_in.size()
261 << std::endl;
262 }
263 const DataObjID *container_data_id=nullptr;
264 const DataObjID *method_data_id=nullptr;
265 bool verbose = m_verbose;
266
267 // Decide whether a variable just needs a container read handle key or a read decor handle key.
268 // Search in data handles for data handles and decor handles:
269 // decor handle : "container_name.decoration_name"
270 // data handle : "container_name"
271 // if a decor handle is found assume that it is a decoration, otherwise assume that it is either a default aux item
272 // or refers to a method call
273 auto set_ids = [&method_data_id,&container_data_id,&var_name,&container_name,verbose](const DataObjID *obj_data_id) -> bool {
274 std::string_view handle_key(obj_data_id->key());
275 std::string::size_type pos=obj_data_id->key().find('+');
276 pos = (pos==std::string::npos ? 0 : pos+1);
277 handle_key=handle_key.substr(pos,handle_key.size()-pos);
278 if (verbose && (handle_key == container_name || handle_key == var_name)) {
279 const SG::BaseInfoBase* base_info = SG::BaseInfoBase::find (obj_data_id->clid());
280 std::cout << "DEBUG SGxAODProxyLoader::updateDataDependencies " << handle_key << " matches " << var_name << " ? "
281 << (handle_key == var_name ? " method " : "")
282 << (handle_key == container_name ? " container " : "")
283 << "-> " << (base_info ? base_info->typeinfo().name() : "")
284 << std::endl;
285 }
286 if (handle_key == var_name) {
287 method_data_id = obj_data_id;
288 if (container_data_id) return true;
289 }
290 else if (handle_key == container_name ) {
291 container_data_id = obj_data_id;
292 if (method_data_id) return true;
293 }
294 return false;
295 };
296 // start with output handles which are expected to contain the decorator handles
297 for( std::vector<const DataObjID *>::const_iterator elm_iter = output_data_in.begin(); elm_iter != output_data_in.end() && !set_ids(*elm_iter); ++elm_iter) {}
298 if (!method_data_id) {
299 for( std::vector<const DataObjID *>::const_iterator elm_iter = input_data_in.begin(); elm_iter != input_data_in.end() && !set_ids(*elm_iter); ++elm_iter) {}
300 }
301 if (method_data_id) {
302 if (!container_data_id) {
303 container_data_id=method_data_id;
304 }
305 }
306 // ---DEBUG
307 if (m_verbose && method_data_id && method_data_id != container_data_id) {
308 std::cout << "DEBUG SGxAODProxyLoader method_clid " << method_data_id->clid() << std::endl;
309 }
310 if (m_verbose && container_data_id) {
311 std::cout << "DEBUG SGxAODProxyLoader container_clid " << container_data_id->clid() << std::endl;
312 }
313 // ___DEBUG
314
315 if (container_data_id) {
316 m_accessor.insert( std::make_pair(var_name, CxxUtils::CachedUniquePtrT<IAccessor>()));
317 bool have_container_read_key = m_readKeys.find(container_name) != m_readKeys.end();
318 if (have_container_read_key && !method_data_id) continue;
319
320 auto clid = container_data_id->clid();
321 (void) clid;
322 const SG::BaseInfoBase* base_info = (container_data_id ? SG::BaseInfoBase::find (container_data_id->clid()) : nullptr);
323 if (!base_info) {
324 std::stringstream msg;
325 msg << "Missing type information about container " << container_name << ".";
326 if (container_data_id) {
327 msg << " It seems that inheritance information is missing for " << container_data_id->className() << "."
328 << " Only container which inherit from SG::AuxVectorBase or data inheriting from SG::AuxElement "
329 << " are supported by the SGxAODProxyLoader loader.";
330 }
331 else {
332 msg << " This problem may occur if the container is read from the input"
333 << " file and not accessed anywhere in the job via read handles. ";
334 }
335 throw std::runtime_error(msg.str());
336 }
337 // ---DEBUG
338 if (m_verbose && base_info) {
339 std::cout << "DEBUG SGxAODProxyLoader " << container_name << " -> " << base_info->typeinfo().name() << std::endl;
340 for ( CLID clid : base_info->get_bases ()) {
341 const SG::BaseInfoBase* a_base_info = SG::BaseInfoBase::find (clid);
342 std::cout << "DEBUG SGxAODProxyLoader " << container_name << " base: " << a_base_info->typeinfo().name() << std::endl;
343 }
344 }
345 // ___DEBUG
346
347
348 std::any read_key;
349 std::any decor_key;
351 if (!have_container_read_key) {
352 read_key = std::make_any<SG::ReadHandleKey<SG::AuxVectorBase> >(container_name);
353 }
354 if (method_data_id) {
355 decor_key = std::make_any<SG::ReadDecorHandleKey<SG::AuxVectorBase> >(var_name);
356 }
357 }
358 else if (base_info->is_base(ClassID_traits<SG::AuxElement>::ID())) {
359 if (!have_container_read_key) {
360 read_key = std::make_any<SG::ReadHandleKey<SG::AuxElement> >(container_name);
361 }
362 if (method_data_id) {
363 decor_key = std::make_any<SG::ReadDecorHandleKey<SG::AuxElement> >(var_name);
364 }
365 }
366 else {
367 if (method_data_id && method_data_id != container_data_id && method_data_id->clid() != container_data_id->clid()) {
368 std::stringstream msg;
369 msg << "Did not expect a \"method\" handle for the plain type " << var_name;
370 throw std::logic_error(msg.str());
371 }
372 bool registered_key = PlainAccessorFactory::instance().registerReadKey(m_readKeys, base_info->typeinfo(), parent, var_name, new_input_handles, m_verbose);
373 if (registered_key) {
374 popRenounced(renounce, new_input_handles);
375 continue;
376 }
377 }
378
379 if (!have_container_read_key) {
380 if (!read_key.has_value()) {
381 std::stringstream msg;
382 msg << "Container " << container_name << " is of unsupported type " << base_info->typeinfo().name()
383 << " expected a type derived from SG::AuxVectorBase or SG::AuxElement";
384 throw std::runtime_error(msg.str());
385 }
386 std::pair<ReadHandleMap::iterator, bool> ret = m_readKeys.insert(std::make_pair(container_name, std::move(read_key)));
387 if (ret.second) {
388 if ( (ReadHandleMap::isVector(ret.first->second) && parent.declare(ReadHandleMap::vectorKey(ret.first->second)).isFailure())
389 || (ReadHandleMap::isElement(ret.first->second) && parent.declare(ReadHandleMap::elementKey(ret.first->second)).isFailure())) {
390 std::stringstream msg;
391 msg << "Failed to add read handle key for " << container_name;
392 throw std::runtime_error(msg.str());
393 }
394 if (m_verbose) {
395 if (ReadHandleMap::isVector(ret.first->second)) dumpDeclare(&ReadHandleMap::vectorKey(ret.first->second) );
396 else dumpDeclare(&ReadHandleMap::elementKey(ret.first->second));
397 }
398 if (ReadHandleMap::isVector(ret.first->second)) initializeHandle(&ReadHandleMap::vectorKey(ret.first->second), new_input_handles);
399 else initializeHandle(&ReadHandleMap::elementKey(ret.first->second),new_input_handles);
400 popRenounced(renounce, new_input_handles);
401
402 }
403 }
404 if (method_data_id) {
405 if (!decor_key.has_value()) {
406 std::stringstream msg;
407 msg << "Container " << container_name << " is of unsupported type " << base_info->typeinfo().name()
408 << " expected a type derived from SG::AuxVectorBase or SG::AuxElement";
409 throw std::runtime_error(msg.str());
410 }
411 std::pair<ReadDecorHandleMap::iterator, bool> ret = m_decorKeys.insert(std::make_pair(var_name,std::move(decor_key)));
412 if (ret.second) {
413 if ( (ReadDecorHandleMap::isVector(ret.first->second) && parent.declare(ReadDecorHandleMap::vectorKey(ret.first->second)).isFailure())
414 || (!ReadDecorHandleMap::isVector(ret.first->second) && parent.declare(ReadDecorHandleMap::elementKey(ret.first->second)).isFailure())) {
415 std::stringstream msg;
416 msg << "Failed to add read decor handle key for " << var_name;
417 throw std::runtime_error(msg.str());
418 }
419 if (m_verbose) {
420 if (ReadDecorHandleMap::isVector(ret.first->second)) dumpDeclare(&ReadDecorHandleMap::vectorKey(ret.first->second) );
421 else dumpDeclare(&ReadDecorHandleMap::elementKey(ret.first->second));
422 }
423 if (ReadDecorHandleMap::isVector(ret.first->second)) initializeHandle(&ReadDecorHandleMap::vectorKey(ret.first->second),new_input_handles );
424 else initializeHandle(&ReadDecorHandleMap::elementKey(ret.first->second),new_input_handles);
425 popRenounced(renounce, new_input_handles);
426 }
427 }
428 }
429 }
430 return initial_size != m_decorKeys.size()+m_readKeys.size();
431 }
uint32_t CLID
The Class ID type.
if(febId1==febId2)
static bool registerReadKey(std::unordered_map< std::string, std::any > &read_keys, SGxAODProxyLoader::IParentHelper &parent, const std::string &var_name, std::vector< Gaudi::DataHandle * > &new_input_handles, bool verbose)
static const BaseInfoBase * find(CLID clid)
Find the BaseInfoBase instance for clid.
Definition BaseInfo.cxx:570
const std::type_info & typeinfo() const
Return the std::type_info for this class.
Definition BaseInfo.cxx:151
const std::vector< CLID > & get_bases() const
Return the class IDs of all known bases of T (that have class IDs).
Definition BaseInfo.cxx:304
bool is_base(CLID clid) const
Return true if clid is the ID of a class that is known to be a base of T.
Definition BaseInfo.cxx:344
void initializeHandle(T_Key *key, std::vector< Gaudi::DataHandle * > &new_input_handles)
Auxiliary function to initialize newly create data handles.
void dumpDeclare(const T *key)
Function for debugging which dumps information about newly declared data handles.
Definition DebugUtils.h:65

◆ variableType()

IAccessor::VariableType ExpressionParsing::SGxAODProxyLoader::variableType ( const std::string & var_name) const
overridevirtual

Implements ExpressionParsing::IAccessor.

Definition at line 187 of file SGxAODProxyLoader.cxx.

187 {
188 // This method has to be implemented because it is part of the interface
189 // but the SGxAODProxyLoader will return pointers to different IAccesor objects
190 // depending on the situation and the method variableType will be called of those
191 // objects. Thus, there is really no need to pass the event context through, because
192 // this method is never called and the event context would not be used in all other cases.
193 const EventContext& ctx = Gaudi::Hive::currentContext();
194 std::pair< IProxyLoader::VariableType, const IAccessor &>
195 ret = getAccessorFromString(ctx, varname);
196 return ret.first;
197 }
virtual std::pair< IProxyLoader::VariableType, const IAccessor & > getAccessorFromString(const EventContext &ctx, const std::string &varname) const override

◆ wrapParent()

template<class T>
ParentHelper< T > ExpressionParsing::SGxAODProxyLoader::wrapParent ( T * parent)
inlinestatic

auxiliary method to create the auxiliary class to declare new data handles with the calling AthAlgTool, AthAlgorithm etc.

Definition at line 94 of file SGxAODProxyLoader.h.

94 {
95 return ParentHelper<T>(parent);
96 }
Template of an auxiliary class to declare the new handles in the parent AthAlgTool,...

Member Data Documentation

◆ m_accessor

std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> > ExpressionParsing::SGxAODProxyLoader::m_accessor
private

Association of variable names to accessors for corresponding xAOD object content.

The map structure is constructed before the event loop. The content of its leaves is completed during the event loop.

Definition at line 212 of file SGxAODProxyLoader.h.

◆ m_decorKeys

ReadDecorHandleMap ExpressionParsing::SGxAODProxyLoader::m_decorKeys
private

Definition at line 206 of file SGxAODProxyLoader.h.

◆ m_emptyVectorAccessor

std::unique_ptr<IAccessor> ExpressionParsing::SGxAODProxyLoader::m_emptyVectorAccessor
private

Special accessor to handle empty vectors Accessor are constructed at time of first evaluation.

This fails for empty containers because empty container do not necessarily provide enough type information to create the correct accessor. This is mitigated by this special accessor which is used until the final accessor can be created.

Definition at line 220 of file SGxAODProxyLoader.h.

◆ m_evtStore

StoreGateSvc_t ExpressionParsing::SGxAODProxyLoader::m_evtStore
private

Definition at line 169 of file SGxAODProxyLoader.h.

◆ m_readKeys

ReadHandleMap ExpressionParsing::SGxAODProxyLoader::m_readKeys
private

Definition at line 205 of file SGxAODProxyLoader.h.

◆ m_verbose

bool ExpressionParsing::SGxAODProxyLoader::m_verbose = false
private

Definition at line 221 of file SGxAODProxyLoader.h.


The documentation for this class was generated from the following files: