Corrected protection.
[u/mrichter/AliRoot.git] / STEER / AliDCSArray.cxx
CommitLineData
d96c6484 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16////////////////////////////////////////////////////////////////////////////////
17// //
18// This class represents the value(s) of a the LHC DPs at a given timestamp //
19// The variuos measurement that occurred at the same timestamp are associated //
20// to the same timestamp. //
21// //
22////////////////////////////////////////////////////////////////////////////////
23
24
25#include "AliDCSArray.h"
30ec5bf7 26#include "AliLog.h"
d96c6484 27
30ec5bf7 28//#include "TTimeStamp.h"
29#include <TObjArray.h>
30#include <TObjString.h>
d96c6484 31#include <TString.h>
30ec5bf7 32#include <TMath.h>
d96c6484 33
34ClassImp(AliDCSArray)
35
36AliDCSArray::AliDCSArray() :
37 TObject(),
38 fType(kInvalid),
39 fnentries(0),
40 fBool(0x0),
41 fChar(0x0),
42 fInt(0x0),
43 fUInt(0x0),
44 fFloat(0x0),
30ec5bf7 45 fStringArray(0x0),
46 fTimeStamp(-1.),
47 fDouble(0x0)
d96c6484 48{
49 //
50 // default constructor
51 //
52}
53
54//--------------------------------------------------------------------------
30ec5bf7 55AliDCSArray::AliDCSArray(Int_t nentries, Bool_t* value, Double_t timeStamp) :
d96c6484 56 TObject(),
57 fType(kBool),
58 fnentries(nentries),
59 fBool(new Bool_t[fnentries]),
60 fChar(0x0),
61 fInt(0x0),
62 fUInt(0x0),
63 fFloat(0x0),
30ec5bf7 64 fStringArray(0x0),
65 fTimeStamp(timeStamp),
66 fDouble(0x0)
d96c6484 67{
68 //
69 // constructor for Bool
70 //
71
72 for (Int_t i = 0; i<fnentries; i++){
73 fBool[i] = value[i];
74 }
75}
76
77//--------------------------------------------------------------------------
30ec5bf7 78AliDCSArray::AliDCSArray(Int_t nentries, Char_t* value, Double_t timeStamp) :
d96c6484 79 TObject(),
80 fType(kChar),
81 fnentries(nentries),
82 fBool(0x0),
83 fChar(new Char_t[fnentries]),
84 fInt(0x0),
85 fUInt(0x0),
86 fFloat(0x0),
30ec5bf7 87 fStringArray(0x0),
88 fTimeStamp(timeStamp),
89 fDouble(0x0)
d96c6484 90{
91 //
92 // constructor for Char
93 //
94 for (Int_t i = 0; i<fnentries; i++){
95 fChar[i] = value[i];
96 }
97}
98
99//-------------------------------------------------------------------------
30ec5bf7 100AliDCSArray::AliDCSArray(Int_t nentries, Int_t* value, Double_t timeStamp) :
d96c6484 101 TObject(),
102 fType(kInt),
103 fnentries(nentries),
104 fBool(0x0),
105 fChar(0x0),
106 fInt(new Int_t[fnentries]),
107 fUInt(0x0),
108 fFloat(0x0),
30ec5bf7 109 fStringArray(0x0),
110 fTimeStamp(timeStamp),
111 fDouble(0x0)
d96c6484 112{
113 //
114 // constructor for Int
115 //
116 for (Int_t i = 0; i<fnentries; i++){
117 fInt[i] = value[i];
118 }
119}
120
121//-------------------------------------------------------------------------
30ec5bf7 122AliDCSArray::AliDCSArray(Int_t nentries, UInt_t* value, Double_t timeStamp) :
d96c6484 123 TObject(),
124 fType(kUInt),
125 fnentries(nentries),
126 fBool(0x0),
127 fChar(0x0),
128 fInt(0x0),
129 fUInt(new UInt_t[fnentries]),
130 fFloat(0x0),
30ec5bf7 131 fStringArray(0x0),
132 fTimeStamp(timeStamp),
133 fDouble(0x0)
d96c6484 134{
135 //
136 // constructor for UInt
137 //
138
139 for (Int_t i = 0; i<fnentries; i++){
140 fUInt[i] = value[i];
141 }
142}
143
144//-------------------------------------------------------------------------
30ec5bf7 145AliDCSArray::AliDCSArray(Int_t nentries, Float_t* value, Double_t timeStamp) :
d96c6484 146 TObject(),
147 fType(kFloat),
148 fnentries(nentries),
149 fBool(0x0),
150 fChar(0x0),
151 fInt(0x0),
152 fUInt(0x0),
153 fFloat(new Float_t[fnentries]),
30ec5bf7 154 fStringArray(0x0),
155 fTimeStamp(timeStamp),
156 fDouble(0x0)
d96c6484 157{
158 //
159 // constructor for Float
160 //
161
162 for (Int_t i = 0; i<fnentries; i++){
163 fFloat[i] = value[i];
164 }
165}
30ec5bf7 166//-------------------------------------------------------------------------
167AliDCSArray::AliDCSArray(Int_t nentries, Double_t* value, Double_t timeStamp) :
168 TObject(),
169 fType(kDouble),
170 fnentries(nentries),
171 fBool(0x0),
172 fChar(0x0),
173 fInt(0x0),
174 fUInt(0x0),
175 fFloat(0x0),
176 fStringArray(0x0),
177 fTimeStamp(timeStamp),
178 fDouble(new Double_t[fnentries])
179{
180 //
181 // constructor for Double
182 //
183
184 for (Int_t i = 0; i<fnentries; i++){
185 fDouble[i] = value[i];
186 }
187}
d96c6484 188
189//------------------------------------------------------------------------
30ec5bf7 190AliDCSArray::AliDCSArray(Int_t nentries, TObjArray* value, Double_t timeStamp) :
d96c6484 191 TObject(),
192 fType(kString),
193 fnentries(nentries),
194 fBool(0x0),
195 fChar(0x0),
196 fInt(0x0),
197 fUInt(0x0),
198 fFloat(0x0),
30ec5bf7 199 fStringArray(new TObjArray()),
200 fTimeStamp(timeStamp),
201 fDouble(0x0)
d96c6484 202{
203 //
204 // constructor for String
205 //
206
30ec5bf7 207 fStringArray->SetOwner(1);
d96c6484 208 for (Int_t i = 0; i<fnentries; i++){
30ec5bf7 209 TObjString* strobj = new TObjString();
210 strobj->SetString(((TObjString*)value->At(i))->String());
211 fStringArray->Add(strobj);
d96c6484 212 }
213}
214
215//-----------------------------------------------------------------------
216AliDCSArray::AliDCSArray(const AliDCSArray& c) :
217 TObject(c),
218 fType(c.fType),
219 fnentries(c.fnentries),
220 fBool(0x0),
221 fChar(0x0),
222 fInt(0x0),
223 fUInt(0x0),
224 fFloat(0x0),
30ec5bf7 225 fStringArray(0x0),
226 fTimeStamp(c.fTimeStamp),
227 fDouble(0x0)
d96c6484 228{
229 //
230 // copy constructor
231 //
232
233 if (fType == kBool && c.fBool){
234 fBool = new Bool_t[fnentries];
235 memcpy(fBool,c.fBool,fnentries*sizeof(Bool_t));
236 }
237 if (fType == kChar && c.fChar){
238 fChar = new Char_t[fnentries];
239 memcpy(fChar,c.fChar,fnentries*sizeof(Char_t));
240 }
241 if (fType == kUInt && c.fUInt){
242 fUInt = new UInt_t[fnentries];
243 memcpy(fUInt,c.fUInt,fnentries*sizeof(UInt_t));
244 }
245 if (fType == kInt && c.fInt){
246 fInt = new Int_t[fnentries];
247 memcpy(fInt,c.fInt,fnentries*sizeof(Int_t));
248 }
249 if (fType == kFloat && c.fFloat){
250 fFloat = new Float_t[fnentries];
251 memcpy(fFloat,c.fFloat,fnentries*sizeof(Float_t));
252 }
30ec5bf7 253 if (fType == kDouble && c.fDouble){
254 fDouble = new Double_t[fnentries];
255 memcpy(fDouble,c.fDouble,fnentries*sizeof(Double_t));
d96c6484 256 }
30ec5bf7 257 if (fType == kString && c.fStringArray){
258 fStringArray = new TObjArray();
259 fStringArray->SetOwner(1);
260 for (Int_t i = 0; i<fnentries; i++){
261 TObjString* strobj = new TObjString(*(TObjString*)(c.fStringArray->At(i)));
262 fStringArray->Add(strobj);
263 }
264 }
d96c6484 265
266}
267
268//-----------------------------------------------------------------------
269AliDCSArray::~AliDCSArray()
270{
271 //
272 // destructor
273 //
274
275 if (fBool){
e541e2aa 276 delete [] fBool;
30ec5bf7 277 fBool = 0x0;
d96c6484 278 }
279 if (fChar){
e541e2aa 280 delete [] fChar;
30ec5bf7 281 fChar = 0x0;
d96c6484 282 }
283 if (fUInt){
e541e2aa 284 delete [] fUInt;
30ec5bf7 285 fUInt = 0x0;
d96c6484 286 }
287 if (fInt){
e541e2aa 288 delete [] fInt;
30ec5bf7 289 fInt = 0x0;
d96c6484 290 }
291 if (fFloat){
e541e2aa 292 delete [] fFloat;
30ec5bf7 293 fFloat = 0x0;
d96c6484 294 }
30ec5bf7 295 if (fStringArray!=0x0){
30ec5bf7 296 delete fStringArray;
297 fStringArray = 0x0;
d96c6484 298 }
30ec5bf7 299 if (fDouble){
e541e2aa 300 delete [] fDouble;
30ec5bf7 301 fDouble = 0x0;
d96c6484 302 }
303}
304
305//-----------------------------------------------------------------------
306AliDCSArray &AliDCSArray::operator=(const AliDCSArray &c)
307{
308 //
309 // operator =
310 //
311
312 if(&c == this) return *this;
313 if (fType == kBool && c.fBool){
314 fBool = new Bool_t[fnentries];
315 memcpy(fBool,c.fBool,fnentries*sizeof(Bool_t));
316 }
317 if (fType == kChar && c.fChar){
318 fChar = new Char_t[fnentries];
319 memcpy(fChar,c.fChar,fnentries*sizeof(Char_t));
320 }
321 if (fType == kUInt && c.fUInt){
322 fUInt = new UInt_t[fnentries];
323 memcpy(fUInt,c.fUInt,fnentries*sizeof(UInt_t));
324 }
325 if (fType == kInt && c.fInt){
326 fInt = new Int_t[fnentries];
327 memcpy(fInt,c.fInt,fnentries*sizeof(Int_t));
328 }
329 if (fType == kFloat && c.fFloat){
330 fFloat = new Float_t[fnentries];
331 memcpy(fFloat,c.fFloat,fnentries*sizeof(Float_t));
332 }
30ec5bf7 333 if (fType == kDouble && c.fDouble){
334 fDouble = new Double_t[fnentries];
335 memcpy(fDouble,c.fDouble,fnentries*sizeof(Double_t));
d96c6484 336 }
30ec5bf7 337 if (fType == kString && c.fStringArray){
338 fStringArray = new TObjArray();
339 fStringArray->SetOwner(1);
340 for (Int_t i = 0; i<fnentries; i++){
341 TObjString* strobj = new TObjString(*(TObjString*)(c.fStringArray->At(i)));
342 fStringArray->Add(strobj);
343 }
344 }
345
d96c6484 346 return *this;
347}
348
349//-----------------------------------------------------------------------
350void AliDCSArray::Init()
351{
352 //
353 // init helper, that initializes everything to 0
354 //
355
356 fType = kInvalid;
357
358 fnentries = 0;
359 fBool = 0x0;
360 fChar = 0x0;
361 fInt = 0x0;
362 fUInt = 0x0;
363 fFloat = 0x0;
30ec5bf7 364 fDouble = 0x0;
365 fStringArray = 0x0;
d96c6484 366
30ec5bf7 367 fTimeStamp = -1.;
d96c6484 368}
30ec5bf7 369