ATLAS Offline Software
Loading...
Searching...
No Matches
RPDUtils.cxx
Go to the documentation of this file.
1#include <stdexcept>
2#include <vector>
3
4#include "ZdcUtils/RPDUtils.h"
5
6namespace RPDUtils {
7 unsigned int ZDCSideToSideIndex(int const ZDCSide) {
8 switch (ZDCSide) {
9 case -1:
10 return sideC;
11 case 1:
12 return sideA;
13 default:
14 throw std::runtime_error("Invalid ZDC side: " + std::to_string(ZDCSide));
15 }
16 return 0;
17 };
18 template<typename T>
19 std::ostream & operator <<(std::ostream & os, const std::vector<T> & v) {
20 os << "{ ";
21 std::copy(v.begin(), v.end(), std::ostream_iterator<T>(os, ", "));
22 os << "}";
23 return os;
24 }
25 template std::ostream & operator << <>(std::ostream &, const std::vector<float> &);
26 template<class T> OptionalToolProperty<T>::OptionalToolProperty() = default;
28 template<class T> bool OptionalToolProperty<T>::has_value() const {
29 return m_hasValue;
30 }
31 template<class T> T const& OptionalToolProperty<T>::value() const {
32 if (!m_hasValue) {
33 throw std::runtime_error("accessed null OptionalToolProperty!");
34 }
35 return m_value;
36 }
37 template<class T> std::ostream & operator<<(std::ostream& os, OptionalToolProperty<T> const& obj) {
38 if (obj.has_value()) {
39 return os << obj.value();
40 }
41 return os << "None";
42 }
43 template std::ostream & operator<<(std::ostream&, OptionalToolProperty<bool> const&);
44 template std::ostream & operator<<(std::ostream&, OptionalToolProperty<unsigned int> const&);
45 template std::ostream & operator<<(std::ostream&, OptionalToolProperty<float> const&);
46 template std::ostream & operator<<(std::ostream&, OptionalToolProperty<std::vector<float>> const&);
47 template<class T> OptionalToolProperty<T>::operator T&() {
48 // this method is called when the value is set from python, so this now has a value
49 m_hasValue = true;
50 return m_value;
51 }
52 template class OptionalToolProperty<bool>;
56 template <typename T>
57 std::string vecToString(std::vector<T> const& v) {
58 std::ostringstream oss;
59 oss << "{ ";
60 std::copy(v.begin(), v.end(), std::ostream_iterator<T>(oss, ", "));
61 oss << "}";
62 return oss.str();
63 }
64 template std::string vecToString(std::vector<float> const& v);
65} // namespace RPDUtils
unsigned int ZDCSideToSideIndex(int const ZDCSide)
Definition RPDUtils.cxx:7
std::ostream & operator<<(std::ostream &os, const std::vector< T > &v)
Definition RPDUtils.cxx:19
unsigned int constexpr sideC
Definition RPDUtils.h:15
unsigned int constexpr sideA
Definition RPDUtils.h:16
std::string vecToString(std::vector< T > const &v)
Definition RPDUtils.cxx:57
template std::ostream & operator<<<>(std::ostream &, const std::vector< float > &)
STL namespace.