Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:07

0001 #ifndef TRACKBASE_ACTSSOURCELINK_H
0002 #define TRACKBASE_ACTSSOURCELINK_H
0003 
0004 #include "TrkrDefs.h"
0005 
0006 #ifndef __clang__
0007 #pragma GCC diagnostic push
0008 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
0009 #include <Acts/Geometry/TrackingGeometry.hpp>
0010 #pragma GCC diagnostic pop
0011 #else
0012 #include <Acts/Geometry/TrackingGeometry.hpp>
0013 #endif
0014 
0015 #include <Acts/EventData/SourceLink.hpp>
0016 #include <Acts/Surfaces/Surface.hpp>
0017 
0018 #include <cassert>
0019 #include <iostream>
0020 
0021 /// A source link that stores just an index.
0022 /// Using an index instead of e.g. a pointer, means source link and
0023 /// measurement are decoupled and the measurement represenation can be
0024 /// easily changed without having to also change the source link.
0025 class ActsSourceLink final
0026 {
0027  public:
0028   using Index = uint8_t;
0029 
0030   /// Construct from geometry identifier and index.
0031   constexpr ActsSourceLink(Acts::GeometryIdentifier gid, Index idx)
0032     : m_geometryId(gid)
0033     , m_index(idx)
0034     , m_cluskey(0)
0035   {
0036   }
0037   constexpr ActsSourceLink(Acts::GeometryIdentifier gid, Index idx, TrkrDefs::cluskey cluskey)
0038     : m_geometryId(gid)
0039     , m_index(idx)
0040     , m_cluskey(cluskey)
0041   {
0042   }
0043 
0044   // Construct an invalid source link. Must be default constructible to
0045   /// satisfy SourceLinkConcept.
0046   ActsSourceLink()
0047     : m_geometryId{Acts::GeometryIdentifier{}}
0048     , m_index(UINT8_MAX)
0049     , m_cluskey(UINT64_MAX)
0050   {
0051   }
0052 
0053   ActsSourceLink(const ActsSourceLink&) = default;
0054   ActsSourceLink(ActsSourceLink&&) = default;
0055   ActsSourceLink& operator=(const ActsSourceLink&) = default;
0056   ActsSourceLink& operator=(ActsSourceLink&&) = default;
0057 
0058   /// Access the index.
0059   constexpr Index index() const { return m_index; }
0060   constexpr TrkrDefs::cluskey cluskey() const { return m_cluskey; }
0061   constexpr Acts::GeometryIdentifier geometryId() const { return m_geometryId; }
0062 
0063   struct SurfaceAccessor
0064   {
0065     const Acts::TrackingGeometry& trackingGeometry;
0066     const Acts::Surface* operator()(const Acts::SourceLink& sourceLink) const
0067     {
0068       const auto& sl = sourceLink.get<ActsSourceLink>();
0069       return trackingGeometry.findSurface(sl.geometryId());
0070     }
0071   };
0072 
0073  private:
0074   Acts::GeometryIdentifier m_geometryId;
0075   Index m_index;
0076   TrkrDefs::cluskey m_cluskey;
0077 
0078   friend constexpr bool operator==(const ActsSourceLink& lhs,
0079                                    const ActsSourceLink& rhs)
0080   {
0081     return (lhs.geometryId() == rhs.geometryId()) and
0082            (lhs.m_index == rhs.m_index) and
0083            (lhs.m_cluskey == rhs.m_cluskey);
0084   }
0085   friend constexpr bool operator!=(const ActsSourceLink& lhs,
0086                                    const ActsSourceLink& rhs)
0087   {
0088     return not(lhs == rhs);
0089   }
0090 };
0091 
0092 #endif