Adding a reminder for coders
[u/mrichter/AliRoot.git] / TOF / AliTOFDataDCS.cxx
CommitLineData
345932e4 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/*
7fffa85b 17$Log: AliTOFDataDCS.cxx,v $
18Revision 1.9 2007/05/04 14:02:45 decaro
19AliTOFDataDCS::Draw(Option_t *) method declared const: compiling warning suppression
20
b52b97c2 21Revision 1.8 2007/05/03 09:45:09 decaro
22Coding convention: RN11 violation -> suppression
23
9d5fd6fe 24Revision 1.7 2007/05/02 14:09:39 arcelli
25Retrieval of Env. Temperature removed (will get it from the GRP)
26
38e3bbf1 27Revision 1.6 2007/04/04 17:19:19 arcelli
28Moved some printout to debug level
29
72bf252d 30Revision 1.5 2007/02/20 15:57:00 decaro
31Raw data update: to read the TOF raw data defined in UNPACKED mode
32
15ec34b9 33Revision 1.4 2007/02/19 15:41:55 decaro
34Coding convention: few corrections
35
3a3ece53 36Revision 1.3 2007/01/24 11:19:58 arcelli
37Modify ProcessData to return a logical (CZ)
38
ebab534a 39Revision 1.2 2006/12/18 18:17:38 arcelli
40Updated Aliases for DCS TOF datapoints (C.Zampolli)
41
8259e6f8 42Revision 1.1 2006/10/26 09:10:52 arcelli
43Class for handling the TOF DCS data in the Shuttle (C.Zampolli)
44
345932e4 45*/
46
051a7fe6 47// AliTOFDataDCS class
48// main aim to introduce the aliases for the TOF DCS
49// data points to be then
50// stored in the OCDB, and to process them.
51// Process() method called by TOFPrepr
52
5c7c93fa 53#include "TString.h"
5c7c93fa 54#include "TTimeStamp.h"
55#include "TMap.h"
56#include "TCanvas.h"
345932e4 57
58#include "AliDCSValue.h"
59#include "AliLog.h"
60
5c7c93fa 61#include "AliTOFDataDCS.h"
345932e4 62#include "AliTOFFormatDCS.h"
345932e4 63
64class TH2;
65class AliCDBMetaData;
66class TDatime;
67
345932e4 68ClassImp(AliTOFDataDCS)
69
70//---------------------------------------------------------------
71AliTOFDataDCS::AliTOFDataDCS():
72 TObject(),
73 fRun(0),
74 fStartTime(0),
75 fEndTime(0),
ff326f84 76 fStartTimeDCSQuery(0),
77 fEndTimeDCSQuery(0),
7fffa85b 78 fIsProcessed(kFALSE),
79 fFDR(kFALSE)
345932e4 80{
81
82 // main constructor
83
8259e6f8 84 for(int i=0;i<kNHV;i++) {
85 fHVvp[i]=0x0;
86 fHVvn[i]=0x0;
87 fHVip[i]=0x0;
88 fHVin[i]=0x0;
89 }
d202b31a 90
8259e6f8 91
345932e4 92}
93
94//---------------------------------------------------------------
ff326f84 95AliTOFDataDCS::AliTOFDataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime, UInt_t startTimeDCSQuery, UInt_t endTimeDCSQuery):
345932e4 96 TObject(),
97 fRun(nRun),
98 fStartTime(startTime),
99 fEndTime(endTime),
ff326f84 100 fStartTimeDCSQuery(startTimeDCSQuery),
101 fEndTimeDCSQuery(endTimeDCSQuery),
7fffa85b 102 fIsProcessed(kFALSE),
103 fFDR(kFALSE)
345932e4 104{
105
106 // constructor with arguments
107
ff326f84 108 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", nRun,
345932e4 109 TTimeStamp(startTime).AsString(),
ff326f84 110 TTimeStamp(endTime).AsString(),
111 TTimeStamp(startTimeDCSQuery).AsString(),
112 TTimeStamp(endTimeDCSQuery).AsString()));
345932e4 113
114 Init();
115
116}
117
118//---------------------------------------------------------------
119
120AliTOFDataDCS::AliTOFDataDCS(const AliTOFDataDCS & data):
8a190ba2 121 TObject(data),
122 fRun(data.fRun),
123 fStartTime(data.fStartTime),
124 fEndTime(data.fEndTime),
125 fStartTimeDCSQuery(data.fStartTimeDCSQuery),
126 fEndTimeDCSQuery(data.fEndTimeDCSQuery),
127 fIsProcessed(data.fIsProcessed),
128 fFDR(data.fFDR)
345932e4 129
130{
131
051a7fe6 132 // copy constructor
345932e4 133
345932e4 134 for(int i=0;i<kNAliases;i++) {
135 fAliasNames[i]=data.fAliasNames[i];
136 }
137
138 for(int i=0;i<kNHV;i++) {
8259e6f8 139 fHVvp[i]=data.fHVvp[i];
140 fHVvn[i]=data.fHVvn[i];
141 fHVip[i]=data.fHVip[i];
142 fHVin[i]=data.fHVin[i];
345932e4 143 }
144
38e3bbf1 145
345932e4 146}
147//---------------------------------------------------------------
148
149AliTOFDataDCS& AliTOFDataDCS:: operator=(const AliTOFDataDCS & data) {
150
051a7fe6 151 // assignment operator
345932e4 152
8a190ba2 153 if (this == &data)
154 return *this;
155
156 TObject::operator=(data);
157 fRun=data.GetRun();
158 fStartTime=data.GetStartTime();
159 fEndTime=data.GetEndTime();
160 fStartTimeDCSQuery=data.GetStartTimeDCSQuery();
161 fEndTimeDCSQuery=data.GetEndTimeDCSQuery();
345932e4 162
163 for(int i=0;i<kNAliases;i++) {
8a190ba2 164 fAliasNames[i]=data.GetAliasName(i);
345932e4 165 }
166
345932e4 167 for(int i=0;i<kNHV;i++) {
8a190ba2 168 fHVvp[i]=data.GetHVvp(i);
169 fHVvn[i]=data.GetHVvn(i);
170 fHVip[i]=data.GetHVip(i);
171 fHVin[i]=data.GetHVin(i);
345932e4 172 }
173
345932e4 174
175 return *this;
176}
177//---------------------------------------------------------------
178AliTOFDataDCS::~AliTOFDataDCS() {
179
180 // destructor
181
8259e6f8 182 for(int i=0;i<kNHV;i++) {
183 delete fHVvp[i];
184 fHVvp[i]=0;
185 delete fHVvn[i];
186 fHVvn[i]=0;
187 delete fHVip[i];
188 fHVip[i]=0;
189 delete fHVin[i];
190 fHVin[i]=0;
191 }
192
345932e4 193}
194
345932e4 195//---------------------------------------------------------------
ebab534a 196Bool_t AliTOFDataDCS::ProcessData(TMap& aliasMap){
345932e4 197
3a3ece53 198 // method to process the data
199
345932e4 200 if(!(fAliasNames[0])) Init();
201
345932e4 202 Float_t val=0;
5f2d4eea 203 Float_t val0=0;
345932e4 204 Float_t val1=0;
205 Float_t time=0;
5f2d4eea 206 Float_t time0=0;
207 Float_t time1=0;
345932e4 208 Float_t delta[2];
209 Float_t timedelta[2];
210
e83a0dd0 211 AliInfo(Form(" Start Time = %i",fStartTime));
212 AliInfo(Form(" End Time = %i",fEndTime));
ff326f84 213 AliInfo(Form(" Start Time DCS Query= %i",fStartTimeDCSQuery));
214 AliInfo(Form(" End Time DCS Query= %i",fEndTimeDCSQuery));
e83a0dd0 215
216 if (fEndTime==fStartTime){
217 AliError(Form(" Run with null time length: start time = %i = end time = %i",fStartTime,fEndTime));
218 return kFALSE;
96fec15b 219 }
220
345932e4 221 TObjArray *aliasArr;
222 AliDCSValue* aValue;
5f2d4eea 223 AliDCSValue* aValue0;
345932e4 224 AliDCSValue* aValue1;
345932e4 225
226 // starting loop on aliases
227 for(int j=0; j<kNAliases; j++){
228 for (Int_t k=0;k<2;k++) {
229 delta[k]=0;
230 timedelta[k]=0;
231 }
232 //AliInfo(Form("j = %i, with alias = %s",j,fAliasNames[j].Data()));
233 aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNames[j].Data());
234 if(!aliasArr){
235 AliError(Form("Alias %s not found!", fAliasNames[j].Data()));
7fffa85b 236 if (!fFDR){
237 return kFALSE; // returning only in case we are not in a FDR run
238 }
239 else {
240 continue;
241 }
345932e4 242 }
243
244 Introduce(j, aliasArr);
245
5f2d4eea 246 if(aliasArr->GetEntries()==0){
247 AliError(Form("Alias %s has no entries! Nothing will be stored",
248 fAliasNames[j].Data()));
249 continue;
250 }
251 if(aliasArr->GetEntries() == 1){
252 AliWarning(Form("Alias %s has just %d entries! Only first value will be stored",
345932e4 253 fAliasNames[j].Data(),aliasArr->GetEntries()));
5f2d4eea 254 aValue0 = (AliDCSValue*) aliasArr->At(0);
255 val0 = aValue0->GetFloat();
256 time0 = (Float_t) (aValue0->GetTimeStamp());
257 if (j<kNHV){
258 fHVvp[j]->SetFloat(0,val0);
259 fHVvp[j]->SetTimeStampFloat(0,time0);
260 }
261 else if (j<kNHV*2){
262 fHVvn[j-kNHV]->SetFloat(0,val0);
263 fHVvn[j-kNHV]->SetTimeStampFloat(0,time0);
264 }
265 else if (j<kNHV*3){
266 fHVip[j-2*kNHV]->SetFloat(0,val0);
267 fHVip[j-2*kNHV]->SetTimeStampFloat(0,time0);
268 }
269 else if (j<kNHV*4){
270 fHVin[j-3*kNHV]->SetFloat(0,val0);
271 fHVin[j-3*kNHV]->SetTimeStampFloat(0,time0);
272 }
273 continue;
274 }
275 if(aliasArr->GetEntries()==2){
276 AliWarning(Form("Alias %s has just %d entries! Storing first and second entry only and the delta between these two",
277 fAliasNames[j].Data(),aliasArr->GetEntries()));
278 aValue0 = (AliDCSValue*) aliasArr->At(0);
279 val0 = aValue0->GetFloat();
280 time0 = (Float_t) (aValue0->GetTimeStamp());
281 aValue1 = (AliDCSValue*) aliasArr->At(1);
282 val1 = aValue1->GetFloat();
283 time1 = (Float_t) (aValue1->GetTimeStamp());
284 if (j<kNHV){
285 fHVvp[j]->SetFloat(0,val0);
286 fHVvp[j]->SetTimeStampFloat(0,time0);
287 fHVvp[j]->SetFloat(1,val1);
288 fHVvp[j]->SetTimeStampFloat(1,time1);
289 fHVvp[j]->SetDelta(0,TMath::Abs(val1-val0));
290 fHVvp[j]->SetTimeStampDelta(0,time1-time0);
291 }
292 else if (j<kNHV*2){
293 fHVvn[j-kNHV]->SetFloat(0,val0);
294 fHVvn[j-kNHV]->SetTimeStampFloat(0,time0);
295 fHVvn[j-kNHV]->SetFloat(1,val1);
296 fHVvn[j-kNHV]->SetTimeStampFloat(1,time1);
297 fHVvn[j-kNHV]->SetDelta(0,TMath::Abs(val1-val0));
298 fHVvn[j-kNHV]->SetTimeStampDelta(0,time1-time0);
299 }
300 else if (j<kNHV*3){
301 fHVip[j-2*kNHV]->SetFloat(0,val0);
302 fHVip[j-2*kNHV]->SetTimeStampFloat(0,time0);
303 fHVip[j-2*kNHV]->SetFloat(1,val1);
304 fHVip[j-2*kNHV]->SetTimeStampFloat(1,time1);
305 fHVip[j-2*kNHV]->SetDelta(0,TMath::Abs(val1-val0));
306 fHVip[j-2*kNHV]->SetTimeStampDelta(0,time1-time0);
307 }
308 else if (j<kNHV*4){
309 fHVin[j-3*kNHV]->SetFloat(0,val0);
310 fHVin[j-3*kNHV]->SetTimeStampFloat(0,time0);
311 fHVin[j-3*kNHV]->SetFloat(1,val1);
312 fHVin[j-3*kNHV]->SetTimeStampFloat(1,time1);
313 fHVin[j-3*kNHV]->SetDelta(0,TMath::Abs(val1-val0));
314 fHVin[j-3*kNHV]->SetTimeStampDelta(0,time1-time0);
315 }
345932e4 316 continue;
317 }
318
319 TIter iterarray(aliasArr);
320
321 Int_t nentries = aliasArr->GetEntries();
345932e4 322 Int_t deltaTimeStamp = (Int_t) nentries/3;
323 Int_t deltaTimeStamp1 = (Int_t) nentries/2;
345932e4 324
325 // filling aliases with 10 floats+1 Usign
38e3bbf1 326 Int_t index = 0;
327 for (Int_t k=0;k<3;k++){
328 index = deltaTimeStamp*k;
329 if (k==0) {
330 index=0;
345932e4 331 }
38e3bbf1 332 else if (k==1) {
333 index=deltaTimeStamp1;
334 }
335 else if (k==2) {
336 index=nentries-1;
345932e4 337 }
38e3bbf1 338 aValue = (AliDCSValue*) aliasArr->At(index);
339 val = aValue->GetFloat();
340 time = (Float_t) (aValue->GetTimeStamp());
341 if (j<kNHV){
342 fHVvp[j]->SetFloat(k,val);
343 fHVvp[j]->SetTimeStampFloat(k,time);
344 }
345 else if (j<kNHV*2){
346 fHVvn[j-kNHV]->SetFloat(k,val);
347 fHVvn[j-kNHV]->SetTimeStampFloat(k,time);
348 }
349 else if (j<kNHV*3){
350 fHVip[j-2*kNHV]->SetFloat(k,val);
351 fHVip[j-2*kNHV]->SetTimeStampFloat(k,time);
352 }
353 else if (j<kNHV*4){
354 fHVin[j-3*kNHV]->SetFloat(k,val);
355 fHVin[j-3*kNHV]->SetTimeStampFloat(k,time);
356 }
345932e4 357 }
38e3bbf1 358
345932e4 359 //computing the most significant variations
360
ff326f84 361 //Float_t timeDiff = (Float_t)(fEndTime-fStartTime);
362 Float_t timeDiff = (Float_t)(fEndTimeDCSQuery-fStartTimeDCSQuery);
e83a0dd0 363 Int_t deltamin = (Int_t)(60/timeDiff*nentries); //sampling every minute
345932e4 364 Int_t klast = nentries-deltamin;
38e3bbf1 365
345932e4 366 for (Int_t k=0;k<klast;k++){
367 aValue = (AliDCSValue*) aliasArr->At(k);
368 aValue1 = (AliDCSValue*) aliasArr->At(k+deltamin);
369 val = aValue->GetFloat();
370 val1 = aValue1->GetFloat();
371 if (delta[0]<=TMath::Abs(val1-val)) {
372 delta[0]=TMath::Abs(val1-val);
373 timedelta[0] = (Float_t)k;
374 }
375 if (delta[1]<=delta[0]) {
376 Float_t temp = delta[1];
377 Float_t timetemp = timedelta[1];
378 delta[1]=delta[0];
379 delta[0]=temp;
380 timedelta[1]=timedelta[0];
381 timedelta[0]=timetemp;
382 }
383 }
384
385 for (Int_t kk=0;kk<2;kk++){
38e3bbf1 386 if (j<kNHV){
387 fHVvp[j]->SetDelta(kk,delta[kk]);
388 fHVvp[j]->SetTimeStampDelta(kk,(Float_t)timedelta[kk]);
345932e4 389 }
38e3bbf1 390 else if (j<kNHV*2){
391 fHVvn[j-kNHV]->SetDelta(kk,delta[kk]);
392 fHVvn[j-kNHV]->SetTimeStampDelta(kk,(Float_t)timedelta[kk]);
393 }
394 else if (j<kNHV*3){
395 fHVip[j-2*kNHV]->SetDelta(kk,delta[kk]);
396 fHVip[j-2*kNHV]->SetTimeStampDelta(kk,(Float_t)timedelta[kk]);
397 }
398 else if (j<kNHV*4){
399 fHVin[j-3*kNHV]->SetDelta(kk,delta[kk]);
400 fHVin[j-3*kNHV]->SetTimeStampDelta(kk,(Float_t)timedelta[kk]);
401 }
8259e6f8 402 }
345932e4 403 }
38e3bbf1 404
345932e4 405 fIsProcessed=kTRUE;
406
ebab534a 407 return kTRUE;
345932e4 408}
409
410//---------------------------------------------------------------
411void AliTOFDataDCS::Init(){
412
413 // initialization of aliases and DCS data
414
8259e6f8 415 TString sindex;
345932e4 416 for(int i=0;i<kNAliases;i++){
8259e6f8 417 //HV, v
345932e4 418 if (i<kNHV){
8259e6f8 419 fAliasNames[i] = "tof_hv_vp_";
420 sindex.Form("%02i",i);
421 fAliasNames[i] += sindex;
422 fHVvp[i] = new AliTOFFormatDCS();
345932e4 423 }
424 else if (i<kNHV*2){
8259e6f8 425 fAliasNames[i] = "tof_hv_vn_";
426 sindex.Form("%02i",i-kNHV);
427 fAliasNames[i] += sindex;
428 fHVvn[i-kNHV] = new AliTOFFormatDCS();
345932e4 429 }
8259e6f8 430 //HV, i
345932e4 431 else if (i<kNHV*3){
8259e6f8 432 fAliasNames[i] = "tof_hv_ip_";
433 sindex.Form("%02i",i-2*kNHV);
434 fAliasNames[i] += sindex;
435 fHVip[i-2*kNHV] = new AliTOFFormatDCS();
345932e4 436 }
437 else if (i<kNHV*4){
8259e6f8 438 fAliasNames[i] = "tof_hv_in_";
439 sindex.Form("%02i",i-3*kNHV);
440 fAliasNames[i] += sindex;
441 fHVin[i-3*kNHV] = new AliTOFFormatDCS();
345932e4 442 }
345932e4 443 }
444}
445
446
447//---------------------------------------------------------------
448void AliTOFDataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr)const
449{
450
451 // method to introduce new aliases
452
453 int entries=0;
454 entries = aliasArr->GetEntries();
455 int nal=0;
456 nal=numAlias;
72bf252d 457 AliDebug(2,Form("************ Alias: %s **********",fAliasNames[numAlias].Data()));
458 AliDebug(2,Form(" %d DP values collected",entries));
345932e4 459
460}
461
462//---------------------------------------------------------------
b52b97c2 463void AliTOFDataDCS::Draw(const Option_t* /*option*/)
345932e4 464{
051a7fe6 465 // Draw all histos and graphs
345932e4 466
467 if(!fIsProcessed) return;
468
469 TCanvas *ch;
470 TString canvasHistoName="Histos";
471 ch=new TCanvas(canvasHistoName,canvasHistoName,20,20,600,600);
472 ch->cd();
473
474 // to be implemented
475
476}
477