ATLAS Offline Software
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
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
 
enum  VariableType {
  VT_UNK, VT_INT, VT_DOUBLE, VT_VECINT,
  VT_VECDOUBLE, VT_VECEMPTY
}
 

Public Member Functions

 SGxAODProxyLoader (StoreGateSvc_t &evtStore, bool verbose=false)
 
virtual ~SGxAODProxyLoader ()
 
virtual void reset ()
 
virtual IProxyLoader::VariableType variableTypeFromString (const std::string &varname) const
 
virtual int loadIntVariableFromString (const std::string &varname) const
 
virtual double loadDoubleVariableFromString (const std::string &varname) const
 
virtual std::vector< int > loadVecIntVariableFromString (const std::string &varname) const
 
virtual std::vector< double > loadVecDoubleVariableFromString (const std::string &varname) const
 
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. More...
 

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. More...
 

Private Types

using ReadHandleMap = ReadHandleMapTmpl< SG::ReadHandleKey< SG::AuxElement >, SG::ReadHandleKey< SG::AuxVectorBase > >
 
using ReadDecorHandleMap = ReadHandleMapTmpl< SG::ReadDecorHandleKey< SG::AuxElement >, SG::ReadDecorHandleKey< SG::AuxVectorBase > >
 

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. More...
 
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. More...
 
IAccessorgetAccessor (const EventContext &ctx, const std::string &varname) const
 Get an existing or create a new accessor for the given variable name. More...
 
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. More...
 

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. More...
 
std::unique_ptr< IAccessorm_emptyVectorAccessor
 Special accessor to handle empty vectors Accessor are constructed at time of first evaluation. More...
 
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 46 of file SGxAODProxyLoader.h.

Member Typedef Documentation

◆ ReadDecorHandleMap

Definition at line 199 of file SGxAODProxyLoader.h.

◆ ReadHandleMap

Definition at line 197 of file SGxAODProxyLoader.h.

◆ StoreGateSvc_t

Definition at line 49 of file SGxAODProxyLoader.h.

Member Enumeration Documentation

◆ VariableType

Enumerator
VT_UNK 
VT_INT 
VT_DOUBLE 
VT_VECINT 
VT_VECDOUBLE 
VT_VECEMPTY 

Definition at line 21 of file IProxyLoader.h.

Constructor & Destructor Documentation

◆ SGxAODProxyLoader()

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

Definition at line 40 of file SGxAODProxyLoader.cxx.

40 : m_evtStore(evtStore), m_emptyVectorAccessor(std::make_unique<EmptyVectorAccessor>()),m_verbose(verbose) { }

◆ ~SGxAODProxyLoader()

ExpressionParsing::SGxAODProxyLoader::~SGxAODProxyLoader ( )
virtual

Definition at line 42 of file SGxAODProxyLoader.cxx.

43  {
44  }

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 136 of file SGxAODProxyLoader.cxx.

139  {
140  const IProxyDict *proxy = Atlas::getExtendedEventContext( ctx ).proxy();
141  (void) proxy;
142  std::string container_name;
143  std::string method_name;
144  splitVarnameIntoContainerAndMethod(varname,container_name, method_name);
145  ReadHandleMap::const_iterator key_iter = m_readKeys.find(container_name);
146  if (key_iter == m_readKeys.end()) {
147  std::stringstream msg;
148  msg << "No read handle key for " << container_name;
149  throw std::runtime_error(msg.str());
150  }
151  SG::auxid_t method_id = SG::null_auxid;
152  ReadDecorHandleMap::const_iterator decor_key_iter = m_decorKeys.end();
153  if (ReadHandleMap::isVector(key_iter->second) || ReadHandleMap::isElement(key_iter->second)) {
154  method_id = SG::AuxTypeRegistry::instance().findAuxID(method_name,"");
155  if (method_id != SG::null_auxid) {
156  decor_key_iter=m_decorKeys.find(varname);
157  }
158  }
159  std::unique_ptr<IAccessor> accessor;
160  if (ReadHandleMap::isVector(key_iter->second)) {
161  if (m_verbose) { std::cout << "DEBUG SGxAODProxyLoader::computeClassForVarname is Vector: " << varname << std::endl; }
162  accessor = createAccessor(ctx,
163  ReadHandleMap::vectorKey(key_iter->second),
164  (decor_key_iter != m_decorKeys.end() ? &ReadDecorHandleMap::vectorKey(decor_key_iter->second) : nullptr),
165  method_id,
166  method_name);
167  }
168  else if (ReadHandleMap::isElement(key_iter->second)) {
169  if (m_verbose) { std::cout << "DEBUG SGxAODProxyLoader::computeClassForVarname is element: " << varname << std::endl; }
170  accessor = createAccessor(ctx,
171  ReadHandleMap::elementKey(key_iter->second),
172  (decor_key_iter != m_decorKeys.end() ? &ReadDecorHandleMap::elementKey(decor_key_iter->second) : nullptr),
173  method_id,
174  method_name);
175  }
176  else {
177  if (m_verbose) { std::cout << "DEBUG SGxAODProxyLoader::computeClassForVarname try to create plain type accessor for " << varname << std::endl; }
179  }
180  if (!accessor) {
181  return *m_emptyVectorAccessor;
182  }
183  IAccessor* accessorPlainPtr = accessor.get();//avoid Wpotentially-evaluated-expression from typeid
184  if (m_verbose) {
185  std::cout << "DEBUG SGxAODProxyLoader use accessor "
186  << typeid(*accessorPlainPtr).name() << " for " << varname
187  << std::endl;
188  }
189  accessor_iter->second.set(std::move(accessor));
190  return *(accessor_iter->second);
191  }

◆ 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 112 of file SGxAODProxyLoader.cxx.

117  {
118  SG::ReadHandle<T_Aux> handle(key, ctx);
119  if (!handle.isValid()) {
120  std::stringstream msg;
121  msg << "Failed to get " << key.key();
122  throw std::runtime_error(msg.str());
123  }
124  if (getContainerSize(*handle)==0) {
125  return std::unique_ptr<IAccessor>();
126  }
127  if (!isAvailable(*handle,method_id)) {
128  std::pair<RootUtils::TSMethodCall,TVirtualCollectionProxy *> method = getMethodCallAccessor(method_name, typeid(*handle));
129  return MethodAccessorFactory::instance().create( key, std::move(method.first), method.second);
130  }
131  else {
132  return ExpressionParsing::AccessorFactory::instance().create( key, method_id , decor_key );
133  }
134  }

◆ 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 138 of file SGxAODProxyLoader.h.

138  {
139  std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> >::const_iterator
140  accessor_iter = m_accessor.find(varname);
141  if (accessor_iter == m_accessor.end()) {
142  std::stringstream msg;
143  msg << "No accessor stub was created for " << varname << " i.e. variable is unknown.";
144  throw std::runtime_error(msg.str());
145  }
146  if (accessor_iter->second) return *(accessor_iter->second);
147  return computeClassForVarname(ctx,accessor_iter, varname);
148  }

◆ 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(?)

Definition at line 60 of file SGxAODProxyLoader.cxx.

60  {
61  if (m_verbose) {
62  std::cout << "DEBUG SGxAODProxyLoader search for " << method_name << " in type " << info.name() << std::endl;
63  }
64  TClass *containerClass = TClass::GetClass(info);
65  if (!containerClass) {
66  if (m_verbose) {
67  std::cout << "DEBUG SGxAODProxyLoader search for " << method_name << " in normalisze type " << SG::normalizedTypeinfoName(info) << std::endl;
68  }
69  containerClass = TClass::GetClass(SG::normalizedTypeinfoName(info).c_str());
70  if (!containerClass) {
71  std::stringstream msg;
72  msg << "No dictionary for " << info.name() << std::endl;
73  throw std::runtime_error(msg.str());
74  }
75  }
76  TClass *elementClass=nullptr;
77  TVirtualCollectionProxy *collection_proxy=nullptr;
78  if( strcmp(containerClass->GetName(),"SG::AuxElementStandaloneData")==0 ) {
79  elementClass=containerClass;
80  }
81  else {
82  collection_proxy = containerClass->GetCollectionProxy();
83  elementClass = (collection_proxy ? collection_proxy->GetValueClass() : nullptr);
84  if (!elementClass) {
85  std::stringstream msg;
86  msg << "No collection proxy or element class for " << info.name() << std::endl;
87  throw std::runtime_error(msg.str());
88  }
89  }
90  RootUtils::TSMethodCall method_call;
91  method_call.setProto (elementClass, method_name, "",
92  ROOT::kConversionMatch);
93  if (!method_call.call() || !method_call.call()->IsValid()) {
94  std::stringstream msg;
95  msg << "No valid method " << method_name << " for " << info.name() << std::endl;
96  throw std::runtime_error(msg.str());
97  }
98  if (m_verbose && method_call.call()->GetMethod()) {
99  // @TODO check signature "() const
100  std::cout << "DEBUG SGxAODProxyLoader got method " << " . " << method_name << " : "
101  << method_call.call()->GetMethod()->GetReturnTypeNormalizedName ()
102  << " proto=" << method_call.call()->GetProto()
103  << " signature=" << method_call.call()->GetMethod()->GetSignature ()
104  << " proto=" << method_call.call()->GetMethod()->GetPrototype()
105  << std::endl;
106  }
107  return std::make_pair( method_call, collection_proxy);
108  }

◆ loadDoubleVariableFromString()

double ExpressionParsing::SGxAODProxyLoader::loadDoubleVariableFromString ( const std::string &  varname) const
virtual

Implements ExpressionParsing::IProxyLoader.

Definition at line 222 of file SGxAODProxyLoader.cxx.

223  {
224  const EventContext& ctx = Gaudi::Hive::currentContext();
225  return dump(varname,getAccessor(ctx, varname).loadDouble(ctx));
226  }

◆ loadIntVariableFromString()

int ExpressionParsing::SGxAODProxyLoader::loadIntVariableFromString ( const std::string &  varname) const
virtual

Implements ExpressionParsing::IProxyLoader.

Definition at line 216 of file SGxAODProxyLoader.cxx.

217  {
218  const EventContext& ctx = Gaudi::Hive::currentContext();
219  return dump(varname,getAccessor(ctx, varname).loadInt(ctx));
220  }

◆ loadVecDoubleVariableFromString()

std::vector< double > ExpressionParsing::SGxAODProxyLoader::loadVecDoubleVariableFromString ( const std::string &  varname) const
virtual

Implements ExpressionParsing::IProxyLoader.

Definition at line 234 of file SGxAODProxyLoader.cxx.

235  {
236  const EventContext& ctx = Gaudi::Hive::currentContext();
237  return dump(varname,getAccessor(ctx, varname).loadVec(ctx));
238  }

◆ loadVecIntVariableFromString()

std::vector< int > ExpressionParsing::SGxAODProxyLoader::loadVecIntVariableFromString ( const std::string &  varname) const
virtual

Implements ExpressionParsing::IProxyLoader.

Definition at line 228 of file SGxAODProxyLoader.cxx.

229  {
230  const EventContext& ctx = Gaudi::Hive::currentContext();
231  return dump(varname,getAccessor(ctx, varname).loadVecInt(ctx));
232  }

◆ reset()

void ExpressionParsing::SGxAODProxyLoader::reset ( )
virtual

Implements ExpressionParsing::IProxyLoader.

Definition at line 46 of file SGxAODProxyLoader.cxx.

46  {
47  m_decorKeys.clear();
48  m_readKeys.clear();
49  m_accessor.clear();
50  }

◆ splitVarnameIntoContainerAndMethod()

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

Definition at line 52 of file SGxAODProxyLoader.cxx.

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

◆ 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 240 of file SGxAODProxyLoader.cxx.

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

◆ variableTypeFromString()

IProxyLoader::VariableType ExpressionParsing::SGxAODProxyLoader::variableTypeFromString ( const std::string &  varname) const
virtual

Implements ExpressionParsing::IProxyLoader.

Definition at line 193 of file SGxAODProxyLoader.cxx.

193  {
194  const EventContext& ctx = Gaudi::Hive::currentContext();
195  return getAccessor(ctx, varname).variableType();
196  }

◆ wrapParent()

template<class T >
static 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 90 of file SGxAODProxyLoader.h.

90  {
91  return ParentHelper<T>(parent);
92  }

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 208 of file SGxAODProxyLoader.h.

◆ m_decorKeys

ReadDecorHandleMap ExpressionParsing::SGxAODProxyLoader::m_decorKeys
private

Definition at line 202 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 216 of file SGxAODProxyLoader.h.

◆ m_evtStore

StoreGateSvc_t ExpressionParsing::SGxAODProxyLoader::m_evtStore
private

Definition at line 165 of file SGxAODProxyLoader.h.

◆ m_readKeys

ReadHandleMap ExpressionParsing::SGxAODProxyLoader::m_readKeys
private

Definition at line 201 of file SGxAODProxyLoader.h.

◆ m_verbose

bool ExpressionParsing::SGxAODProxyLoader::m_verbose = false
private

Definition at line 217 of file SGxAODProxyLoader.h.


The documentation for this class was generated from the following files:
RunTileTBRec.method
method
Definition: RunTileTBRec.py:73
grepfile.info
info
Definition: grepfile.py:38
ExpressionParsing::PlainAccessorFactory::registerReadKey
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)
Definition: PlainAccessor.h:112
ExpressionParsing::IProxyLoader::VT_VECEMPTY
@ VT_VECEMPTY
Definition: IProxyLoader.h:21
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
ExpressionParsing::SGxAODProxyLoader::m_verbose
bool m_verbose
Definition: SGxAODProxyLoader.h:217
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
SG::AuxTypeRegistry::findAuxID
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
Definition: AuxTypeRegistry.cxx:159
SG::normalizedTypeinfoName
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
Definition: normalizedTypeinfoName.cxx:120
CheckAppliedSFs.var_name
var_name
Definition: CheckAppliedSFs.py:241
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ExpressionParsing::IProxyLoader::VT_VECDOUBLE
@ VT_VECDOUBLE
Definition: IProxyLoader.h:21
CxxUtils::CachedUniquePtrT
Cached pointer with atomic update.
Definition: CachedUniquePtr.h:54
ExpressionParsing::SGxAODProxyLoader::splitVarnameIntoContainerAndMethod
void splitVarnameIntoContainerAndMethod(const std::string &varname, std::string &containerName, std::string &methodName) const
Definition: SGxAODProxyLoader.cxx:52
ExpressionParsing::SGxAODProxyLoader::ReadHandleMapTmpl< SG::ReadHandleKey< SG::AuxElement >, SG::ReadHandleKey< SG::AuxVectorBase > >::elementKey
static SG::ReadHandleKey< SG::AuxElement > & elementKey(std::any &anything)
Get a reference to the element object referred to by any or throw an exception.
Definition: SGxAODProxyLoader.h:189
ExpressionParsing::SGxAODProxyLoader::getMethodCallAccessor
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 met...
Definition: SGxAODProxyLoader.cxx:60
ExpressionParsing::AccessorFactory::create
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.
Definition: xAODAccessor.h:198
SG::BaseInfoBase::get_bases
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
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:51
ExpressionParsing::SGxAODProxyLoader::m_readKeys
ReadHandleMap m_readKeys
Definition: SGxAODProxyLoader.h:201
ExpressionParsing::Singleton< PlainAccessorFactory >::instance
static PlainAccessorFactory & instance()
Definition: PhysicsAnalysis/CommonTools/ExpressionEvaluation/src/Utils.h:90
ExpressionParsing::isAvailable
bool isAvailable(const T_Aux &cont, SG::auxid_t auxid)
RootUtils::TSMethodCall
Helper for making a thread-safe function call.
Definition: TSMethodCall.h:33
Atlas::getExtendedEventContext
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Definition: ExtendedEventContext.cxx:32
ExpressionParsing::SGxAODProxyLoader::m_accessor
std::unordered_map< std::string, CxxUtils::CachedUniquePtrT< IAccessor > > m_accessor
Association of variable names to accessors for corresponding xAOD object content.
Definition: SGxAODProxyLoader.h:208
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
ExpressionParsing::IProxyLoader::VT_DOUBLE
@ VT_DOUBLE
Definition: IProxyLoader.h:21
ExpressionParsing::IProxyLoader::VT_UNK
@ VT_UNK
Definition: IProxyLoader.h:21
ExpressionParsing::MethodAccessorFactory::create
std::unique_ptr< IAccessor > create(const SG::ReadHandleKey< SG::AuxElement > &key, RootUtils::TSMethodCall &&method_call, TVirtualCollectionProxy *proxy=nullptr) const
Create an accessor which calls the specified method of an AuxElement.
Definition: MethodAccessor.h:224
ret
T ret(T t)
Definition: rootspy.cxx:260
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ExpressionParsing::SGxAODProxyLoader::ReadHandleMapTmpl< SG::ReadHandleKey< SG::AuxElement >, SG::ReadHandleKey< SG::AuxVectorBase > >::isVector
static bool isVector(const std::any &anything)
Check whether the given any is the "vector" object.
Definition: SGxAODProxyLoader.h:185
ExpressionParsing::IProxyLoader::VT_VECINT
@ VT_VECINT
Definition: IProxyLoader.h:21
RootUtils::TSMethodCall::call
TMethodCall * call()
Return a pointer to the thread-specific TMethodCall.
Definition: TSMethodCall.cxx:109
ExpressionParsing::PlainAccessorFactory::createAccessor
std::unique_ptr< IAccessor > createAccessor(const std::any &handle_key) const
Definition: PlainAccessor.h:208
python.ChapPy.dump
def dump(buf, stdout=sys.stdout)
Definition: ChapPy.py:25
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
ExpressionParsing::IAccessor::variableType
virtual IProxyLoader::VariableType variableType() const =0
ExpressionParsing::SGxAODProxyLoader::m_decorKeys
ReadDecorHandleMap m_decorKeys
Definition: SGxAODProxyLoader.h:202
ExpressionParsing::IProxyLoader::VT_INT
@ VT_INT
Definition: IProxyLoader.h:21
ExpressionParsing::SGxAODProxyLoader::getAccessor
IAccessor & getAccessor(const EventContext &ctx, const std::string &varname) const
Get an existing or create a new accessor for the given variable name.
Definition: SGxAODProxyLoader.h:138
ExpressionParsing::SGxAODProxyLoader::m_evtStore
StoreGateSvc_t m_evtStore
Definition: SGxAODProxyLoader.h:165
SG::BaseInfoBase::find
static const BaseInfoBase * find(CLID clid)
Find the BaseInfoBase instance for clid.
Definition: BaseInfo.cxx:569
RootUtils::TSMethodCall::setProto
void setProto(TClass *cls, const std::string &fname, const std::string &args, ROOT::EFunctionMatchMode mode=ROOT::kExactMatch)
Set the function that we're to call.
Definition: TSMethodCall.cxx:90
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ExpressionParsing::getContainerSize
std::size_t getContainerSize(const T &cont)
Definition: PhysicsAnalysis/CommonTools/ExpressionEvaluation/src/Utils.h:73
ExpressionParsing::SGxAODProxyLoader::ReadHandleMapTmpl< SG::ReadHandleKey< SG::AuxElement >, SG::ReadHandleKey< SG::AuxVectorBase > >::vectorKey
static SG::ReadHandleKey< SG::AuxVectorBase > & vectorKey(std::any &anything)
Get a reference to the vector object referred to by any or throw an exception.
Definition: SGxAODProxyLoader.h:191
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
ExpressionParsing::dumpDeclare
void dumpDeclare(const T *key)
Function for debugging which dumps information about newly declared data handles.
Definition: DebugUtils.h:65
ExpressionParsing::SGxAODProxyLoader::createAccessor
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.
Definition: SGxAODProxyLoader.cxx:112
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
SG::BaseInfoBase
The non-template portion of the BaseInfo implementation.
Definition: Control/AthenaKernel/AthenaKernel/BaseInfo.h:451
ExpressionParsing::SGxAODProxyLoader::ReadHandleMapTmpl< SG::ReadHandleKey< SG::AuxElement >, SG::ReadHandleKey< SG::AuxVectorBase > >::isElement
static bool isElement(const std::any &anything)
Check whether the given any is the "element" object.
Definition: SGxAODProxyLoader.h:187
ExpressionParsing::SGxAODProxyLoader::computeClassForVarname
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.
Definition: SGxAODProxyLoader.cxx:136
ExpressionParsing::SGxAODProxyLoader::m_emptyVectorAccessor
std::unique_ptr< IAccessor > m_emptyVectorAccessor
Special accessor to handle empty vectors Accessor are constructed at time of first evaluation.
Definition: SGxAODProxyLoader.h:216
SG::BaseInfoBase::typeinfo
const std::type_info & typeinfo() const
Return the std::type_info for this class.
Definition: BaseInfo.cxx:151
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
ExpressionParsing::initializeHandle
void initializeHandle(T_Key *key, std::vector< Gaudi::DataHandle * > &new_input_handles)
Auxiliary function to initialize newly create data handles.
Definition: PhysicsAnalysis/CommonTools/ExpressionEvaluation/src/Utils.h:17
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
SG::BaseInfoBase::is_base
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