ATLAS Offline Software
Loading...
Searching...
No Matches
ToolConstants.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
10
11
13#include "GaudiKernel/GaudiException.h"
14#include <sstream>
15
16
17namespace CaloRec {
18
19
27
28
40ToolConstants::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
59ToolConstants::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
79void ToolConstants::setrep (const std::string& key,
80 const CxxUtils::Arrayrep& rep)
81{
82 m_map[key] = rep;
83}
84
85
91void ToolConstants::setrep (const std::string& key,
93{
94 m_map[key] = std::move (rep);
95}
96
97
101bool ToolConstants::hasrep (const std::string& key) const
102{
103 return m_map.contains(key);
104}
105
106
113[[noreturn]]
114void 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
126void ToolConstants::writeConstants(std::ostream& stream,
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
141std::string ToolConstants::toString (const std::string& name) const
142{
143 std::ostringstream ss;
144 writeConstants (ss, name);
145 return ss.str();
146}
147
148
152const std::string& ToolConstants::clsname() const
153{
154 return m_clsname;
155}
156
157
161void ToolConstants::clsname (const std::string& name)
162{
163 m_clsname = name;
164}
165
166
171{
172 return m_version;
173}
174
175
183
184
189{
190 return m_map;
191}
192
193
194} // namespace CaloRec
static Double_t ss
Container for the tool constants managed by ToolWithConstants.
Maptype m_map
The map of keys to values.
const CxxUtils::Arrayrep & newrep(const std::string &context, const std::string &key, const std::string &val)
Make a new entry.
int m_version
Version number of the C++ class that operates on these constants.
std::map< std::string, CxxUtils::Arrayrep > Maptype
Type of the map from keys to values.
static void error(const std::string &context, const std::string &key, const std::string &msg)
Report an error.
void setrep(const std::string &key, const CxxUtils::Arrayrep &rep)
Set an entry.
bool hasrep(const std::string &key) const
Test to see if a given key is present.
int version() const
Return the version of the C++ class that operates on these constants.
const CxxUtils::Arrayrep & getrep(const std::string &context, const std::string &key) const
Look up an entry.
ToolConstants()
Default constructor.
const std::string & clsname() const
Return the name of the C++ class that operates on these constants.
const Maptype & map() const
Return the key -> value map.
std::string m_clsname
Name of the C++ class that operates on these constants.
void writeConstants(std::ostream &stream, const std::string &name) const
Writes out constants in a python-like format.
std::string toString(const std::string &name) const
Return the data as a formatted string.
Namespace for helper functions.
Representation class for Array's.
MsgStream & msg
Definition testRead.cxx:32