1 | #ifndef MARS_MArrayF
|
---|
2 | #define MARS_MArrayF
|
---|
3 |
|
---|
4 | #ifndef MARS_MArray
|
---|
5 | #include "MArray.h"
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #include <string.h>
|
---|
9 |
|
---|
10 | class TArrayF;
|
---|
11 | class MArrayF : public MArray
|
---|
12 | {
|
---|
13 | private:
|
---|
14 | Float_t *fArray; //[fN] Array of fN chars
|
---|
15 |
|
---|
16 | public:
|
---|
17 |
|
---|
18 | MArrayF()
|
---|
19 | {
|
---|
20 | fN = 0;
|
---|
21 | fArray = NULL;
|
---|
22 | }
|
---|
23 |
|
---|
24 | MArrayF(UInt_t n)
|
---|
25 | {
|
---|
26 | fN = 0;
|
---|
27 | fArray = NULL;
|
---|
28 | Set(n);
|
---|
29 | }
|
---|
30 |
|
---|
31 | MArrayF(UInt_t n, Float_t *array)
|
---|
32 | {
|
---|
33 | // Create TArrayC object and initialize it with values of array.
|
---|
34 | fN = 0;
|
---|
35 | fArray = NULL;
|
---|
36 | Set(n, array);
|
---|
37 | }
|
---|
38 |
|
---|
39 | MArrayF(const MArrayF &array) : MArray()
|
---|
40 | {
|
---|
41 | // Copy constructor.
|
---|
42 | fArray = NULL;
|
---|
43 | Set(array.fN, array.fArray);
|
---|
44 | }
|
---|
45 |
|
---|
46 | UInt_t GetSize() const
|
---|
47 | {
|
---|
48 | return fN;
|
---|
49 | }
|
---|
50 |
|
---|
51 | MArrayF &operator=(const MArrayF &rhs)
|
---|
52 | {
|
---|
53 | // TArrayC assignment operator.
|
---|
54 | if (this != &rhs)
|
---|
55 | Set(rhs.fN, rhs.fArray);
|
---|
56 | return *this;
|
---|
57 | }
|
---|
58 |
|
---|
59 | virtual ~MArrayF()
|
---|
60 | {
|
---|
61 | // Delete TArrayC object.
|
---|
62 | delete [] fArray;
|
---|
63 | fArray = NULL;
|
---|
64 | }
|
---|
65 |
|
---|
66 | void Adopt(UInt_t n, Float_t *array)
|
---|
67 | {
|
---|
68 | // Adopt array arr into TArrayC, i.e. don't copy arr but use it directly
|
---|
69 | // in TArrayC. User may not delete arr, TArrayC dtor will do it.
|
---|
70 | if (fArray)
|
---|
71 | delete [] fArray;
|
---|
72 |
|
---|
73 | fN = n;
|
---|
74 | fArray = array;
|
---|
75 | }
|
---|
76 |
|
---|
77 | void AddAt(Float_t c, UInt_t i)
|
---|
78 | {
|
---|
79 | // Add char c at position i. Check for out of bounds.
|
---|
80 | fArray[i] = c;
|
---|
81 | }
|
---|
82 |
|
---|
83 | Float_t At(UInt_t i) const
|
---|
84 | {
|
---|
85 | return fArray[i];
|
---|
86 | }
|
---|
87 |
|
---|
88 | Float_t *GetArray() const
|
---|
89 | {
|
---|
90 | return fArray;
|
---|
91 | }
|
---|
92 |
|
---|
93 | void Reset()
|
---|
94 | {
|
---|
95 | memset(fArray, 0, fN*sizeof(Float_t));
|
---|
96 | }
|
---|
97 |
|
---|
98 | void Reset(Float_t f)
|
---|
99 | {
|
---|
100 | for (UInt_t i=0; i<fN; i++)
|
---|
101 | fArray[i] = f;
|
---|
102 | }
|
---|
103 |
|
---|
104 | void Set(UInt_t n)
|
---|
105 | {
|
---|
106 | // Set size of this array to n chars.
|
---|
107 | // A new array is created, the old contents copied to the new array,
|
---|
108 | // then the old array is deleted.
|
---|
109 |
|
---|
110 | if (n==fN)
|
---|
111 | return;
|
---|
112 |
|
---|
113 | Float_t *temp = fArray;
|
---|
114 | if (n == 0)
|
---|
115 | fArray = NULL;
|
---|
116 | else
|
---|
117 | {
|
---|
118 | fArray = new Float_t[n];
|
---|
119 | if (n < fN)
|
---|
120 | memcpy(fArray, temp, n*sizeof(Float_t));
|
---|
121 | else
|
---|
122 | {
|
---|
123 | memcpy(fArray, temp, fN*sizeof(Float_t));
|
---|
124 | memset(&fArray[fN], 0, (n-fN)*sizeof(Float_t));
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (fN)
|
---|
129 | delete [] temp;
|
---|
130 |
|
---|
131 | fN = n;
|
---|
132 | }
|
---|
133 |
|
---|
134 | void Set(UInt_t n, Float_t *array)
|
---|
135 | {
|
---|
136 | // Set size of this array to n chars and set the contents.
|
---|
137 | if (!array)
|
---|
138 | return;
|
---|
139 |
|
---|
140 | if (fArray && fN != n)
|
---|
141 | {
|
---|
142 | delete [] fArray;
|
---|
143 | fArray = 0;
|
---|
144 | }
|
---|
145 | fN = n;
|
---|
146 |
|
---|
147 | if (fN == 0)
|
---|
148 | return;
|
---|
149 |
|
---|
150 | if (!fArray)
|
---|
151 | fArray = new Float_t[fN];
|
---|
152 |
|
---|
153 | memcpy(fArray, array, n*sizeof(Float_t));
|
---|
154 | }
|
---|
155 |
|
---|
156 | Float_t &operator[](UInt_t i)
|
---|
157 | {
|
---|
158 | return fArray[i];
|
---|
159 | }
|
---|
160 | const Float_t &operator[](UInt_t i) const
|
---|
161 | {
|
---|
162 | return fArray[i];
|
---|
163 | }
|
---|
164 |
|
---|
165 | static void StripZeros(TArrayF &arr);
|
---|
166 | void StripZeros();
|
---|
167 |
|
---|
168 | ClassDef(MArrayF, 1) //Array of Float_t
|
---|
169 | };
|
---|
170 |
|
---|
171 | #endif
|
---|