Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-15 08:53:26

0001 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
0002 
0003 #ifndef EDM4HEP_TrackerHit_H
0004 #define EDM4HEP_TrackerHit_H
0005 
0006 #include "edm4hep/TrackerHit3DCollection.h"
0007 #include "edm4hep/TrackerHitPlaneCollection.h"
0008 
0009 #include "podio/ObjectID.h"
0010 #include "podio/detail/OrderKey.h"
0011 #include "podio/utilities/TypeHelpers.h"
0012 
0013 #include <memory>
0014 #include <ostream>
0015 #include <stdexcept>
0016 
0017 namespace edm4hep {
0018 
0019 /** @class TrackerHit
0020  *  Tracker hit interface class
0021  *  @author: Thomas Madlener, DESY
0022  */
0023 class TrackerHit {
0024 public:
0025   /// type alias containing all the types this interface should work for in a
0026   /// tuple
0027   using interfaced_types = std::tuple<::edm4hep::TrackerHit3D, ::edm4hep::TrackerHitPlane>;
0028 
0029   /// Mark interfaces as always acting as default datatypes.
0030   ///
0031   /// @note We only detect the member typedef, not whether it is actually usable
0032   /// in any meaningful way
0033   using mutable_type = podio::det::nonesuch;
0034 
0035 private:
0036   /// type alias containing all the mutable types that can be used to initialize
0037   /// this interface
0038   using InterfacedMutableTypes = podio::detail::TupleOfMutableTypes<interfaced_types>;
0039 
0040   /// template variable for determining whether type T is a valid interface type
0041   template <typename T>
0042   constexpr static bool isInterfacedType = podio::detail::isInTuple<T, interfaced_types>;
0043 
0044 public:
0045   /// template variable for determining whether type T can be used to initialize
0046   /// this interface
0047   template <typename T>
0048   constexpr static bool isInitializableFrom =
0049       isInterfacedType<T> || podio::detail::isInTuple<T, InterfacedMutableTypes>;
0050 
0051 private:
0052   struct Concept {
0053     virtual ~Concept() = default;
0054     virtual std::unique_ptr<Concept> clone() const = 0;
0055     virtual void print(std::ostream&) const = 0;
0056 
0057     virtual podio::ObjectID getObjectID() const = 0;
0058     virtual bool isAvailable() const = 0;
0059     virtual void unlink() = 0;
0060     virtual std::uint64_t getCellID() const = 0;
0061 
0062     virtual std::int32_t getType() const = 0;
0063 
0064     virtual std::int32_t getQuality() const = 0;
0065 
0066     virtual float getTime() const = 0;
0067 
0068     virtual float getEDep() const = 0;
0069 
0070     virtual float getEDepError() const = 0;
0071 
0072     virtual const edm4hep::Vector3d& getPosition() const = 0;
0073 
0074     virtual const std::type_info& typeInfo() const = 0;
0075     virtual bool equal(const Concept* rhs) const = 0;
0076     virtual podio::detail::OrderKey objOrderKey() const = 0;
0077   };
0078 
0079   template <typename ValueT>
0080   struct Model final : Concept {
0081     ~Model() = default;
0082     Model(ValueT value) : m_value(value) {
0083     }
0084 
0085     std::unique_ptr<Concept> clone() const final {
0086       return std::make_unique<Model<ValueT>>(m_value);
0087     }
0088 
0089     void print(std::ostream& os) const final {
0090       os << m_value;
0091     }
0092 
0093     void unlink() final {
0094       m_value.unlink();
0095     }
0096     bool isAvailable() const final {
0097       return m_value.isAvailable();
0098     }
0099     podio::ObjectID getObjectID() const final {
0100       return m_value.getObjectID();
0101     }
0102 
0103     const std::type_info& typeInfo() const final {
0104       return typeid(ValueT);
0105     }
0106 
0107     bool equal(const Concept* rhs) const final {
0108       if (typeInfo() == rhs->typeInfo()) {
0109         return m_value == static_cast<const Model<ValueT>*>(rhs)->m_value;
0110       }
0111       return false;
0112     }
0113 
0114     podio::detail::OrderKey objOrderKey() const final {
0115       return podio::detail::getOrderKey(m_value);
0116     }
0117 
0118     std::uint64_t getCellID() const final {
0119       return m_value.getCellID();
0120     }
0121 
0122     std::int32_t getType() const final {
0123       return m_value.getType();
0124     }
0125 
0126     std::int32_t getQuality() const final {
0127       return m_value.getQuality();
0128     }
0129 
0130     float getTime() const final {
0131       return m_value.getTime();
0132     }
0133 
0134     float getEDep() const final {
0135       return m_value.getEDep();
0136     }
0137 
0138     float getEDepError() const final {
0139       return m_value.getEDepError();
0140     }
0141 
0142     const edm4hep::Vector3d& getPosition() const final {
0143       return m_value.getPosition();
0144     }
0145 
0146     ValueT m_value{};
0147   };
0148 
0149   std::unique_ptr<Concept> m_self{nullptr};
0150 
0151 public:
0152   // TrackerHit can only be initialized with one of the following types (and their Mutable counter parts):
0153   // ::edm4hep::TrackerHit3D, ::edm4hep::TrackerHitPlane
0154   template <typename ValueT, typename = std::enable_if_t<isInitializableFrom<ValueT>>>
0155   TrackerHit(ValueT value) : m_self(std::make_unique<Model<podio::detail::GetDefaultHandleType<ValueT>>>(value)) {
0156   }
0157 
0158   TrackerHit(const TrackerHit& other) : m_self(other.m_self->clone()) {
0159   }
0160   TrackerHit& operator=(const TrackerHit& other) {
0161     TrackerHit tmp{other};
0162     std::swap(tmp.m_self, this->m_self);
0163     return *this;
0164   }
0165 
0166   ~TrackerHit() = default;
0167   TrackerHit(TrackerHit&&) = default;
0168   TrackerHit& operator=(TrackerHit&&) = default;
0169 
0170   /// Create an empty handle
0171   static TrackerHit makeEmpty() {
0172     // We simply chose the first type of the interfaced types here to initialize
0173     // an empty handle
0174     return ::edm4hep::TrackerHit3D::makeEmpty();
0175   }
0176 
0177   static constexpr auto typeName = "edm4hep::TrackerHit";
0178 
0179   /// check whether the object is actually available
0180   bool isAvailable() const {
0181     return m_self->isAvailable();
0182   }
0183   /// disconnect from the underlying value
0184   void unlink() {
0185     m_self->unlink();
0186   }
0187 
0188   podio::ObjectID id() const {
0189     return getObjectID();
0190   }
0191   podio::ObjectID getObjectID() const {
0192     return m_self->getObjectID();
0193   }
0194 
0195   /// Check if the object currently holds a value of the requested type
0196   template <typename T>
0197   bool isA() const {
0198     static_assert(
0199         isInterfacedType<T>,
0200         "TrackerHit can only ever be one of the following types: ::edm4hep::TrackerHit3D, ::edm4hep::TrackerHitPlane");
0201     return typeid(T) == m_self->typeInfo();
0202   }
0203 
0204   /// Get the contained value as the concrete type it was put in. This will
0205   /// throw a std::runtime_error if T is not the type of the currently held
0206   /// value. Use isA to check beforehand if necessary
0207   template <typename T>
0208   T as() const {
0209     if (!isA<T>()) {
0210       throw std::runtime_error("Cannot get value as object currently holds another type");
0211     }
0212     // We can safely cast here since we check types before
0213     return static_cast<Model<T>*>(m_self.get())->m_value;
0214   }
0215 
0216   template <typename T>
0217   [[deprecated("Use 'as' instead.")]] T getValue() const {
0218     return as<T>();
0219   }
0220 
0221   friend bool operator==(const TrackerHit& lhs, const TrackerHit& rhs) {
0222     return lhs.m_self->equal(rhs.m_self.get());
0223   }
0224 
0225   friend bool operator!=(const TrackerHit& lhs, const TrackerHit& rhs) {
0226     return !(lhs == rhs);
0227   }
0228 
0229   friend bool operator<(const TrackerHit& lhs, const TrackerHit& rhs) {
0230     return lhs.m_self->objOrderKey() < rhs.m_self->objOrderKey();
0231   }
0232 
0233   /// Access the ID of the sensor that created this hit
0234   std::uint64_t getCellID() const {
0235     return m_self->getCellID();
0236   }
0237 
0238   /// Access the type of the raw data hit
0239   std::int32_t getType() const {
0240     return m_self->getType();
0241   }
0242 
0243   /// Access the quality bit flag of the hit
0244   std::int32_t getQuality() const {
0245     return m_self->getQuality();
0246   }
0247 
0248   /// Access the time of the hit [ns]
0249   float getTime() const {
0250     return m_self->getTime();
0251   }
0252 
0253   /// Access the energy deposited on the hit [GeV]
0254   float getEDep() const {
0255     return m_self->getEDep();
0256   }
0257 
0258   /// Access the error measured on eDep [GeV]
0259   float getEDepError() const {
0260     return m_self->getEDepError();
0261   }
0262 
0263   /// Access the hit position [mm]
0264   const edm4hep::Vector3d& getPosition() const {
0265     return m_self->getPosition();
0266   }
0267 
0268   friend std::ostream& operator<<(std::ostream& os, const TrackerHit& value) {
0269     value.m_self->print(os);
0270     return os;
0271   }
0272 };
0273 
0274 } // namespace edm4hep
0275 
0276 #endif