]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQAv1.cxx
Method GetCellPosition added.
[u/mrichter/AliRoot.git] / STEER / AliQAv1.cxx
1
2 /**************************************************************************
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  *                                                                        *
5  * Author: The ALICE Off-line Project.                                    *
6  * Contributors are mentioned in the code where appropriate.              *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16 /* $Id: AliQAv1.cxx 31503 2009-03-16 11:01:16Z schutz $ */
17
18 //////////////////////////////////////////////////////////////////////////////
19 //
20 // Quality Assurance Object//_________________________________________________________________________
21 // Quality Assurance object. The QA status is held in one word per detector,
22 // each bit corresponds to a different status.
23 // bit 0-3   : QA raised during simulation      (RAW)
24 // bit 4-7   : QA raised during simulation      (SIM)
25 // bit 8-11  : QA raised during reconstruction  (REC)
26 // bit 12-15 : QA raised during ESD checking    (ESD)
27 // bit 16-19 : QA raised during analysis        (ANA)
28 // Each of the 4 bits corresponds to a severity level of increasing importance
29 // from lower to higher bit (INFO, WARNING, ERROR, FATAL)
30 //
31 //*-- Yves Schutz CERN, July 2007 
32 //////////////////////////////////////////////////////////////////////////////
33
34
35 #include <cstdlib>
36 // --- ROOT system ---
37 #include <TClass.h>
38 #include <TFile.h>
39 #include <TSystem.h>
40 #include <TROOT.h>
41
42 // --- Standard library ---
43
44 // --- AliRoot header files ---
45 #include "AliLog.h"
46 #include "AliQAv1.h"
47
48
49 ClassImp(AliQAv1)
50 AliQAv1  *     AliQAv1::fgQA                   = 0x0 ;
51 TFile    *     AliQAv1::fgQADataFile           = 0x0 ;   
52 TString        AliQAv1::fgQADataFileName       = "QA" ;  // will transform into Det.QA.run.root  
53 TFile    *     AliQAv1::fgQARefFile            = 0x0 ;   
54 TString        AliQAv1::fgQARefDirName         = "" ; 
55 TString        AliQAv1::fgQARefFileName        = "QA.root" ;
56 TFile    *     AliQAv1::fgQAResultFile         = 0x0 ;  
57 TString        AliQAv1::fgQAResultDirName      = "" ;  
58 TString        AliQAv1::fgQAResultFileName     = "QA.root" ; 
59 TString        AliQAv1::fgDetNames[]           = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
60                                                   "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT", "Global", "CORR"} ;   
61 TString        AliQAv1::fgGRPPath              = "GRP/GRP/Data" ; 
62 TString        AliQAv1::fgTaskNames[]          = {"Raws", "Hits", "SDigits", "Digits", "DigitsR", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;   
63 TString        AliQAv1::fgModeNames[]          = {"", "Sim", "Rec"} ;   
64 const TString  AliQAv1::fgkLabLocalFile        = "file://"  ; 
65 const TString  AliQAv1::fgkLabLocalOCDB        = "local://" ;  
66 const TString  AliQAv1::fgkLabAliEnOCDB        = "alien://" ;  
67 const TString  AliQAv1::fgkRefFileName         = "QA.root" ; 
68 const TString  AliQAv1::fgkQAName              = "QA"  ; 
69 const TString  AliQAv1::fgkQACorrNtName        = "CorrQA" ;  
70 const TString  AliQAv1::fgkRefOCDBDirName      = "QA"  ; 
71 TString AliQAv1::fgRefDataDirName                    = ""  ; 
72 const TString  AliQAv1::fgkQARefOCDBDefault    = "alien://folder=/alice/QA/20"  ; 
73 const TString  AliQAv1::fgkExpert              = "Expert" ; 
74 const UInt_t   AliQAv1::fgkExpertBit           = 0x40000 ; 
75 const UInt_t   AliQAv1::fgkQABit               = 0x80000 ; 
76 const UInt_t   AliQAv1::fgkImageBit            = 0x100000 ; 
77 const Int_t    AliQAv1::fgkQADebugLevel        = 99 ; 
78 const TString  AliQAv1::fImageFileName         = "QAImage" ; 
79 const TString  AliQAv1::fImageFileFormat       = "ps" ; 
80 const UShort_t AliQAv1::fgkMaxQAObjects        = 10000 ; 
81
82 //____________________________________________________________________________
83 AliQAv1::AliQAv1() : 
84   TNamed("", ""), 
85   fNdet(kNDET), 
86   fNEventSpecies(AliRecoParam::kNSpecies), 
87   fLengthQA(fNdet*fNEventSpecies),
88   fQA(new ULong_t[fLengthQA]), 
89   fDet(kNULLDET),
90   fTask(kNULLTASK), 
91   fEventSpecie(AliRecoParam::kDefault), 
92   fEventSpecies(new Bool_t[fNEventSpecies])
93 {
94   // default constructor
95   memset(fQA,0,fLengthQA*sizeof(ULong_t));
96   memset(fEventSpecies,kFALSE,fNEventSpecies*sizeof(Bool_t));
97 }
98
99 //____________________________________________________________________________
100 AliQAv1::AliQAv1(const AliQAv1& qa) :
101   TNamed(qa),
102   fNdet(qa.fNdet), 
103   fNEventSpecies(qa.fNEventSpecies), 
104   fLengthQA(qa.fLengthQA),
105   fQA(new ULong_t[fLengthQA]), 
106   fDet(qa.fDet),
107   fTask(qa.fTask), 
108   fEventSpecie(qa.fEventSpecie), 
109   fEventSpecies(new Bool_t[fNEventSpecies])
110
111   // cpy ctor
112   memcpy(fQA,qa.fQA,fLengthQA*sizeof(ULong_t));
113   memcpy(fEventSpecies,qa.fEventSpecies,fNEventSpecies*sizeof(Bool_t));
114 }
115
116 //_____________________________________________________________________________
117 AliQAv1& AliQAv1::operator = (const AliQAv1& qa)
118 {
119   // assignment operator
120   if(&qa != this) {
121     TNamed::operator=(qa);
122     fNdet          = qa.fNdet;
123     fNEventSpecies = qa.fNEventSpecies; 
124     fLengthQA      = qa.fLengthQA;
125
126     if(fQA) delete [] fQA;
127     fQA = new ULong_t[fLengthQA];
128     memcpy(fQA,qa.fQA,fLengthQA*sizeof(ULong_t));
129
130     fDet = qa.fDet;
131     fTask = qa.fTask;
132     fEventSpecie = qa.fEventSpecie; 
133     if(fEventSpecies) delete [] fEventSpecies;
134     fEventSpecies = new Bool_t[fNEventSpecies];
135     memcpy(fEventSpecies,qa.fEventSpecies,fNEventSpecies*sizeof(Bool_t));
136   }  
137   return *this;
138 }
139
140 //_______________________________________________________________
141 AliQAv1::AliQAv1(const Int_t qalength, ULong_t * qa, const Int_t eslength, Bool_t * es) :
142 TNamed("QA", "Quality Assurance status"),
143 fNdet(kNDET), 
144 fNEventSpecies(eslength), 
145 fLengthQA(qalength),
146 fQA(new ULong_t[fLengthQA]), 
147 fDet(kNULLDET),
148 fTask(kNULLTASK), 
149 fEventSpecie(AliRecoParam::kDefault), 
150 fEventSpecies(new Bool_t[fNEventSpecies])
151 {
152   // constructor to be used
153   memcpy(fQA, qa, fLengthQA*sizeof(ULong_t));
154   memcpy(fEventSpecies, es, fNEventSpecies*sizeof(Bool_t));
155 }
156
157 //_______________________________________________________________
158 AliQAv1::AliQAv1(const DETECTORINDEX_t det) :
159   TNamed("QA", "Quality Assurance status"),
160   fNdet(kNDET), 
161   fNEventSpecies(AliRecoParam::kNSpecies), 
162   fLengthQA(fNdet*fNEventSpecies),
163   fQA(new ULong_t[fLengthQA]), 
164   fDet(det),
165   fTask(kNULLTASK), 
166   fEventSpecie(AliRecoParam::kDefault), 
167   fEventSpecies(new Bool_t[fNEventSpecies])
168 {
169   // constructor to be used
170   if (! CheckRange(det) ) fDet = kNULLDET ; 
171   memset(fQA,0,fLengthQA*sizeof(ULong_t));
172   memset(fEventSpecies,kFALSE,fNEventSpecies*sizeof(Bool_t));
173 }
174   
175 //_______________________________________________________________
176 AliQAv1::AliQAv1(const ALITASK_t tsk) :
177   TNamed("QA", "Quality Assurance status"),
178   fNdet(kNDET), 
179   fNEventSpecies(AliRecoParam::kNSpecies), 
180   fLengthQA(fNdet*fNEventSpecies),
181   fQA(new ULong_t[fLengthQA]), 
182   fDet(kNULLDET),
183   fTask(tsk), 
184   fEventSpecie(AliRecoParam::kDefault), 
185   fEventSpecies(new Bool_t[fNEventSpecies])
186 {
187   // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
188   if (! CheckRange(tsk) ) fTask = kNULLTASK ; 
189   memset(fQA,0,fLengthQA*sizeof(ULong_t));
190   memset(fEventSpecies,kFALSE,fNEventSpecies*sizeof(Bool_t));
191 }
192
193 //____________________________________________________________________________
194 AliQAv1::~AliQAv1() 
195 {
196   // dtor  
197   delete [] fQA;
198   delete [] fEventSpecies;
199 }
200
201 //_______________________________________________________________
202 void AliQAv1::Close() 
203 {
204         // close the open files
205         if (fgQADataFile) 
206                 if (fgQADataFile->IsOpen())
207                         fgQADataFile->Close() ; 
208         if (fgQAResultFile) 
209                 if (fgQAResultFile->IsOpen()) 
210                         fgQAResultFile->Close() ;
211         if (fgQARefFile)
212                 if (fgQARefFile->IsOpen())
213                         fgQARefFile->Close() ; 
214
215
216 //_______________________________________________________________
217 Bool_t AliQAv1::CheckFatal() const
218 {
219   // check if any FATAL status is set
220   Bool_t rv = kFALSE ;
221   Int_t index ;
222   for (index = 0; index < kNDET ; index++)
223     rv = rv || IsSet(DETECTORINDEX_t(index), fTask, fEventSpecie, kFATAL) ;
224   return rv ;
225 }
226
227 //_______________________________________________________________
228 Bool_t AliQAv1::CheckRange(DETECTORINDEX_t det) const
229
230   // check if detector is in given detector range: 0-kNDET
231
232   Bool_t rv = ( det < 0 || det > kNDET )  ? kFALSE : kTRUE ;
233   if (!rv)
234     AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
235   return rv ;
236 }
237
238 //_______________________________________________________________
239 Bool_t AliQAv1::CheckRange(ALITASK_t task) const
240
241   // check if task is given taskk range: 0:kNTASK
242   Bool_t rv = ( task < kRAW || task > kNTASK )  ? kFALSE : kTRUE ;
243   if (!rv)
244     AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
245   return rv ;
246 }
247
248 //_______________________________________________________________
249 Bool_t AliQAv1::CheckRange(QABIT_t bit) const
250
251   // check if bit is in given bit range: 0-kNBit
252
253   Bool_t rv = ( bit < 0 || bit > kNBIT )  ? kFALSE : kTRUE ;
254   if (!rv)
255     AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
256   return rv ;
257 }
258
259 //_______________________________________________________________
260 Bool_t AliQAv1::CheckRange(AliRecoParam::EventSpecie_t es) const
261
262   // check if bit is in given bit range: 0-kNBit
263   Bool_t rv = kFALSE ; 
264   switch (es) {
265     case AliRecoParam::kDefault: 
266       rv = kTRUE ; 
267       break ; 
268     case AliRecoParam::kLowMult: 
269       rv = kTRUE ; 
270       break ; 
271     case AliRecoParam::kHighMult: 
272       rv = kTRUE ; 
273       break ; 
274     case AliRecoParam::kCosmic: 
275       rv = kTRUE ; 
276       break ; 
277     case AliRecoParam::kCalib: 
278       rv = kTRUE ; 
279       break ; 
280   }
281   if (!rv)
282     AliFatal(Form("Event Specie %d is not valid", es)) ;
283   return rv ;
284 }
285
286 //_______________________________________________________________
287 const char * AliQAv1::GetAliTaskName(ALITASK_t tsk)
288 {
289         // returns the char name corresponding to module index
290         TString tskName ;
291         switch (tsk) {
292                 case kNULLTASK:
293                         break ; 
294                 case kRAW:
295                         tskName = "RAW" ;
296                         break ;  
297                 case kSIM:
298                         tskName = "SIM" ;
299                         break ;
300                 case kREC:
301                         tskName = "REC" ;
302                         break ;
303                 case kESD:
304                         tskName = "ESD" ;
305                         break ;
306                 case kANA:
307                         tskName = "ANA" ;
308                         break ;
309                 default:
310                         tsk = kNULLTASK ; 
311                         break ;
312         }
313         return tskName.Data() ;
314 }
315
316 //_______________________________________________________________
317 const char * AliQAv1::GetBitName(QABIT_t bit) const
318 {
319         // returns the char name corresponding to bit 
320         TString bitName ;
321         switch (bit) {
322                 case kNULLBit:
323                         break ; 
324                 case kINFO:
325                         bitName = "INFO" ;
326                         break ;  
327                 case kWARNING:
328                         bitName = "WARNING" ;
329                         break ;
330                 case kERROR:
331                         bitName = "ERROR" ;
332                         break ;
333                 case kFATAL:
334                         bitName = "FATAL" ;
335                         break ;
336                 default:
337                         bit = kNULLBit ; 
338                         break ;
339         }
340         return bitName.Data() ;
341 }
342
343 //_______________________________________________________________
344 AliQAv1::DETECTORINDEX_t AliQAv1::GetDetIndex(const char * name) 
345 {
346         // returns the detector index corresponding to a given name
347         TString sname(name) ; 
348         DETECTORINDEX_t rv = kNULLDET ; 
349         for (Int_t det = 0; det < kNDET ; det++) {
350                 if ( GetDetName(det) == sname ) {
351                         rv = DETECTORINDEX_t(det) ; 
352                         break ; 
353                 }
354         }
355         return rv ;             
356 }
357
358 //_______________________________________________________________
359 const char * AliQAv1::GetDetName(Int_t det) 
360 {
361         // returns the detector name corresponding to a given index (needed in a loop)
362         
363         if ( det >= 0 &&  det < kNDET) 
364                 return (fgDetNames[det]).Data() ; 
365         else 
366                 return NULL ; 
367 }
368
369 //_______________________________________________________________
370 TFile * AliQAv1::GetQADataFile(const char * name, Int_t run) 
371 {
372   // opens the file to store the detectors Quality Assurance Data Maker results
373         const char * temp = Form("%s.%s.%d.root", name, fgQADataFileName.Data(), run) ; 
374         TString opt ; 
375         if (! fgQADataFile ) {     
376                 if  (gSystem->AccessPathName(temp))
377                         opt = "NEW" ;
378                 else 
379                         opt = "UPDATE" ; 
380                 fgQADataFile = TFile::Open(temp, opt.Data()) ;
381         } else {
382                 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
383                         fgQADataFile = static_cast<TFile *>(gROOT->FindObject(temp)) ;
384                         if ( !fgQADataFile ) {
385           if  (gSystem->AccessPathName(temp))
386             opt = "NEW" ;
387           else 
388             opt = "UPDATE" ; 
389                                 fgQADataFile = TFile::Open(temp, opt.Data()) ;
390                         }
391                 }
392   }
393         return fgQADataFile ;
394
395
396 //_____________________________________________________________________________
397 AliQAv1::MODE_t AliQAv1::Mode(TASKINDEX_t task) {
398   // return "rec" or "sim" depending on the task
399   
400   switch (task) {
401     case AliQAv1::kRAWS:
402       return kRECMODE ; 
403       break;
404     case AliQAv1::kHITS:
405       return kSIMMODE ; 
406       break;
407     case AliQAv1::kSDIGITS:
408       return kSIMMODE ; 
409       break;
410     case AliQAv1::kDIGITS:
411       return kSIMMODE ; 
412       break;
413     case AliQAv1::kDIGITSR:
414       return kRECMODE ; 
415       break;
416     case AliQAv1::kRECPOINTS:
417       return kRECMODE ; 
418       break ; 
419     case AliQAv1::kTRACKSEGMENTS:
420       return kRECMODE ; 
421       break;
422     case AliQAv1::kRECPARTICLES:
423       return kRECMODE ; 
424       break;
425     case AliQAv1::kESDS:
426       return kRECMODE ; 
427       break;
428     default:
429       break;
430   }
431 }
432
433 //_____________________________________________________________________________
434 TFile * AliQAv1::GetQADataFile(const char * fileName)
435 {
436   // Open if necessary the Data file and return its pointer
437
438   if (!fgQADataFile) 
439         if (!fileName) 
440                 fileName = AliQAv1::GetQADataFileName() ; 
441         if  (!gSystem->AccessPathName(fileName)) {
442                 fgQADataFile =  TFile::Open(fileName) ;
443         } else {
444                 AliFatalClass(Form("File %s not found", fileName)) ;
445         }
446   return fgQADataFile ; 
447 }
448
449 //_______________________________________________________________
450 TFile * AliQAv1::GetQAResultFile() 
451 {
452   // opens the file to store the  Quality Assurance Data Checker results
453         if (fgQAResultFile) 
454                 fgQAResultFile->Close() ; 
455         fgQAResultFile = 0x0 ; 
456 //      if (!fgQAResultFile) { 
457                 TString dirName(fgQAResultDirName) ; 
458                 if ( dirName.Contains(fgkLabLocalFile)) 
459                         dirName.ReplaceAll(fgkLabLocalFile, "") ;
460                 TString fileName(dirName + fgQAResultFileName) ; 
461                 TString opt("") ; 
462                 if ( !gSystem->AccessPathName(fileName) )
463                         opt = "UPDATE" ; 
464                 else { 
465                         if ( gSystem->AccessPathName(dirName) )
466                                 gSystem->mkdir(dirName) ; 
467                         opt = "NEW" ; 
468                 }
469                 fgQAResultFile = TFile::Open(fileName, opt) ;   
470 //      }
471         
472         return fgQAResultFile ;
473 }
474
475 //_______________________________________________________________
476 AliQAv1::TASKINDEX_t AliQAv1::GetTaskIndex(const char * name) 
477 {
478         // returns the detector index corresponding to a given name
479         TString sname(name) ; 
480         TASKINDEX_t rv = kNULLTASKINDEX ; 
481         for (Int_t tsk = 0; tsk < kNTASKINDEX ; tsk++) {
482                 if ( GetTaskName(tsk) == sname ) {
483                         rv = TASKINDEX_t(tsk) ; 
484                         break ; 
485                 }
486         }
487         return rv ;             
488 }
489
490 //_______________________________________________________________
491 Bool_t AliQAv1::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, Int_t ies, QABIT_t bit) const 
492 {
493   // Checks is the requested bit is set
494    
495   const AliRecoParam::EventSpecie_t es = AliRecoParam::Convert(ies) ; 
496   return IsSet(det, tsk, es, bit) ; 
497   
498 }  
499
500 //_______________________________________________________________
501 Bool_t AliQAv1::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit) const
502 {
503   // Checks is the requested bit is set
504         
505   CheckRange(det) ; 
506   CheckRange(tsk) ;
507   CheckRange(bit) ;
508   CheckRange(es) ;
509         
510   ULong_t offset = Offset(tsk) ;
511   ULong_t status = GetStatus(det, es) ;
512   offset+= bit ;
513   status = (status & 1 << offset) != 0 ;
514   return status ;
515 }
516
517 //_______________________________________________________________
518 Bool_t AliQAv1::IsSetAny(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
519 {
520   // Checks is the requested bit is set
521         
522   CheckRange(det) ; 
523   CheckRange(tsk) ;
524   CheckRange(es) ;
525         
526   ULong_t offset = Offset(tsk) ;
527   ULong_t status = GetStatus(det, es) ;
528         ULong_t st = 0 ; 
529         for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
530                 offset+= bit ;
531                 st += (status & 1 << offset) != 0 ;             
532         }
533         if ( st == 0 ) 
534                 return kFALSE ; 
535         else 
536                 return kTRUE ;
537 }
538 //_______________________________________________________________
539 Bool_t AliQAv1::IsSetAny(DETECTORINDEX_t det, AliRecoParam::EventSpecie_t es) const
540 {
541   // Checks is the requested bit is set
542         
543   CheckRange(det) ; 
544   CheckRange(es) ; 
545         
546         ULong_t status = GetStatus(det, es) ;
547         ULong_t st = 0 ; 
548         for ( Int_t tsk = 0 ; tsk < kNTASK ; tsk++) {
549                 ULong_t offset = Offset(ALITASK_t(tsk)) ;
550                 for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
551                         offset+= bit ;
552                         st += (status & 1 << offset) != 0 ;             
553                 }
554         }
555         if ( st == 0 ) 
556                 return kFALSE ; 
557         else 
558                 return kTRUE ;
559 }
560
561 //_______________________________________________________________
562 AliQAv1 * AliQAv1::Instance()
563 {
564   // Get an instance of the singleton. The only authorized way to call the ctor
565
566   if ( ! fgQA) {
567     TFile * f = GetQAResultFile() ; 
568     fgQA = static_cast<AliQAv1 *>(f->Get("QA")) ; 
569     if ( ! fgQA ) 
570       fgQA = new AliQAv1() ;
571   }
572   return fgQA ;
573 }
574
575 //_______________________________________________________________
576 AliQAv1 * AliQAv1::Instance(const Int_t qalength, ULong_t * qa, const Int_t eslength, Bool_t * es)
577 {
578   // Get an instance of the singleton. The only authorized way to call the ctor
579   
580   if ( ! fgQA) 
581     fgQA = new AliQAv1(qalength, qa, eslength, es) ;
582   return fgQA ;
583 }
584
585 //_______________________________________________________________
586 AliQAv1 * AliQAv1::Instance(const DETECTORINDEX_t det)
587 {
588   // Get an instance of the singleton. The only authorized way to call the ctor
589   
590   if ( ! fgQA) {
591     TFile * f = GetQAResultFile() ; 
592     fgQA = static_cast<AliQAv1 *>(f->Get("QA")) ; 
593     if ( ! fgQA ) 
594       fgQA = new AliQAv1(det) ;
595   }             
596   fgQA->Set(det) ;
597   return fgQA ;
598 }
599
600 //_______________________________________________________________
601 AliQAv1 * AliQAv1::Instance(const ALITASK_t tsk)
602 {
603   // Get an instance of the singleton. The only authorized way to call the ctor
604
605   if ( ! fgQA)
606     switch (tsk) {
607     case kNULLTASK:
608       break ;
609         case kRAW:
610       fgQA = new AliQAv1(tsk) ;
611       break ;
612         case kSIM:
613       fgQA = new AliQAv1(tsk) ;
614       break ;
615     case kREC:
616       AliInfoClass("fgQA = gAlice->GetQA()") ;
617       break ;
618     case kESD:
619       AliInfoClass("fgQA = static_cast<AliQAv1 *> (esdFile->Get(\"QA\")") ;
620       break ;
621     case kANA:
622       AliInfoClass("fgQA = static_cast<AliQAv1 *> (esdFile->Get(\"QA\")") ;
623       break ;
624     case kNTASK:
625       break ;
626     }
627   if (fgQA) 
628     fgQA->Set(tsk) ;
629   return fgQA ;
630 }
631
632 //_______________________________________________________________
633 AliQAv1 *  AliQAv1::Instance(const TASKINDEX_t tsk) 
634 {
635         // get an instance of the singleton.
636         
637         ALITASK_t index = kNULLTASK ; 
638
639         if ( tsk == kRAWS )
640                 index = kRAW ;
641         else if (tsk < kDIGITS)
642                 index = kSIM ;
643         else if (tsk < kRECPARTICLES)
644                 index = kREC ; 
645         else if (tsk == kESDS) 
646                 index = kESD ; 
647
648         return Instance(index) ; 
649 }
650
651 //_______________________________________________________________
652 void AliQAv1::Merge(TCollection * list) {
653         // Merge the QA resuls in the list into this single AliQAv1 object
654         
655         for (Int_t det = 0 ; det < kNDET ; det++) {
656                 Set(DETECTORINDEX_t(det)) ; 
657                 for (Int_t task = 0 ; task < kNTASK ; task++) {
658                         Set(ALITASK_t(task)) ; 
659                         for (Int_t bit = 0 ; bit < kNBIT ; bit++) {
660                                 TIter next(list) ;
661                                 AliQAv1 * qa ; 
662                                 while ( (qa = (AliQAv1*)next() ) ) {
663           for (Int_t es = 0 ; es < fNEventSpecies ; es++) {
664             if (qa->IsSet(DETECTORINDEX_t(det), ALITASK_t(task), es, QABIT_t(bit)))
665               Set(QABIT_t(bit), es) ; 
666           }
667                                 } // qa list
668                         } // bit
669                 } // task
670         } // detector
671 }
672
673 //_______________________________________________________________
674 ULong_t AliQAv1::Offset(ALITASK_t tsk) const
675 {
676   // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
677
678   CheckRange(tsk) ; 
679
680   ULong_t offset = 0 ;
681   switch (tsk) {
682   case kNULLTASK:
683     break ;
684   case kRAW:
685     offset+= 0 ;
686     break ;
687   case kSIM:
688     offset+= 4 ;
689     break ;
690   case kREC:
691     offset+= 8 ;
692     break ;
693   case kESD:
694     offset+= 12 ;
695     break ;
696   case kANA:
697     offset+= 16 ;
698     break ;
699   case kNTASK:
700     break ;
701   }
702
703   return offset ;
704 }
705
706 //_______________________________________________________________
707 void AliQAv1::ResetStatus(DETECTORINDEX_t det) 
708
709   // reset the status of det for all event specie
710   for (Int_t es = 0 ; es < fNEventSpecies ; es++)
711     fQA[det*fNdet+es] = 0 ; 
712 }
713
714 //_______________________________________________________________
715 void AliQAv1::Set(QABIT_t bit, Int_t ies)
716 {
717   // Set the status bit of the current detector in the current module and for the current event specie 
718    Set(bit, AliRecoParam::Convert(ies)) ;
719 }
720
721 //_______________________________________________________________
722 void AliQAv1::Set(QABIT_t bit, AliRecoParam::EventSpecie_t es)
723 {
724   // Set the status bit of the current detector in the current module and for the current event specie 
725   
726   SetStatusBit(fDet, fTask, es, bit) ;
727 }
728
729 //_____________________________________________________________________________
730 void AliQAv1::SetQARefStorage(const char * name)
731 {
732         // Set the root directory where the QA reference data are stored
733
734         fgQARefDirName = name ; 
735         if ( fgQARefDirName.Contains(fgkLabLocalFile) )
736                 fgQARefFileName =  fgkRefFileName ; 
737         else if ( fgQARefDirName.Contains(fgkLabLocalOCDB) )
738                 fgQARefFileName =  fgkQAName ; 
739         else if ( fgQARefDirName.Contains(fgkLabAliEnOCDB) )
740                 fgQARefFileName =  fgkQAName ; 
741
742   else {
743           AliErrorClass(Form("ERROR: %s is an invalid storage definition\n", name)) ; 
744           fgQARefDirName  = "" ; 
745           fgQARefFileName = "" ; 
746   }     
747         TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
748         AliInfoClass(Form("AliQAv1::SetQARefDir: QA references are in  %s\n", tmp.Data() )) ;
749 }
750
751 //_____________________________________________________________________________
752 void AliQAv1::SetQAResultDirName(const char * name)
753 {
754   // Set the root directory where to store the QA status object
755
756   fgQAResultDirName.Prepend(name) ; 
757   AliInfoClass(Form("AliQAv1::SetQAResultDirName: QA results are in  %s\n", fgQAResultDirName.Data())) ;
758   if ( fgQAResultDirName.Contains(fgkLabLocalFile)) 
759     fgQAResultDirName.ReplaceAll(fgkLabLocalFile, "") ;
760   fgQAResultFileName.Prepend(fgQAResultDirName) ;
761 }
762
763 //_______________________________________________________________
764 void AliQAv1::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
765 {
766  // Set the status bit for a given detector and a given task
767
768   CheckRange(det) ;
769   CheckRange(tsk) ;
770   CheckRange(bit) ;
771   CheckRange(es) ;
772
773   ULong_t offset = Offset(tsk) ;
774   ULong_t status = GetStatus(det, es) ;
775   offset+= bit ;
776   status = status | 1 << offset ;
777   SetStatus(det, es, status) ;
778 }
779
780 //_______________________________________________________________
781 void AliQAv1::Show(DETECTORINDEX_t det) const 
782
783   // dispplay the QA status word
784   if ( det == kNULLDET) 
785     det = fDet ;  
786   for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
787     if ( IsEventSpecieSet(ies) )
788       ShowStatus(det, kNULLTASK, AliRecoParam::ConvertIndex(ies)) ; 
789   }
790 }
791
792 //_______________________________________________________________
793 void AliQAv1::ShowAll() const 
794 {
795   // dispplay the QA status word
796   Int_t index ;
797   for (index = 0 ; index < kNDET ; index++) {
798                 for (Int_t tsk = kRAW ; tsk < kNTASK ; tsk++) {
799       for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
800         if ( IsEventSpecieSet(ies) )
801           ShowStatus(DETECTORINDEX_t(index), ALITASK_t(tsk), AliRecoParam::ConvertIndex(ies)) ;
802       }
803     }
804         }
805 }
806
807 //_______________________________________________________________
808 void AliQAv1::ShowStatus(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
809 {
810         // Prints the full QA status of a given detector
811         CheckRange(det) ;
812         CheckRange(es) ;
813         ULong_t status = GetStatus(det, es) ;
814         ULong_t tskStatus[kNTASK] ; 
815         tskStatus[kRAW] = status & 0x0000f ;
816         tskStatus[kSIM] = status & 0x000f0 ;
817         tskStatus[kREC] = status & 0x00f00 ;
818         tskStatus[kESD] = status & 0x0f000 ;
819         tskStatus[kANA] = status & 0xf0000 ;
820
821         AliInfo(Form("====> QA Status for %8s %8s raw =0x%x, sim=0x%x, rec=0x%x, esd=0x%x, ana=0x%x", GetDetName(det).Data(), AliRecoParam::GetEventSpecieName(es), 
822                                  tskStatus[kRAW], tskStatus[kSIM], tskStatus[kREC], tskStatus[kESD], tskStatus[kANA] )) ;
823         if (tsk == kNULLTASK) {
824                 for (Int_t itsk = kRAW ; itsk < kNTASK ; itsk++) {
825                         ShowASCIIStatus(es, det, ALITASK_t(itsk), tskStatus[itsk]) ; 
826                 } 
827         } else {
828                         ShowASCIIStatus(es, det, tsk, tskStatus[tsk]) ; 
829         }
830 }
831
832 //_______________________________________________________________
833 void AliQAv1::ShowASCIIStatus(AliRecoParam::EventSpecie_t es, DETECTORINDEX_t det, ALITASK_t tsk, const ULong_t status) const 
834 {
835         // print the QA status in human readable format
836         TString text; 
837         for (Int_t bit = kINFO ; bit < kNBIT ; bit++) {
838                 if (IsSet(det, tsk, es, QABIT_t(bit))) {
839                         text = GetBitName(QABIT_t(bit)) ; 
840                         text += " " ; 
841                 }
842         }
843         if (! text.IsNull())
844                 AliInfoClass(Form("           %8s %8s %4s 0x%4lx, Problem signalled: %8s \n", AliRecoParam::GetEventSpecieName(es), GetDetName(det).Data(), GetAliTaskName(tsk), status, text.Data())) ; 
845 }
846
847 //_______________________________________________________________
848 void AliQAv1::UnSet(QABIT_t bit, Int_t ies)
849 {
850         // UnSet the status bit of the current detector in the current module
851                 UnSet(bit, AliRecoParam::Convert(ies)) ;
852 }
853
854 //_______________________________________________________________
855 void AliQAv1::UnSet(QABIT_t bit, AliRecoParam::EventSpecie_t es)
856 {
857         // UnSet the status bit of the current detector in the current module
858         
859         UnSetStatusBit(fDet, fTask, es, bit) ;
860 }
861
862 //_______________________________________________________________
863 void AliQAv1::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
864 {
865         // UnSet the status bit for a given detector and a given task
866         
867         CheckRange(det) ;
868         CheckRange(tsk) ;
869         CheckRange(bit) ;
870         CheckRange(es) ;
871         
872         ULong_t offset = Offset(tsk) ;
873         ULong_t status = GetStatus(det, es) ;
874         offset+= bit ;
875         status = status & 0 << offset ;
876         SetStatus(det, es, status) ;
877 }