]>
Commit | Line | Data |
---|---|---|
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$ | |
06b09194 | 18 | Revision 1.4 2006/09/04 17:42:34 hristov |
19 | Changes required by Effective C++ | |
20 | ||
fe12e09c | 21 | Revision 1.3 2006/07/20 09:43:46 jgrosseo |
22 | removing dynamic types | |
23 | ||
60d864bd | 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 | ||
45a493ce | 27 | Revision 1.1 2006/06/02 14:14:36 hristov |
28 | Separate library for CDB (Jan) | |
29 | ||
57459306 | 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 | // | |
45a493ce | 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 | // | |
57459306 | 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" | |
f2a58588 | 59 | #include "AliLog.h" |
57459306 | 60 | |
61 | #include "TTimeStamp.h" | |
45a493ce | 62 | #include <TString.h> |
57459306 | 63 | |
64 | ClassImp(AliDCSValue) | |
65 | ||
fe12e09c | 66 | AliDCSValue::AliDCSValue() : |
67 | TObject(), | |
68 | fType(kInvalid), | |
69 | fBool(kFALSE), | |
70 | fChar(0), | |
71 | fInt(0), | |
72 | fUInt(0), | |
73 | fFloat(0), | |
74 | fTimeStamp(0) | |
45a493ce | 75 | { |
76 | // default constructor | |
45a493ce | 77 | } |
78 | ||
fe12e09c | 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) | |
45a493ce | 88 | { |
89 | // constructor | |
45a493ce | 90 | } |
91 | ||
fe12e09c | 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) | |
45a493ce | 101 | { |
102 | // constructor | |
45a493ce | 103 | } |
104 | ||
fe12e09c | 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) | |
45a493ce | 114 | { |
115 | // constructor | |
45a493ce | 116 | } |
117 | ||
fe12e09c | 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) | |
45a493ce | 127 | { |
128 | // constructor | |
45a493ce | 129 | } |
130 | ||
fe12e09c | 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) | |
45a493ce | 140 | { |
141 | // constructor | |
142 | ||
143 | Init(); | |
144 | ||
145 | fTimeStamp = timeStamp; | |
146 | ||
147 | fType = kFloat; | |
148 | fFloat = value; | |
149 | } | |
150 | ||
fe12e09c | 151 | AliDCSValue::AliDCSValue(const AliDCSValue& c) : |
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), | |
159 | fTimeStamp(c.fTimeStamp) | |
45a493ce | 160 | { |
161 | // copy constructor | |
45a493ce | 162 | } |
163 | ||
164 | void AliDCSValue::Init() | |
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 | ||
45a493ce | 176 | fTimeStamp = 0; |
177 | } | |
178 | ||
179 | AliDCSValue::~AliDCSValue() | |
180 | { | |
181 | // destructor | |
57459306 | 182 | } |
183 | ||
45a493ce | 184 | AliDCSValue &AliDCSValue::operator=(const AliDCSValue &c) |
57459306 | 185 | { |
45a493ce | 186 | // assigment operator |
57459306 | 187 | |
45a493ce | 188 | if (this != &c) |
189 | ((AliDCSValue &) c).Copy(*this); | |
190 | ||
191 | return *this; | |
57459306 | 192 | } |
193 | ||
45a493ce | 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; | |
57459306 | 203 | |
45a493ce | 204 | target.fBool = fBool; |
205 | target.fChar = fChar; | |
206 | target.fInt = fInt; | |
207 | target.fUInt = fUInt; | |
208 | target.fFloat = fFloat; | |
57459306 | 209 | |
45a493ce | 210 | target.fTimeStamp = fTimeStamp; |
57459306 | 211 | } |
212 | ||
45a493ce | 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 | ||
45a493ce | 227 | case kInvalid: break; |
228 | } | |
57459306 | 229 | |
45a493ce | 230 | return size; |
231 | } | |
232 | ||
45a493ce | 233 | const Char_t* AliDCSValue::ToString() const |
234 | { | |
235 | TString str; | |
236 | ||
237 | switch (fType) | |
238 | { | |
06b09194 | 239 | case kBool: str = (fBool == kFALSE) ? "FALSE" : "TRUE"; break; |
45a493ce | 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 | ||
45a493ce | 245 | case kInvalid: break; |
246 | } | |
247 | ||
24f1f0cd | 248 | return Form("%s Timestamp: %s (%d)", str.Data(), TTimeStamp(fTimeStamp).AsString(), fTimeStamp); |
45a493ce | 249 | } |
06b09194 | 250 | |
251 | void AliDCSValue::Print(Option_t* /*opt*/) const | |
252 | { | |
253 | printf("%s\n", ToString()); | |
254 | } | |
f2a58588 | 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 | } |