ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ActsExtension.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ActsExtension.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 // ActsExtension.hpp, Acts project, DD4hepDetector plugin
12 
13 #pragma once
14 
15 #include <string>
16 #include <utility>
17 #include "DD4hep/Detector.h"
18 
19 namespace Acts {
20 
33  public:
36  // @param axes is the definition of the TGeo axes system w.r.t Acts
37  ActsExtension(const std::string& axes = "XYZ");
38 
42  ActsExtension(const ActsExtension& ext) = default;
43 
47  ActsExtension(const ActsExtension& ext, const dd4hep::DetElement& elem);
48 
50  ~ActsExtension() = default;
51 
56  double getValue(const std::string& tag,
57  const std::string& category = "") const noexcept(false);
58 
64  void addValue(double value, const std::string& tag,
65  const std::string& category = "");
66 
71  bool hasValue(const std::string& tag, const std::string& category = "") const;
72 
77  bool hasType(const std::string& type, const std::string& category = "") const;
78 
84  void addType(const std::string& type, const std::string& category = "",
85  const std::string& word = "");
86 
91  const std::string getType(const std::string& type,
92  const std::string& category = "") const
93  noexcept(false);
94 
96  std::string toString() const;
97 
98  private:
100  template <typename T>
101  void addT(std::map<std::string, T>& map, const T& val, const std::string& tag,
102  const std::string& category, const T& catDeco);
103 
105  template <typename T>
106  const T getT(const std::map<std::string, T>& map, const std::string& tag,
107  const std::string& category = "") const noexcept(false);
108 
110  template <typename T>
111  bool hasT(const std::map<std::string, T>& map, const std::string& tag,
112  const std::string& category = "") const;
113 
115  std::map<std::string, std::string> m_flagStore;
116 
118  std::map<std::string, double> m_values;
119 };
120 
121 // Templated helper method to get from the value/type store
122 template <typename T>
123 const T ActsExtension::getT(const std::map<std::string, T>& map,
124  const std::string& tag,
125  const std::string& category) const noexcept(false) {
126  std::string ctag = "/";
127  if (!category.empty()) {
128  ctag += category;
129  ctag += "/";
130  }
131  ctag += tag;
132  auto search = map.find(ctag);
133  if (search == map.end()) {
134  std::string error_message = "Acts::ActsExtension does not contain: ";
135  error_message += ctag;
136  error_message += '\n';
137  error_message += toString();
138  throw std::runtime_error(error_message.c_str());
139  }
140  return search->second;
141 }
142 
143 // Templated helper method to set from the value/type store
144 template <typename T>
145 void ActsExtension::addT(std::map<std::string, T>& map, const T& val,
146  const std::string& tag, const std::string& category,
147  const T& catDeco) {
148  std::string ctag = "/";
149  if (!category.empty()) {
150  ctag += category;
151  map[ctag] = catDeco;
152  ctag += "/";
153  }
154  ctag += tag;
155  map[ctag] = val;
156 }
157 
158 // Templated helper method to get from the value/type store
159 template <typename T>
160 bool ActsExtension::hasT(const std::map<std::string, T>& map,
161  const std::string& tag,
162  const std::string& category) const {
163  std::string ctag = "/";
164  if (!category.empty()) {
165  ctag += category;
166  ctag += "/";
167  }
168  ctag += tag;
169  auto search = map.find(ctag);
170  return (search != map.end());
171 }
172 
173 } // namespace Acts