ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetToolHelpers
JetToolHelpers
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-2026 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
#include <string>
18
#include <string_view>
19
#include <format>
20
#include "
CxxUtils/transparent_string_hash.h
"
21
22
namespace
JetHelper
{
23
26
27
class
JetContext
{
28
public
:
29
30
template
<
typename
T>
bool
setValue
(std::string_view name,
const
T value,
bool
allowOverwrite =
false
);
31
template
<
typename
T>
void
getValue
(std::string_view name, T& value)
const
;
32
template
<
typename
T> T
getValue
(std::string_view name)
const
;
33
34
bool
isAvailable
(std::string_view name)
const
{
35
return
m_dict_
.find(name) !=
m_dict_
.end();
36
};
37
38
private
:
39
std::unordered_map<std::string, std::variant<int, float>,
40
CxxUtils::TransparentStringHash
,std::equal_to<> >
m_dict_
;
41
};
42
43
template
<
typename
T>
void
JetContext::getValue
(std::string_view name, T& value)
const
{
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
}
51
52
template
<
typename
T> T
JetContext::getValue
(std::string_view name)
const
{
53
T value;
54
getValue
(name, value);
55
return
value;
56
}
57
58
template
<
typename
T>
bool
JetContext::setValue
(std::string_view name,
const
T value,
bool
allowOverwrite) {
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
}
69
}
// namespace JetHelper
70
#endif
71
JetHelper::JetContext
Class JetContext Designed to read AOD information related to the event, N vertices,...
Definition
JetContext.h:27
JetHelper::JetContext::isAvailable
bool isAvailable(std::string_view name) const
Definition
JetContext.h:34
JetHelper::JetContext::getValue
void getValue(std::string_view name, T &value) const
Definition
JetContext.h:43
JetHelper::JetContext::m_dict_
std::unordered_map< std::string, std::variant< int, float >, CxxUtils::TransparentStringHash, std::equal_to<> > m_dict_
Definition
JetContext.h:40
JetHelper::JetContext::setValue
bool setValue(std::string_view name, const T value, bool allowOverwrite=false)
Definition
JetContext.h:58
JetHelper
class IJetCalibStep
Definition
IInputVariable.h:18
CxxUtils::TransparentStringHash
Transparent hash functor for string-like keys.
Definition
transparent_string_hash.h:60
transparent_string_hash.h
Generated on
for ATLAS Offline Software by
1.17.0