ATLAS Offline Software
RPDUtils.cxx
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <vector>
3 
4 #include "ZdcUtils/RPDUtils.h"
5 
6 namespace 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;
27  template<class T> OptionalToolProperty<T>::OptionalToolProperty(T value) : m_value(std::move(value)) {}
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
RPDUtils::vecToString
std::string vecToString(std::vector< T > const &v)
Definition: RPDUtils.cxx:57
athena.value
value
Definition: athena.py:124
RPDUtils
Definition: RPDUtils.cxx:6
RPDUtils::OptionalToolProperty
Definition: RPDUtils.h:44
RPDUtils::OptionalToolProperty::has_value
bool has_value() const
Definition: RPDUtils.cxx:28
RPDUtils::OptionalToolProperty::OptionalToolProperty
OptionalToolProperty()
RPDUtils::OptionalToolProperty::value
T const & value() const
Definition: RPDUtils.cxx:31
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
RPDUtils::sideA
unsigned constexpr int sideA
Definition: RPDUtils.h:16
RPDUtils.h
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
python.PyAthena.v
v
Definition: PyAthena.py:154
RPDUtils::operator<<
std::ostream & operator<<(std::ostream &os, const std::vector< T > &v)
Definition: RPDUtils.cxx:19
RPDUtils::sideC
unsigned constexpr int sideC
Definition: RPDUtils.h:15
calibdata.copy
bool copy
Definition: calibdata.py:27
RPDUtils::ZDCSideToSideIndex
unsigned int ZDCSideToSideIndex(int const ZDCSide)
Definition: RPDUtils.cxx:7
python.PyAthena.obj
obj
Definition: PyAthena.py:132