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 
18 #include "DD4hep/Detector.h"
19 
20 namespace Acts {
21 
34  public:
37  // @param axes is the definition of the TGeo axes system w.r.t Acts
38  ActsExtension(const std::string& axes = "XYZ");
39 
43  ActsExtension(const ActsExtension& ext) = default;
44 
48  ActsExtension(const ActsExtension& ext, const dd4hep::DetElement& elem);
49 
51  ~ActsExtension() = default;
52 
57  double getValue(const std::string& tag,
58  const std::string& category = "") const noexcept(false);
59 
65  void addValue(double value, const std::string& tag,
66  const std::string& category = "");
67 
72  bool hasValue(const std::string& tag, const std::string& category = "") const;
73 
78  bool hasType(const std::string& type, const std::string& category = "") const;
79 
85  void addType(const std::string& type, const std::string& category = "",
86  const std::string& word = "");
87 
92  const std::string getType(const std::string& type,
93  const std::string& category = "") const
94  noexcept(false);
95 
97  std::string toString() const;
98 
99  private:
101  template <typename T>
102  void addT(std::map<std::string, T>& map, const T& val, const std::string& tag,
103  const std::string& category, const T& catDeco);
104 
106  template <typename T>
107  const T getT(const std::map<std::string, T>& map, const std::string& tag,
108  const std::string& category = "") const noexcept(false);
109 
111  template <typename T>
112  bool hasT(const std::map<std::string, T>& map, const std::string& tag,
113  const std::string& category = "") const;
114 
116  std::map<std::string, std::string> m_flagStore;
117 
119  std::map<std::string, double> m_values;
120 };
121 
122 // Templated helper method to get from the value/type store
123 template <typename T>
124 const T ActsExtension::getT(const std::map<std::string, T>& map,
125  const std::string& tag,
126  const std::string& category) const noexcept(false) {
127  std::string ctag = "/";
128  if (!category.empty()) {
129  ctag += category;
130  ctag += "/";
131  }
132  ctag += tag;
133  auto search = map.find(ctag);
134  if (search == map.end()) {
135  std::string error_message = "Acts::ActsExtension does not contain: ";
136  error_message += ctag;
137  error_message += '\n';
138  error_message += toString();
139  throw std::runtime_error(error_message.c_str());
140  }
141  return search->second;
142 }
143 
144 // Templated helper method to set from the value/type store
145 template <typename T>
146 void ActsExtension::addT(std::map<std::string, T>& map, const T& val,
147  const std::string& tag, const std::string& category,
148  const T& catDeco) {
149  std::string ctag = "/";
150  if (!category.empty()) {
151  ctag += category;
152  map[ctag] = catDeco;
153  ctag += "/";
154  }
155  ctag += tag;
156  map[ctag] = val;
157 }
158 
159 // Templated helper method to get from the value/type store
160 template <typename T>
161 bool ActsExtension::hasT(const std::map<std::string, T>& map,
162  const std::string& tag,
163  const std::string& category) const {
164  std::string ctag = "/";
165  if (!category.empty()) {
166  ctag += category;
167  ctag += "/";
168  }
169  ctag += tag;
170  auto search = map.find(ctag);
171  return (search != map.end());
172 }
173 
174 } // namespace Acts