ATLAS Offline Software
Loading...
Searching...
No Matches
CaloRec::ToolConstants Class Reference

Container for the tool constants managed by ToolWithConstants. More...

#include <ToolConstants.h>

Collaboration diagram for CaloRec::ToolConstants:

Public Types

typedef std::map< std::string, CxxUtils::ArrayrepMaptype
 Type of the map from keys to values.

Public Member Functions

 ToolConstants ()
 Default constructor.
const CxxUtils::Arrayrepnewrep (const std::string &context, const std::string &key, const std::string &val)
 Make a new entry.
const CxxUtils::Arrayrepgetrep (const std::string &context, const std::string &key) const
 Look up an entry.
void setrep (const std::string &key, const CxxUtils::Arrayrep &rep)
 Set an entry.
void setrep (const std::string &key, CxxUtils::Arrayrep &&rep)
 Set an entry.
bool hasrep (const std::string &key) const
 Test to see if a given key is present.
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.
const std::string & clsname () const
 Return the name of the C++ class that operates on these constants.
void clsname (const std::string &name)
 Set the name of the C++ class that operates on these constants.
int version () const
 Return the version of the C++ class that operates on these constants.
void version (int version)
 Set the version of the C++ class that operates on these constants.
const Maptypemap () const
 Return the key -> value map.

Static Private Member Functions

static void error (const std::string &context, const std::string &key, const std::string &msg)
 Report an error.

Private Attributes

Maptype m_map
 The map of keys to values.
std::string m_clsname
 Name of the C++ class that operates on these constants.
int m_version
 Version number of the C++ class that operates on these constants.

Detailed Description

Container for the tool constants managed by ToolWithConstants.

This is just a simple map from constant name to Arrayrep.

Definition at line 31 of file ToolConstants.h.

Member Typedef Documentation

◆ Maptype

typedef std::map<std::string, CxxUtils::Arrayrep> CaloRec::ToolConstants::Maptype

Type of the map from keys to values.

Definition at line 35 of file ToolConstants.h.

Constructor & Destructor Documentation

◆ ToolConstants()

CaloRec::ToolConstants::ToolConstants ( )

Default constructor.

Definition at line 23 of file ToolConstants.cxx.

24 : m_version (0)
25{
26}
int m_version
Version number of the C++ class that operates on these constants.

Member Function Documentation

◆ clsname() [1/2]

const std::string & CaloRec::ToolConstants::clsname ( ) const

Return the name of the C++ class that operates on these constants.

Definition at line 152 of file ToolConstants.cxx.

153{
154 return m_clsname;
155}
std::string m_clsname
Name of the C++ class that operates on these constants.

◆ clsname() [2/2]

void CaloRec::ToolConstants::clsname ( const std::string & name)

Set the name of the C++ class that operates on these constants.

Definition at line 161 of file ToolConstants.cxx.

◆ error()

void CaloRec::ToolConstants::error ( const std::string & context,
const std::string & key,
const std::string & msg )
staticprivate

Report an error.

Parameters
contextContext string for the error.
keyKey involved in the error.
msgError message.

Definition at line 114 of file ToolConstants.cxx.

117{
118 throw GaudiException (msg, context+":"+key, StatusCode::FAILURE);
119}
MsgStream & msg
Definition testRead.cxx:32

◆ getrep()

const CxxUtils::Arrayrep & CaloRec::ToolConstants::getrep ( const std::string & context,
const std::string & key ) const

Look up an entry.

Parameters
contextThe context name, for error reporting.
keyThe key of the new entry.

Looks up key and returns its Arrayrep. Raises an exception if key isn't found.

Definition at line 59 of file ToolConstants.cxx.

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}
static Double_t ss
Maptype m_map
The map of keys to values.
static void error(const std::string &context, const std::string &key, const std::string &msg)
Report an error.

◆ hasrep()

bool CaloRec::ToolConstants::hasrep ( const std::string & key) const

Test to see if a given key is present.

Definition at line 101 of file ToolConstants.cxx.

102{
103 return m_map.contains(key);
104}

◆ map()

const ToolConstants::Maptype & CaloRec::ToolConstants::map ( ) const

Return the key -> value map.

Definition at line 188 of file ToolConstants.cxx.

189{
190 return m_map;
191}

◆ newrep()

const CxxUtils::Arrayrep & CaloRec::ToolConstants::newrep ( const std::string & context,
const std::string & key,
const std::string & val )

Make a new entry.

Parameters
contextThe context name, for error reporting.
keyThe key of the new entry.
valThe value of the new entry, as a string.

Converts val to an Arrayrep and stores it. Raises an exception if the key already exists or if there's a conversion error.

Definition at line 40 of file ToolConstants.cxx.

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}

◆ setrep() [1/2]

void CaloRec::ToolConstants::setrep ( const std::string & key,
const CxxUtils::Arrayrep & rep )

Set an entry.

Parameters
keyThe key of the entry to set.
repThe value of the new entry.

Definition at line 79 of file ToolConstants.cxx.

81{
82 m_map[key] = rep;
83}

◆ setrep() [2/2]

void CaloRec::ToolConstants::setrep ( const std::string & key,
CxxUtils::Arrayrep && rep )

Set an entry.

Parameters
keyThe key of the entry to set.
repThe value of the new entry.

Definition at line 91 of file ToolConstants.cxx.

93{
94 m_map[key] = std::move (rep);
95}

◆ toString()

std::string CaloRec::ToolConstants::toString ( const std::string & name) const

Return the data as a formatted string.

Parameters
nameName of the Maker-Algorithm.

Definition at line 141 of file ToolConstants.cxx.

142{
143 std::ostringstream ss;
144 writeConstants (ss, name);
145 return ss.str();
146}
void writeConstants(std::ostream &stream, const std::string &name) const
Writes out constants in a python-like format.

◆ version() [1/2]

int CaloRec::ToolConstants::version ( ) const

Return the version of the C++ class that operates on these constants.

Definition at line 170 of file ToolConstants.cxx.

171{
172 return m_version;
173}

◆ version() [2/2]

void CaloRec::ToolConstants::version ( int version)

Set the version of the C++ class that operates on these constants.

Definition at line 179 of file ToolConstants.cxx.

180{
182}
int version() const
Return the version of the C++ class that operates on these constants.

◆ writeConstants()

void CaloRec::ToolConstants::writeConstants ( std::ostream & stream,
const std::string & name ) const

Writes out constants in a python-like format.

Parameters
streamStream to which to write (file or cout)
nameName of the Maker-Algorithm (used only for output)
streamStream to wirte to (file or cout)
nameName of the Maker-Algorithm (used only for output)

Definition at line 126 of file ToolConstants.cxx.

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}

Member Data Documentation

◆ m_clsname

std::string CaloRec::ToolConstants::m_clsname
private

Name of the C++ class that operates on these constants.

Definition at line 151 of file ToolConstants.h.

◆ m_map

Maptype CaloRec::ToolConstants::m_map
private

The map of keys to values.

Definition at line 148 of file ToolConstants.h.

◆ m_version

int CaloRec::ToolConstants::m_version
private

Version number of the C++ class that operates on these constants.

Definition at line 154 of file ToolConstants.h.


The documentation for this class was generated from the following files: