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