Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
Array.h
1/*
2 * HalMemoryManagerArrays.h
3 *
4 * Created on: 30-04-2022
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#ifndef HALMEMORYMANAGERARRAYS_H_
10#define HALMEMORYMANAGERARRAYS_H_
11#include <TNamed.h>
12#include <TObject.h>
13
17namespace Hal {
18 template<typename T>
19 class Array_1 : public TObject {
20 Int_t fSize;
21 T* fArray; //[fSize]
22 public:
23 Array_1() : TObject(), fSize(0), fArray(nullptr) {}
24 Array_1(Int_t size);
29 Array_1(const Array_1<T>& obj);
34 void MakeBigger(Int_t new_dim);
39 void Resize(Int_t new_dim);
45 inline T& operator[](const int index) { return fArray[index]; };
50 inline Int_t GetSize() const { return fSize; }
55 inline T* GetArray() const { return fArray; };
61 void Add(Array_1<T> const& rhs);
67 Array_1<T>& operator=(const Array_1<T>& rhs);
73 Array_1<T>& operator+=(const Array_1<T>& rhs);
74
75 Array_1<T>& operator-=(const Array_1<T>& rhs);
76
77 Array_1<T>& operator+(const Array_1<T>& rhs);
78
79 Array_1<T>& operator-(const Array_1<T>& rhs);
80
81 Array_1<T>& operator*(const T& val);
82
83 Array_1<T>& operator/(const T& val);
84
85 Array_1<T>& operator*=(const T& val);
86
87 Array_1<T>& operator/=(const T& val);
88
89 T FindMin(Int_t& index) const;
90
91 T FindMax(Int_t& index) const;
92
97 inline T Get(Int_t i) const { return fArray[i]; };
103 inline void Set(Int_t index, T val) { fArray[index] = val; };
109 inline T IncrementAfter(Int_t i); //{return fArray[i]++;};
110 virtual ~Array_1() {
111 if (fArray) delete[] fArray;
112 };
113 ClassDef(Array_1, 1)
114 };
115 template<typename T>
117 return fArray[i]++;
118 }
119 template<>
120 inline Bool_t Array_1<Bool_t>::IncrementAfter(Int_t i) {
121 return fArray[i];
122 }
126 template<typename T>
127 class Array_2 : public TObject {
128 Int_t fSize;
129 Array_1<T>* fArray; //[fSize]
130 public:
131 Array_2() : TObject(), fSize(0), fArray(NULL) {};
137 Array_2(Int_t x, Int_t y);
142 Array_2(const Array_2<T>& obj);
148 void MakeBigger(Int_t sizeA, Int_t sizeB);
153 inline Int_t GetSize() const { return fSize; }
159 inline Array_1<T>* At(const Int_t i) { return &fArray[i]; };
165 Array_2<T>& operator=(const Array_2<T>& rhs);
169 Array_2<T>& operator+=(const Array_2<T>& rhs);
174 inline T Get(Int_t i, Int_t j) const { return fArray[i].Get(j); };
175 inline Array_1<T>& operator[](const int index) { return fArray[index]; };
182 inline void Set(Int_t i, Int_t j, T val) { fArray[i].Set(j, val); };
189 inline T IncrementAfter(Int_t i, Int_t j) { return fArray[i].IncrementAfter(j); };
190 virtual ~Array_2() {
191 if (fArray) delete[] fArray;
192 };
193 ClassDef(Array_2, 1)
194 };
198 template<typename T>
199 class Array_3 : public TObject {
200 Int_t fSize;
201 Array_2<T>* fArray; //[fSize]
202 public:
203 Array_3() : TObject(), fSize(0), fArray(NULL) {};
204 Array_3(Int_t x, Int_t y, Int_t z);
209 Array_3(const Array_3<T>& obj);
216 void MakeBigger(Int_t sizeA, Int_t sizeB, Int_t sizeC);
221 inline Int_t GetSize() const { return fSize; }
222 inline Array_2<T>& operator[](const int index) { return fArray[index]; };
228 inline Array_2<T>* At(Int_t i) const { return &fArray[i]; };
234 Array_3<T>& operator=(const Array_3<T>& rhs);
240 Array_3<T>& operator+=(const Array_3<T>& rhs);
248 inline T Get(Int_t A, Int_t B, Int_t C) const { return fArray[A].Get(B, C); };
256 inline T IncrementAfter(Int_t A, Int_t B, Int_t C) { return fArray[A].IncrementAfter(B, C); }; // do i++ and return i !
265 inline void Set(Int_t A, Int_t B, Int_t C, T val) { fArray[A].Set(B, C, val); };
266 virtual ~Array_3() {
267 if (fArray) delete[] fArray;
268 }
269 ClassDef(Array_3, 1)
270 };
271
272 template<typename T>
276 class Array_4 : public TObject {
277 Int_t fSize;
278 Array_3<T>* fArray; //[fSize]
279 public:
280 Array_4() : TObject(), fSize(0), fArray(NULL) {};
281 Array_4(Int_t x, Int_t y, Int_t z, Int_t t);
286 Array_4(const Array_4<T>& obj);
294 void MakeBigger(Int_t sizeA, Int_t sizeB, Int_t sizeC, Int_t sizeD);
295 inline Array_3<T>& operator[](const int index) { return fArray[index]; };
301 inline Array_3<T>* At(Int_t i) const { return &fArray[i]; };
307 Array_4<T>& operator=(const Array_4<T>& rhs);
313 Array_4<T>& operator+=(const Array_4<T>& rhs);
318 inline Int_t GetSize() const { return fSize; }
327 inline T Get(Int_t A, Int_t B, Int_t C, Int_t D) const { return fArray[A].Get(B, C, D); };
336 inline T IncrementAfter(Int_t A, Int_t B, Int_t C, Int_t D) { return fArray[A].IncrementAfter(B, C, D); };
345 inline void Set(Int_t A, Int_t B, Int_t C, Int_t D, T val) { fArray[A].Set(B, C, D, val); };
346 virtual ~Array_4() {
347 if (fArray) delete[] fArray;
348 }
349 ClassDef(Array_4, 1)
350 };
351} // namespace Hal
352#endif /* HALMEMORYMANAGERARRAYS_H_ */
void Set(Int_t index, T val)
Definition Array.h:103
T * GetArray() const
Definition Array.h:55
T IncrementAfter(Int_t i)
Definition Array.h:116
void Add(Array_1< T > const &rhs)
Definition Array.cxx:176
void Resize(Int_t new_dim)
Definition Array.cxx:21
T Get(Int_t i) const
Definition Array.h:97
T & operator[](const int index)
Definition Array.h:45
void MakeBigger(Int_t new_dim)
Definition Array.cxx:5
Array_1< T > & operator+=(const Array_1< T > &rhs)
Definition Array.cxx:63
Int_t GetSize() const
Definition Array.h:50
Array_1< T > & operator=(const Array_1< T > &rhs)
Definition Array.cxx:45
void MakeBigger(Int_t sizeA, Int_t sizeB)
Definition Array.cxx:197
Array_2< T > & operator=(const Array_2< T > &rhs)
Definition Array.cxx:218
T IncrementAfter(Int_t i, Int_t j)
Definition Array.h:189
T Get(Int_t i, Int_t j) const
Definition Array.h:174
Array_1< T > * At(const Int_t i)
Definition Array.h:159
void Set(Int_t i, Int_t j, T val)
Definition Array.h:182
Int_t GetSize() const
Definition Array.h:153
Array_2< T > * At(Int_t i) const
Definition Array.h:228
Int_t GetSize() const
Definition Array.h:221
void Set(Int_t A, Int_t B, Int_t C, T val)
Definition Array.h:265
Array_3< T > & operator=(const Array_3< T > &rhs)
Definition Array.cxx:284
void MakeBigger(Int_t sizeA, Int_t sizeB, Int_t sizeC)
Definition Array.cxx:263
Array_3< T > & operator+=(const Array_3< T > &rhs)
Definition Array.cxx:302
T IncrementAfter(Int_t A, Int_t B, Int_t C)
Definition Array.h:256
T Get(Int_t A, Int_t B, Int_t C) const
Definition Array.h:248
void Set(Int_t A, Int_t B, Int_t C, Int_t D, T val)
Definition Array.h:345
Array_4< T > & operator+=(const Array_4< T > &rhs)
Definition Array.cxx:365
Array_3< T > * At(Int_t i) const
Definition Array.h:301
Array_4< T > & operator=(const Array_4< T > &rhs)
Definition Array.cxx:347
T Get(Int_t A, Int_t B, Int_t C, Int_t D) const
Definition Array.h:327
T IncrementAfter(Int_t A, Int_t B, Int_t C, Int_t D)
Definition Array.h:336
void MakeBigger(Int_t sizeA, Int_t sizeB, Int_t sizeC, Int_t sizeD)
Definition Array.cxx:326
Int_t GetSize() const
Definition Array.h:318