Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:26:03

0001 /// \file SOA.h
0002 /// \author Johannes de Fine Licht (johannes.definelicht@cern.ch)
0003 
0004 #ifndef VECGEOM_BASE_SOA_H_
0005 #define VECGEOM_BASE_SOA_H_
0006 
0007 #include "VecGeom/base/Global.h"
0008 
0009 #include "VecGeom/base/AlignedBase.h"
0010 
0011 namespace vecgeom {
0012 
0013 inline namespace VECGEOM_IMPL_NAMESPACE {
0014 
0015 template <typename T, int rows, int columns>
0016 struct SOAData : public AlignedBase {
0017   T fHead[rows] VECGEOM_ALIGNED;
0018   SOAData<T, rows, columns - 1> fTail;
0019 };
0020 template <typename T, int rows>
0021 struct SOAData<T, rows, 0> : public AlignedBase {
0022 };
0023 
0024 template <typename T, int columns, int rows>
0025 class SOA : public AlignedBase {
0026 
0027 private:
0028   SOAData<T, rows, columns> fData;
0029 
0030   VECCORE_ATT_HOST_DEVICE
0031   VECGEOM_FORCE_INLINE
0032 #ifndef VECCORE_CUDA
0033   static constexpr int ColumnSize();
0034 #else
0035   static int ColumnSize();
0036 #endif
0037 
0038 public:
0039   typedef T Column_t[rows];
0040 
0041   SOA() {}
0042 
0043   VECCORE_ATT_HOST_DEVICE
0044   VECGEOM_FORCE_INLINE
0045   Column_t &operator[](int index);
0046 
0047   VECCORE_ATT_HOST_DEVICE
0048   VECGEOM_FORCE_INLINE
0049   Column_t const &operator[](int index) const;
0050 };
0051 
0052 template <typename T, int columns, int rows>
0053 #ifndef VECCORE_CUDA
0054 constexpr int SOA<T, columns, rows>::ColumnSize()
0055 {
0056 #else
0057 int SOA<T, columns, rows>::ColumnSize()
0058 {
0059 #endif
0060   return sizeof(SOA<T, columns, rows>) / columns;
0061 }
0062 
0063 template <typename T, int columns, int rows>
0064 VECCORE_ATT_HOST_DEVICE
0065 typename SOA<T, columns, rows>::Column_t &SOA<T, columns, rows>::operator[](int index)
0066 {
0067   return *(&fData.fHead + index * ColumnSize());
0068 }
0069 
0070 template <typename T, int columns, int rows>
0071 VECCORE_ATT_HOST_DEVICE
0072 typename SOA<T, columns, rows>::Column_t const &SOA<T, columns, rows>::operator[](int index) const
0073 {
0074   return *(&fData.fHead + index * ColumnSize());
0075 }
0076 
0077 } // End inline namespace
0078 
0079 } // End global namespace
0080 
0081 #endif // VECGEOM_BASE_SOA_H_