ATLAS Offline Software
Loading...
Searching...
No Matches
JetContext.h
Go to the documentation of this file.
1/*
2 * @file JetContext.h
3 * @brief a class for storing arbitrary event data.
4 * @date 2022-06-01
5 *
6 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
7 *
8 */
9
10#ifndef JETTOOLHELPERS_JETCONTEXT_H
11#define JETTOOLHELPERS_JETCONTEXT_H
12
13#include <unordered_map>
14#include <stdexcept>
15#include <variant>
16#include <type_traits>
17
18namespace JetHelper {
19
22
24 public:
25
26 template <typename T> bool setValue(const std::string& name, const T value, bool allowOverwrite = false);
27 template <typename T> void getValue(const std::string& name, T& value) const;
28 template <typename T> T getValue(const std::string& name) const;
29
30 bool isAvailable(const std::string& name) const {
31 return m_dict_.find(name) != m_dict_.end();
32 };
33
34 private:
35 std::unordered_map<std::string, std::variant<int, float>> m_dict_;
36};
37
38template <typename T> void JetContext::getValue(const std::string& name, T& value) const {
39 if(isAvailable(name))
40 value = std::get<T>(m_dict_.at(name));
41 else
42 throw std::invalid_argument(std::string("Key Error : ") + name + std::string(" not found in JetContext."));
43}
44
45template <typename T> T JetContext::getValue(const std::string& name) const {
46 T value;
47 getValue(name, value);
48 return value;
49}
50
51template <typename T> bool JetContext::setValue(const std::string& name, const T value, bool allowOverwrite) {
52 if(( !allowOverwrite && isAvailable(name)) ) return false;
53
54 if constexpr (!std::is_same<T, int>::value && !std::is_same<T, float>::value) {
55 static_assert(std::is_same<T, double>::value, "Unsupported type provided, please use integers or doubles.");
56 m_dict_.insert_or_assign(name, (float) value);
57 } else {
58 m_dict_.insert_or_assign(name, value); // insert returns pair with iterator and return code
59 }
60 return true; // if true => insertion, if false => assignement.
61}
62} // namespace JetHelper
63#endif
64
Class JetContext Designed to read AOD information related to the event, N vertices,...
Definition JetContext.h:23
std::unordered_map< std::string, std::variant< int, float > > m_dict_
Definition JetContext.h:35
bool setValue(const std::string &name, const T value, bool allowOverwrite=false)
Definition JetContext.h:51
bool isAvailable(const std::string &name) const
Definition JetContext.h:30
void getValue(const std::string &name, T &value) const
Definition JetContext.h:38
class IJetCalibStep