Remove old raw reader class
[u/mrichter/AliRoot.git] / TOF / AliTOFLvHvDataPoints.cxx
CommitLineData
ea932f75 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: AliTOFLvHvDataPoints.cxx,v $
18*/
19
20// AliTOFLvHvDataPoints class
21// main aim to introduce the aliases for the TOF LV and HV DCS
22// data points to be then
23// stored in the OCDB, and to process them.
24// Process() method called by TOF preprocessor
25
26#include "TString.h"
27#include "TTimeStamp.h"
28#include "TMap.h"
29#include "TMath.h"
b7a60cff 30#include "TH1C.h"
ea932f75 31
32#include "AliDCSValue.h"
33#include "AliLog.h"
34#include "AliBitPacking.h"
35
ea932f75 36#include "AliTOFGeometry.h"
b7a60cff 37#include "AliTOFDCSmaps.h"
38#include "AliTOFLvHvDataPoints.h"
ea932f75 39
40class AliCDBMetaData;
41class TDatime;
42
43ClassImp(AliTOFLvHvDataPoints)
44
45//---------------------------------------------------------------
46AliTOFLvHvDataPoints::AliTOFLvHvDataPoints():
47 TObject(),
48 fRun(0),
49 fStartTime(0),
50 fEndTime(0),
51 fStartTimeDCSQuery(0),
52 fEndTimeDCSQuery(0),
53 fIsProcessed(kFALSE),
54 fFDR(kFALSE),
55 fNumberOfLVdataPoints(0),
56 fNumberOfHVdataPoints(0),
57 fNumberOfHVandLVmaps(0),
b7a60cff 58 fStartingLVmap(0x0),
59 fStartingHVmap(0x0),
38ef64f3 60 fHisto(0x0),
61 fNSecondsBeforeEOR(60)
ea932f75 62{
63 // main constructor
64
65}
66
67//---------------------------------------------------------------
68AliTOFLvHvDataPoints::AliTOFLvHvDataPoints(Int_t nRun, UInt_t startTime, UInt_t endTime, UInt_t startTimeDCSQuery, UInt_t endTimeDCSQuery):
69 TObject(),
70 fRun(nRun),
71 fStartTime(startTime),
72 fEndTime(endTime),
73 fStartTimeDCSQuery(startTimeDCSQuery),
74 fEndTimeDCSQuery(endTimeDCSQuery),
75 fIsProcessed(kFALSE),
76 fFDR(kFALSE),
77 fNumberOfLVdataPoints(0),
78 fNumberOfHVdataPoints(0),
79 fNumberOfHVandLVmaps(0),
b7a60cff 80 fStartingLVmap(new AliTOFDCSmaps()),
81 fStartingHVmap(new AliTOFDCSmaps()),
38ef64f3 82 fHisto(new TH1C("histo","",kNpads,-0.5,kNpads-0.5)),
83 fNSecondsBeforeEOR(60)
ea932f75 84{
85
86 // constructor with arguments
87
88 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", nRun,
89 TTimeStamp(startTime).AsString(),
90 TTimeStamp(endTime).AsString(),
91 TTimeStamp(startTimeDCSQuery).AsString(),
92 TTimeStamp(endTimeDCSQuery).AsString()));
93
94 Init();
95
96}
97
98//---------------------------------------------------------------
99
100AliTOFLvHvDataPoints::AliTOFLvHvDataPoints(const AliTOFLvHvDataPoints & data):
101 TObject(data),
102 fRun(data.fRun),
103 fStartTime(data.fStartTime),
104 fEndTime(data.fEndTime),
105 fStartTimeDCSQuery(data.fStartTimeDCSQuery),
106 fEndTimeDCSQuery(data.fEndTimeDCSQuery),
107 fIsProcessed(data.fIsProcessed),
108 fFDR(data.fFDR),
109 fNumberOfLVdataPoints(data.fNumberOfLVdataPoints),
110 fNumberOfHVdataPoints(data.fNumberOfHVdataPoints),
111 fNumberOfHVandLVmaps(data.fNumberOfHVandLVmaps),
b7a60cff 112 fStartingLVmap(data.fStartingLVmap),
113 fStartingHVmap(data.fStartingHVmap),
38ef64f3 114 fHisto(data.fHisto),
115 fNSecondsBeforeEOR(data.fNSecondsBeforeEOR)
ea932f75 116{
117
b7a60cff 118 // copy constructor
ea932f75 119
120 for(int i=0;i<kNddl;i++)
121 fAliasNamesXLVmap[i]=data.fAliasNamesXLVmap[i];
122
123 for(int i=0;i<kNsectors;i++)
124 for(int j=0;j<kNplates;j++)
125 fAliasNamesXHVmap[i][j]=data.fAliasNamesXHVmap[i][j];
126
127}
128//---------------------------------------------------------------
129
130AliTOFLvHvDataPoints& AliTOFLvHvDataPoints:: operator=(const AliTOFLvHvDataPoints & data) {
131
b7a60cff 132 // assignment operator
ea932f75 133
134 if (this == &data)
135 return *this;
136
137 TObject::operator=(data);
138 fRun=data.GetRun();
139 fStartTime=data.GetStartTime();
140 fEndTime=data.GetEndTime();
141 fStartTimeDCSQuery=data.GetStartTimeDCSQuery();
142 fEndTimeDCSQuery=data.GetEndTimeDCSQuery();
143
144 fNumberOfLVdataPoints=data.fNumberOfLVdataPoints;
145 fNumberOfHVdataPoints=data.fNumberOfHVdataPoints;
146 fNumberOfHVandLVmaps=data.fNumberOfHVandLVmaps;
147
b7a60cff 148 fStartingLVmap=data.fStartingLVmap;
149 fStartingHVmap=data.fStartingHVmap;
150
ea932f75 151 for(int i=0;i<kNddl;i++)
152 fAliasNamesXLVmap[i]=data.fAliasNamesXLVmap[i];
153
154 for(int i=0;i<kNsectors;i++)
155 for(int j=0;j<kNplates;j++)
156 fAliasNamesXHVmap[i][j]=data.fAliasNamesXHVmap[i][j];
157
158 fHisto=data.fHisto;
159
38ef64f3 160 fNSecondsBeforeEOR=data.fNSecondsBeforeEOR;
161
ea932f75 162 return *this;
163}
164//---------------------------------------------------------------
165AliTOFLvHvDataPoints::~AliTOFLvHvDataPoints() {
166
167 // destructor
168
b7a60cff 169 delete fStartingLVmap;
170 delete fStartingHVmap;
171
ea932f75 172}
173
174//---------------------------------------------------------------
175Bool_t AliTOFLvHvDataPoints::ProcessData(TMap& aliasMap) {
176 //
177 // method to process the data
178 //
179
180 if(!(fAliasNamesXHVmap[0][0]) || !(fAliasNamesXLVmap[0])) Init();
181
182 AliInfo(Form(" Start Time = %i",fStartTime));
183 AliInfo(Form(" End Time = %i",fEndTime));
184 AliInfo(Form(" Start Time DCS Query= %i",fStartTimeDCSQuery));
185 AliInfo(Form(" End Time DCS Query= %i",fEndTimeDCSQuery));
186
187 if (fEndTime==fStartTime){
188 AliError(Form(" Run with null time length: start time = %d = end time = %d",fStartTime,fEndTime));
189 return kFALSE;
190 }
191
192
ea932f75 193 if (!ReadLVDataPoints(aliasMap)) return kFALSE;
b7a60cff 194 AliDebug(1,Form(" Number of LV dp value changes = %d",fNumberOfLVdataPoints));
ea932f75 195
b7a60cff 196 if (!ReadHVDataPoints(aliasMap)) return kFALSE;
197 AliDebug(1,Form(" Number of HV dp value changes = %d",fNumberOfHVdataPoints));
17f2cd01 198
ea932f75 199 if (!MergeLVmap()) return kFALSE;
200
b7a60cff 201 if (!MergeHVmap()) return kFALSE;
202
ea932f75 203 if (!MergeMaps()) return kFALSE;
204
205 fIsProcessed=kTRUE;
206
207 return kTRUE;
208
209}
210
211//---------------------------------------------------------------
212Bool_t AliTOFLvHvDataPoints::MergeMaps() {
213 //
214 // Merge together LV and HV maps
215 //
216
ea932f75 217 Int_t timeMaps[kNmaxDataPoints];
218 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) timeMaps[ii]=0;
219
b7a60cff 220 for (Int_t ii=0; ii<fNumberOfHVdataPoints; ii++) {
38ef64f3 221 AliDebug(1,Form(" fNumberOfHVandLVmaps = %d (HV=%d, LV=%d) - time=%d",fNumberOfHVandLVmaps,fNumberOfHVdataPoints,fNumberOfLVdataPoints,timeMaps[fNumberOfHVandLVmaps]));
b7a60cff 222 timeMaps[fNumberOfHVandLVmaps++]=fHVDataPoints[ii]->GetTime();
b7a60cff 223 }
ea932f75 224
38ef64f3 225 AliDebug(1,Form(" fNumberOfHVandLVmaps = %d (HV=%d) ",fNumberOfHVandLVmaps,fNumberOfHVdataPoints));
226
ea932f75 227 Bool_t check = kTRUE;
228 for (Int_t jj=0; jj<fNumberOfLVdataPoints; jj++) {
229 check = kTRUE;
230 for (Int_t ii=0; ii<fNumberOfHVdataPoints; ii++)
231 check=check&&(fLVDataPoints[jj]->GetTime()!=timeMaps[ii]);
232
233 if (check) {
38ef64f3 234 AliDebug(1,Form(" fNumberOfHVandLVmaps = %d (HV=%d, LV=%d) - time=%d",fNumberOfHVandLVmaps,fNumberOfHVdataPoints,fNumberOfLVdataPoints,timeMaps[fNumberOfHVandLVmaps]));
b7a60cff 235 timeMaps[fNumberOfHVandLVmaps++]=fLVDataPoints[jj]->GetTime();
ea932f75 236 }
237 }
b7a60cff 238
239 AliInfo(Form(" TOF HV dps = %d; TOF LV dps = %d; TOF HVandLV dps %d",
240 fNumberOfHVdataPoints, fNumberOfLVdataPoints, fNumberOfHVandLVmaps));
241
ea932f75 242
38ef64f3 243 Int_t *controller = new Int_t[fNumberOfHVandLVmaps];
244 for (Int_t ii=0; ii<fNumberOfHVandLVmaps; ii++) controller[ii]=-1;
ea932f75 245 TMath::Sort(fNumberOfHVandLVmaps,timeMaps,controller,kFALSE); // increasing order
246
38ef64f3 247 for (Int_t ii=0; ii<fNumberOfHVandLVmaps; ii++)
248 AliDebug(1, Form(" Time Order - time[controller[%d]] = %d", ii, timeMaps[controller[ii]]));
ea932f75 249
250 Short_t array[kNpads];
251 for (Int_t iPad=0; iPad<kNpads; iPad++) array[iPad]=-1;
252 Int_t time = 0;
253
ea932f75 254 // HVandLV status map during run
b7a60cff 255 for (Int_t index=0; index<fNumberOfHVandLVmaps; index++) {
ea932f75 256 time = timeMaps[controller[index]];
ea932f75 257
38ef64f3 258 AliDebug(2, Form(" Time Order - time[controller[%d]] = %d", index, timeMaps[controller[index]]));
ea932f75 259
38ef64f3 260 for (Int_t ii=0; ii<fNumberOfHVdataPoints; ii++)
261 for (Int_t jj=0; jj<fNumberOfLVdataPoints; jj++) {
ea932f75 262
38ef64f3 263 AliDebug(2,Form(" time=%d --- HVdp_time[%d]=%d, LVdp_time[%d]=%d",
264 time,
b7a60cff 265 ii,fHVDataPoints[ii]->GetTime(),
266 jj,fLVDataPoints[jj]->GetTime()));
ea932f75 267
38ef64f3 268 if ( (fHVDataPoints[ii]->GetTime()==time && fLVDataPoints[jj]->GetTime()<=time) ||
269 (fLVDataPoints[jj]->GetTime()==time && fHVDataPoints[ii]->GetTime()<=time) ) {
ea932f75 270
38ef64f3 271 AliDebug(2,Form(" HVdp_time[%d]=%d, LVdp_time[%d]=%d",
272 ii,fHVDataPoints[ii]->GetTime(),
273 jj,fLVDataPoints[jj]->GetTime()));
274 for (Int_t iPad=0; iPad<kNpads; iPad++)
275 array[iPad] = fHVDataPoints[ii]->GetCellValue(iPad)*fLVDataPoints[jj]->GetCellValue(iPad);
276 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,array);
277 fMap[index]= object;
278 break;
ea932f75 279
38ef64f3 280 }
281 else if ( fHVDataPoints[ii]->GetTime()==time && fLVDataPoints[jj]->GetTime()>time ) {
b7a60cff 282
38ef64f3 283 AliDebug(2,Form(" HVdp_time[%d]=%d, (no LVdp)",ii,fHVDataPoints[ii]->GetTime()));
284 for (Int_t iPad=0; iPad<kNpads; iPad++)
285 array[iPad] = fHVDataPoints[ii]->GetCellValue(iPad);
286 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,array);
287 fMap[index]= object;
288 break;
b7a60cff 289
38ef64f3 290 } else if ( fLVDataPoints[jj]->GetTime()==time && fHVDataPoints[ii]->GetTime()>time ) {
ea932f75 291
38ef64f3 292 AliDebug(2,Form(" LVdp_time[%d]=%d, (no HVdp)",jj,fLVDataPoints[jj]->GetTime()));
293 for (Int_t iPad=0; iPad<kNpads; iPad++)
294 array[iPad] = fLVDataPoints[jj]->GetCellValue(iPad);
295 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,array);
296 fMap[index]= object;
297 break;
298
299 }
300
301 }
b7a60cff 302
303 }
ea932f75 304
4ce766eb 305 delete [] controller;
38ef64f3 306
307 for (Int_t ii=0; ii<fNumberOfHVandLVmaps; ii++)
308 AliDebug(1,Form(" fMap[%d]->GetTime() = %d ",ii,fMap[ii]->GetTime()));
309
ea932f75 310 return kTRUE;
311
312}
313
314//---------------------------------------------------------------
315Bool_t AliTOFLvHvDataPoints::MergeHVmap() {
316 //
317 // Create HV maps from HV dps
318 //
319
320 Bool_t check= kFALSE;
321
b7a60cff 322 if (fNumberOfHVdataPoints==0)
323 return check;
ea932f75 324 else {
ea932f75 325
b7a60cff 326 // first map construction
327 for (Int_t iPad=0; iPad<kNpads; iPad++) {
328 if (fHVDataPoints[0]->GetCellValue(iPad)==-1)
329 fHVDataPoints[0]->SetCellValue(iPad,fStartingHVmap->GetCellValue(iPad));
330 //else
331 //fHVDataPoints[0]->SetCellValue(iPad,fHVDataPoints[0]->GetCellValue(iPad)*fStartingHVmap->GetCellValue(iPad));
332
333 if (iPad%(96*91)==0)
334 AliDebug(2,Form("HVdp0: channel=%6d -> %1d",iPad,fHVDataPoints[0]->GetCellValue(iPad)));
335 }
336
337 // other maps construction
338 for (Int_t ii=1; ii<fNumberOfHVdataPoints; ii++) {
ea932f75 339 for (Int_t iPad=0; iPad<kNpads; iPad++) {
340 if (fHVDataPoints[ii]->GetCellValue(iPad)==-1)
341 fHVDataPoints[ii]->SetCellValue(iPad,fHVDataPoints[ii-1]->GetCellValue(iPad));
b7a60cff 342
343 if (iPad%(96*91)==0)
344 AliDebug(2,Form("HVdp%d: channel=%6d -> %1d",ii,iPad,fHVDataPoints[ii]->GetCellValue(iPad)));
ea932f75 345 }
ea932f75 346 }
347
348 check=kTRUE;
349 }
350
351 return kTRUE;
352
353}
354
355//---------------------------------------------------------------
356Bool_t AliTOFLvHvDataPoints::MergeLVmap() {
357 //
358 // Create LV maps from LV dps
359 //
360
361 Bool_t check= kFALSE;
362
b7a60cff 363 if (fNumberOfLVdataPoints==0)
364 return check;
ea932f75 365 else {
ea932f75 366
b7a60cff 367 // first map construction
368 for (Int_t iPad=0; iPad<kNpads; iPad++) {
369 if (fLVDataPoints[0]->GetCellValue(iPad)==-1)
370 fLVDataPoints[0]->SetCellValue(iPad,fStartingLVmap->GetCellValue(iPad));
371 //else
372 //fLVDataPoints[0]->SetCellValue(iPad,fLVDataPoints[0]->GetCellValue(iPad)*fStartingLVmap->GetCellValue(iPad));
373
374 if (iPad%(96*91)==0)
375 AliDebug(2,Form("LVdp0: channel=%6d -> %1d",iPad,fLVDataPoints[0]->GetCellValue(iPad)));
376 }
377
378 // other maps construction
379 for (Int_t ii=1; ii<fNumberOfLVdataPoints; ii++) {
ea932f75 380 for (Int_t iPad=0; iPad<kNpads; iPad++) {
381 if (fLVDataPoints[ii]->GetCellValue(iPad)==-1)
382 fLVDataPoints[ii]->SetCellValue(iPad,fLVDataPoints[ii-1]->GetCellValue(iPad));
b7a60cff 383
384 if (iPad%(96*91)==0)
385 AliDebug(2,Form("LVdp%d: channel=%6d -> %1d",ii,iPad,fLVDataPoints[ii]->GetCellValue(iPad)));
ea932f75 386 }
ea932f75 387 }
388
389 check=kTRUE;
390 }
391
392 return check;
393
394}
395
396//---------------------------------------------------------------
397Bool_t AliTOFLvHvDataPoints::ReadHVDataPoints(TMap& aliasMap) {
398 //
399 // Read HV dps
400 //
401
402 TObjArray *aliasArr;
403 AliDCSValue* aValue;
404 AliDCSValue* aValuePrev;
b7a60cff 405 Int_t val = 0;
ea932f75 406 Int_t time = 0;
407 Int_t nEntries = 0;
408
409 Short_t dummy[kNpads];
410
411 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
412 // starting loop on aliases
413 for (int i=0; i<kNsectors; i++)
414 for (int j=0; j<kNplates; j++) {
415 aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNamesXHVmap[i][j].Data());
416 if (!aliasArr) {
417 AliError(Form("Alias %s not found!", fAliasNamesXHVmap[i][j].Data()));
418 if (!fFDR)
419 return kFALSE; // returning only in case we are not in a FDR run
420 else
421 continue;
422 }
423
424 nEntries = aliasArr->GetEntries();
425
b7a60cff 426 if (nEntries<2) AliDebug(1, Form(" NB: number of values for dp %s %d (less than 2)",fAliasNamesXHVmap[i][j].Data(),nEntries));
427
ea932f75 428 if (nEntries==0) {
429 AliError(Form("Alias %s has no entries! Nothing will be stored",
430 fAliasNamesXHVmap[i][j].Data()));
431 continue;
432 }
433 else {
434
b7a60cff 435 // read the first value
436 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
437 aValue = (AliDCSValue*) aliasArr->At(0);
438 val = aValue->GetInt();
439 time = aValue->GetTimeStamp();
440 AliDebug(1, Form(" at t=%d, 1st value for dp %s = %d", time, fAliasNamesXHVmap[i][j].Data(), val));
441 FillHVarrayPerDataPoint(i,j,val,dummy);
442 AliTOFDCSmaps *object0 = new AliTOFDCSmaps(time,dummy);
443 if (InsertHVDataPoint(object0)!=0) return kTRUE; // to be verified
444
445 // read the values from the second one
446 for (Int_t iEntry=1; iEntry<nEntries; iEntry++) {
ea932f75 447 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
448 aValue = (AliDCSValue*) aliasArr->At(iEntry);
b7a60cff 449 val = aValue->GetInt();
ea932f75 450 time = aValue->GetTimeStamp();
38ef64f3 451 AliDebug(2, Form(" at t=%d, %dth value for dp %s = %d", time, iEntry+1, fAliasNamesXHVmap[i][j].Data(), val));
b7a60cff 452 aValuePrev = (AliDCSValue*) aliasArr->At(iEntry-1);
453 if (aValuePrev->GetInt()!=val) {
38ef64f3 454 AliDebug(1, Form(" CHANGE - at t=%d, %dth value for dp %s = %d", time, iEntry+1, fAliasNamesXHVmap[i][j].Data(), val));
ea932f75 455 FillHVarrayPerDataPoint(i,j,val,dummy);
456 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,dummy);
b7a60cff 457 if (InsertHVDataPoint(object)!=0) return kTRUE; // to be verified
ea932f75 458 }
459
460 }
461 }
462 }
463
104ba366 464 if (fNumberOfHVdataPoints==0) {
b7a60cff 465 AliInfo("Valid HV dps not found. By default all HV TOF channels (except the ones in the PHOS holes) switched ON, at SOR.");
466 if (InsertHVDataPoint(fStartingHVmap)!=0) return kTRUE; // to be verified
104ba366 467 }
38ef64f3 468
ea932f75 469 return kTRUE;
470
471}
472
473//---------------------------------------------------------------
474Bool_t AliTOFLvHvDataPoints::ReadLVDataPoints(TMap& aliasMap) {
475 //
476 // Read LV dps
477 //
478
479 TObjArray *aliasArr;
480 AliDCSValue* aValue;
481 AliDCSValue* aValuePrev;
b7a60cff 482 Int_t val = 0;
ea932f75 483 Int_t time = 0;
484 Int_t nEntries = 0;
485
486 Short_t dummy[kNpads];
487
488 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
489 // starting loop on aliases
490 for (int i=0; i<kNddl; i++) {
491 aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNamesXLVmap[i].Data());
492 if (!aliasArr) {
493 AliError(Form("Alias %s not found!", fAliasNamesXLVmap[i].Data()));
494 if (!fFDR)
495 return kFALSE; // returning only in case we are not in a FDR run
496 else
497 continue;
498 }
499
500 nEntries = aliasArr->GetEntries();
501
b7a60cff 502 if (nEntries<2) AliDebug(1, Form(" NB: number of values for dp %s %d (less than 2)",fAliasNamesXLVmap[i].Data(),nEntries));
503
ea932f75 504 if (nEntries==0) {
505 AliError(Form("Alias %s has no entries! Nothing will be stored",
506 fAliasNamesXLVmap[i].Data()));
507 continue;
508 }
509 else {
510
b7a60cff 511 // read the first value
512 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
513 aValue = (AliDCSValue*) aliasArr->At(0);
514 val = aValue->GetInt();
515 time = aValue->GetTimeStamp();
38ef64f3 516 AliDebug(1, Form(" at t=%d, 1st value for dp %s = %d", time, fAliasNamesXLVmap[i].Data(), val));
b7a60cff 517 FillLVarrayPerDataPoint(i,val,dummy);
518 AliTOFDCSmaps *object0 = new AliTOFDCSmaps(time,dummy);
519 if (InsertLVDataPoint(object0)!=0) return kTRUE; // to be verified
520
521 // read the values from the second one
522 for (Int_t iEntry=1; iEntry<nEntries; iEntry++) {
ea932f75 523 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
524 aValue = (AliDCSValue*) aliasArr->At(iEntry);
b7a60cff 525 val = aValue->GetInt();
ea932f75 526 time = aValue->GetTimeStamp();
38ef64f3 527 AliDebug(2, Form(" at t=%d, %dth value for dp %s = %d", time, iEntry+1, fAliasNamesXLVmap[i].Data(), val));
b7a60cff 528 aValuePrev = (AliDCSValue*) aliasArr->At(iEntry-1);
529 if (aValuePrev->GetInt()!=val) {
38ef64f3 530 AliDebug(1, Form(" CHANGE - at t=%d, %dth value for dp %s = %d", time, iEntry+1, fAliasNamesXLVmap[i].Data(), val));
ea932f75 531 FillLVarrayPerDataPoint(i,val,dummy);
532 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,dummy);
b7a60cff 533 if (InsertLVDataPoint(object)!=0) return kTRUE; // to be verified
ea932f75 534 }
b7a60cff 535
ea932f75 536 }
537 }
538 }
539
104ba366 540 if (fNumberOfLVdataPoints==0) {
b7a60cff 541 AliInfo("Valid LV dps not found. By default all LV TOF channels switched ON, at SOR.");
542 if (InsertLVDataPoint(fStartingLVmap)!=0) return kTRUE; // to be verified
104ba366 543 }
38ef64f3 544
ea932f75 545 return kTRUE;
546
547}
548
549//---------------------------------------------------------------
550Int_t AliTOFLvHvDataPoints::InsertHVDataPoint(AliTOFDCSmaps *object)
551{
552 //
553 // Insert HV dp in the HV dps array.
554 // The HV dps array is sorted according to increasing dp timeStamp value
555 //
556
557 if (fNumberOfHVdataPoints==kNmaxDataPoints) {
558 AliError("Too many HV data points!");
559 return 1;
560 }
561
562 if (fNumberOfHVdataPoints==0) {
563 fHVDataPoints[fNumberOfHVdataPoints++] = object;
564 return 0;
565 }
566
567 for (Int_t index=0; index<fNumberOfHVdataPoints; index++) {
568 if (object->GetTime()==fHVDataPoints[index]->GetTime()) {
569 fHVDataPoints[index]->Update(object);
570 return 0;
571 }
572 }
573
574 Int_t ii = FindHVdpIndex(object->GetTime());
575 memmove(fHVDataPoints+ii+1 ,fHVDataPoints+ii,(fNumberOfHVdataPoints-ii)*sizeof(AliTOFDCSmaps*));
576 fHVDataPoints[ii] = object;
577 fNumberOfHVdataPoints++;
578
579 return 0;
580
581}
582
583//_________________________________________________________________________
584Int_t AliTOFLvHvDataPoints::FindHVdpIndex(Int_t z) const {
585 //
586 // This function returns the index of the nearest HV DP in time
587 //
588
589 if (fNumberOfHVdataPoints==0) return 0;
590 if (z <= fHVDataPoints[0]->GetTime()) return 0;
591 if (z > fHVDataPoints[fNumberOfHVdataPoints-1]->GetTime()) return fNumberOfHVdataPoints;
592 Int_t b = 0, e = fNumberOfHVdataPoints-1, m = (b+e)/2;
593 for (; b<e; m=(b+e)/2) {
594 if (z > fHVDataPoints[m]->GetTime()) b=m+1;
595 else e=m;
596 }
597
598 return m;
599
600}
601
602//---------------------------------------------------------------
603Int_t AliTOFLvHvDataPoints::InsertLVDataPoint(AliTOFDCSmaps *object)
604{
605 //
606 // Insert LV dp in the LV dps array.
607 // The LV dps array is sorted according to increasing dp timeStamp value
608 //
609
610 if (fNumberOfLVdataPoints==kNmaxDataPoints) {
611 AliError("Too many LV data points!");
612 return 1;
613 }
614
615 if (fNumberOfLVdataPoints==0) {
616 fLVDataPoints[fNumberOfLVdataPoints++] = object;
617 return 0;
618 }
619
620 for (Int_t index=0; index<fNumberOfLVdataPoints; index++) {
621 if (object->GetTime()==fLVDataPoints[index]->GetTime()) {
622 fLVDataPoints[index]->Update(object);
623 return 0;
624 }
625 }
626
627 Int_t ii = FindLVdpIndex(object->GetTime());
628 memmove(fLVDataPoints+ii+1 ,fLVDataPoints+ii,(fNumberOfLVdataPoints-ii)*sizeof(AliTOFDCSmaps*));
629 fLVDataPoints[ii] = object;
630 fNumberOfLVdataPoints++;
631
632 return 0;
633
634}
635
636//_________________________________________________________________________
637Int_t AliTOFLvHvDataPoints::FindLVdpIndex(Int_t z) const {
638 //
639 // This function returns the index of the nearest LV DP in time
640 //
641
642 if (fNumberOfLVdataPoints==0) return 0;
643 if (z <= fLVDataPoints[0]->GetTime()) return 0;
644 if (z > fLVDataPoints[fNumberOfLVdataPoints-1]->GetTime()) return fNumberOfLVdataPoints;
645 Int_t b = 0, e = fNumberOfLVdataPoints-1, m = (b+e)/2;
646 for (; b<e; m=(b+e)/2) {
647 if (z > fLVDataPoints[m]->GetTime()) b=m+1;
648 else e=m;
649 }
650
651 return m;
652
653}
654
655//---------------------------------------------------------------
656void AliTOFLvHvDataPoints::Init(){
657 //
658 // Initialize aliases and DCS data
659 //
660
661 TString sindex;
662 for(int i=0;i<kNsectors;i++)
663 for(int j=0;j<kNplates;j++) {
664 fAliasNamesXHVmap[i][j] = "TOF_HVSTATUS_";
665 sindex.Form("SM%02dMOD%1d",i,j);
666 fAliasNamesXHVmap[i][j] += sindex;
667 }
668
669
670 for(int i=0;i<kNddl;i++) {
671 fAliasNamesXLVmap[i] = "TOF_FEACSTATUS_";
672 sindex.Form("%02d",i);
673 fAliasNamesXLVmap[i] += sindex;
674 }
675
b7a60cff 676 fStartingLVmap->SetTime(0);
677 for (Int_t iPad=0; iPad<kNpads; iPad++)
678 fStartingLVmap->SetCellValue(iPad,1);
679
680 fStartingHVmap->SetTime(0);
681 for (Int_t iPad=0; iPad<kNpads; iPad++) {
682 Int_t vol[5] = {-1,-1,-1,-1,-1};
683 AliTOFGeometry::GetVolumeIndices(iPad,vol);
684 if ( (vol[0]==13 || vol[0]==14 || vol[0]==15) &&
685 vol[1]==2)
686 fStartingHVmap->SetCellValue(iPad,0);
687 else
688 fStartingHVmap->SetCellValue(iPad,1);
689 }
690
ea932f75 691}
692
693//---------------------------------------------------------------
b7a60cff 694void AliTOFLvHvDataPoints::FillHVarrayPerDataPoint(Int_t sector, Int_t plate, UInt_t baseWord, Short_t *array) const
ea932f75 695{
696 //
697 // Set the status of the TOF pads connected to the HV dp
698 // labelled by sector and plate numbers
699 //
700
701 Int_t det[5] = {sector, plate, -1, -1, -1};
702 UInt_t checkBit = 0;
703
704 Int_t channel = -1;
705
706 for (Int_t iStrip=0; iStrip<AliTOFGeometry::NStrip(plate); iStrip++) {
707 checkBit = AliBitPacking::UnpackWord(baseWord,iStrip,iStrip);
708 for (Int_t iPadZ=0; iPadZ<AliTOFGeometry::NpadZ(); iPadZ++)
709 for (Int_t iPadX=0; iPadX<AliTOFGeometry::NpadX(); iPadX++) {
710 det[2] = iStrip;
711 det[3] = iPadZ;
712 det[4] = iPadX;
713 channel = AliTOFGeometry::GetIndex(det);
714 array[channel]=checkBit;
715 }
716 }
717
718
719}
720
721//---------------------------------------------------------------
b7a60cff 722void AliTOFLvHvDataPoints::FillLVarrayPerDataPoint(Int_t nDDL, UInt_t baseWord, Short_t *array) const
ea932f75 723{
724 //
725 // Set the status of the TOF pads connected to the LV dp
726 // labelled by TOF crate number
727 //
728
729 Int_t det[5] = {nDDL/4, -1, -1, -1, -1};
730 UInt_t checkBit = 0;
731
732 Int_t iStripXsm[6] = {-1,-1,-1,-1,-1,-1};
733 Int_t firstPadX = -1;
734 Int_t lastPadX = -1;
735 Int_t plate = -1;
736 Int_t strip = -1;
737
738 Int_t channel = -1;
739
740 for (Int_t nFEAC=0; nFEAC<8; nFEAC++) {
741 checkBit = AliBitPacking::UnpackWord(baseWord,nFEAC,nFEAC);
742 firstPadX = -1;
743 lastPadX = -1;
744 GetStripsConnectedToFEAC(nDDL, nFEAC, iStripXsm, firstPadX,lastPadX);
745 for (Int_t index=0; index<6; index++) {
746 if (iStripXsm[index]==-1) continue;
747
748 for (Int_t iPadZ=0; iPadZ<AliTOFGeometry::NpadZ(); iPadZ++)
749 for (Int_t iPadX=firstPadX; iPadX<=lastPadX; iPadX++) {
750 AliTOFGeometry::GetStripAndModule(iStripXsm[index],plate,strip);
751 det[1] = plate;
752 det[2] = strip;
753 det[3] = iPadZ;
754 det[4] = iPadX;
755 channel = AliTOFGeometry::GetIndex(det);
756 array[channel]=checkBit;
757 }
758 }
759 }
760
761
762}
763
764//---------------------------------------------------------------
b7a60cff 765void AliTOFLvHvDataPoints::GetStripsConnectedToFEAC(Int_t nDDL, Int_t nFEAC, Int_t *iStrip, Int_t &firstPadX, Int_t &lastPadX) const
ea932f75 766{
767 //
768 // FEAC-strip mapping:
769 // return the strips and first PadX numbers
770 // connected to the FEAC number nFEAC in the crate number nDDL
771 //
772
773 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=-1;
774
775 if (nDDL<0 || nDDL>=kNddl || nFEAC<0 || nFEAC>=8) return;
776
777 switch (nDDL%4) {
778 case 0:
779 firstPadX = 0;
780 lastPadX = AliTOFGeometry::NpadX()/2-1;
781
782 if (nFEAC<=2)
783 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC;
784 else if (nFEAC==3)
785 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC;
786 else if (nFEAC==4)
787 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-1;
788 else if (nFEAC==5)
789 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC-1;
790 else if (nFEAC==6)
791 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-2;
792 else if (nFEAC==7)
793 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC-2;
794
795 break;
796 case 1:
797 firstPadX = AliTOFGeometry::NpadX()/2;
798 lastPadX = AliTOFGeometry::NpadX()-1;
799
800 if (nFEAC<=2)
801 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC;
802 else if (nFEAC==3)
803 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC;
804 else if (nFEAC==4)
805 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-1;
806 else if (nFEAC==5)
807 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-1;
808 else if (nFEAC==6)
809 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC-1;
810 else if (nFEAC==7)
811 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-2;
812
813 break;
814 case 2:
815 firstPadX = AliTOFGeometry::NpadX()/2;
816 lastPadX = AliTOFGeometry::NpadX()-1;
817
818 if (nFEAC<=2)
819 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC);
820 else if (nFEAC==3)
821 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC);
822 else if (nFEAC==4)
823 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
824 else if (nFEAC==5)
825 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
826 else if (nFEAC==6)
827 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-2);
828 else if (nFEAC==7)
829 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC-2);
830
831 break;
832 case 3:
833 firstPadX = 0;
834 lastPadX = AliTOFGeometry::NpadX()/2-1;
835
836 if (nFEAC<=2)
837 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC);
838 else if (nFEAC==3)
839 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC);
840 else if (nFEAC==4)
841 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
842 else if (nFEAC==5)
843 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
844 else if (nFEAC==6)
845 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
846 else if (nFEAC==7)
847 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-2);
848
849 break;
850 }
851
852}
853
854//---------------------------------------------------------------
855void AliTOFLvHvDataPoints::Draw(const Option_t* /*option*/)
856{
857 //
858 // Draw all histos and graphs
859 //
860
861 if(!fIsProcessed) return;
862 /*
863 TCanvas *ch;
864 TString canvasHistoName="Histos";
865 ch = new TCanvas(canvasHistoName,canvasHistoName,20,20,600,600);
866 ch->cd();
867 */
868 // to be implemented
869
870}
871
872
873//---------------------------------------------------------------
874void AliTOFLvHvDataPoints::DrawHVandLVMap(Int_t index)
875{
876 //
877 // Draw HV+LV map labelled as index
878 //
879
880 if(!fIsProcessed) return;
881
882 if (index>=fNumberOfHVandLVmaps) return;
883
884 AliTOFDCSmaps *mappa=(AliTOFDCSmaps*)GetHVandLVmap(index);
885
886 char title[100];
887 if (index==0) sprintf(title,"HVandLV map at time %d (%dst map)",mappa->GetTime(),index+1);
888 else if (index==1) sprintf(title,"HVandLV map at time %d (%dnd map)",mappa->GetTime(),index+1);
889 else if (index==2) sprintf(title,"HVandLV map at time %d (%drd map)",mappa->GetTime(),index+1);
890 else if (index>=3) sprintf(title,"HVandLV map at time %d (%dth map)",mappa->GetTime(),index+1);
891 fHisto->Delete();
892 fHisto = new TH1C("histo","",kNpads,-0.5,kNpads-0.5);
893 //fHisto->Clear();
894 fHisto->SetTitle(title);
895
896 for (Int_t ii=0; ii<kNpads; ii++)
897 fHisto->SetBinContent(ii+1,mappa->GetCellValue(ii));
898
899 fHisto->Draw();
900
901}
902
903//---------------------------------------------------------------
904void AliTOFLvHvDataPoints::DrawLVMap(Int_t index)
905{
906 //
907 // Draw LV map labelled as index
908 //
909
910 if(!fIsProcessed) return;
911
912 if (index>=fNumberOfLVdataPoints) return;
913
914 AliTOFDCSmaps *mappa=(AliTOFDCSmaps*)GetLVmap(index);
915
916 char title[100];
917 if (index==0) sprintf(title,"LV map at time %d (%dst map)",mappa->GetTime(),index+1);
918 else if (index==1) sprintf(title,"LV map at time %d (%dnd map)",mappa->GetTime(),index+1);
919 else if (index==2) sprintf(title,"LV map at time %d (%drd map)",mappa->GetTime(),index+1);
920 else if (index>=3) sprintf(title,"LV map at time %d (%dth map)",mappa->GetTime(),index+1);
921 fHisto->Delete();
922 fHisto = new TH1C("histo","",kNpads,-0.5,kNpads-0.5);
923 //fHisto->Clear();
924 fHisto->SetTitle(title);
925
926 for (Int_t ii=0; ii<kNpads; ii++)
927 fHisto->SetBinContent(ii+1,mappa->GetCellValue(ii));
928
929 fHisto->Draw();
930
931}
932
933//---------------------------------------------------------------
934void AliTOFLvHvDataPoints::DrawHVMap(Int_t index)
935{
936 //
937 // Draw HV map labelled as index
938 //
939
940 if(!fIsProcessed) return;
941
942 if (index>=fNumberOfHVdataPoints) return;
943
944 AliTOFDCSmaps *mappa=(AliTOFDCSmaps*)GetHVmap(index);
945
946 char title[100];
947 if (index==0) sprintf(title,"HV map at time %d (%dst map)",mappa->GetTime(),index+1);
948 else if (index==1) sprintf(title,"HV map at time %d (%dnd map)",mappa->GetTime(),index+1);
949 else if (index==2) sprintf(title,"HV map at time %d (%drd map)",mappa->GetTime(),index+1);
950 else if (index>=3) sprintf(title,"HV map at time %d (%dth map)",mappa->GetTime(),index+1);
951 fHisto->Delete();
952 fHisto = new TH1C("histo","",kNpads,-0.5,kNpads-0.5);
953 //fHisto->Clear();
954 fHisto->SetTitle(title);
955
956 for (Int_t ii=0; ii<kNpads; ii++)
957 fHisto->SetBinContent(ii+1,mappa->GetCellValue(ii));
958
959 fHisto->Draw();
960
961}
962
963//---------------------------------------------------------------
964AliTOFDCSmaps *AliTOFLvHvDataPoints::GetHVandLVmapAtEOR()
965{
966 //
967 // Returns HVandLV status map at EOR.
968 // If the end-of-run has been caused by TOF self,
38ef64f3 969 // the second-last value of HVandLV status map
970 // will be taken into account, i.e. the value immediately before
971 // the change that caused EOR.
ea932f75 972 // This last condition is true
38ef64f3 973 // if the time interval between the last map value and the EOR
ea932f75 974 // is less than 60s.
38ef64f3 975 // If the run ended correctly, last map value will be take into account.
976 // If nothing changed during the run, the SOR map will be take into account.
ea932f75 977 //
978
979 AliTOFDCSmaps * lvANDhvMap = 0;
980
38ef64f3 981 if (fNumberOfHVandLVmaps==1) { // nothing changed during the run
982
983 AliInfo(Form("Nothing changed in the TOF channels LV and HV status during the run number %d",fRun));
ea932f75 984
985 lvANDhvMap = fMap[fNumberOfHVandLVmaps-1];
986
987 }
988 else {
989
38ef64f3 990 if ( (fEndTimeDCSQuery-fMap[fNumberOfHVandLVmaps-1]->GetTime()<=fNSecondsBeforeEOR) ||
991 (fEndTime-fMap[fNumberOfHVandLVmaps-1]->GetTime()<=fNSecondsBeforeEOR) ) {
992 lvANDhvMap = (AliTOFDCSmaps*)fMap[fNumberOfHVandLVmaps-2];
993 AliInfo(Form("Probably, TOF caused the EOR (EOR-t(last map))<%d).For run number %d the second-last HVandLV map will be take into account.",fNSecondsBeforeEOR,fRun));
994 }
995 else {
ea932f75 996 lvANDhvMap = (AliTOFDCSmaps*)fMap[fNumberOfHVandLVmaps-1];
38ef64f3 997 AliInfo(Form("The run number %d ended correctly. The last HVandLV map will be take into account.",fRun));
998 }
ea932f75 999
1000 }
1001
1002 return lvANDhvMap;
1003
1004}