ATLAS Offline Software
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ExpressionParsing::xAODVectorProxyLoader Class Reference

#include <xAODVariableProxyLoaders.h>

Inheritance diagram for ExpressionParsing::xAODVectorProxyLoader:
Collaboration diagram for ExpressionParsing::xAODVectorProxyLoader:

Public Types

enum  VariableType {
  VT_UNK, VT_INT, VT_DOUBLE, VT_VECINT,
  VT_VECDOUBLE, VT_VECEMPTY
}
 

Public Member Functions

 xAODVectorProxyLoader ()=default
 
 xAODVectorProxyLoader (const SG::AuxVectorData *auxVectorData)
 
void setData (const SG::AuxVectorData *auxElement)
 
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
 
virtual void reset ()
 

Protected Types

using accessorCache_t = CxxUtils::ConcurrentStrMap< BaseAccessorWrapper *, CxxUtils::SimpleUpdater >
 

Protected Member Functions

template<class TYPE , class AUX >
bool try_type (const std::string &varname, const std::type_info *ti, const AUX *data) const
 
template<class AUX >
IProxyLoader::VariableType try_all_known_types (const std::string &varname, const AUX *data, bool isVector) const
 

Protected Attributes

accessorCache_t m_accessorCache ATLAS_THREAD_SAFE
 

Private Attributes

const SG::AuxVectorDatam_auxVectorData {nullptr}
 

Detailed Description

Definition at line 187 of file xAODVariableProxyLoaders.h.

Member Typedef Documentation

◆ accessorCache_t

Definition at line 164 of file xAODVariableProxyLoaders.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

◆ xAODVectorProxyLoader() [1/2]

ExpressionParsing::xAODVectorProxyLoader::xAODVectorProxyLoader ( )
default

◆ xAODVectorProxyLoader() [2/2]

ExpressionParsing::xAODVectorProxyLoader::xAODVectorProxyLoader ( const SG::AuxVectorData auxVectorData)

Definition at line 312 of file xAODVariableProxyLoaders.cxx.

313  : m_auxVectorData(auxVectorData)
314  {
315  }

Member Function Documentation

◆ loadDoubleVariableFromString()

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

Implements ExpressionParsing::IProxyLoader.

Definition at line 351 of file xAODVariableProxyLoaders.cxx.

352  {
353  throw std::runtime_error("xAODVectorProxyLoader can't load scalar types");
354  }

◆ loadIntVariableFromString()

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

Implements ExpressionParsing::IProxyLoader.

Definition at line 346 of file xAODVariableProxyLoaders.cxx.

347  {
348  throw std::runtime_error("xAODVectorProxyLoader can't load scalar types");
349  }

◆ loadVecDoubleVariableFromString()

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

Implements ExpressionParsing::IProxyLoader.

Definition at line 361 of file xAODVariableProxyLoaders.cxx.

362  {/*
363  // Check whether we have an accessor already:
364  std::map< std::string, BaseAccessorWrapper* >::const_iterator itr;
365  if( ( itr = m_accessorCache.find( varname ) ) == m_accessorCache.end() ) {
366  // For an empty container let's not bother too much:
367  if( m_auxVectorData->size_v() == 0 ) {
368  return std::vector< double >();
369  }
370  // If it's not empty, then let the variableTypeFromString function
371  // figure out the variable type, and create the accessor:
372  if( variableTypeFromString( varname ) == VT_UNK ) {
373  throw std::runtime_error( "Couldn't find variable type for " +
374  varname );
375  }
376  // Update the iterator:
377  itr = m_accessorCache.find( varname );
378  }
379  // Now do the "regular thing". Note that even if the type turns out
380  // to be an integer type, the accessor wrapper does the conversion
381  // reasonably anyway, behind the scenes.
382  return itr->second->getVecDoubleValue(m_auxVectorData);*/
383  return m_accessorCache.at(varname)->getVecDoubleValue(m_auxVectorData);
384  }

◆ loadVecIntVariableFromString()

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

Implements ExpressionParsing::IProxyLoader.

Definition at line 356 of file xAODVariableProxyLoaders.cxx.

357  {
358  return m_accessorCache.at(varname)->getVecIntValue(m_auxVectorData);
359  }

◆ reset()

void ExpressionParsing::xAODProxyLoader::reset ( )
virtualinherited

Implements ExpressionParsing::IProxyLoader.

Definition at line 196 of file xAODVariableProxyLoaders.cxx.

197  {
198  for (auto x : m_accessorCache) delete x.second;
199  // m_accessorCache.clear(); // not supported by ConcurrentStrMap
200  }

◆ setData()

void ExpressionParsing::xAODVectorProxyLoader::setData ( const SG::AuxVectorData auxElement)

Definition at line 317 of file xAODVariableProxyLoaders.cxx.

318  {
319  m_auxVectorData = auxVectorData;
320  }

◆ try_all_known_types()

template<class AUX >
IProxyLoader::VariableType ExpressionParsing::xAODProxyLoader::try_all_known_types ( const std::string &  varname,
const AUX *  data,
bool  isVector 
) const
protectedinherited

Definition at line 220 of file xAODVariableProxyLoaders.cxx.

222  {
224  const SG::auxid_t auxid = r.findAuxID(varname);
225  if (auxid != SG::null_auxid) {
226  const std::type_info *ti = r.getType(auxid);
227  // Try integer types:
228  if ( try_type<int>(varname, ti, data) ||
229  try_type<bool>(varname, ti, data) ||
230  try_type<unsigned int>(varname, ti, data) ||
231  try_type<char>(varname, ti, data) ||
232  try_type<uint8_t>(varname, ti, data) ||
233  try_type<unsigned short>(varname, ti, data) ||
234  try_type<short>(varname, ti, data) ) {
236  }
237  // Try floating point types:
238  if ( try_type<float>(varname, ti, data) ||
239  try_type<double>(varname, ti, data) ) {
241  }
242  }
243  return VT_UNK;
244  }

◆ try_type()

template<class TYPE , class AUX >
bool ExpressionParsing::xAODProxyLoader::try_type ( const std::string &  varname,
const std::type_info *  ti,
const AUX *  data 
) const
protectedinherited

Definition at line 203 of file xAODVariableProxyLoaders.cxx.

204  {
205  if (*ti == typeid(TYPE)) {
206  auto accWrap = std::make_unique<AccessorWrapper<TYPE>>(varname);
207  if (accWrap && accWrap->isValid(data)) {
208  m_accessorCache.insert_or_assign(varname, accWrap.release());
209  return true;
210  } else if (accWrap) {
212  const SG::auxid_t auxid = r.findAuxID(varname);
213  throw std::runtime_error("Unsupported aux element type '"+r.getTypeName(auxid)+"' for '"+varname+"'");
214  }
215  }
216  return false;
217  }

◆ variableTypeFromString()

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

Implements ExpressionParsing::IProxyLoader.

Definition at line 322 of file xAODVariableProxyLoaders.cxx.

323  {
324  auto accWrap = std::make_unique<TMethodCollectionWrapper>(typeid(*m_auxVectorData), varname);
325  if (accWrap && accWrap->isValid(m_auxVectorData)) {
326  const IProxyLoader::VariableType vtype = accWrap->variableType();
327  m_accessorCache.insert_or_assign(varname, accWrap.release());
328  return vtype;
329  }
330 
332 
333  // Before giving up completely, check the size of the vector. If it's
334  // 0, it may be that it's empty on *all* events of the current input
335  // file. Meaning that dynamic variables will be missing from each event.
336  if( vtype==VT_UNK && m_auxVectorData->size_v() == 0 ) {
337  // Let's claim a vector<double> type, that seems to be the safest bet.
338  // Even if the variable should actually be vector<int>, this is a
339  // simple conversion at least.
340  vtype = VT_VECDOUBLE;
341  }
342 
343  return vtype;
344  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

accessorCache_t m_accessorCache ExpressionParsing::xAODProxyLoader::ATLAS_THREAD_SAFE
mutableprotectedinherited

Definition at line 165 of file xAODVariableProxyLoaders.h.

◆ m_auxVectorData

const SG::AuxVectorData* ExpressionParsing::xAODVectorProxyLoader::m_auxVectorData {nullptr}
private

Definition at line 201 of file xAODVariableProxyLoaders.h.


The documentation for this class was generated from the following files:
beamspotman.r
def r
Definition: beamspotman.py:676
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ExpressionParsing::IProxyLoader::VT_VECEMPTY
@ VT_VECEMPTY
Definition: IProxyLoader.h:21
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:639
ExpressionParsing::IProxyLoader::VT_VECDOUBLE
@ VT_VECDOUBLE
Definition: IProxyLoader.h:21
ExpressionParsing::xAODVectorProxyLoader::m_auxVectorData
const SG::AuxVectorData * m_auxVectorData
Definition: xAODVariableProxyLoaders.h:201
x
#define x
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
ExpressionParsing::IProxyLoader::VariableType
VariableType
Definition: IProxyLoader.h:21
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::xAODProxyLoader::try_all_known_types
IProxyLoader::VariableType try_all_known_types(const std::string &varname, const AUX *data, bool isVector) const
Definition: xAODVariableProxyLoaders.cxx:220
ExpressionParsing::IProxyLoader::VT_VECINT
@ VT_VECINT
Definition: IProxyLoader.h:21
ExpressionParsing::IProxyLoader::VT_INT
@ VT_INT
Definition: IProxyLoader.h:21
TYPE
#define TYPE(CODE, TYP, IOTYP)
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
runLayerRecalibration.isVector
string isVector
Definition: runLayerRecalibration.py:125
SG::AuxVectorData::size_v
virtual size_t size_v() const =0
Return the size of the container.