ATLAS Offline Software
Loading...
Searching...
No Matches
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

Member Enumeration Documentation

◆ VariableType

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 }
#define x

◆ 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 {
223 const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
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 }
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
bool try_type(const std::string &varname, const std::type_info *ti, const AUX *data) const
static AuxTypeRegistry & instance()
Return the singleton registry instance.
int r
Definition globals.cxx:22
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27

◆ 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) {
211 const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
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 }
#define TYPE(CODE, TYP, IOTYP)

◆ 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 }
IProxyLoader::VariableType try_all_known_types(const std::string &varname, const AUX *data, bool isVector) const

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.

201{nullptr};

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