CbmRoot
CbmL1Def.h
Go to the documentation of this file.
1 #ifndef CbmL1Def_h
2 #define CbmL1Def_h 1
3 
4 // #define FAST_CODE // FAST_CODE = more unsafe
5 
6 
7 #include "TStopwatch.h"
8 #include <assert.h>
9 #include <iostream>
10 #include <vector>
11 #ifdef HAVE_SSE
12 #include "vectors/P4_F32vec4.h"
13 #else
14 #include "vectors/PSEUDO_F32vec4.h"
15 #error NoSseFound
16 #endif // HAVE_SSE
17 
18 //#include "vectors/PSEUDO_F64vec1.h"
19 
20 template<typename T>
21 T finite(T x) {
22  return std::isfinite(x);
23 }
24 
25 #ifdef FAST_CODE
26 
27 #define L1_NO_ASSERT // use with asserts, etc.
28 #define L1_DYNAMIC_CAST static_cast
29 
30 #else // FAST_CODE
31 
32 #define L1_DYNAMIC_CAST dynamic_cast
33 
34 #endif // FAST_CODE
35 
36 #if 1 && defined(__GNUC__) && __GNUC__ - 0 >= 3 // for speed up conditions
37 #define ISLIKELY(x) __builtin_expect(!!(x), 1)
38 #define ISUNLIKELY(x) __builtin_expect(!!(x), 0)
39 #else
40 #define ISLIKELY(x) (x)
41 #define ISUNLIKELY(x) (x)
42 #endif
43 
44 #if defined(NDEBUG) || defined(L1_NO_ASSERT)
45 #define L1_ASSERT(v, msg)
46 #define L1_assert(v)
47 #else
48 #define L1_ASSERT(v, msg) \
49  if (v) { \
50  } else { \
51  std::cerr << __FILE__ << ":" << __LINE__ << " assertion failed: " << #v \
52  << " = " << (v) << "\n" \
53  << msg << std::endl; \
54  abort(); \
55  }
56 #define L1_assert(v) assert(v)
57 #endif
58 
59 
60 using namespace std;
61 
62 typedef int index_type;
63 
64 
65 template<typename T>
66 class L1Vector : public std::vector<T> {
67 public:
68  L1Vector() : std::vector<T>(), fSize(0) {};
69  L1Vector(const unsigned int n) : std::vector<T>(n), fSize(0) {};
70  L1Vector(const unsigned int n, const unsigned int value)
71  : std::vector<T>(n, value), fSize(0) {};
72 
73 
74  unsigned int Size() const { return fSize; } // Size() return number
75  void Reset() { fSize = 0; }
76 
77  void Resize(const unsigned int n) {
78  if (n > std::vector<T>::size()) {
79 #ifdef _OPENMP
80 #pragma omp critical
81 #endif
82  std::vector<T>::resize(n);
83  }
84 
85  fSize = n;
86  }
87 
88  void Store(const T& element) {
89  if (fSize >= std::vector<T>::size()) {
90 #ifdef _OPENMP
91 #pragma omp critical
92 #endif
93  std::vector<T>::push_back(element);
94  } else
95  std::vector<T>::at(fSize) = element;
96 
97  fSize++;
98  }
99 
100 
101  T& operator[](const size_t index) {
102  if (index >= std::vector<T>::size()) {
103 #ifdef _OPENMP
104 #pragma omp critical
105 #endif
106  std::vector<T>::resize(index + 1);
107  std::cout << index << " index " << std::endl;
108  }
109  if (index >= fSize) fSize = index + 1;
110 
111  return std::vector<T>::operator[](index);
112  }
113 
114  const T& operator[](const size_t index) const {
115 
116  return std::vector<T>::operator[](index);
117  }
118 
119 private:
120  unsigned int fSize;
121 };
122 
123 #endif // CbmL1Def_h
L1Vector::Store
void Store(const T &element)
Definition: CbmL1Def.h:88
L1Vector::Resize
void Resize(const unsigned int n)
Definition: CbmL1Def.h:77
L1Vector::operator[]
const T & operator[](const size_t index) const
Definition: CbmL1Def.h:114
index_type
int index_type
Definition: CbmL1Def.h:62
L1Vector
Definition: CbmL1Def.h:66
L1Vector::L1Vector
L1Vector(const unsigned int n, const unsigned int value)
Definition: CbmL1Def.h:70
finite
T finite(T x)
Definition: CbmL1Def.h:21
L1Vector::L1Vector
L1Vector(const unsigned int n)
Definition: CbmL1Def.h:69
PSEUDO_F32vec4.h
L1Vector::Reset
void Reset()
Definition: CbmL1Def.h:75
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
L1Vector::operator[]
T & operator[](const size_t index)
Definition: CbmL1Def.h:101
L1Vector::fSize
unsigned int fSize
Definition: CbmL1Def.h:120
L1Vector::L1Vector
L1Vector()
Definition: CbmL1Def.h:68
L1Vector::Size
unsigned int Size() const
Definition: CbmL1Def.h:74
operator[]
float & operator[](int i)
Definition: L1/vectors/P4_F32vec4.h:3