PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
GenericParameters.cc
Go to the documentation of this file.
2
3#include <algorithm>
4#include <iomanip>
5
6namespace podio {
7
9 m_intMtx(std::make_unique<std::mutex>()),
10 m_floatMtx(std::make_unique<std::mutex>()),
11 m_stringMtx(std::make_unique<std::mutex>()),
12 m_doubleMtx(std::make_unique<std::mutex>()) {
13}
14
16 m_intMtx(std::make_unique<std::mutex>()),
17 m_floatMtx(std::make_unique<std::mutex>()),
18 m_stringMtx(std::make_unique<std::mutex>()),
19 m_doubleMtx(std::make_unique<std::mutex>()) {
20 {
21 // acquire all three locks at once to make sure all three internal maps are
22 // copied at the same "state" of the GenericParameters
23 auto& intMtx = other.getMutex<int>();
24 auto& floatMtx = other.getMutex<float>();
25 auto& stringMtx = other.getMutex<std::string>();
26 auto& doubleMtx = other.getMutex<double>();
27 std::scoped_lock lock(intMtx, floatMtx, stringMtx, doubleMtx);
28 _intMap = other._intMap;
29 _floatMap = other._floatMap;
30 _stringMap = other._stringMap;
31 _doubleMap = other._doubleMap;
32 }
33}
34
35int GenericParameters::getIntVal(const std::string& key) const {
36 return getValue<int>(key);
37}
38
39float GenericParameters::getFloatVal(const std::string& key) const {
40 return getValue<float>(key);
41}
42
43const std::string& GenericParameters::getStringVal(const std::string& key) const {
44 return getValue<std::string>(key);
45}
46
47IntVec& GenericParameters::getIntVals(const std::string& key, IntVec& values) const {
48 for (const auto v : getValue<std::vector<int>>(key)) {
49 values.push_back(v);
50 }
51 return values;
52}
53
54FloatVec& GenericParameters::getFloatVals(const std::string& key, FloatVec& values) const {
55 for (const auto v : getValue<std::vector<float>>(key)) {
56 values.push_back(v);
57 }
58 return values;
59}
60
61StringVec& GenericParameters::getStringVals(const std::string& key, StringVec& values) const {
62 for (const auto& v : getValue<std::vector<std::string>>(key)) {
63 values.push_back(v);
64 }
65 return values;
66}
67
69 for (const auto& k : getKeys<int>()) {
70 keys.push_back(k);
71 }
72 return keys;
73}
74
76 for (const auto& k : getKeys<float>()) {
77 keys.push_back(k);
78 }
79 return keys;
80}
81
83 for (const auto& k : getKeys<std::string>()) {
84 keys.push_back(k);
85 }
86 return keys;
87}
88
89int GenericParameters::getNInt(const std::string& key) const {
90 return getN<int>(key);
91}
92
93int GenericParameters::getNFloat(const std::string& key) const {
94 return getN<float>(key);
95}
96
97int GenericParameters::getNString(const std::string& key) const {
98 return getN<std::string>(key);
99}
100
101void GenericParameters::setValues(const std::string& key, const IntVec& values) {
102 setValue(key, values);
103}
104
105void GenericParameters::setValues(const std::string& key, const FloatVec& values) {
106 setValue(key, values);
107}
108
109void GenericParameters::setValues(const std::string& key, const StringVec& values) {
110 setValue(key, values);
111}
112
113template <typename T>
114std::ostream& operator<<(std::ostream& os, const std::vector<T>& values) {
115 os << "[";
116 if (!values.empty()) {
117 os << values[0];
118 for (size_t i = 1; i < values.size(); ++i) {
119 os << ", " << values[i];
120 }
121 }
122
123 return os << "]";
124}
125
126template <typename MapType>
127void printMap(const MapType& map, std::ostream& os) {
128 os << std::left << std::setw(30) << "Key "
129 << "Value " << '\n';
130 os << "--------------------------------------------------------------------------------\n";
131 for (const auto& [key, value] : map) {
132 os << std::left << std::setw(30) << key << value << '\n';
133 }
134}
135
136void GenericParameters::print(std::ostream& os, bool flush) {
137 os << "int parameters\n\n";
138 printMap(getMap<int>(), os);
139 os << "\nfloat parameters\n";
140 printMap(getMap<float>(), os);
141 os << "\ndouble parameters\n";
142 printMap(getMap<double>(), os);
143 os << "\nstd::string parameters\n";
144 printMap(getMap<std::string>(), os);
145
146 if (flush) {
147 os.flush();
148 }
149}
150
151} // namespace podio
DEPRECATED_ACCESS int getIntVal(const std::string &key) const
DEPRECATED_ACCESS IntVec & getIntVals(const std::string &key, IntVec &values) const
GenericDataReturnType< T > getValue(const std::string &) const
DEPRECATED_ACCESS int getNString(const std::string &key) const
void setValue(const std::string &key, T value)
Store (a copy of) the passed value under the given key.
DEPRECATED_ACCESS void setValues(const std::string &key, const IntVec &values)
DEPRECATED_ACCESS FloatVec & getFloatVals(const std::string &key, FloatVec &values) const
DEPRECATED_ACCESS const std::string & getStringVal(const std::string &key) const
DEPRECATED_ACCESS int getNFloat(const std::string &key) const
DEPRECATED_ACCESS int getNInt(const std::string &key) const
DEPRECATED_ACCESS StringVec & getStringVals(const std::string &key, StringVec &values) const
DEPRECATED_ACCESS float getFloatVal(const std::string &key) const
void print(std::ostream &os=std::cout, bool flush=true)
DEPRECATED_ACCESS const StringVec & getIntKeys(StringVec &keys) const
DEPRECATED_ACCESS const StringVec & getFloatKeys(StringVec &keys) const
DEPRECATED_ACCESS const StringVec & getStringKeys(StringVec &keys) const
std::vector< float > FloatVec
void printMap(const MapType &map, std::ostream &os)
std::vector< int > IntVec
std::ostream & operator<<(std::ostream &o, const podio::UserDataCollection< BasicType > &coll)
std::vector< std::string > StringVec