AliRoot Core  3dc7879 (3dc7879)
AliDCSValue.cxx
Go to the documentation of this file.
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$
18 Revision 1.4 2006/09/04 17:42:34 hristov
19 Changes required by Effective C++
20 
21 Revision 1.3 2006/07/20 09:43:46 jgrosseo
22 removing dynamic types
23 
24 Revision 1.2 2006/07/04 14:58:11 jgrosseo
25 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
26 
27 Revision 1.1 2006/06/02 14:14:36 hristov
28 Separate library for CDB (Jan)
29 
30 Revision 1.2 2006/03/07 07:52:34 hristov
31 New version (B.Yordanov)
32 
33 Revision 1.2 2005/11/17 14:43:23 byordano
34 import to local CVS
35 
36 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
37 Initial import as subdirectory in AliRoot
38 
39 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
40 SHUTTLE package
41 
42 Revision 1.2 2005/08/30 10:53:23 byordano
43 some more descriptions added
44 
45 */
46 
47 //
48 // This class represents the value(s) of
49 // a DCS data point at a given timestamp.
50 // It stores different data types, the current implementation has a member for all of them.
51 // This is definitly not efficient, but the only way to use the automatic streamers generated by ROOT.
52 //
53 // Each element of this value series has two fields:
54 // fValue - primitive value which represents the real measured value
55 // fTimestamp - timestamp when the measurement was made
56 //
57 
58 #include "AliDCSValue.h"
59 #include "AliLog.h"
60 
61 #include "TTimeStamp.h"
62 #include <TString.h>
63 
64 ClassImp(AliDCSValue)
65 
67  TObject(),
68  fType(kInvalid),
69  fBool(kFALSE),
70  fChar(0),
71  fInt(0),
72  fUInt(0),
73  fFloat(0),
74  fTimeStamp(0)
75 {
76  // default constructor
77 }
78 
79 AliDCSValue::AliDCSValue(Bool_t value, UInt_t timeStamp) :
80  TObject(),
81  fType(kBool),
82  fBool(value),
83  fChar(0),
84  fInt(0),
85  fUInt(0),
86  fFloat(0),
87  fTimeStamp(timeStamp)
88 {
89  // constructor
90 }
91 
92 AliDCSValue::AliDCSValue(Char_t value, UInt_t timeStamp) :
93  TObject(),
94  fType(kChar),
95  fBool(kFALSE),
96  fChar(value),
97  fInt(0),
98  fUInt(0),
99  fFloat(0),
100  fTimeStamp(timeStamp)
101 {
102  // constructor
103 }
104 
105 AliDCSValue::AliDCSValue(Int_t value, UInt_t timeStamp) :
106  TObject(),
107  fType(kInt),
108  fBool(kFALSE),
109  fChar(0),
110  fInt(value),
111  fUInt(0),
112  fFloat(0),
113  fTimeStamp(timeStamp)
114 {
115  // constructor
116 }
117 
118 AliDCSValue::AliDCSValue(UInt_t value, UInt_t timeStamp) :
119  TObject(),
120  fType(kUInt),
121  fBool(kFALSE),
122  fChar(0),
123  fInt(0),
124  fUInt(value),
125  fFloat(0),
126  fTimeStamp(timeStamp)
127 {
128  // constructor
129 }
130 
131 AliDCSValue::AliDCSValue(Float_t value, UInt_t timeStamp) :
132  TObject(),
133  fType(kFloat),
134  fBool(kFALSE),
135  fChar(0),
136  fInt(0),
137  fUInt(0),
138  fFloat(value),
139  fTimeStamp(timeStamp)
140 {
141  // constructor
142 
143  Init();
144 
145  fTimeStamp = timeStamp;
146 
147  fType = kFloat;
148  fFloat = value;
149 }
150 
152  TObject(c),
153  fType(c.fType),
154  fBool(c.fBool),
155  fChar(c.fChar),
156  fInt(c.fInt),
157  fUInt(c.fUInt),
158  fFloat(c.fFloat),
160 {
161  // copy constructor
162 }
163 
165 {
166  // init helper, that initializes everything to 0
167 
168  fType = kInvalid;
169 
170  fBool = kFALSE;
171  fChar = 0;
172  fInt = 0;
173  fUInt = 0;
174  fFloat = 0;
175 
176  fTimeStamp = 0;
177 }
178 
180 {
181  // destructor
182 }
183 
185 {
186  // assigment operator
187 
188  if (this != &c)
189  ((AliDCSValue &) c).Copy(*this);
190 
191  return *this;
192 }
193 
194 void AliDCSValue::Copy(TObject& c) const
195 {
196  // copy function
197 
198  AliDCSValue& target = (AliDCSValue &) c;
199 
200  target.Init();
201 
202  target.fType = fType;
203 
204  target.fBool = fBool;
205  target.fChar = fChar;
206  target.fInt = fInt;
207  target.fUInt = fUInt;
208  target.fFloat = fFloat;
209 
210  target.fTimeStamp = fTimeStamp;
211 }
212 
213 Int_t AliDCSValue::GetSize() const
214 {
215  // returns size in bytes of stored structure
216 
217  Int_t size = sizeof(fTimeStamp);
218 
219  switch (fType)
220  {
221  case kBool: size += sizeof(Bool_t); break;
222  case kChar: size += sizeof(Char_t); break;
223  case kInt: size += sizeof(Int_t); break;
224  case kUInt: size += sizeof(UInt_t); break;
225  case kFloat: size += sizeof(Float_t); break;
226 
227  case kInvalid: break;
228  }
229 
230  return size;
231 }
232 
233 const Char_t* AliDCSValue::ToString() const
234 {
235  TString str;
236 
237  switch (fType)
238  {
239  case kBool: str = (fBool == kFALSE) ? "FALSE" : "TRUE"; break;
240  case kChar: str.Form("%d", fChar); break;
241  case kInt: str.Form("%d", fInt); break;
242  case kUInt: str.Form("%d", fUInt); break;
243  case kFloat: str.Form("%f", fFloat); break;
244 
245  case kInvalid: break;
246  }
247 
248  return Form("%s Timestamp: %s (%d)", str.Data(), TTimeStamp(fTimeStamp).AsString(), fTimeStamp);
249 }
250 
251 void AliDCSValue::Print(Option_t* /*opt*/) const
252 {
253  printf("%s\n", ToString());
254 }
255 
256 Bool_t AliDCSValue::GetBool() const
257 {
258  // return bool value
259  if (fType!=kBool) AliError(Form("invalid request, object is not of type kBool (%d) but %d", kBool, fType));
260  return fBool;
261 }
262 
263 Char_t AliDCSValue::GetChar() const
264 {
265  // return char value
266  if (fType!=kChar) AliError(Form("invalid request, object is not of type kChar (%d) but %d", kChar, fType));
267  return fChar;
268 }
269 
270 Int_t AliDCSValue::GetInt() const
271 {
272  // return int value
273  if (fType!=kInt) AliError(Form("invalid request, object is not of type kInt (%d) but %d", kInt, fType));
274  return fInt;
275 }
276 
277 UInt_t AliDCSValue::GetUInt() const
278 {
279  // return uint value
280  if (fType!=kUInt) AliError(Form("invalid request, object is not of type kUInt (%d) but %d", kUInt, fType));
281  return fUInt;
282 }
283 
284 Float_t AliDCSValue::GetFloat() const
285 {
286  // return float value
287  if (fType!=kFloat) AliError(Form("invalid request, object is not of type kFloat (%d) but %d", kFloat, fType));
288  return fFloat;
289 }
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
Int_t fInt
Definition: AliDCSValue.h:84
virtual void Copy(TObject &c) const
UInt_t fTimeStamp
Definition: AliDCSValue.h:88
UInt_t GetUInt() const
Float_t GetFloat() const
Float_t fFloat
Definition: AliDCSValue.h:86
AliDCSValue & operator=(const AliDCSValue &c)
Bool_t fBool
Definition: AliDCSValue.h:82
const Char_t * ToString() const
Int_t GetSize() const
UInt_t fUInt
Definition: AliDCSValue.h:85
Char_t GetChar() const
Bool_t GetBool() const
Int_t GetInt() const
#define AliError(message)
Definition: AliLog.h:591
Char_t fChar
Definition: AliDCSValue.h:83
void Print(Option_t *) const
virtual ~AliDCSValue()