1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 $Log: AliTOFLvHvDataPoints.cxx,v $
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
27 #include "TTimeStamp.h"
32 #include "AliDCSValue.h"
34 #include "AliBitPacking.h"
36 #include "AliTOFGeometry.h"
37 #include "AliTOFDCSmaps.h"
38 #include "AliTOFLvHvDataPoints.h"
43 ClassImp(AliTOFLvHvDataPoints)
45 //---------------------------------------------------------------
46 AliTOFLvHvDataPoints::AliTOFLvHvDataPoints():
51 fStartTimeDCSQuery(0),
55 fNumberOfLVdataPoints(0),
56 fNumberOfHVdataPoints(0),
57 fNumberOfHVandLVmaps(0),
61 fNSecondsBeforeEOR(60)
65 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fLVDataPoints[ii]= 0x0;
66 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fHVDataPoints[ii]= 0x0;
67 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fMap[ii]= 0x0;
71 //---------------------------------------------------------------
72 AliTOFLvHvDataPoints::AliTOFLvHvDataPoints(Int_t nRun, UInt_t startTime, UInt_t endTime, UInt_t startTimeDCSQuery, UInt_t endTimeDCSQuery):
75 fStartTime(startTime),
77 fStartTimeDCSQuery(startTimeDCSQuery),
78 fEndTimeDCSQuery(endTimeDCSQuery),
81 fNumberOfLVdataPoints(0),
82 fNumberOfHVdataPoints(0),
83 fNumberOfHVandLVmaps(0),
84 fStartingLVmap(new AliTOFDCSmaps()),
85 fStartingHVmap(new AliTOFDCSmaps()),
86 fHisto(new TH1C("histo","",kNpads,-0.5,kNpads-0.5)),
87 fNSecondsBeforeEOR(60)
90 // constructor with arguments
92 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fLVDataPoints[ii]= 0x0;
93 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fHVDataPoints[ii]= 0x0;
94 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fMap[ii]= 0x0;
96 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", nRun,
97 TTimeStamp(startTime).AsString(),
98 TTimeStamp(endTime).AsString(),
99 TTimeStamp(startTimeDCSQuery).AsString(),
100 TTimeStamp(endTimeDCSQuery).AsString()));
106 //---------------------------------------------------------------
108 AliTOFLvHvDataPoints::AliTOFLvHvDataPoints(const AliTOFLvHvDataPoints & data):
111 fStartTime(data.fStartTime),
112 fEndTime(data.fEndTime),
113 fStartTimeDCSQuery(data.fStartTimeDCSQuery),
114 fEndTimeDCSQuery(data.fEndTimeDCSQuery),
115 fIsProcessed(data.fIsProcessed),
117 fNumberOfLVdataPoints(data.fNumberOfLVdataPoints),
118 fNumberOfHVdataPoints(data.fNumberOfHVdataPoints),
119 fNumberOfHVandLVmaps(data.fNumberOfHVandLVmaps),
120 fStartingLVmap(data.fStartingLVmap),
121 fStartingHVmap(data.fStartingHVmap),
123 fNSecondsBeforeEOR(data.fNSecondsBeforeEOR)
128 for(int i=0;i<kNddl;i++)
129 fAliasNamesXLVmap[i]=data.fAliasNamesXLVmap[i];
131 for(int i=0;i<kNsectors;i++)
132 for(int j=0;j<kNplates;j++)
133 fAliasNamesXHVmap[i][j]=data.fAliasNamesXHVmap[i][j];
135 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fLVDataPoints[ii]= data.fLVDataPoints[ii];
136 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fHVDataPoints[ii]= data.fLVDataPoints[ii];
137 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fMap[ii]= data.fMap[ii];
140 //---------------------------------------------------------------
142 AliTOFLvHvDataPoints& AliTOFLvHvDataPoints:: operator=(const AliTOFLvHvDataPoints & data) {
144 // assignment operator
149 TObject::operator=(data);
151 fStartTime=data.GetStartTime();
152 fEndTime=data.GetEndTime();
153 fStartTimeDCSQuery=data.GetStartTimeDCSQuery();
154 fEndTimeDCSQuery=data.GetEndTimeDCSQuery();
156 fNumberOfLVdataPoints=data.fNumberOfLVdataPoints;
157 fNumberOfHVdataPoints=data.fNumberOfHVdataPoints;
158 fNumberOfHVandLVmaps=data.fNumberOfHVandLVmaps;
160 fStartingLVmap=data.fStartingLVmap;
161 fStartingHVmap=data.fStartingHVmap;
163 for(int i=0;i<kNddl;i++)
164 fAliasNamesXLVmap[i]=data.fAliasNamesXLVmap[i];
166 for(int i=0;i<kNsectors;i++)
167 for(int j=0;j<kNplates;j++)
168 fAliasNamesXHVmap[i][j]=data.fAliasNamesXHVmap[i][j];
172 fNSecondsBeforeEOR=data.fNSecondsBeforeEOR;
174 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fLVDataPoints[ii]= data.fLVDataPoints[ii];
175 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fHVDataPoints[ii]= data.fLVDataPoints[ii];
176 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) fMap[ii]= data.fMap[ii];
180 //---------------------------------------------------------------
181 AliTOFLvHvDataPoints::~AliTOFLvHvDataPoints() {
185 delete fStartingLVmap;
186 delete fStartingHVmap;
188 for (Int_t ii=0; ii<kNmaxDataPoints; ii++)
189 if (fLVDataPoints[ii]) fLVDataPoints[ii]->Delete();
190 for (Int_t ii=0; ii<kNmaxDataPoints; ii++)
191 if (fHVDataPoints[ii]) fHVDataPoints[ii]->Delete();
192 for (Int_t ii=0; ii<kNmaxDataPoints; ii++)
193 if (fMap[ii]) fMap[ii]->Delete();
197 //---------------------------------------------------------------
198 Bool_t AliTOFLvHvDataPoints::ProcessData(TMap& aliasMap) {
200 // method to process the data
203 if(!(fAliasNamesXHVmap[0][0]) || !(fAliasNamesXLVmap[0])) Init();
205 AliInfo(Form(" Start Time = %i",fStartTime));
206 AliInfo(Form(" End Time = %i",fEndTime));
207 AliInfo(Form(" Start Time DCS Query= %i",fStartTimeDCSQuery));
208 AliInfo(Form(" End Time DCS Query= %i",fEndTimeDCSQuery));
210 if (fEndTime==fStartTime){
211 AliError(Form(" Run with null time length: start time = %d = end time = %d",fStartTime,fEndTime));
216 if (!ReadLVDataPoints(aliasMap)) return kFALSE;
217 AliDebug(1,Form(" Number of LV dp value changes = %d",fNumberOfLVdataPoints));
219 if (!ReadHVDataPoints(aliasMap)) return kFALSE;
220 AliDebug(1,Form(" Number of HV dp value changes = %d",fNumberOfHVdataPoints));
222 if (!MergeLVmap()) return kFALSE;
224 if (!MergeHVmap()) return kFALSE;
226 if (!MergeMaps()) return kFALSE;
234 //---------------------------------------------------------------
235 Bool_t AliTOFLvHvDataPoints::MergeMaps() {
237 // Merge together LV and HV maps
240 Int_t timeMaps[kNmaxDataPoints];
241 for (Int_t ii=0; ii<kNmaxDataPoints; ii++) timeMaps[ii]=0;
243 for (Int_t ii=0; ii<fNumberOfHVdataPoints; ii++) {
244 AliDebug(1,Form(" fNumberOfHVandLVmaps = %d (HV=%d, LV=%d) - time=%d",fNumberOfHVandLVmaps,fNumberOfHVdataPoints,fNumberOfLVdataPoints,timeMaps[fNumberOfHVandLVmaps]));
245 timeMaps[fNumberOfHVandLVmaps++]=fHVDataPoints[ii]->GetTime();
248 AliDebug(1,Form(" fNumberOfHVandLVmaps = %d (HV=%d) ",fNumberOfHVandLVmaps,fNumberOfHVdataPoints));
250 Bool_t check = kTRUE;
251 for (Int_t jj=0; jj<fNumberOfLVdataPoints; jj++) {
253 for (Int_t ii=0; ii<fNumberOfHVdataPoints; ii++)
254 check=check&&(fLVDataPoints[jj]->GetTime()!=timeMaps[ii]);
257 AliDebug(1,Form(" fNumberOfHVandLVmaps = %d (HV=%d, LV=%d) - time=%d",fNumberOfHVandLVmaps,fNumberOfHVdataPoints,fNumberOfLVdataPoints,timeMaps[fNumberOfHVandLVmaps]));
258 timeMaps[fNumberOfHVandLVmaps++]=fLVDataPoints[jj]->GetTime();
262 AliInfo(Form(" TOF HV dps = %d; TOF LV dps = %d; TOF HVandLV dps %d",
263 fNumberOfHVdataPoints, fNumberOfLVdataPoints, fNumberOfHVandLVmaps));
266 Int_t *controller = new Int_t[sizeof(Int_t)*fNumberOfHVandLVmaps]; // fix for coverity
267 for (Int_t ii=0; ii<fNumberOfHVandLVmaps; ii++) controller[ii]=-1;
268 TMath::Sort(fNumberOfHVandLVmaps,timeMaps,controller,kFALSE); // increasing order
270 for (Int_t ii=0; ii<fNumberOfHVandLVmaps; ii++)
271 AliDebug(1, Form(" Time Order - time[controller[%d]] = %d", ii, timeMaps[controller[ii]]));
273 Short_t array[kNpads];
274 for (Int_t iPad=0; iPad<kNpads; iPad++) array[iPad]=-1;
277 // HVandLV status map during run
278 for (Int_t index=0; index<fNumberOfHVandLVmaps; index++) {
279 time = timeMaps[controller[index]];
281 AliDebug(2, Form(" Time Order - time[controller[%d]] = %d", index, timeMaps[controller[index]]));
283 for (Int_t ii=0; ii<fNumberOfHVdataPoints; ii++)
284 for (Int_t jj=0; jj<fNumberOfLVdataPoints; jj++) {
286 AliDebug(2,Form(" time=%d --- HVdp_time[%d]=%d, LVdp_time[%d]=%d",
288 ii,fHVDataPoints[ii]->GetTime(),
289 jj,fLVDataPoints[jj]->GetTime()));
291 if ( (fHVDataPoints[ii]->GetTime()==time && fLVDataPoints[jj]->GetTime()<=time) ||
292 (fLVDataPoints[jj]->GetTime()==time && fHVDataPoints[ii]->GetTime()<=time) ) {
294 AliDebug(2,Form(" HVdp_time[%d]=%d, LVdp_time[%d]=%d",
295 ii,fHVDataPoints[ii]->GetTime(),
296 jj,fLVDataPoints[jj]->GetTime()));
297 for (Int_t iPad=0; iPad<kNpads; iPad++)
298 array[iPad] = fHVDataPoints[ii]->GetCellValue(iPad)*fLVDataPoints[jj]->GetCellValue(iPad);
299 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,array);
304 else if ( fHVDataPoints[ii]->GetTime()==time && fLVDataPoints[jj]->GetTime()>time ) {
306 AliDebug(2,Form(" HVdp_time[%d]=%d, (no LVdp)",ii,fHVDataPoints[ii]->GetTime()));
307 for (Int_t iPad=0; iPad<kNpads; iPad++)
308 array[iPad] = fHVDataPoints[ii]->GetCellValue(iPad);
309 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,array);
313 } else if ( fLVDataPoints[jj]->GetTime()==time && fHVDataPoints[ii]->GetTime()>time ) {
315 AliDebug(2,Form(" LVdp_time[%d]=%d, (no HVdp)",jj,fLVDataPoints[jj]->GetTime()));
316 for (Int_t iPad=0; iPad<kNpads; iPad++)
317 array[iPad] = fLVDataPoints[jj]->GetCellValue(iPad);
318 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,array);
328 delete [] controller;
330 for (Int_t ii=0; ii<fNumberOfHVandLVmaps; ii++)
331 AliDebug(1,Form(" fMap[%d]->GetTime() = %d ",ii,fMap[ii]->GetTime()));
337 //---------------------------------------------------------------
338 Bool_t AliTOFLvHvDataPoints::MergeHVmap() {
340 // Create HV maps from HV dps
343 Bool_t check= kFALSE;
345 if (fNumberOfHVdataPoints==0)
349 // first map construction
350 for (Int_t iPad=0; iPad<kNpads; iPad++) {
351 if (fHVDataPoints[0]->GetCellValue(iPad)==-1)
352 fHVDataPoints[0]->SetCellValue(iPad,fStartingHVmap->GetCellValue(iPad));
354 //fHVDataPoints[0]->SetCellValue(iPad,fHVDataPoints[0]->GetCellValue(iPad)*fStartingHVmap->GetCellValue(iPad));
357 AliDebug(2,Form("HVdp0: channel=%6d -> %1d",iPad,fHVDataPoints[0]->GetCellValue(iPad)));
360 // other maps construction
361 for (Int_t ii=1; ii<fNumberOfHVdataPoints; ii++) {
362 for (Int_t iPad=0; iPad<kNpads; iPad++) {
363 if (fHVDataPoints[ii]->GetCellValue(iPad)==-1)
364 fHVDataPoints[ii]->SetCellValue(iPad,fHVDataPoints[ii-1]->GetCellValue(iPad));
367 AliDebug(2,Form("HVdp%d: channel=%6d -> %1d",ii,iPad,fHVDataPoints[ii]->GetCellValue(iPad)));
378 //---------------------------------------------------------------
379 Bool_t AliTOFLvHvDataPoints::MergeLVmap() {
381 // Create LV maps from LV dps
384 Bool_t check= kFALSE;
386 if (fNumberOfLVdataPoints==0)
390 // first map construction
391 for (Int_t iPad=0; iPad<kNpads; iPad++) {
392 if (fLVDataPoints[0]->GetCellValue(iPad)==-1)
393 fLVDataPoints[0]->SetCellValue(iPad,fStartingLVmap->GetCellValue(iPad));
395 //fLVDataPoints[0]->SetCellValue(iPad,fLVDataPoints[0]->GetCellValue(iPad)*fStartingLVmap->GetCellValue(iPad));
398 AliDebug(2,Form("LVdp0: channel=%6d -> %1d",iPad,fLVDataPoints[0]->GetCellValue(iPad)));
401 // other maps construction
402 for (Int_t ii=1; ii<fNumberOfLVdataPoints; ii++) {
403 for (Int_t iPad=0; iPad<kNpads; iPad++) {
404 if (fLVDataPoints[ii]->GetCellValue(iPad)==-1)
405 fLVDataPoints[ii]->SetCellValue(iPad,fLVDataPoints[ii-1]->GetCellValue(iPad));
408 AliDebug(2,Form("LVdp%d: channel=%6d -> %1d",ii,iPad,fLVDataPoints[ii]->GetCellValue(iPad)));
419 //---------------------------------------------------------------
420 Bool_t AliTOFLvHvDataPoints::ReadHVDataPoints(TMap& aliasMap) {
427 AliDCSValue* aValuePrev;
432 Short_t dummy[kNpads];
434 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
435 // starting loop on aliases
436 for (int i=0; i<kNsectors; i++)
437 for (int j=0; j<kNplates; j++) {
438 aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNamesXHVmap[i][j].Data());
440 AliError(Form("Alias %s not found!", fAliasNamesXHVmap[i][j].Data()));
442 return kFALSE; // returning only in case we are not in a FDR run
447 nEntries = aliasArr->GetEntries();
449 if (nEntries<2) AliDebug(1, Form(" NB: number of values for dp %s %d (less than 2)",fAliasNamesXHVmap[i][j].Data(),nEntries));
452 AliError(Form("Alias %s has no entries! Nothing will be stored",
453 fAliasNamesXHVmap[i][j].Data()));
458 // read the first value
459 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
460 aValue = (AliDCSValue*) aliasArr->At(0);
461 val = aValue->GetInt();
462 time = aValue->GetTimeStamp();
463 AliDebug(1, Form(" at t=%d, 1st value for dp %s = %d", time, fAliasNamesXHVmap[i][j].Data(), val));
464 FillHVarrayPerDataPoint(i,j,val,dummy);
465 AliTOFDCSmaps *object0 = new AliTOFDCSmaps(time,dummy);
466 if (InsertHVDataPoint(object0)!=0) return kTRUE; // to be verified
468 // read the values from the second one
469 for (Int_t iEntry=1; iEntry<nEntries; iEntry++) {
470 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
471 aValue = (AliDCSValue*) aliasArr->At(iEntry);
472 val = aValue->GetInt();
473 time = aValue->GetTimeStamp();
474 AliDebug(2, Form(" at t=%d, %dth value for dp %s = %d", time, iEntry+1, fAliasNamesXHVmap[i][j].Data(), val));
475 aValuePrev = (AliDCSValue*) aliasArr->At(iEntry-1);
476 if (aValuePrev->GetInt()!=val) {
477 AliDebug(1, Form(" CHANGE - at t=%d, %dth value for dp %s = %d", time, iEntry+1, fAliasNamesXHVmap[i][j].Data(), val));
478 FillHVarrayPerDataPoint(i,j,val,dummy);
479 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,dummy);
480 if (InsertHVDataPoint(object)!=0) return kTRUE; // to be verified
487 if (fNumberOfHVdataPoints==0) {
488 AliInfo("Valid HV dps not found. By default all HV TOF channels (except the ones in the PHOS holes) switched ON, at SOR.");
489 if (InsertHVDataPoint(fStartingHVmap)!=0) return kTRUE; // to be verified
496 //---------------------------------------------------------------
497 Bool_t AliTOFLvHvDataPoints::ReadLVDataPoints(TMap& aliasMap) {
504 AliDCSValue* aValuePrev;
509 Short_t dummy[kNpads];
511 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
512 // starting loop on aliases
513 for (int i=0; i<kNddl; i++) {
514 aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNamesXLVmap[i].Data());
516 AliError(Form("Alias %s not found!", fAliasNamesXLVmap[i].Data()));
518 return kFALSE; // returning only in case we are not in a FDR run
523 nEntries = aliasArr->GetEntries();
525 if (nEntries<2) AliDebug(1, Form(" NB: number of values for dp %s %d (less than 2)",fAliasNamesXLVmap[i].Data(),nEntries));
528 AliError(Form("Alias %s has no entries! Nothing will be stored",
529 fAliasNamesXLVmap[i].Data()));
534 // read the first value
535 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
536 aValue = (AliDCSValue*) aliasArr->At(0);
537 val = aValue->GetInt();
538 time = aValue->GetTimeStamp();
539 AliDebug(1, Form(" at t=%d, 1st value for dp %s = %d", time, fAliasNamesXLVmap[i].Data(), val));
540 FillLVarrayPerDataPoint(i,val,dummy);
541 AliTOFDCSmaps *object0 = new AliTOFDCSmaps(time,dummy);
542 if (InsertLVDataPoint(object0)!=0) return kTRUE; // to be verified
544 // read the values from the second one
545 for (Int_t iEntry=1; iEntry<nEntries; iEntry++) {
546 for (Int_t iBin=0; iBin<kNpads; iBin++) dummy[iBin]=-1;
547 aValue = (AliDCSValue*) aliasArr->At(iEntry);
548 val = aValue->GetInt();
549 time = aValue->GetTimeStamp();
550 AliDebug(2, Form(" at t=%d, %dth value for dp %s = %d", time, iEntry+1, fAliasNamesXLVmap[i].Data(), val));
551 aValuePrev = (AliDCSValue*) aliasArr->At(iEntry-1);
552 if (aValuePrev->GetInt()!=val) {
553 AliDebug(1, Form(" CHANGE - at t=%d, %dth value for dp %s = %d", time, iEntry+1, fAliasNamesXLVmap[i].Data(), val));
554 FillLVarrayPerDataPoint(i,val,dummy);
555 AliTOFDCSmaps *object = new AliTOFDCSmaps(time,dummy);
556 if (InsertLVDataPoint(object)!=0) return kTRUE; // to be verified
563 if (fNumberOfLVdataPoints==0) {
564 AliInfo("Valid LV dps not found. By default all LV TOF channels switched ON, at SOR.");
565 if (InsertLVDataPoint(fStartingLVmap)!=0) return kTRUE; // to be verified
572 //---------------------------------------------------------------
573 Int_t AliTOFLvHvDataPoints::InsertHVDataPoint(AliTOFDCSmaps *object)
576 // Insert HV dp in the HV dps array.
577 // The HV dps array is sorted according to increasing dp timeStamp value
580 if (fNumberOfHVdataPoints==kNmaxDataPoints) {
581 AliError("Too many HV data points!");
585 if (fNumberOfHVdataPoints==0) {
586 fHVDataPoints[fNumberOfHVdataPoints++] = object;
590 for (Int_t index=0; index<fNumberOfHVdataPoints; index++) {
591 if (object->GetTime()==fHVDataPoints[index]->GetTime()) {
592 fHVDataPoints[index]->Update(object);
597 Int_t ii = FindHVdpIndex(object->GetTime());
598 memmove(fHVDataPoints+ii+1 ,fHVDataPoints+ii,(fNumberOfHVdataPoints-ii)*sizeof(AliTOFDCSmaps*));
599 fHVDataPoints[ii] = object;
600 fNumberOfHVdataPoints++;
606 //_________________________________________________________________________
607 Int_t AliTOFLvHvDataPoints::FindHVdpIndex(Int_t z) const {
609 // This function returns the index of the nearest HV DP in time
612 if (fNumberOfHVdataPoints==0) return 0;
613 if (z <= fHVDataPoints[0]->GetTime()) return 0;
614 if (z > fHVDataPoints[fNumberOfHVdataPoints-1]->GetTime()) return fNumberOfHVdataPoints;
615 Int_t b = 0, e = fNumberOfHVdataPoints-1, m = (b+e)/2;
616 for (; b<e; m=(b+e)/2) {
617 if (z > fHVDataPoints[m]->GetTime()) b=m+1;
625 //---------------------------------------------------------------
626 Int_t AliTOFLvHvDataPoints::InsertLVDataPoint(AliTOFDCSmaps *object)
629 // Insert LV dp in the LV dps array.
630 // The LV dps array is sorted according to increasing dp timeStamp value
633 if (fNumberOfLVdataPoints==kNmaxDataPoints) {
634 AliError("Too many LV data points!");
638 if (fNumberOfLVdataPoints==0) {
639 fLVDataPoints[fNumberOfLVdataPoints++] = object;
643 for (Int_t index=0; index<fNumberOfLVdataPoints; index++) {
644 if (object->GetTime()==fLVDataPoints[index]->GetTime()) {
645 fLVDataPoints[index]->Update(object);
650 Int_t ii = FindLVdpIndex(object->GetTime());
651 memmove(fLVDataPoints+ii+1 ,fLVDataPoints+ii,(fNumberOfLVdataPoints-ii)*sizeof(AliTOFDCSmaps*));
652 fLVDataPoints[ii] = object;
653 fNumberOfLVdataPoints++;
659 //_________________________________________________________________________
660 Int_t AliTOFLvHvDataPoints::FindLVdpIndex(Int_t z) const {
662 // This function returns the index of the nearest LV DP in time
665 if (fNumberOfLVdataPoints==0) return 0;
666 if (z <= fLVDataPoints[0]->GetTime()) return 0;
667 if (z > fLVDataPoints[fNumberOfLVdataPoints-1]->GetTime()) return fNumberOfLVdataPoints;
668 Int_t b = 0, e = fNumberOfLVdataPoints-1, m = (b+e)/2;
669 for (; b<e; m=(b+e)/2) {
670 if (z > fLVDataPoints[m]->GetTime()) b=m+1;
678 //---------------------------------------------------------------
679 void AliTOFLvHvDataPoints::Init(){
681 // Initialize aliases and DCS data
685 for(int i=0;i<kNsectors;i++)
686 for(int j=0;j<kNplates;j++) {
687 fAliasNamesXHVmap[i][j] = "TOF_HVSTATUS_";
688 sindex.Form("SM%02dMOD%1d",i,j);
689 fAliasNamesXHVmap[i][j] += sindex;
693 for(int i=0;i<kNddl;i++) {
694 fAliasNamesXLVmap[i] = "TOF_FEACSTATUS_";
695 sindex.Form("%02d",i);
696 fAliasNamesXLVmap[i] += sindex;
699 fStartingLVmap->SetTime(0);
700 for (Int_t iPad=0; iPad<kNpads; iPad++)
701 fStartingLVmap->SetCellValue(iPad,1);
703 fStartingHVmap->SetTime(0);
704 for (Int_t iPad=0; iPad<kNpads; iPad++) {
705 Int_t vol[5] = {-1,-1,-1,-1,-1};
706 AliTOFGeometry::GetVolumeIndices(iPad,vol);
707 if ( (vol[0]==13 || vol[0]==14 || vol[0]==15) &&
709 fStartingHVmap->SetCellValue(iPad,0);
711 fStartingHVmap->SetCellValue(iPad,1);
716 //---------------------------------------------------------------
717 void AliTOFLvHvDataPoints::FillHVarrayPerDataPoint(Int_t sector, Int_t plate, UInt_t baseWord, Short_t *array) const
720 // Set the status of the TOF pads connected to the HV dp
721 // labelled by sector and plate numbers
724 Int_t det[5] = {sector, plate, -1, -1, -1};
729 for (Int_t iStrip=0; iStrip<AliTOFGeometry::NStrip(plate); iStrip++) {
730 checkBit = AliBitPacking::UnpackWord(baseWord,iStrip,iStrip);
731 for (Int_t iPadZ=0; iPadZ<AliTOFGeometry::NpadZ(); iPadZ++)
732 for (Int_t iPadX=0; iPadX<AliTOFGeometry::NpadX(); iPadX++) {
736 channel = AliTOFGeometry::GetIndex(det);
737 array[channel]=checkBit;
744 //---------------------------------------------------------------
745 void AliTOFLvHvDataPoints::FillLVarrayPerDataPoint(Int_t nDDL, UInt_t baseWord, Short_t *array) const
748 // Set the status of the TOF pads connected to the LV dp
749 // labelled by TOF crate number
752 Int_t det[5] = {nDDL/4, -1, -1, -1, -1};
755 Int_t iStripXsm[6] = {-1,-1,-1,-1,-1,-1};
756 Int_t firstPadX = -1;
763 for (Int_t nFEAC=0; nFEAC<8; nFEAC++) {
764 checkBit = AliBitPacking::UnpackWord(baseWord,nFEAC,nFEAC);
767 GetStripsConnectedToFEAC(nDDL, nFEAC, iStripXsm, firstPadX,lastPadX);
768 for (Int_t index=0; index<6; index++) {
769 if (iStripXsm[index]==-1) continue;
771 for (Int_t iPadZ=0; iPadZ<AliTOFGeometry::NpadZ(); iPadZ++)
772 for (Int_t iPadX=firstPadX; iPadX<=lastPadX; iPadX++) {
773 AliTOFGeometry::GetStripAndModule(iStripXsm[index],plate,strip);
778 channel = AliTOFGeometry::GetIndex(det);
779 array[channel]=checkBit;
787 //---------------------------------------------------------------
788 void AliTOFLvHvDataPoints::GetStripsConnectedToFEAC(Int_t nDDL, Int_t nFEAC, Int_t *iStrip, Int_t &firstPadX, Int_t &lastPadX) const
791 // FEAC-strip mapping:
792 // return the strips and first PadX numbers
793 // connected to the FEAC number nFEAC in the crate number nDDL
796 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=-1;
798 if (nDDL<0 || nDDL>=kNddl || nFEAC<0 || nFEAC>=8) return;
803 lastPadX = AliTOFGeometry::NpadX()/2-1;
806 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC;
808 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC;
810 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-1;
812 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC-1;
814 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-2;
816 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC-2;
820 firstPadX = AliTOFGeometry::NpadX()/2;
821 lastPadX = AliTOFGeometry::NpadX()-1;
824 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC;
826 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC;
828 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-1;
830 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-1;
832 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=ii+6*nFEAC-1;
834 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=ii+6*nFEAC-2;
838 firstPadX = AliTOFGeometry::NpadX()/2;
839 lastPadX = AliTOFGeometry::NpadX()-1;
842 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC);
844 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC);
846 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
848 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
850 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-2);
852 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC-2);
857 lastPadX = AliTOFGeometry::NpadX()/2-1;
860 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC);
862 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC);
864 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
866 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
868 for (Int_t ii=0; ii<5; ii++) iStrip[ii]=90-(ii+6*nFEAC-1);
870 for (Int_t ii=0; ii<6; ii++) iStrip[ii]=90-(ii+6*nFEAC-2);
877 //---------------------------------------------------------------
878 void AliTOFLvHvDataPoints::Draw(const Option_t* /*option*/)
881 // Draw all histos and graphs
884 if(!fIsProcessed) return;
887 TString canvasHistoName="Histos";
888 ch = new TCanvas(canvasHistoName,canvasHistoName,20,20,600,600);
896 //---------------------------------------------------------------
897 void AliTOFLvHvDataPoints::DrawHVandLVMap(Int_t index)
900 // Draw HV+LV map labelled as index
903 const Int_t kSize = 100;
905 if(!fIsProcessed) return;
907 if (index>=fNumberOfHVandLVmaps) return;
909 AliTOFDCSmaps *mappa=(AliTOFDCSmaps*)GetHVandLVmap(index);
912 if (index==0) snprintf(title,kSize,"HVandLV map at time %d (%dst map)",mappa->GetTime(),index+1);
913 else if (index==1) snprintf(title,kSize,"HVandLV map at time %d (%dnd map)",mappa->GetTime(),index+1);
914 else if (index==2) snprintf(title,kSize,"HVandLV map at time %d (%drd map)",mappa->GetTime(),index+1);
915 else if (index>=3) snprintf(title,kSize,"HVandLV map at time %d (%dth map)",mappa->GetTime(),index+1);
917 fHisto = new TH1C("histo","",kNpads,-0.5,kNpads-0.5);
919 fHisto->SetTitle(title);
921 for (Int_t ii=0; ii<kNpads; ii++)
922 fHisto->SetBinContent(ii+1,mappa->GetCellValue(ii));
928 //---------------------------------------------------------------
929 void AliTOFLvHvDataPoints::DrawLVMap(Int_t index)
932 // Draw LV map labelled as index
935 const Int_t kSize = 100;
937 if(!fIsProcessed) return;
939 if (index>=fNumberOfLVdataPoints) return;
941 AliTOFDCSmaps *mappa=(AliTOFDCSmaps*)GetLVmap(index);
944 if (index==0) snprintf(title,kSize,"LV map at time %d (%dst map)",mappa->GetTime(),index+1);
945 else if (index==1) snprintf(title,kSize,"LV map at time %d (%dnd map)",mappa->GetTime(),index+1);
946 else if (index==2) snprintf(title,kSize,"LV map at time %d (%drd map)",mappa->GetTime(),index+1);
947 else if (index>=3) snprintf(title,kSize,"LV map at time %d (%dth map)",mappa->GetTime(),index+1);
949 fHisto = new TH1C("histo","",kNpads,-0.5,kNpads-0.5);
951 fHisto->SetTitle(title);
953 for (Int_t ii=0; ii<kNpads; ii++)
954 fHisto->SetBinContent(ii+1,mappa->GetCellValue(ii));
960 //---------------------------------------------------------------
961 void AliTOFLvHvDataPoints::DrawHVMap(Int_t index)
964 // Draw HV map labelled as index
967 const Int_t kSize = 100;
969 if(!fIsProcessed) return;
971 if (index>=fNumberOfHVdataPoints) return;
973 AliTOFDCSmaps *mappa=(AliTOFDCSmaps*)GetHVmap(index);
976 if (index==0) snprintf(title,kSize,"HV map at time %d (%dst map)",mappa->GetTime(),index+1);
977 else if (index==1) snprintf(title,kSize,"HV map at time %d (%dnd map)",mappa->GetTime(),index+1);
978 else if (index==2) snprintf(title,kSize,"HV map at time %d (%drd map)",mappa->GetTime(),index+1);
979 else if (index>=3) snprintf(title,kSize,"HV map at time %d (%dth map)",mappa->GetTime(),index+1);
981 fHisto = new TH1C("histo","",kNpads,-0.5,kNpads-0.5);
983 fHisto->SetTitle(title);
985 for (Int_t ii=0; ii<kNpads; ii++)
986 fHisto->SetBinContent(ii+1,mappa->GetCellValue(ii));
992 //---------------------------------------------------------------
993 AliTOFDCSmaps *AliTOFLvHvDataPoints::GetHVandLVmapAtEOR()
996 // Returns HVandLV status map at EOR.
997 // If the end-of-run has been caused by TOF self,
998 // the second-last value of HVandLV status map
999 // will be taken into account, i.e. the value immediately before
1000 // the change that caused EOR.
1001 // This last condition is true
1002 // if the time interval between the last map value and the EOR
1003 // is less than 60s.
1004 // If the run ended correctly, last map value will be take into account.
1005 // If nothing changed during the run, the SOR map will be take into account.
1008 AliTOFDCSmaps * lvANDhvMap = 0;
1010 if (fNumberOfHVandLVmaps==1) { // nothing changed during the run
1012 AliInfo(Form("Nothing changed in the TOF channels LV and HV status during the run number %d",fRun));
1014 lvANDhvMap = fMap[fNumberOfHVandLVmaps-1];
1019 if ( (fEndTimeDCSQuery-fMap[fNumberOfHVandLVmaps-1]->GetTime()<=fNSecondsBeforeEOR) ||
1020 (fEndTime-fMap[fNumberOfHVandLVmaps-1]->GetTime()<=fNSecondsBeforeEOR) ) {
1021 lvANDhvMap = (AliTOFDCSmaps*)fMap[fNumberOfHVandLVmaps-2];
1022 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));
1025 lvANDhvMap = (AliTOFDCSmaps*)fMap[fNumberOfHVandLVmaps-1];
1026 AliInfo(Form("The run number %d ended correctly. The last HVandLV map will be take into account.",fRun));