ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
ElectronPhotonID
EgammaAnalysisHelpers
Root
AsgEGammaConfigHelper.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
EgammaAnalysisHelpers/AsgEGammaConfigHelper.h
"
6
#include "
AsgMessaging/AsgMessaging.h
"
7
#include "TEnv.h"
8
#include <iostream>
9
#include <sstream>
10
#include <limits>
11
12
namespace
AsgConfigHelper
{
13
14
std::string
15
findConfigFile
(
const
std::string& input,
16
const
std::map<std::string, std::string>& configmap)
17
{
18
auto
confFile_itr = configmap.find(input);
19
if
(confFile_itr == configmap.end()) {
20
static
const
asg::AsgMessaging
msg
(
"Egamma::AsgConfigHelper"
);
21
msg
.msg(MSG::WARNING) <<
"Key "
<< input
22
<<
" not found in map, no config file returned"
23
<<
endmsg
;
24
return
""
;
25
}
26
return
confFile_itr->second;
27
}
28
29
unsigned
int
30
findMask
(
const
std::string& input,
31
const
std::map<std::string, unsigned int>& maskmap)
32
{
33
auto
mask_itr = maskmap.find(input);
34
if
(mask_itr == maskmap.end()) {
35
static
const
asg::AsgMessaging
msg
(
"Egamma::AsgConfigHelper"
);
36
msg
.msg(MSG::WARNING)
37
<<
"Key "
<< input
38
<<
" not found in map, egammaPID::EgPidUndefined mask returned"
39
<<
endmsg
;
40
// mask has the choice to default to all 1 or all 0 bits, choose the former
41
return
std::numeric_limits<unsigned int>::max();
42
}
43
return
static_cast<
unsigned
int
>
(mask_itr->second);
44
}
45
46
template
<
typename
T>
47
bool
48
strtof
(
const
std::string& input, T& f)
49
{
50
int
diff
= 0;
51
std::string tmp = input;
52
std::string::size_type first(0);
53
std::string::size_type last(0);
54
first = (input.find(
'#'
));
55
56
// if we do not find a comment character "#" we are fine
57
if
(first == std::string::npos) {
58
std::istringstream buffer(tmp);
59
buffer >> f;
60
return
true
;
61
}
else
{
62
// if we have found comment character check if it is inlined between two "#"
63
last = (input.find(
'#'
, first + 1));
64
// if nor error
65
if
(last == std::string::npos) {
66
static
const
asg::AsgMessaging
msg
(
"Egamma::AsgConfigHelper"
);
67
msg
.msg(MSG::WARNING) <<
" Improper comment format , inline comment "
68
"should be enclosed between two # "
69
<<
endmsg
;
70
return
false
;
71
}
72
// else if between two "#" remove this part
73
diff
= last - first;
74
tmp = tmp.erase(first,
diff
+ 1);
75
std::istringstream buffer(tmp);
76
buffer >> f;
77
return
true
;
78
}
79
}
80
81
template
<
typename
T>
82
std::vector<T>
83
Helper
(
const
std::string& input, TEnv& env)
84
{
85
std::vector<T> CutVector;
86
std::string env_input(env.GetValue(input.c_str(),
""
));
87
if
(!env_input.empty()) {
88
std::string::size_type end;
89
do
{
90
end = env_input.find(
';'
);
91
T myValue{};
//default init
92
if
(
AsgConfigHelper::strtof
(env_input.substr(0, end), myValue)) {
93
CutVector.push_back(std::move(myValue));
94
}
95
if
(end != std::string::npos) {
96
env_input = env_input.substr(end + 1);
97
}
98
}
while
(end != std::string::npos);
99
}
100
return
CutVector;
101
}
102
}
103
104
// use the specializations
105
std::vector<double>
106
AsgConfigHelper::HelperDouble
(
const
std::string& input, TEnv& env)
107
{
108
return
AsgConfigHelper::Helper<double>
(input, env);
109
}
110
std::vector<float>
111
AsgConfigHelper::HelperFloat
(
const
std::string& input, TEnv& env)
112
{
113
return
AsgConfigHelper::Helper<float>
(input, env);
114
}
115
std::vector<int>
116
AsgConfigHelper::HelperInt
(
const
std::string& input, TEnv& env)
117
{
118
return
AsgConfigHelper::Helper<int>
(input, env);
119
}
120
// template does not work for std::string because of the T myValue(0);
121
// declaration, so implement it again for std::string
122
std::vector<std::string>
123
AsgConfigHelper::HelperString
(
const
std::string& input, TEnv& env)
124
{
125
return
AsgConfigHelper::Helper<std::string>
(input, env);
126
}
127
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:61
AsgEGammaConfigHelper.h
AsgMessaging.h
diff
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition
Jet.cxx:631
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition
AsgMessaging.h:40
AsgConfigHelper
Definition
AsgEGammaConfigHelper.h:21
AsgConfigHelper::Helper
std::vector< T > Helper(const std::string &input, TEnv &env)
Definition
AsgEGammaConfigHelper.cxx:83
AsgConfigHelper::HelperInt
std::vector< int > HelperInt(const std::string &input, TEnv &env)
Definition
AsgEGammaConfigHelper.cxx:116
AsgConfigHelper::HelperString
std::vector< std::string > HelperString(const std::string &input, TEnv &env)
Definition
AsgEGammaConfigHelper.cxx:123
AsgConfigHelper::strtof
bool strtof(const std::string &input, T &f)
Definition
AsgEGammaConfigHelper.cxx:48
AsgConfigHelper::findMask
unsigned int findMask(const std::string &input, const std::map< std::string, unsigned int > &maskmap)
Definition
AsgEGammaConfigHelper.cxx:30
AsgConfigHelper::HelperDouble
std::vector< double > HelperDouble(const std::string &input, TEnv &env)
Definition
AsgEGammaConfigHelper.cxx:106
AsgConfigHelper::findConfigFile
std::string findConfigFile(const std::string &input, const std::map< std::string, std::string > &configmap)
Definition
AsgEGammaConfigHelper.cxx:15
AsgConfigHelper::HelperFloat
std::vector< float > HelperFloat(const std::string &input, TEnv &env)
Definition
AsgEGammaConfigHelper.cxx:111
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0