ATLAS Offline Software
Loading...
Searching...
No Matches
JetHelper::JetContext Class Reference

Class JetContext Designed to read AOD information related to the event, N vertices, Ntracks, mu etc ... More...

#include <JetContext.h>

Collaboration diagram for JetHelper::JetContext:

Public Member Functions

template<typename T>
bool setValue (std::string_view name, const T value, bool allowOverwrite=false)
template<typename T>
void getValue (std::string_view name, T &value) const
template<typename T>
getValue (std::string_view name) const
bool isAvailable (std::string_view name) const

Private Attributes

std::unordered_map< std::string, std::variant< int, float >, CxxUtils::TransparentStringHash, std::equal_to<> > m_dict_

Detailed Description

Class JetContext Designed to read AOD information related to the event, N vertices, Ntracks, mu etc ...

Definition at line 27 of file JetContext.h.

Member Function Documentation

◆ getValue() [1/2]

template<typename T>
T JetHelper::JetContext::getValue ( std::string_view name) const

Definition at line 52 of file JetContext.h.

52 {
53 T value;
54 getValue(name, value);
55 return value;
56}
void getValue(std::string_view name, T &value) const
Definition JetContext.h:43
unsigned long long T

◆ getValue() [2/2]

template<typename T>
void JetHelper::JetContext::getValue ( std::string_view name,
T & value ) const

Definition at line 43 of file JetContext.h.

43 {
44 //don't effectively 'find' twice
45 auto it = m_dict_.find(name);
46 if(it != m_dict_.end())
47 value = std::get<T>(it->second);
48 else
49 throw std::invalid_argument(std::format("Key Error : {} not found in JetContext.", name ));
50}
std::unordered_map< std::string, std::variant< int, float >, CxxUtils::TransparentStringHash, std::equal_to<> > m_dict_
Definition JetContext.h:40

◆ isAvailable()

bool JetHelper::JetContext::isAvailable ( std::string_view name) const
inline

Definition at line 34 of file JetContext.h.

34 {
35 return m_dict_.find(name) != m_dict_.end();
36 };

◆ setValue()

template<typename T>
bool JetHelper::JetContext::setValue ( std::string_view name,
const T value,
bool allowOverwrite = false )

Definition at line 58 of file JetContext.h.

58 {
59 if(( !allowOverwrite && isAvailable(name)) ) return false;
60
61 if constexpr (!std::is_same<T, int>::value && !std::is_same<T, float>::value) {
62 static_assert(std::is_same<T, double>::value, "Unsupported type provided, please use integers or doubles.");
63 m_dict_.insert_or_assign(std::string{name}, (float) value);
64 } else {
65 m_dict_.insert_or_assign(std::string{name}, value); // insert returns pair with iterator and return code
66 }
67 return true;
68}
bool isAvailable(std::string_view name) const
Definition JetContext.h:34

Member Data Documentation

◆ m_dict_

std::unordered_map<std::string, std::variant<int, float>, CxxUtils::TransparentStringHash,std::equal_to<> > JetHelper::JetContext::m_dict_
private

Definition at line 40 of file JetContext.h.


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