ATLAS Offline Software
Loading...
Searching...
No Matches
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
7#include "TEnv.h"
8#include <iostream>
9#include <sstream>
10#include <limits>
11
12namespace AsgConfigHelper {
13
14std::string
15findConfigFile(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
29unsigned int
30findMask(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
46template<typename T>
47bool
48strtof(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
81template<typename T>
82std::vector<T>
83Helper(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
105std::vector<double>
106AsgConfigHelper::HelperDouble(const std::string& input, TEnv& env)
107{
108 return AsgConfigHelper::Helper<double>(input, env);
109}
110std::vector<float>
111AsgConfigHelper::HelperFloat(const std::string& input, TEnv& env)
112{
113 return AsgConfigHelper::Helper<float>(input, env);
114}
115std::vector<int>
116AsgConfigHelper::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
122std::vector<std::string>
123AsgConfigHelper::HelperString(const std::string& input, TEnv& env)
124{
125 return AsgConfigHelper::Helper<std::string>(input, env);
126}
127
#define endmsg
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
Class mimicking the AthMessaging class from the offline software.
std::vector< T > Helper(const std::string &input, TEnv &env)
std::vector< int > HelperInt(const std::string &input, TEnv &env)
std::vector< std::string > HelperString(const std::string &input, TEnv &env)
bool strtof(const std::string &input, T &f)
unsigned int findMask(const std::string &input, const std::map< std::string, unsigned int > &maskmap)
std::vector< double > HelperDouble(const std::string &input, TEnv &env)
std::string findConfigFile(const std::string &input, const std::map< std::string, std::string > &configmap)
std::vector< float > HelperFloat(const std::string &input, TEnv &env)
MsgStream & msg
Definition testRead.cxx:32