Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:01

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2017-2021 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <string>
0012 #include <utility>
0013 
0014 #include "DD4hep/Detector.h"
0015 
0016 namespace Acts {
0017 
0018 /// @class ActsExtension
0019 ///
0020 /// @brief Extension of the \a %DD4hep \a DetElement needed for translation
0021 /// into the Acts tracking geometry
0022 ///
0023 /// This is a simple value / flag container to be:
0024 /// - filled by the Detector constructors if Acts is needed
0025 /// - interpreted by the DD4Hep layer builders and detector converters
0026 ///
0027 /// The minimal requirement for an ActsExtension is to define how the
0028 /// DD4hep (TGeo) element is oriented with respect to the Acts definition
0029 class ActsExtension {
0030  public:
0031   /// Minimal constructor, sets the defail of the axis
0032   ///
0033   // @param axes is the definition of the TGeo axes system w.r.t Acts
0034   ActsExtension(const std::string& axes = "XYZ");
0035 
0036   /// Standard copy constructor
0037   ///
0038   /// @param ext the source extension
0039   ActsExtension(const ActsExtension& ext) = default;
0040 
0041   /// Copy constructor with element for DD4hep::DetElement::clone
0042   ///
0043   /// @param ext the source extension
0044   /// @param elem the detector element
0045   ActsExtension(const ActsExtension& ext, const dd4hep::DetElement& elem);
0046 
0047   /// Destructor
0048   ~ActsExtension() = default;
0049 
0050   /// Get the value
0051   ///
0052   /// @param tag the entry identifier in the value store
0053   /// @param category the (optional) category in the value store
0054   double getValue(const std::string& tag,
0055                   const std::string& category = "") const noexcept(false);
0056 
0057   /// Add the parameter to the store
0058   ///
0059   /// @param value the value to be added
0060   /// @param tag the entry identifier in the value store
0061   /// @param category the (optional) category in the value store
0062   void addValue(double value, const std::string& tag,
0063                 const std::string& category = "");
0064 
0065   /// Check if the ActsExtension has a value (with optional category)
0066   ///
0067   /// @param tag the primary identifier in the flag store
0068   /// @param category the (optional) category in the flag store
0069   bool hasValue(const std::string& tag, const std::string& category = "") const;
0070 
0071   /// Check if the ActsExtension has a value (with optional category)
0072   ///
0073   /// @param type the primary identifier in the flag store
0074   /// @param category the (optional) category in the flag store
0075   bool hasType(const std::string& type, const std::string& category = "") const;
0076 
0077   /// Check if the ActsExtension has a category
0078   ///
0079   /// @param category the category in the flag store
0080   bool hasCategory(const std::string& category) const;
0081 
0082   /// Add the characteristics
0083   ///
0084   /// @param type the primary identifier in the flag store
0085   /// @param category the (optional) category in the flag store
0086   /// @param word the word to be stored
0087   void addType(const std::string& type, const std::string& category = "",
0088                const std::string& word = "");
0089 
0090   /// Get the string content
0091   ///
0092   /// @param type the primary identifier in the flag store
0093   /// @param category the (optional) category in the flag store
0094   const std::string getType(const std::string& type,
0095                             const std::string& category = "") const
0096       noexcept(false);
0097 
0098   /// Output to string
0099   std::string toString() const;
0100 
0101  private:
0102   /// Templated helper method
0103   template <typename T>
0104   void addT(std::map<std::string, T>& map, const T& val, const std::string& tag,
0105             const std::string& category, const T& catDeco);
0106 
0107   /// Templated helper method
0108   template <typename T>
0109   const T getT(const std::map<std::string, T>& map, const std::string& tag,
0110                const std::string& category = "") const noexcept(false);
0111 
0112   /// Templated helper method
0113   template <typename T>
0114   bool hasT(const std::map<std::string, T>& map, const std::string& tag,
0115             const std::string& category = "") const;
0116 
0117   /// Multiple flags to be stored, existance defines set
0118   std::map<std::string, std::string> m_flagStore;
0119 
0120   /// Unique value store for doubles
0121   std::map<std::string, double> m_values;
0122 };
0123 
0124 // Templated helper method to get from the value/type store
0125 template <typename T>
0126 const T ActsExtension::getT(const std::map<std::string, T>& map,
0127                             const std::string& tag,
0128                             const std::string& category) const noexcept(false) {
0129   std::string ctag = "/";
0130   if (!category.empty()) {
0131     ctag += category;
0132     ctag += "/";
0133   }
0134   ctag += tag;
0135   auto search = map.find(ctag);
0136   if (search == map.end()) {
0137     std::string error_message = "Acts::ActsExtension does not contain: ";
0138     error_message += ctag;
0139     error_message += '\n';
0140     error_message += toString();
0141     throw std::runtime_error(error_message.c_str());
0142   }
0143   return search->second;
0144 }
0145 
0146 // Templated helper method to set from the value/type store
0147 template <typename T>
0148 void ActsExtension::addT(std::map<std::string, T>& map, const T& val,
0149                          const std::string& tag, const std::string& category,
0150                          const T& catDeco) {
0151   std::string ctag = "/";
0152   if (!category.empty()) {
0153     ctag += category;
0154     map[ctag] = catDeco;
0155     ctag += "/";
0156   }
0157   ctag += tag;
0158   map[ctag] = val;
0159 }
0160 
0161 // Templated helper method to get from the value/type store
0162 template <typename T>
0163 bool ActsExtension::hasT(const std::map<std::string, T>& map,
0164                          const std::string& tag,
0165                          const std::string& category) const {
0166   std::string ctag = "/";
0167   if (!category.empty()) {
0168     ctag += category;
0169     ctag += "/";
0170   }
0171   ctag += tag;
0172   auto search = map.find(ctag);
0173   return (search != map.end());
0174 }
0175 
0176 }  // namespace Acts
0177 
0178 #include "ActsExtension.ipp"