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