]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliDCSValue.cxx
Update of material budget and positions
[u/mrichter/AliRoot.git] / STEER / AliDCSValue.cxx
CommitLineData
57459306 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$Log$
45a493ce 18Revision 1.1 2006/06/02 14:14:36 hristov
19Separate library for CDB (Jan)
20
57459306 21Revision 1.2 2006/03/07 07:52:34 hristov
22New version (B.Yordanov)
23
24Revision 1.2 2005/11/17 14:43:23 byordano
25import to local CVS
26
27Revision 1.1.1.1 2005/10/28 07:33:58 hristov
28Initial import as subdirectory in AliRoot
29
30Revision 1.1.1.1 2005/09/12 22:11:40 byordano
31SHUTTLE package
32
33Revision 1.2 2005/08/30 10:53:23 byordano
34some more descriptions added
35
36*/
37
38//
45a493ce 39// This class represents the value(s) of
40// a DCS data point at a given timestamp.
41// It stores different data types, the current implementation has a member for all of them.
42// This is definitly not efficient, but the only way to use the automatic streamers generated by ROOT.
43//
57459306 44// Each element of this value series has two fields:
45// fValue - primitive value which represents the real measured value
46// fTimestamp - timestamp when the measurement was made
47//
48
49#include "AliDCSValue.h"
50
51#include "TTimeStamp.h"
45a493ce 52#include <TString.h>
57459306 53
54ClassImp(AliDCSValue)
55
45a493ce 56AliDCSValue::AliDCSValue() : TObject()
57{
58 // default constructor
59
60 Init();
61}
62
63AliDCSValue::AliDCSValue(Bool_t value, UInt_t timeStamp) : TObject()
64{
65 // constructor
66
67 Init();
68
69 fTimeStamp = timeStamp;
70
71 fType = kBool;
72 fBool = value;
73}
74
75AliDCSValue::AliDCSValue(Char_t value, UInt_t timeStamp) : TObject()
76{
77 // constructor
78
79 Init();
80
81 fTimeStamp = timeStamp;
82
83 fType = kChar;
84 fChar = value;
85}
86
87AliDCSValue::AliDCSValue(Int_t value, UInt_t timeStamp) : TObject()
88{
89 // constructor
90
91 Init();
92
93 fTimeStamp = timeStamp;
94
95 fType = kInt;
96 fInt = value;
97}
98
99AliDCSValue::AliDCSValue(UInt_t value, UInt_t timeStamp) : TObject()
100{
101 // constructor
102
103 Init();
104
105 fTimeStamp = timeStamp;
106
107 fType = kUInt;
108 fUInt = value;
109}
110
111AliDCSValue::AliDCSValue(Float_t value, UInt_t timeStamp) : TObject()
112{
113 // constructor
114
115 Init();
116
117 fTimeStamp = timeStamp;
118
119 fType = kFloat;
120 fFloat = value;
121}
122
123AliDCSValue::AliDCSValue(Int_t size, Bool_t* vals, UInt_t timeStamp) : TObject()
124{
125 // constructor
126
127 Init();
128
129 fTimeStamp = timeStamp;
130
131 fType = kDynBool;
132 fBoolPtr = vals;
133 fLength = size;
134}
135
136AliDCSValue::AliDCSValue(Int_t size, Char_t* vals, UInt_t timeStamp) : TObject()
137{
138 // constructor
139
140 Init();
141
142 fTimeStamp = timeStamp;
143
144 fType = kDynChar;
145 fCharPtr = vals;
146 fLength = size;
147}
148
149AliDCSValue::AliDCSValue(Int_t size, Int_t* vals, UInt_t timeStamp) : TObject()
150{
151 // constructor
152
153 Init();
154
155 fTimeStamp = timeStamp;
156
157 fType = kDynInt;
158 fIntPtr = vals;
159 fLength = size;
160}
161
162AliDCSValue::AliDCSValue(Int_t size, UInt_t* vals, UInt_t timeStamp) : TObject()
163{
164 // constructor
165
166 Init();
167
168 fTimeStamp = timeStamp;
169
170 fType = kDynUInt;
171 fUIntPtr = vals;
172 fLength = size;
173}
174
175AliDCSValue::AliDCSValue(Int_t size, Float_t* vals, UInt_t timeStamp) : TObject()
176{
177 // constructor
178
179 Init();
180
181 fTimeStamp = timeStamp;
182
183 fType = kDynFloat;
184 fFloatPtr = vals;
185 fLength = size;
186}
187
188AliDCSValue::AliDCSValue(const AliDCSValue& c) : TObject(c)
189{
190 // copy constructor
191
192 ((AliDCSValue &)c).Copy(*this);
193}
194
195void AliDCSValue::Init()
196{
197 // init helper, that initializes everything to 0
198
199 fType = kInvalid;
200
201 fBool = kFALSE;
202 fChar = 0;
203 fInt = 0;
204 fUInt = 0;
205 fFloat = 0;
206
207 fLength = 0;
208
209 fBoolPtr = 0;
210 fCharPtr = 0;
211 fIntPtr = 0;
212 fUIntPtr = 0;
213 fFloatPtr = 0;
214
215 fTimeStamp = 0;
216}
217
218AliDCSValue::~AliDCSValue()
219{
220 // destructor
221
222 if (fBoolPtr)
223 {
224 delete[] fBoolPtr;
225 fBoolPtr = 0;
226 }
227
228 if (fCharPtr)
229 {
230 delete[] fCharPtr;
231 fCharPtr = 0;
232 }
57459306 233
45a493ce 234 if (fIntPtr)
235 {
236 delete[] fIntPtr;
237 fIntPtr = 0;
238 }
239
240 if (fUIntPtr)
241 {
242 delete[] fUIntPtr;
243 fUIntPtr = 0;
244 }
245
246 if (fFloatPtr)
247 {
248 delete[] fFloatPtr;
249 fFloatPtr = 0;
250 }
57459306 251}
252
45a493ce 253AliDCSValue &AliDCSValue::operator=(const AliDCSValue &c)
57459306 254{
45a493ce 255 // assigment operator
57459306 256
45a493ce 257 if (this != &c)
258 ((AliDCSValue &) c).Copy(*this);
259
260 return *this;
57459306 261}
262
45a493ce 263void AliDCSValue::Copy(TObject& c) const
264{
265 // copy function
266
267 AliDCSValue& target = (AliDCSValue &) c;
268
269 target.Init();
270
271 target.fType = fType;
57459306 272
45a493ce 273 target.fBool = fBool;
274 target.fChar = fChar;
275 target.fInt = fInt;
276 target.fUInt = fUInt;
277 target.fFloat = fFloat;
57459306 278
45a493ce 279 target.fLength = fLength;
280
281 if (fLength > 0)
282 {
283 if (fBoolPtr)
284 {
285 target.fBoolPtr = new Bool_t[fLength];
286 for (UInt_t i=0; i<fLength; ++i)
287 target.fBoolPtr[i] = fBoolPtr[i];
288 }
289 if (fCharPtr)
290 {
291 target.fCharPtr = new Char_t[fLength];
292 for (UInt_t i=0; i<fLength; ++i)
293 target.fCharPtr[i] = fCharPtr[i];
294 }
295 if (fIntPtr)
296 {
297 target.fIntPtr = new Int_t[fLength];
298 for (UInt_t i=0; i<fLength; ++i)
299 target.fIntPtr[i] = fIntPtr[i];
300 }
301 if (fUIntPtr)
302 {
303 target.fUIntPtr = new UInt_t[fLength];
304 for (UInt_t i=0; i<fLength; ++i)
305 target.fUIntPtr[i] = fUIntPtr[i];
306 }
307 if (fFloatPtr)
308 {
309 target.fFloatPtr = new Float_t[fLength];
310 for (UInt_t i=0; i<fLength; ++i)
311 target.fFloatPtr[i] = fFloatPtr[i];
312 }
313 }
314
315 target.fTimeStamp = fTimeStamp;
57459306 316}
317
45a493ce 318Int_t AliDCSValue::GetSize() const
319{
320 // returns size in bytes of stored structure
321
322 Int_t size = sizeof(fTimeStamp);
323
324 switch (fType)
325 {
326 case kBool: size += sizeof(Bool_t); break;
327 case kChar: size += sizeof(Char_t); break;
328 case kInt: size += sizeof(Int_t); break;
329 case kUInt: size += sizeof(UInt_t); break;
330 case kFloat: size += sizeof(Float_t); break;
331
332 case kDynBool: size += fLength * sizeof(Bool_t); break;
333 case kDynChar: size += fLength * sizeof(Char_t); break;
334 case kDynInt: size += fLength * sizeof(Int_t); break;
335 case kDynUInt: size += fLength * sizeof(UInt_t); break;
336 case kDynFloat: size += fLength * sizeof(Float_t); break;
337
338 case kInvalid: break;
339 }
57459306 340
45a493ce 341 return size;
342}
343
344Bool_t AliDCSValue::IsDynamic(Type type)
345{
346 // return if the given type is dynamic
347
348 switch (type)
349 {
350 case kDynBool:
351 case kDynChar:
352 case kDynInt:
353 case kDynUInt:
354 case kDynFloat: return kTRUE; break;
355
356 default: return kFALSE; break;
357 }
358}
359
360const Char_t* AliDCSValue::ToString() const
361{
362 TString str;
363
364 switch (fType)
365 {
366 case kBool: str.Form("%d", fBool); break;
367 case kChar: str.Form("%d", fChar); break;
368 case kInt: str.Form("%d", fInt); break;
369 case kUInt: str.Form("%d", fUInt); break;
370 case kFloat: str.Form("%f", fFloat); break;
371
372 case kDynBool: for (UInt_t i=0; i<fLength; ++i) str += Form("%d ", fBoolPtr[i]); break;
373 case kDynChar: for (UInt_t i=0; i<fLength; ++i) str += Form("%d ", fCharPtr[i]); break;
374 case kDynInt: for (UInt_t i=0; i<fLength; ++i) str += Form("%d ", fIntPtr[i]); break;
375 case kDynUInt: for (UInt_t i=0; i<fLength; ++i) str += Form("%d ", fUIntPtr[i]); break;
376 case kDynFloat: for (UInt_t i=0; i<fLength; ++i) str += Form("%f ", fFloatPtr[i]); break;
377
378 case kInvalid: break;
379 }
380
381 return Form("%s Timestamp: %s", str.Data(), TTimeStamp(fTimeStamp).AsString());
382}