CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
trackAlgoPriorityOrder.h
Go to the documentation of this file.
1 #ifndef DataFormats_TrackReco_trackAlgoPriorityOrder_h
2 #define DataFormats_TrackReco_trackAlgoPriorityOrder_h
3 
5 
6 #include <array>
7 
14 namespace impl {
15 
71  };
72 
73  static_assert(reco::TrackBase::algoSize == sizeof(algoPriorityOrder)/sizeof(unsigned int), "Please update me too after adding new enumerators to reco::TrackBase::TrackAlgorithm");
74 
83  constexpr unsigned int findIndex(const reco::TrackBase::TrackAlgorithm algo, const unsigned int index) {
84  return index < sizeof(algoPriorityOrder)/sizeof(unsigned int) ?
85  (algo == algoPriorityOrder[index] ? index : findIndex(algo, index+1)) :
86  throw "Index out of bounds, this means that some reco::TrackBase::TrackAlgorithm enumerator is missing from impl::algoPriorityOrder array.";
87  }
88 
99  return findIndex(algo, 0);
100  }
101 
102 
118  template <typename T, size_t N, size_t I>
119  struct MakeArray {
120  template <typename ...Args>
121  constexpr static
122  std::array<T, N> value(Args&&... args) {
123  return MakeArray<T, N, I-1>::value(priorityForAlgo(static_cast<reco::TrackBase::TrackAlgorithm>(I-1)), std::forward<Args>(args)...);
124  }
125  };
126 
130  template <typename T, size_t N>
131  struct MakeArray<T, N, 0> {
132  template <typename ...Args>
133  constexpr static
134  std::array<T, N> value(Args&&... args) {
135  return std::array<T, N>{{std::forward<Args>(args)...}};
136  }
137  };
138 
139 
148  template <typename T, size_t N>
149  constexpr
150  std::array<T, N> makeArray() {
151  return MakeArray<T, N, N>::value();
152  }
153 
154 }
155 
160 constexpr std::array<unsigned int, reco::TrackBase::algoSize> trackAlgoPriorityOrder = impl::makeArray<unsigned int, reco::TrackBase::algoSize>();
161 
162 
163 #endif // DataFormats_TrackReco_trackAlgoPriorityOrder_h
164 
static std::array< T, N > value(Args &&...args)
std::array< T, N > makeArray()
unsigned int findIndex(const reco::TrackBase::TrackAlgorithm algo, const unsigned int index)
#define constexpr
unsigned int priorityForAlgo(const reco::TrackBase::TrackAlgorithm algo)
TrackAlgorithm
track algorithm
Definition: TrackBase.h:99
const std::complex< double > I
Definition: I.h:8
#define N
Definition: blowfish.cc:9
std::array< unsigned int, reco::TrackBase::algoSize > trackAlgoPriorityOrder
static std::array< T, N > value(Args &&...args)
reco::TrackBase::TrackAlgorithm algoPriorityOrder[]
long double T