|
ATLAS Offline Software
|
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>
|
void | splitVarnameIntoContainerAndMethod (const std::string &varname, std::string &containerName, std::string &methodName) const |
|
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. 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...
|
|
IAccessor & | getAccessor (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< 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. More...
|
|
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.
◆ ReadDecorHandleMap
◆ ReadHandleMap
◆ StoreGateSvc_t
◆ VariableType
Enumerator |
---|
VT_UNK | |
VT_INT | |
VT_DOUBLE | |
VT_VECINT | |
VT_VECDOUBLE | |
VT_VECEMPTY | |
Definition at line 21 of file IProxyLoader.h.
◆ SGxAODProxyLoader()
ExpressionParsing::SGxAODProxyLoader::SGxAODProxyLoader |
( |
StoreGateSvc_t & |
evtStore, |
|
|
bool |
verbose = false |
|
) |
| |
◆ ~SGxAODProxyLoader()
ExpressionParsing::SGxAODProxyLoader::~SGxAODProxyLoader |
( |
| ) |
|
|
virtual |
◆ computeClassForVarname()
Auxiliary method to create an xAOD object content accessor for the given variable name.
- Parameters
-
ctx | the current event context |
accessor_iter | location where the newly created accessor will be stored. |
varname | the variable name which defines the xAOD container and the content. |
Definition at line 136 of file SGxAODProxyLoader.cxx.
142 std::string container_name;
143 std::string method_name;
145 ReadHandleMap::const_iterator key_iter =
m_readKeys.find(container_name);
147 std::stringstream
msg;
148 msg <<
"No read handle key for " << container_name;
149 throw std::runtime_error(
msg.str());
152 ReadDecorHandleMap::const_iterator decor_key_iter =
m_decorKeys.end();
155 if (method_id != SG::null_auxid) {
159 std::unique_ptr<IAccessor>
accessor;
161 if (
m_verbose) { std::cout <<
"DEBUG SGxAODProxyLoader::computeClassForVarname is Vector: " <<
varname << std::endl; }
169 if (
m_verbose) { std::cout <<
"DEBUG SGxAODProxyLoader::computeClassForVarname is element: " <<
varname << std::endl; }
177 if (
m_verbose) { std::cout <<
"DEBUG SGxAODProxyLoader::computeClassForVarname try to create plain type accessor for " <<
varname << std::endl; }
183 IAccessor* accessorPlainPtr =
accessor.get();
185 std::cout <<
"DEBUG SGxAODProxyLoader use accessor "
186 <<
typeid(*accessorPlainPtr).name() <<
" for " <<
varname
189 accessor_iter->second.set(std::move(
accessor));
190 return *(accessor_iter->second);
◆ createAccessor()
Auxiliary method to create an accessor for the given method_name.
- Parameters
-
ctx | the current event context. |
key | a valid read handle key to retrieve the corresponding container. |
decor_key | a valid read handle key or nullptr to create a decoration handle for the given method |
method_id | the xAOD ID of the given method |
the | name of the method. |
- Returns
- returns an accessor for the xAOD content.
Definition at line 112 of file SGxAODProxyLoader.cxx.
119 if (!handle.isValid()) {
120 std::stringstream
msg;
121 msg <<
"Failed to get " <<
key.key();
122 throw std::runtime_error(
msg.str());
125 return std::unique_ptr<IAccessor>();
◆ 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
-
ctx | the current event context |
varname | the 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.
139 std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> >::const_iterator
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());
146 if (accessor_iter->second)
return *(accessor_iter->second);
◆ 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_name | the name of the method to be called. |
info | the 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.
62 std::cout <<
"DEBUG SGxAODProxyLoader search for " << method_name <<
" in type " <<
info.name() << std::endl;
64 TClass *containerClass = TClass::GetClass(
info);
65 if (!containerClass) {
70 if (!containerClass) {
71 std::stringstream
msg;
72 msg <<
"No dictionary for " <<
info.name() << std::endl;
73 throw std::runtime_error(
msg.str());
76 TClass *elementClass=
nullptr;
77 TVirtualCollectionProxy *collection_proxy=
nullptr;
78 if( strcmp(containerClass->GetName(),
"SG::AuxElementStandaloneData")==0 ) {
79 elementClass=containerClass;
82 collection_proxy = containerClass->GetCollectionProxy();
83 elementClass = (collection_proxy ? collection_proxy->GetValueClass() :
nullptr);
85 std::stringstream
msg;
86 msg <<
"No collection proxy or element class for " <<
info.name() << std::endl;
87 throw std::runtime_error(
msg.str());
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());
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()
107 return std::make_pair( method_call, collection_proxy);
◆ loadDoubleVariableFromString()
double ExpressionParsing::SGxAODProxyLoader::loadDoubleVariableFromString |
( |
const std::string & |
varname | ) |
const |
|
virtual |
◆ loadIntVariableFromString()
int ExpressionParsing::SGxAODProxyLoader::loadIntVariableFromString |
( |
const std::string & |
varname | ) |
const |
|
virtual |
◆ loadVecDoubleVariableFromString()
std::vector< double > ExpressionParsing::SGxAODProxyLoader::loadVecDoubleVariableFromString |
( |
const std::string & |
varname | ) |
const |
|
virtual |
◆ loadVecIntVariableFromString()
std::vector< int > ExpressionParsing::SGxAODProxyLoader::loadVecIntVariableFromString |
( |
const std::string & |
varname | ) |
const |
|
virtual |
◆ reset()
void ExpressionParsing::SGxAODProxyLoader::reset |
( |
| ) |
|
|
virtual |
◆ splitVarnameIntoContainerAndMethod()
void ExpressionParsing::SGxAODProxyLoader::splitVarnameIntoContainerAndMethod |
( |
const std::string & |
varname, |
|
|
std::string & |
containerName, |
|
|
std::string & |
methodName |
|
) |
| const |
|
private |
◆ 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
-
parent | auxiliary class to declare new data handles with the calling parent |
var_names | the variables for which data dependencies might be created. |
renounce | a list of output data keys, which should be renounced from the new_input_handles list. |
input_data_in | read data object IDs declared by all algorithms and tools |
output_data_in | write data object IDs declared by all algorithms and tools |
new_input_handles | will be filled with read data handles newly created by this loader |
new_output_handles | will 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.
248 (void) new_output_handles;
250 for (
const std::string &
var_name : var_names) {
252 std::string container_name;
253 std::string method_name;
256 std::cout <<
"DEBUG SGxAODProxyLoader::updateDataDependencies var " <<
var_name <<
" -> " << container_name <<
" . " << method_name
257 <<
" i:" << input_data_in.size() <<
" o:" << output_data_in.size()
260 const DataObjID *container_data_id=
nullptr;
261 const DataObjID *method_data_id=
nullptr;
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)) {
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() :
"")
284 method_data_id = obj_data_id;
285 if (container_data_id)
return true;
287 else if (handle_key == container_name ) {
288 container_data_id = obj_data_id;
289 if (method_data_id)
return true;
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) {}
298 if (method_data_id) {
299 if (!container_data_id) {
300 container_data_id=method_data_id;
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;
308 std::cout <<
"DEBUG SGxAODProxyLoader container_clid " << container_data_id->clid() << std::endl;
312 if (container_data_id) {
315 if (have_container_read_key && !method_data_id)
continue;
317 auto clid = container_data_id->clid();
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.";
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. ";
332 throw std::runtime_error(
msg.str());
336 std::cout <<
"DEBUG SGxAODProxyLoader " << container_name <<
" -> " << base_info->
typeinfo().name() << std::endl;
339 std::cout <<
"DEBUG SGxAODProxyLoader " << container_name <<
" base: " << a_base_info->
typeinfo().name() << std::endl;
348 if (!have_container_read_key) {
349 read_key = std::make_any<SG::ReadHandleKey<SG::AuxVectorBase> >(container_name);
351 if (method_data_id) {
352 decor_key = std::make_any<SG::ReadDecorHandleKey<SG::AuxVectorBase> >(
var_name);
356 if (!have_container_read_key) {
357 read_key = std::make_any<SG::ReadHandleKey<SG::AuxElement> >(container_name);
359 if (method_data_id) {
360 decor_key = std::make_any<SG::ReadDecorHandleKey<SG::AuxElement> >(
var_name);
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());
370 if (registered_key) {
371 popRenounced(renounce, new_input_handles);
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());
383 std::pair<ReadHandleMap::iterator, bool> ret =
m_readKeys.insert(std::make_pair(container_name, std::move(read_key)));
387 std::stringstream
msg;
388 msg <<
"Failed to add read handle key for " << container_name;
389 throw std::runtime_error(
msg.str());
397 popRenounced(renounce, new_input_handles);
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());
408 std::pair<ReadDecorHandleMap::iterator, bool> ret =
m_decorKeys.insert(std::make_pair(
var_name,std::move(decor_key)));
412 std::stringstream
msg;
413 msg <<
"Failed to add read decor handle key for " <<
var_name;
414 throw std::runtime_error(
msg.str());
422 popRenounced(renounce, new_input_handles);
◆ variableTypeFromString()
◆ wrapParent()
template<class T >
static ParentHelper<T> ExpressionParsing::SGxAODProxyLoader::wrapParent |
( |
T * |
parent | ) |
|
|
inlinestatic |
◆ m_accessor
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
◆ 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
◆ m_readKeys
◆ m_verbose
bool ExpressionParsing::SGxAODProxyLoader::m_verbose = false |
|
private |
The documentation for this class was generated from the following files:
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 AuxTypeRegistry & instance()
Return the singleton registry instance.
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
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...
Cached pointer with atomic update.
void splitVarnameIntoContainerAndMethod(const std::string &varname, std::string &containerName, std::string &methodName) const
static SG::ReadHandleKey< SG::AuxElement > & elementKey(std::any &anything)
Get a reference to the element object referred to by any or throw an exception.
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...
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.
const std::vector< CLID > & get_bases() const
Return the class IDs of all known bases of T (that have class IDs).
static PlainAccessorFactory & instance()
bool isAvailable(const T_Aux &cont, SG::auxid_t auxid)
Helper for making a thread-safe function call.
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
std::unordered_map< std::string, CxxUtils::CachedUniquePtrT< IAccessor > > m_accessor
Association of variable names to accessors for corresponding xAOD object content.
size_t auxid_t
Identifier for a particular aux data item.
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.
Default, invalid implementation of ClassID_traits.
static bool isVector(const std::any &anything)
Check whether the given any is the "vector" object.
TMethodCall * call()
Return a pointer to the thread-specific TMethodCall.
std::unique_ptr< IAccessor > createAccessor(const std::any &handle_key) const
uint32_t CLID
The Class ID type.
virtual IProxyLoader::VariableType variableType() const =0
ReadDecorHandleMap m_decorKeys
IAccessor & getAccessor(const EventContext &ctx, const std::string &varname) const
Get an existing or create a new accessor for the given variable name.
StoreGateSvc_t m_evtStore
static const BaseInfoBase * find(CLID clid)
Find the BaseInfoBase instance for clid.
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.
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
std::size_t getContainerSize(const T &cont)
static SG::ReadHandleKey< SG::AuxVectorBase > & vectorKey(std::any &anything)
Get a reference to the vector object referred to by any or throw an exception.
void dumpDeclare(const T *key)
Function for debugging which dumps information about newly declared data handles.
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.
The non-template portion of the BaseInfo implementation.
static bool isElement(const std::any &anything)
Check whether the given any is the "element" object.
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.
std::unique_ptr< IAccessor > m_emptyVectorAccessor
Special accessor to handle empty vectors Accessor are constructed at time of first evaluation.
const std::type_info & typeinfo() const
Return the std::type_info for this class.
void initializeHandle(T_Key *key, std::vector< Gaudi::DataHandle * > &new_input_handles)
Auxiliary function to initialize newly create data handles.
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.