Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-02 10:14:53

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