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