ATLAS Offline Software
Classes | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
ExpressionParsing::PlainAccessorFactory Class Reference

#include <PlainAccessor.h>

Inheritance diagram for ExpressionParsing::PlainAccessorFactory:
Collaboration diagram for ExpressionParsing::PlainAccessorFactory:

Classes

class  IKit
 
class  PlainValueKit
 
class  StdVectorKit
 

Public Member Functions

template<typename T , IProxyLoader::VariableType T_variable_type>
void registerStdVectorKit ()
 
template<typename T , IProxyLoader::VariableType T_variable_type>
void registerPlainValueKit ()
 
 PlainAccessorFactory ()
 
std::unique_ptr< IAccessorcreateAccessor (const std::any &handle_key) const
 
bool registerReadKey (std::unordered_map< std::string, std::any > &read_keys, const std::type_info &the_type, SGxAODProxyLoader::IParentHelper &parent, const std::string &var_name, std::vector< Gaudi::DataHandle * > &new_input_handles, bool verbose=false)
 

Static Public Member Functions

static void throwFailedToAddHandle (const std::string &var_name)
 
template<class T_Cont >
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 PlainAccessorFactoryinstance ()
 

Private Attributes

std::unordered_map< std::size_t, std::unique_ptr< IKit > > m_kits
 

Static Private Attributes

static CxxUtils::CachedUniquePtrT< PlainAccessorFactory > s_instance ATLAS_THREAD_SAFE
 

Detailed Description

Definition at line 91 of file PlainAccessor.h.

Constructor & Destructor Documentation

◆ PlainAccessorFactory()

ExpressionParsing::PlainAccessorFactory::PlainAccessorFactory ( )
inline

Definition at line 194 of file PlainAccessor.h.

194  {
195  // registerPlainValueKit<bool,IProxyLoader::VT_INT>();
196  registerPlainValueKit<bool,IProxyLoader::VT_INT>();
197  registerPlainValueKit<int,IProxyLoader::VT_INT>();
198  registerPlainValueKit<unsigned int,IProxyLoader::VT_INT>();
199  registerPlainValueKit<float,IProxyLoader::VT_DOUBLE>();
200  registerPlainValueKit<double,IProxyLoader::VT_DOUBLE>();
201 
202  registerStdVectorKit<bool,IProxyLoader::VT_VECINT>();
203  registerStdVectorKit<int,IProxyLoader::VT_VECINT>();
204  registerStdVectorKit<unsigned int,IProxyLoader::VT_VECINT>();
205  registerStdVectorKit<float,IProxyLoader::VT_VECDOUBLE>();
206  registerStdVectorKit<double,IProxyLoader::VT_VECDOUBLE>();
207  }

Member Function Documentation

◆ createAccessor()

std::unique_ptr<IAccessor> ExpressionParsing::PlainAccessorFactory::createAccessor ( const std::any &  handle_key) const
inline

Definition at line 208 of file PlainAccessor.h.

208  {
209  std::unordered_map<std::size_t,std::unique_ptr<IKit> >::const_iterator
210  kit_iter=m_kits.find(handle_key.type().hash_code());
211  if (kit_iter == m_kits.end()) {
212  std::stringstream msg;
213  msg << "ExpressionParsing::PlainAccessorFactory: no kit for type " << handle_key.type().name();
214  throw std::runtime_error(msg.str());
215  }
216  return kit_iter->second->createAccessor(handle_key);
217  }

◆ instance()

static PlainAccessorFactory & ExpressionParsing::Singleton< PlainAccessorFactory >::instance
inlinestaticinherited

Definition at line 90 of file PhysicsAnalysis/CommonTools/ExpressionEvaluation/src/Utils.h.

90  {
91  if (!s_instance) {
92  s_instance.set(std::make_unique<T_Derived>());
93  }
94  return *s_instance;
95  }

◆ registerPlainValueKit()

template<typename T , IProxyLoader::VariableType T_variable_type>
void ExpressionParsing::PlainAccessorFactory::registerPlainValueKit ( )
inline

Definition at line 189 of file PlainAccessor.h.

189  {
190  m_kits.insert( std::make_pair(typeid(SG::ReadHandleKey<T>).hash_code(), std::make_unique<PlainValueKit<T,T_variable_type> >()));
191  m_kits.insert( std::make_pair(typeid(T).hash_code(), std::make_unique<PlainValueKit<T,T_variable_type> >()));
192  }

◆ registerReadKey() [1/2]

bool ExpressionParsing::PlainAccessorFactory::registerReadKey ( std::unordered_map< std::string, std::any > &  read_keys,
const std::type_info &  the_type,
SGxAODProxyLoader::IParentHelper parent,
const std::string &  var_name,
std::vector< Gaudi::DataHandle * > &  new_input_handles,
bool  verbose = false 
)
inline

Definition at line 218 of file PlainAccessor.h.

223  {
224  std::unordered_map<std::size_t,std::unique_ptr<IKit> >::const_iterator
225  kit_iter=m_kits.find(the_type.hash_code());
226  if (kit_iter == m_kits.end()) {
227  if (verbose) {
228  std::cout << "DEBUG PlainAccessorFactory::createReadKey no matching kit for " << the_type.name() << " " << the_type.hash_code() << std::endl;
229  for (const std::pair<const std::size_t,std::unique_ptr<IKit> > &elm : m_kits) {
230  std::cout << "DEBUG PlainAccessorFactory::createReadKey have " << elm.first << std::endl;
231  }
232  }
233  return false;
234  }
235  return kit_iter->second->registerReadKey(read_keys, parent, var_name, new_input_handles, verbose);
236  }

◆ registerReadKey() [2/2]

template<class T_Cont >
static bool ExpressionParsing::PlainAccessorFactory::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 
)
inlinestatic

Definition at line 112 of file PlainAccessor.h.

116  {
118  std::pair<std::unordered_map<std::string, std::any >::iterator, bool> ret = read_keys.insert(std::make_pair(var_name, std::move(key)));
119  if (!ret.second) {
120  if (ret.first != read_keys.end()
121  && ret.first->first == var_name
122  && ret.first->second.type().hash_code() == typeid(key).hash_code()) {
123  return true;
124  }
126  }
127  SG::ReadHandleKey< T_Cont > *key_final( std::any_cast<SG::ReadHandleKey< T_Cont > >( &ret.first->second));
128  if (!key_final) {
130  }
131  if (parent.declare(*key_final).isFailure()) {
133  }
134  if (verbose) dumpDeclare(key_final);
135  initializeHandle(key_final, new_input_handles);
136  if (verbose) {
137  std::cout << "DEBUG PlainAccessorFactory::registerReadKey register read handle key for " << var_name << " [" << typeid(T_Cont).name() << "]."<< std::endl;
138  }
139  return true;
140  }

◆ registerStdVectorKit()

template<typename T , IProxyLoader::VariableType T_variable_type>
void ExpressionParsing::PlainAccessorFactory::registerStdVectorKit ( )
inline

Definition at line 184 of file PlainAccessor.h.

184  {
185  m_kits.insert( std::make_pair(typeid(std::vector<T>).hash_code(), std::make_unique< StdVectorKit<T,T_variable_type> >()));
186  m_kits.insert( std::make_pair(typeid(SG::ReadHandleKey<std::vector<T> >).hash_code(), std::make_unique< StdVectorKit<T,T_variable_type> >()));
187  }

◆ throwFailedToAddHandle()

static void ExpressionParsing::PlainAccessorFactory::throwFailedToAddHandle ( const std::string &  var_name)
inlinestatic

Definition at line 105 of file PlainAccessor.h.

105  {
106  std::stringstream msg;
107  msg << "Failed to add read handle key for " << var_name;
108  throw std::runtime_error(msg.str());
109  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

CxxUtils::CachedUniquePtrT<PlainAccessorFactory > s_instance ExpressionParsing::Singleton< PlainAccessorFactory >::ATLAS_THREAD_SAFE
staticprivateinherited

◆ m_kits

std::unordered_map<std::size_t,std::unique_ptr<IKit> > ExpressionParsing::PlainAccessorFactory::m_kits
private

Definition at line 238 of file PlainAccessor.h.


The documentation for this class was generated from the following file:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
CheckAppliedSFs.var_name
var_name
Definition: CheckAppliedSFs.py:241
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
test_pyathena.parent
parent
Definition: test_pyathena.py:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ExpressionParsing::PlainAccessorFactory::m_kits
std::unordered_map< std::size_t, std::unique_ptr< IKit > > m_kits
Definition: PlainAccessor.h:238
ExpressionParsing::PlainAccessorFactory::throwFailedToAddHandle
static void throwFailedToAddHandle(const std::string &var_name)
Definition: PlainAccessor.h:105
ExpressionParsing::dumpDeclare
void dumpDeclare(const T *key)
Function for debugging which dumps information about newly declared data handles.
Definition: DebugUtils.h:65
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
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