Line data Source code
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 128 : ClassImp(AliDCSValue)
65 :
66 : AliDCSValue::AliDCSValue() :
67 7484 : TObject(),
68 7484 : fType(kInvalid),
69 7484 : fBool(kFALSE),
70 7484 : fChar(0),
71 7484 : fInt(0),
72 7484 : fUInt(0),
73 7484 : fFloat(0),
74 7484 : fTimeStamp(0)
75 37420 : {
76 : // default constructor
77 14968 : }
78 :
79 : AliDCSValue::AliDCSValue(Bool_t value, UInt_t timeStamp) :
80 0 : TObject(),
81 0 : fType(kBool),
82 0 : fBool(value),
83 0 : fChar(0),
84 0 : fInt(0),
85 0 : fUInt(0),
86 0 : fFloat(0),
87 0 : fTimeStamp(timeStamp)
88 0 : {
89 : // constructor
90 0 : }
91 :
92 : AliDCSValue::AliDCSValue(Char_t value, UInt_t timeStamp) :
93 0 : TObject(),
94 0 : fType(kChar),
95 0 : fBool(kFALSE),
96 0 : fChar(value),
97 0 : fInt(0),
98 0 : fUInt(0),
99 0 : fFloat(0),
100 0 : fTimeStamp(timeStamp)
101 0 : {
102 : // constructor
103 0 : }
104 :
105 : AliDCSValue::AliDCSValue(Int_t value, UInt_t timeStamp) :
106 0 : TObject(),
107 0 : fType(kInt),
108 0 : fBool(kFALSE),
109 0 : fChar(0),
110 0 : fInt(value),
111 0 : fUInt(0),
112 0 : fFloat(0),
113 0 : fTimeStamp(timeStamp)
114 0 : {
115 : // constructor
116 0 : }
117 :
118 : AliDCSValue::AliDCSValue(UInt_t value, UInt_t timeStamp) :
119 0 : TObject(),
120 0 : fType(kUInt),
121 0 : fBool(kFALSE),
122 0 : fChar(0),
123 0 : fInt(0),
124 0 : fUInt(value),
125 0 : fFloat(0),
126 0 : fTimeStamp(timeStamp)
127 0 : {
128 : // constructor
129 0 : }
130 :
131 : AliDCSValue::AliDCSValue(Float_t value, UInt_t timeStamp) :
132 376 : TObject(),
133 376 : fType(kFloat),
134 376 : fBool(kFALSE),
135 376 : fChar(0),
136 376 : fInt(0),
137 376 : fUInt(0),
138 376 : fFloat(value),
139 376 : fTimeStamp(timeStamp)
140 1880 : {
141 : // constructor
142 :
143 376 : Init();
144 :
145 376 : fTimeStamp = timeStamp;
146 :
147 376 : fType = kFloat;
148 376 : fFloat = value;
149 752 : }
150 :
151 : AliDCSValue::AliDCSValue(const AliDCSValue& c) :
152 0 : TObject(c),
153 0 : fType(c.fType),
154 0 : fBool(c.fBool),
155 0 : fChar(c.fChar),
156 0 : fInt(c.fInt),
157 0 : fUInt(c.fUInt),
158 0 : fFloat(c.fFloat),
159 0 : fTimeStamp(c.fTimeStamp)
160 0 : {
161 : // copy constructor
162 0 : }
163 :
164 : void AliDCSValue::Init()
165 : {
166 : // init helper, that initializes everything to 0
167 :
168 752 : fType = kInvalid;
169 :
170 376 : fBool = kFALSE;
171 376 : fChar = 0;
172 376 : fInt = 0;
173 376 : fUInt = 0;
174 376 : fFloat = 0;
175 :
176 376 : fTimeStamp = 0;
177 376 : }
178 :
179 : AliDCSValue::~AliDCSValue()
180 12032 : {
181 : // destructor
182 12032 : }
183 :
184 : AliDCSValue &AliDCSValue::operator=(const AliDCSValue &c)
185 : {
186 : // assigment operator
187 :
188 0 : if (this != &c)
189 0 : ((AliDCSValue &) c).Copy(*this);
190 :
191 0 : return *this;
192 : }
193 :
194 : void AliDCSValue::Copy(TObject& c) const
195 : {
196 : // copy function
197 :
198 0 : AliDCSValue& target = (AliDCSValue &) c;
199 :
200 0 : target.Init();
201 :
202 0 : target.fType = fType;
203 :
204 0 : target.fBool = fBool;
205 0 : target.fChar = fChar;
206 0 : target.fInt = fInt;
207 0 : target.fUInt = fUInt;
208 0 : target.fFloat = fFloat;
209 :
210 0 : target.fTimeStamp = fTimeStamp;
211 0 : }
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 0 : switch (fType)
220 : {
221 0 : case kBool: size += sizeof(Bool_t); break;
222 0 : case kChar: size += sizeof(Char_t); break;
223 0 : case kInt: size += sizeof(Int_t); break;
224 0 : case kUInt: size += sizeof(UInt_t); break;
225 0 : case kFloat: size += sizeof(Float_t); break;
226 :
227 : case kInvalid: break;
228 : }
229 :
230 0 : return size;
231 : }
232 :
233 : const Char_t* AliDCSValue::ToString() const
234 : {
235 0 : TString str;
236 :
237 0 : switch (fType)
238 : {
239 0 : case kBool: str = (fBool == kFALSE) ? "FALSE" : "TRUE"; break;
240 0 : case kChar: str.Form("%d", fChar); break;
241 0 : case kInt: str.Form("%d", fInt); break;
242 0 : case kUInt: str.Form("%d", fUInt); break;
243 0 : case kFloat: str.Form("%f", fFloat); break;
244 :
245 : case kInvalid: break;
246 : }
247 :
248 0 : return Form("%s Timestamp: %s (%d)", str.Data(), TTimeStamp(fTimeStamp).AsString(), fTimeStamp);
249 0 : }
250 :
251 : void AliDCSValue::Print(Option_t* /*opt*/) const
252 : {
253 0 : printf("%s\n", ToString());
254 0 : }
255 :
256 : Bool_t AliDCSValue::GetBool() const
257 : {
258 : // return bool value
259 7200 : if (fType!=kBool) AliError(Form("invalid request, object is not of type kBool (%d) but %d", kBool, fType));
260 3600 : return fBool;
261 : }
262 :
263 : Char_t AliDCSValue::GetChar() const
264 : {
265 : // return char value
266 0 : if (fType!=kChar) AliError(Form("invalid request, object is not of type kChar (%d) but %d", kChar, fType));
267 0 : return fChar;
268 : }
269 :
270 : Int_t AliDCSValue::GetInt() const
271 : {
272 : // return int value
273 0 : if (fType!=kInt) AliError(Form("invalid request, object is not of type kInt (%d) but %d", kInt, fType));
274 0 : return fInt;
275 : }
276 :
277 : UInt_t AliDCSValue::GetUInt() const
278 : {
279 : // return uint value
280 0 : if (fType!=kUInt) AliError(Form("invalid request, object is not of type kUInt (%d) but %d", kUInt, fType));
281 0 : return fUInt;
282 : }
283 :
284 : Float_t AliDCSValue::GetFloat() const
285 : {
286 : // return float value
287 13208 : if (fType!=kFloat) AliError(Form("invalid request, object is not of type kFloat (%d) but %d", kFloat, fType));
288 6604 : return fFloat;
289 : }
|