Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/edm4hep/TrackerHit.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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/utilities/TypeHelpers.h"
0011 #include "podio/detail/OrderKey.h"
0012 
0013 #include <memory>
0014 #include <ostream>
0015 #include <stdexcept>
0016 
0017 namespace edm4hep {
0018 
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>;
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 = 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 
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() = default;
0084     Model(ValueT value) : m_value(value) {}
0085 
0086     std::unique_ptr<Concept> clone() const final {
0087       return std::make_unique<Model<ValueT>>(m_value);
0088     }
0089 
0090     void print(std::ostream& os) const final {
0091       os << m_value;
0092     }
0093 
0094     void unlink() final { m_value.unlink(); }
0095     bool isAvailable() const final { return m_value.isAvailable(); }
0096     podio::ObjectID getObjectID() const final { return m_value.getObjectID(); }
0097 
0098     const std::type_info& typeInfo() const final { return typeid(ValueT); }
0099 
0100     bool equal(const Concept* rhs) const final {
0101       if (typeInfo() == rhs->typeInfo()) {
0102         return m_value == static_cast<const Model<ValueT>*>(rhs)->m_value;
0103       }
0104       return false;
0105     }
0106 
0107     podio::detail::OrderKey objOrderKey() const final {
0108       return podio::detail::getOrderKey(m_value);
0109     }
0110 
0111     size_t objHash() const final {return std::hash<ValueT>{}(m_value); }
0112 
0113     std::uint64_t getCellID() const final { return m_value.getCellID(); }
0114 
0115     std::int32_t getType() const final { return m_value.getType(); }
0116 
0117     std::int32_t getQuality() const final { return m_value.getQuality(); }
0118 
0119     float getTime() const final { return m_value.getTime(); }
0120 
0121     float getEDep() const final { return m_value.getEDep(); }
0122 
0123     float getEDepError() const final { return m_value.getEDepError(); }
0124 
0125     const edm4hep::Vector3d& getPosition() const final { return m_value.getPosition(); }
0126 
0127 
0128 
0129     ValueT m_value{};
0130   };
0131 
0132  std::unique_ptr<Concept> m_self{nullptr};
0133 
0134 public:
0135   // TrackerHit can only be initialized with one of the following types (and their Mutable counter parts): ::edm4hep::TrackerHit3D, ::edm4hep::TrackerHitPlane
0136   template<typename ValueT>
0137   requires isInitializableFrom<ValueT>
0138   TrackerHit(ValueT value) :
0139     m_self(std::make_unique<Model<podio::detail::GetDefaultHandleType<ValueT>>>(value)) {
0140   }
0141 
0142   TrackerHit(const TrackerHit& other) :
0143     m_self(other.m_self->clone()) {}
0144   TrackerHit& operator=(const TrackerHit& other) {
0145     TrackerHit tmp{other};
0146     std::swap(tmp.m_self, this->m_self);
0147     return *this;
0148   }
0149 
0150   ~TrackerHit() = default;
0151   TrackerHit(TrackerHit&&) = default;
0152   TrackerHit& operator=(TrackerHit&&) = default;
0153 
0154   /// Create an empty handle
0155   static TrackerHit makeEmpty() {
0156     // We simply chose the first type of the interfaced types here to initialize
0157     // an empty handle
0158     return ::edm4hep::TrackerHit3D::makeEmpty();
0159   }
0160 
0161   static constexpr std::string_view typeName = "edm4hep::TrackerHit";
0162 
0163   /// check whether the object is actually available
0164   bool isAvailable() const { return m_self->isAvailable(); }
0165   /// disconnect from the underlying value
0166   void unlink() { m_self->unlink(); }
0167 
0168   podio::ObjectID id() const { return getObjectID(); }
0169   podio::ObjectID getObjectID() const { return m_self->getObjectID(); }
0170 
0171   /// Check if the object currently holds a value of the requested type
0172   template<typename T>
0173   bool isA() const {
0174     static_assert(isInterfacedType<T>, "TrackerHit can only ever be one of the following types: ::edm4hep::TrackerHit3D, ::edm4hep::TrackerHitPlane");
0175     return typeid(T) == m_self->typeInfo();
0176   }
0177 
0178   /// Get the contained value as the concrete type it was put in. This will
0179   /// throw a std::runtime_error if T is not the type of the currently held
0180   /// value. Use isA to check beforehand if necessary
0181   template<typename T>
0182   T as() const {
0183     if (!isA<T>()) {
0184       throw std::runtime_error("Cannot get value as object currently holds another type");
0185     }
0186     // We can safely cast here since we check types before
0187     return static_cast<Model<T>*>(m_self.get())->m_value;
0188   }
0189 
0190   template<typename T>
0191   [[deprecated("Use 'as' instead.")]]
0192   T getValue() const {
0193     return as<T>();
0194   }
0195 
0196   friend bool operator==(const TrackerHit& lhs, const TrackerHit& rhs) {
0197     return lhs.m_self->equal(rhs.m_self.get());
0198   }
0199 
0200   friend bool operator!=(const TrackerHit& lhs, const TrackerHit& rhs) {
0201     return !(lhs == rhs);
0202   }
0203 
0204   friend bool operator<(const TrackerHit& lhs, const TrackerHit& rhs) {
0205     return lhs.m_self->objOrderKey() < rhs.m_self->objOrderKey();
0206   }
0207 
0208   /// Access the ID of the sensor that created this hit
0209   std::uint64_t getCellID() const { return m_self->getCellID(); }
0210 
0211   /// Access the type of the raw data hit
0212   std::int32_t getType() const { return m_self->getType(); }
0213 
0214   /// Access the quality bit flag of the hit
0215   std::int32_t getQuality() const { return m_self->getQuality(); }
0216 
0217   /// Access the time of the hit [ns]
0218   float getTime() const { return m_self->getTime(); }
0219 
0220   /// Access the energy deposited on the hit [GeV]
0221   float getEDep() const { return m_self->getEDep(); }
0222 
0223   /// Access the error measured on eDep [GeV]
0224   float getEDepError() const { return m_self->getEDepError(); }
0225 
0226   /// Access the hit position [mm]
0227   const edm4hep::Vector3d& getPosition() const { return m_self->getPosition(); }
0228 
0229 
0230 
0231   friend std::ostream& operator<<(std::ostream& os, const TrackerHit& value) {
0232     value.m_self->print(os);
0233     return os;
0234   }
0235 
0236   friend std::hash<TrackerHit>;
0237 };
0238 
0239 } // namespace edm4hep
0240 
0241 
0242 template<>
0243 struct std::hash<edm4hep::TrackerHit> {
0244   std::size_t operator()(const edm4hep::TrackerHit& obj) const {
0245     return obj.m_self->objHash();
0246   }
0247 };
0248 
0249 #endif