]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQAv1.cxx
24be2719f45530b3e3440d671156b98722de52d0
[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   return AliQAv1::kNULLMODE;
432 }
433
434 //_____________________________________________________________________________
435 TFile * AliQAv1::GetQADataFile(const char * fileName)
436 {
437   // Open if necessary the Data file and return its pointer
438
439   if (!fgQADataFile) {
440     if (!fileName) 
441       fileName = AliQAv1::GetQADataFileName() ; 
442     if  (!gSystem->AccessPathName(fileName)) {
443       fgQADataFile =  TFile::Open(fileName) ;
444     } else {
445       AliFatalClass(Form("File %s not found", fileName)) ;
446     }
447   }
448   return fgQADataFile ; 
449 }
450
451 //_______________________________________________________________
452 TFile * AliQAv1::GetQAResultFile() 
453 {
454   // opens the file to store the  Quality Assurance Data Checker results
455         if (fgQAResultFile) 
456                 fgQAResultFile->Close() ; 
457         fgQAResultFile = 0x0 ; 
458 //      if (!fgQAResultFile) { 
459                 TString dirName(fgQAResultDirName) ; 
460                 if ( dirName.Contains(fgkLabLocalFile)) 
461                         dirName.ReplaceAll(fgkLabLocalFile, "") ;
462                 TString fileName(dirName + fgQAResultFileName) ; 
463                 TString opt("") ; 
464                 if ( !gSystem->AccessPathName(fileName) )
465                         opt = "UPDATE" ; 
466                 else { 
467                         if ( gSystem->AccessPathName(dirName) )
468                                 gSystem->mkdir(dirName) ; 
469                         opt = "NEW" ; 
470                 }
471                 fgQAResultFile = TFile::Open(fileName, opt) ;   
472 //      }
473         
474         return fgQAResultFile ;
475 }
476
477 //_______________________________________________________________
478 AliQAv1::TASKINDEX_t AliQAv1::GetTaskIndex(const char * name) 
479 {
480         // returns the detector index corresponding to a given name
481         TString sname(name) ; 
482         TASKINDEX_t rv = kNULLTASKINDEX ; 
483         for (Int_t tsk = 0; tsk < kNTASKINDEX ; tsk++) {
484                 if ( GetTaskName(tsk) == sname ) {
485                         rv = TASKINDEX_t(tsk) ; 
486                         break ; 
487                 }
488         }
489         return rv ;             
490 }
491
492 //_______________________________________________________________
493 Bool_t AliQAv1::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, Int_t ies, QABIT_t bit) const 
494 {
495   // Checks is the requested bit is set
496    
497   const AliRecoParam::EventSpecie_t es = AliRecoParam::Convert(ies) ; 
498   return IsSet(det, tsk, es, bit) ; 
499   
500 }  
501
502 //_______________________________________________________________
503 Bool_t AliQAv1::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit) const
504 {
505   // Checks is the requested bit is set
506         
507   CheckRange(det) ; 
508   CheckRange(tsk) ;
509   CheckRange(bit) ;
510   CheckRange(es) ;
511         
512   ULong_t offset = Offset(tsk) ;
513   ULong_t status = GetStatus(det, es) ;
514   offset+= bit ;
515   status = (status & 1 << offset) != 0 ;
516   return status ;
517 }
518
519 //_______________________________________________________________
520 Bool_t AliQAv1::IsSetAny(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
521 {
522   // Checks is the requested bit is set
523         
524   CheckRange(det) ; 
525   CheckRange(tsk) ;
526   CheckRange(es) ;
527         
528   ULong_t offset = Offset(tsk) ;
529   ULong_t status = GetStatus(det, es) ;
530         ULong_t st = 0 ; 
531         for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
532                 offset+= bit ;
533                 st += (status & 1 << offset) != 0 ;             
534         }
535         if ( st == 0 ) 
536                 return kFALSE ; 
537         else 
538                 return kTRUE ;
539 }
540 //_______________________________________________________________
541 Bool_t AliQAv1::IsSetAny(DETECTORINDEX_t det, AliRecoParam::EventSpecie_t es) const
542 {
543   // Checks is the requested bit is set
544         
545   CheckRange(det) ; 
546   CheckRange(es) ; 
547         
548         ULong_t status = GetStatus(det, es) ;
549         ULong_t st = 0 ; 
550         for ( Int_t tsk = 0 ; tsk < kNTASK ; tsk++) {
551                 ULong_t offset = Offset(ALITASK_t(tsk)) ;
552                 for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
553                         offset+= bit ;
554                         st += (status & 1 << offset) != 0 ;             
555                 }
556         }
557         if ( st == 0 ) 
558                 return kFALSE ; 
559         else 
560                 return kTRUE ;
561 }
562
563 //_______________________________________________________________
564 AliQAv1 * AliQAv1::Instance()
565 {
566   // Get an instance of the singleton. The only authorized way to call the ctor
567
568   if ( ! fgQA) {
569     TFile * f = GetQAResultFile() ; 
570     fgQA = static_cast<AliQAv1 *>(f->Get("QA")) ; 
571     if ( ! fgQA ) 
572       fgQA = new AliQAv1() ;
573   }
574   return fgQA ;
575 }
576
577 //_______________________________________________________________
578 AliQAv1 * AliQAv1::Instance(const Int_t qalength, ULong_t * qa, const Int_t eslength, Bool_t * es)
579 {
580   // Get an instance of the singleton. The only authorized way to call the ctor
581   
582   if ( ! fgQA) 
583     fgQA = new AliQAv1(qalength, qa, eslength, es) ;
584   return fgQA ;
585 }
586
587 //_______________________________________________________________
588 AliQAv1 * AliQAv1::Instance(const DETECTORINDEX_t det)
589 {
590   // Get an instance of the singleton. The only authorized way to call the ctor
591   
592   if ( ! fgQA) {
593     TFile * f = GetQAResultFile() ; 
594     fgQA = static_cast<AliQAv1 *>(f->Get("QA")) ; 
595     if ( ! fgQA ) 
596       fgQA = new AliQAv1(det) ;
597   }             
598   fgQA->Set(det) ;
599   return fgQA ;
600 }
601
602 //_______________________________________________________________
603 AliQAv1 * AliQAv1::Instance(const ALITASK_t tsk)
604 {
605   // Get an instance of the singleton. The only authorized way to call the ctor
606
607   if ( ! fgQA)
608     switch (tsk) {
609     case kNULLTASK:
610       break ;
611         case kRAW:
612       fgQA = new AliQAv1(tsk) ;
613       break ;
614         case kSIM:
615       fgQA = new AliQAv1(tsk) ;
616       break ;
617     case kREC:
618       AliInfoClass("fgQA = gAlice->GetQA()") ;
619       break ;
620     case kESD:
621       AliInfoClass("fgQA = static_cast<AliQAv1 *> (esdFile->Get(\"QA\")") ;
622       break ;
623     case kANA:
624       AliInfoClass("fgQA = static_cast<AliQAv1 *> (esdFile->Get(\"QA\")") ;
625       break ;
626     case kNTASK:
627       break ;
628     }
629   if (fgQA) 
630     fgQA->Set(tsk) ;
631   return fgQA ;
632 }
633
634 //_______________________________________________________________
635 AliQAv1 *  AliQAv1::Instance(const TASKINDEX_t tsk) 
636 {
637         // get an instance of the singleton.
638         
639         ALITASK_t index = kNULLTASK ; 
640
641         if ( tsk == kRAWS )
642                 index = kRAW ;
643         else if (tsk < kDIGITS)
644                 index = kSIM ;
645         else if (tsk < kRECPARTICLES)
646                 index = kREC ; 
647         else if (tsk == kESDS) 
648                 index = kESD ; 
649
650         return Instance(index) ; 
651 }
652
653 //_______________________________________________________________
654 void AliQAv1::Merge(TCollection * list) {
655         // Merge the QA resuls in the list into this single AliQAv1 object
656         
657         for (Int_t det = 0 ; det < kNDET ; det++) {
658                 Set(DETECTORINDEX_t(det)) ; 
659                 for (Int_t task = 0 ; task < kNTASK ; task++) {
660                         Set(ALITASK_t(task)) ; 
661                         for (Int_t bit = 0 ; bit < kNBIT ; bit++) {
662                                 TIter next(list) ;
663                                 AliQAv1 * qa ; 
664                                 while ( (qa = (AliQAv1*)next() ) ) {
665           for (Int_t es = 0 ; es < fNEventSpecies ; es++) {
666             if (qa->IsSet(DETECTORINDEX_t(det), ALITASK_t(task), es, QABIT_t(bit)))
667               Set(QABIT_t(bit), es) ; 
668           }
669                                 } // qa list
670                         } // bit
671                 } // task
672         } // detector
673 }
674
675 //_______________________________________________________________
676 ULong_t AliQAv1::Offset(ALITASK_t tsk) const
677 {
678   // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
679
680   CheckRange(tsk) ; 
681
682   ULong_t offset = 0 ;
683   switch (tsk) {
684   case kNULLTASK:
685     break ;
686   case kRAW:
687     offset+= 0 ;
688     break ;
689   case kSIM:
690     offset+= 4 ;
691     break ;
692   case kREC:
693     offset+= 8 ;
694     break ;
695   case kESD:
696     offset+= 12 ;
697     break ;
698   case kANA:
699     offset+= 16 ;
700     break ;
701   case kNTASK:
702     break ;
703   }
704
705   return offset ;
706 }
707
708 //_______________________________________________________________
709 void AliQAv1::ResetStatus(DETECTORINDEX_t det) 
710
711   // reset the status of det for all event specie
712   for (Int_t es = 0 ; es < fNEventSpecies ; es++)
713     fQA[det*fNdet+es] = 0 ; 
714 }
715
716 //_______________________________________________________________
717 void AliQAv1::Set(QABIT_t bit, Int_t ies)
718 {
719   // Set the status bit of the current detector in the current module and for the current event specie 
720    Set(bit, AliRecoParam::Convert(ies)) ;
721 }
722
723 //_______________________________________________________________
724 void AliQAv1::Set(QABIT_t bit, AliRecoParam::EventSpecie_t es)
725 {
726   // Set the status bit of the current detector in the current module and for the current event specie 
727   
728   SetStatusBit(fDet, fTask, es, bit) ;
729 }
730
731 //_____________________________________________________________________________
732 void AliQAv1::SetQARefStorage(const char * name)
733 {
734         // Set the root directory where the QA reference data are stored
735
736         fgQARefDirName = name ; 
737         if ( fgQARefDirName.Contains(fgkLabLocalFile) )
738                 fgQARefFileName =  fgkRefFileName ; 
739         else if ( fgQARefDirName.Contains(fgkLabLocalOCDB) )
740                 fgQARefFileName =  fgkQAName ; 
741         else if ( fgQARefDirName.Contains(fgkLabAliEnOCDB) )
742                 fgQARefFileName =  fgkQAName ; 
743
744   else {
745           AliErrorClass(Form("ERROR: %s is an invalid storage definition\n", name)) ; 
746           fgQARefDirName  = "" ; 
747           fgQARefFileName = "" ; 
748   }     
749         TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
750         AliInfoClass(Form("AliQAv1::SetQARefDir: QA references are in  %s\n", tmp.Data() )) ;
751 }
752
753 //_____________________________________________________________________________
754 void AliQAv1::SetQAResultDirName(const char * name)
755 {
756   // Set the root directory where to store the QA status object
757
758   fgQAResultDirName.Prepend(name) ; 
759   AliInfoClass(Form("AliQAv1::SetQAResultDirName: QA results are in  %s\n", fgQAResultDirName.Data())) ;
760   if ( fgQAResultDirName.Contains(fgkLabLocalFile)) 
761     fgQAResultDirName.ReplaceAll(fgkLabLocalFile, "") ;
762   fgQAResultFileName.Prepend(fgQAResultDirName) ;
763 }
764
765 //_______________________________________________________________
766 void AliQAv1::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
767 {
768  // Set the status bit for a given detector and a given task
769
770   CheckRange(det) ;
771   CheckRange(tsk) ;
772   CheckRange(bit) ;
773   CheckRange(es) ;
774
775   ULong_t offset = Offset(tsk) ;
776   ULong_t status = GetStatus(det, es) ;
777   offset+= bit ;
778   status = status | 1 << offset ;
779   SetStatus(det, es, status) ;
780 }
781
782 //_______________________________________________________________
783 void AliQAv1::Show(DETECTORINDEX_t det) const 
784
785   // dispplay the QA status word
786   if ( det == kNULLDET) 
787     det = fDet ;  
788   for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
789     if ( IsEventSpecieSet(ies) )
790       ShowStatus(det, kNULLTASK, AliRecoParam::ConvertIndex(ies)) ; 
791   }
792 }
793
794 //_______________________________________________________________
795 void AliQAv1::ShowAll() const 
796 {
797   // dispplay the QA status word
798   Int_t index ;
799   for (index = 0 ; index < kNDET ; index++) {
800                 for (Int_t tsk = kRAW ; tsk < kNTASK ; tsk++) {
801       for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
802         if ( IsEventSpecieSet(ies) )
803           ShowStatus(DETECTORINDEX_t(index), ALITASK_t(tsk), AliRecoParam::ConvertIndex(ies)) ;
804       }
805     }
806         }
807 }
808
809 //_______________________________________________________________
810 void AliQAv1::ShowStatus(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
811 {
812         // Prints the full QA status of a given detector
813         CheckRange(det) ;
814         CheckRange(es) ;
815         ULong_t status = GetStatus(det, es) ;
816         ULong_t tskStatus[kNTASK] ; 
817         tskStatus[kRAW] = status & 0x0000f ;
818         tskStatus[kSIM] = status & 0x000f0 ;
819         tskStatus[kREC] = status & 0x00f00 ;
820         tskStatus[kESD] = status & 0x0f000 ;
821         tskStatus[kANA] = status & 0xf0000 ;
822
823         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), 
824                                  tskStatus[kRAW], tskStatus[kSIM], tskStatus[kREC], tskStatus[kESD], tskStatus[kANA] )) ;
825         if (tsk == kNULLTASK) {
826                 for (Int_t itsk = kRAW ; itsk < kNTASK ; itsk++) {
827                         ShowASCIIStatus(es, det, ALITASK_t(itsk), tskStatus[itsk]) ; 
828                 } 
829         } else {
830                         ShowASCIIStatus(es, det, tsk, tskStatus[tsk]) ; 
831         }
832 }
833
834 //_______________________________________________________________
835 void AliQAv1::ShowASCIIStatus(AliRecoParam::EventSpecie_t es, DETECTORINDEX_t det, ALITASK_t tsk, const ULong_t status) const 
836 {
837         // print the QA status in human readable format
838         TString text; 
839         for (Int_t bit = kINFO ; bit < kNBIT ; bit++) {
840                 if (IsSet(det, tsk, es, QABIT_t(bit))) {
841                         text = GetBitName(QABIT_t(bit)) ; 
842                         text += " " ; 
843                 }
844         }
845         if (! text.IsNull())
846                 AliInfoClass(Form("           %8s %8s %4s 0x%4lx, Problem signalled: %8s \n", AliRecoParam::GetEventSpecieName(es), GetDetName(det).Data(), GetAliTaskName(tsk), status, text.Data())) ; 
847 }
848
849 //_______________________________________________________________
850 void AliQAv1::UnSet(QABIT_t bit, Int_t ies)
851 {
852         // UnSet the status bit of the current detector in the current module
853                 UnSet(bit, AliRecoParam::Convert(ies)) ;
854 }
855
856 //_______________________________________________________________
857 void AliQAv1::UnSet(QABIT_t bit, AliRecoParam::EventSpecie_t es)
858 {
859         // UnSet the status bit of the current detector in the current module
860         
861         UnSetStatusBit(fDet, fTask, es, bit) ;
862 }
863
864 //_______________________________________________________________
865 void AliQAv1::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
866 {
867         // UnSet the status bit for a given detector and a given task
868         
869         CheckRange(det) ;
870         CheckRange(tsk) ;
871         CheckRange(bit) ;
872         CheckRange(es) ;
873         
874         ULong_t offset = Offset(tsk) ;
875         ULong_t status = GetStatus(det, es) ;
876         offset+= bit ;
877         status = status & 0 << offset ;
878         SetStatus(det, es, status) ;
879 }