ATLAS Offline Software
ToolConstants.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
13 #include "GaudiKernel/GaudiException.h"
14 #include <sstream>
15 
16 
17 namespace CaloRec {
18 
19 
24  : m_version (0)
25 {
26 }
27 
28 
39 const CxxUtils::Arrayrep&
40 ToolConstants::newrep (const std::string& context,
41  const std::string& key,
42  const std::string& val)
43 {
44  if (m_map.contains(key)) {
45  error (context, key, "Duplicate key");
46  }
47  return m_map[key] = CxxUtils::Arrayrep (val, context+":"+key);
48 }
49 
58 const CxxUtils::Arrayrep&
59 ToolConstants::getrep (const std::string& context,
60  const std::string& key) const
61 {
62  Maptype::const_iterator i = m_map.find (key);
63  if (i == m_map.end()) {
64  std::ostringstream ss;
65  for (const auto& p : m_map) {
66  ss << " " << p.first;
67  }
68  error (context, key, "Can't find key in" + ss.str());
69  }
70  return i->second;
71 }
72 
73 
79 void ToolConstants::setrep (const std::string& key,
80  const CxxUtils::Arrayrep& rep)
81 {
82  m_map[key] = rep;
83 }
84 
85 
91 void ToolConstants::setrep (const std::string& key,
93 {
94  m_map[key] = std::move (rep);
95 }
96 
97 
101 bool ToolConstants::hasrep (const std::string& key) const
102 {
103  return m_map.contains(key);
104 }
105 
106 
113 [[noreturn]]
114 void ToolConstants::error (const std::string& context,
115  const std::string& key,
116  const std::string& msg)
117 {
118  throw GaudiException (msg, context+":"+key, StatusCode::FAILURE);
119 }
120 
127  const std::string& name) const
128 {
129  for (const std::pair<const std::string, CxxUtils::Arrayrep>& p : m_map) {
130  stream << name << "." << p.first << " = ";
131  p.second.write_array(stream);
132  }
133  stream << std::endl;
134 }
135 
136 
141 std::string ToolConstants::toString (const std::string& name) const
142 {
143  std::ostringstream ss;
145  return ss.str();
146 }
147 
148 
152 const std::string& ToolConstants::clsname() const
153 {
154  return m_clsname;
155 }
156 
157 
161 void ToolConstants::clsname (const std::string& name)
162 {
163  m_clsname = name;
164 }
165 
166 
171 {
172  return m_version;
173 }
174 
175 
180 {
181  m_version = version;
182 }
183 
184 
189 {
190  return m_map;
191 }
192 
193 
194 } // namespace CaloRec
CaloRec::ToolConstants::m_clsname
std::string m_clsname
Name of the C++ class that operates on these constants.
Definition: ToolConstants.h:151
CaloRec::ToolConstants::writeConstants
void writeConstants(std::ostream &stream, const std::string &name) const
Writes out constants in a python-like format.
Definition: ToolConstants.cxx:126
CaloRec::ToolConstants::version
int version() const
Return the version of the C++ class that operates on these constants.
Definition: ToolConstants.cxx:170
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ToolConstants.h
Container for the tool constants managed by ToolWithConstants.
CaloRec::ToolConstants::ToolConstants
ToolConstants()
Default constructor.
Definition: ToolConstants.cxx:23
make_hlt_rep.rep
rep
Definition: make_hlt_rep.py:32
CaloRec::ToolConstants::m_version
int m_version
Version number of the C++ class that operates on these constants.
Definition: ToolConstants.h:154
CaloRec::ToolConstants::error
static void error(const std::string &context, const std::string &key, const std::string &msg)
Report an error.
Definition: ToolConstants.cxx:114
CaloRec::ToolConstants::hasrep
bool hasrep(const std::string &key) const
Test to see if a given key is present.
Definition: ToolConstants.cxx:101
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
CaloRec::ToolConstants::toString
std::string toString(const std::string &name) const
Return the data as a formatted string.
Definition: ToolConstants.cxx:141
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloRec::ToolConstants::Maptype
std::map< std::string, CxxUtils::Arrayrep > Maptype
Type of the map from keys to values.
Definition: ToolConstants.h:35
CaloRec::ToolConstants::map
const Maptype & map() const
Return the key -> value map.
Definition: ToolConstants.cxx:188
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CaloRec
Namespace for helper functions.
Definition: CaloCellFactor.h:22
CaloRec::ToolConstants::newrep
const CxxUtils::Arrayrep & newrep(const std::string &context, const std::string &key, const std::string &val)
Make a new entry.
Definition: ToolConstants.cxx:40
CaloRec::ToolConstants::m_map
Maptype m_map
The map of keys to values.
Definition: ToolConstants.h:148
get_generator_info.version
version
Definition: get_generator_info.py:33
CaloRec::ToolConstants::setrep
void setrep(const std::string &key, const CxxUtils::Arrayrep &rep)
Set an entry.
Definition: ToolConstants.cxx:79
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CaloRec::Arrayrep
Representation class for Array's.
Definition: Control/CxxUtils/CxxUtils/Arrayrep.h:62
CaloRec::ToolConstants::getrep
const CxxUtils::Arrayrep & getrep(const std::string &context, const std::string &key) const
Look up an entry.
Definition: ToolConstants.cxx:59
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
CaloRec::ToolConstants::clsname
const std::string & clsname() const
Return the name of the C++ class that operates on these constants.
Definition: ToolConstants.cxx:152