]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQAv1.cxx
modification be Michael Knichel
[u/mrichter/AliRoot.git] / 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", "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 const UInt_t   AliQAv1::fgkExpertBit           = BIT(19);  
75 const UInt_t   AliQAv1::fgkQABit               = BIT(20) ; 
76 const UInt_t   AliQAv1::fgkImageBit            = BIT(21) ; 
77 const Int_t    AliQAv1::fgkQADebugLevel        = 99 ; 
78 const TString  AliQAv1::fgkImageFileName       = "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         switch (tsk) {
291                 case kNULLTASK:
292                         break ; 
293                 case kRAW:
294                         return "RAW" ;
295                         break ;  
296                 case kSIM:
297                         return "SIM" ;
298                         break ;
299                 case kREC:
300                         return "REC" ;
301                         break ;
302                 case kESD:
303                         return "ESD" ;
304                         break ;
305                 case kANA:
306                         return "ANA" ;
307                         break ;
308                 default:
309       return "" ; 
310                         break ;
311         }
312   return "" ;
313 }
314
315 //_______________________________________________________________
316 const char * AliQAv1::GetBitName(QABIT_t bit) const
317 {
318         // returns the char name corresponding to bit 
319         TString bitName ;
320         switch (bit) {
321                 case kNULLBit:
322                         bitName = "NONE" ;
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 TH1 * AliQAv1::GetData(TObjArray** list, Int_t index, AliRecoParam::EventSpecie_t eventSpecie)
345 {
346     // retrieve QA data from the list at a given index and for a given event specie 
347   TH1 * rv = NULL ; 
348   Int_t esindex = AliRecoParam::AConvert(eventSpecie) ; 
349   TObjArray * arr = list[esindex] ;
350   if (arr) {
351     if ( index > AliQAv1::GetMaxQAObj() ) {
352                         AliErrorClass(Form("Max number of authorized QA objects is %d", AliQAv1::GetMaxQAObj())) ; 
353                 } else {
354       if ( arr->At(index) )  {
355         rv = static_cast<TH1*>(arr->At(index)) ; 
356       }         
357     }
358   }  
359   return rv ; 
360 }
361
362 //_______________________________________________________________
363 AliQAv1::DETECTORINDEX_t AliQAv1::GetDetIndex(const char * name) 
364 {
365         // returns the detector index corresponding to a given name
366         TString sname(name) ; 
367         DETECTORINDEX_t rv = kNULLDET ; 
368         for (Int_t det = 0; det < kNDET ; det++) {
369                 if ( GetDetName(det) == sname ) {
370                         rv = DETECTORINDEX_t(det) ; 
371                         break ; 
372                 }
373         }
374         return rv ;             
375 }
376
377 //_______________________________________________________________
378 const char * AliQAv1::GetDetName(Int_t det) 
379 {
380         // returns the detector name corresponding to a given index (needed in a loop)
381         
382         if ( det >= 0 &&  det < kNDET) 
383                 return (fgDetNames[det]).Data() ; 
384         else 
385                 return NULL ; 
386 }
387
388 //_______________________________________________________________
389 TFile * AliQAv1::GetQADataFile(const char * name, Int_t run) 
390 {
391   // opens the file to store the detectors Quality Assurance Data Maker results
392         const char * temp = Form("%s.%s.%d.root", name, fgQADataFileName.Data(), run) ; 
393         TString opt ; 
394         if (! fgQADataFile ) {     
395                 if  (gSystem->AccessPathName(temp))
396                         opt = "NEW" ;
397                 else 
398                         opt = "UPDATE" ; 
399                 fgQADataFile = TFile::Open(temp, opt.Data()) ;
400         } else {
401                 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
402                         fgQADataFile = static_cast<TFile *>(gROOT->FindObject(temp)) ;
403                         if ( !fgQADataFile ) {
404           if  (gSystem->AccessPathName(temp))
405             opt = "NEW" ;
406           else 
407             opt = "UPDATE" ; 
408                                 fgQADataFile = TFile::Open(temp, opt.Data()) ;
409                         }
410                 }
411   }
412         return fgQADataFile ;
413
414
415 //_____________________________________________________________________________
416 AliQAv1::MODE_t AliQAv1::Mode(TASKINDEX_t task) {
417   // return "rec" or "sim" depending on the task
418   
419   switch (task) {
420     case AliQAv1::kRAWS:
421       return kRECMODE ; 
422       break;
423     case AliQAv1::kHITS:
424       return kSIMMODE ; 
425       break;
426     case AliQAv1::kSDIGITS:
427       return kSIMMODE ; 
428       break;
429     case AliQAv1::kDIGITS:
430       return kSIMMODE ; 
431       break;
432     case AliQAv1::kDIGITSR:
433       return kRECMODE ; 
434       break;
435     case AliQAv1::kRECPOINTS:
436       return kRECMODE ; 
437       break ; 
438     case AliQAv1::kTRACKSEGMENTS:
439       return kRECMODE ; 
440       break;
441     case AliQAv1::kRECPARTICLES:
442       return kRECMODE ; 
443       break;
444     case AliQAv1::kESDS:
445       return kRECMODE ; 
446       break;
447     default:
448       break;
449   }
450   return AliQAv1::kNULLMODE;
451 }
452
453 //_____________________________________________________________________________
454 TFile * AliQAv1::GetQADataFile(const char * fileName)
455 {
456   // Open if necessary the Data file and return its pointer
457
458   if (!fgQADataFile) {
459     if (!fileName) 
460       fileName = AliQAv1::GetQADataFileName() ; 
461     if  (!gSystem->AccessPathName(fileName)) {
462       fgQADataFile =  TFile::Open(fileName) ;
463     } else {
464       AliFatalClass(Form("File %s not found", fileName)) ;
465     }
466   }
467   return fgQADataFile ; 
468 }
469
470 //_______________________________________________________________
471 TFile * AliQAv1::GetQAResultFile() 
472 {
473   // opens the file to store the  Quality Assurance Data Checker results        
474   if (fgQAResultFile) {
475    if (fgQAResultFile->IsOpen()) 
476     fgQAResultFile->Close();
477    delete fgQAResultFile;
478   }
479   TString dirName(fgQAResultDirName) ; 
480   if ( dirName.Contains(fgkLabLocalFile)) 
481     dirName.ReplaceAll(fgkLabLocalFile, "") ;
482   TString fileName(dirName + fgQAResultFileName) ; 
483   TString opt("") ; 
484   if ( !gSystem->AccessPathName(fileName) )
485     opt = "UPDATE" ; 
486   else { 
487     if ( gSystem->AccessPathName(dirName) )
488       gSystem->mkdir(dirName) ; 
489     opt = "NEW" ; 
490   }
491   fgQAResultFile = TFile::Open(fileName, opt) ;   
492   return fgQAResultFile ; 
493 }
494
495 //_______________________________________________________________
496 AliQAv1::QABIT_t AliQAv1::GetQAStatusBit(AliRecoParam::EventSpecie_t es, DETECTORINDEX_t det, ALITASK_t tsk) const
497 {
498     // returns the QA bit set
499   QABIT_t rv = kNULLBit ; 
500   if ( es == AliRecoParam::kDefault) 
501     es = fEventSpecie ; 
502   if ( det == kNULLDET ) 
503     det = fDet ; 
504   if ( tsk == kNULLTASK ) 
505     tsk = fTask ; 
506   for (Int_t bit = kINFO ; bit < kNBIT ; bit++) {
507                 if (IsSet(det, tsk, es, QABIT_t(bit))) 
508       rv = QABIT_t(bit) ;
509         }
510   return rv ; 
511 }
512
513 //_______________________________________________________________
514 AliQAv1::TASKINDEX_t AliQAv1::GetTaskIndex(const char * name) 
515 {
516         // returns the detector index corresponding to a given name
517         TString sname(name) ; 
518         TASKINDEX_t rv = kNULLTASKINDEX ; 
519         for (Int_t tsk = 0; tsk < kNTASKINDEX ; tsk++) {
520                 if ( GetTaskName(tsk) == sname ) {
521                         rv = TASKINDEX_t(tsk) ; 
522                         break ; 
523                 }
524         }
525         return rv ;             
526 }
527
528 //_______________________________________________________________
529 Bool_t AliQAv1::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, Int_t ies, QABIT_t bit) const 
530 {
531   // Checks is the requested bit is set
532    
533   const AliRecoParam::EventSpecie_t es = AliRecoParam::Convert(ies) ; 
534   return IsSet(det, tsk, es, bit) ; 
535   
536 }  
537
538 //_______________________________________________________________
539 Bool_t AliQAv1::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit) const
540 {
541   // Checks is the requested bit is set
542         
543   CheckRange(det) ; 
544   CheckRange(tsk) ;
545   CheckRange(bit) ;
546   CheckRange(es) ;
547         
548   ULong_t offset = Offset(tsk) ;
549   ULong_t status = GetStatus(det, es) ;
550   offset+= bit ;
551   status = (status & 1 << offset) != 0 ;
552   return status ;
553 }
554
555 //_______________________________________________________________
556 Bool_t AliQAv1::IsSetAny(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
557 {
558   // Checks is the requested bit is set
559         
560   CheckRange(det) ; 
561   CheckRange(tsk) ;
562   CheckRange(es) ;
563         
564   ULong_t offset = Offset(tsk) ;
565   ULong_t status = GetStatus(det, es) ;
566         ULong_t st = 0 ; 
567         for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
568                 offset+= bit ;
569                 st += (status & 1 << offset) != 0 ;             
570         }
571         if ( st == 0 ) 
572                 return kFALSE ; 
573         else 
574                 return kTRUE ;
575 }
576 //_______________________________________________________________
577 Bool_t AliQAv1::IsSetAny(DETECTORINDEX_t det, AliRecoParam::EventSpecie_t es) const
578 {
579   // Checks is the requested bit is set
580         
581   CheckRange(det) ; 
582   CheckRange(es) ; 
583         
584         ULong_t status = GetStatus(det, es) ;
585         ULong_t st = 0 ; 
586         for ( Int_t tsk = 0 ; tsk < kNTASK ; tsk++) {
587                 ULong_t offset = Offset(ALITASK_t(tsk)) ;
588                 for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
589                         offset+= bit ;
590                         st += (status & 1 << offset) != 0 ;             
591                 }
592         }
593         if ( st == 0 ) 
594                 return kFALSE ; 
595         else 
596                 return kTRUE ;
597 }
598
599 //_______________________________________________________________
600 AliQAv1 * AliQAv1::Instance()
601 {
602   // Get an instance of the singleton. The only authorized way to call the ctor
603
604   if ( ! fgQA) {
605     GetQAResultFile() ; 
606     fgQA = static_cast<AliQAv1 *>(fgQAResultFile->Get("QA")) ; 
607     if ( ! fgQA ) 
608       fgQA = new AliQAv1() ;
609   }
610   return fgQA ;
611 }
612
613 //_______________________________________________________________
614 AliQAv1 * AliQAv1::Instance(const Int_t qalength, ULong_t * qa, const Int_t eslength, Bool_t * es)
615 {
616   // Get an instance of the singleton. The only authorized way to call the ctor
617   
618   if ( ! fgQA) 
619     fgQA = new AliQAv1(qalength, qa, eslength, es) ;
620   return fgQA ;
621 }
622
623 //_______________________________________________________________
624 AliQAv1 * AliQAv1::Instance(const DETECTORINDEX_t det)
625 {
626   // Get an instance of the singleton. The only authorized way to call the ctor
627   
628   if ( ! fgQA) {
629     GetQAResultFile() ; 
630     fgQA = static_cast<AliQAv1 *>(fgQAResultFile->Get(GetQAName())) ; 
631     if ( ! fgQA ) 
632       fgQA = new AliQAv1(det) ;
633   }             
634   fgQA->Set(det) ;
635   return fgQA ;
636 }
637
638 //_______________________________________________________________
639 AliQAv1 * AliQAv1::Instance(const ALITASK_t tsk)
640 {
641   // Get an instance of the singleton. The only authorized way to call the ctor
642
643   if ( ! fgQA)
644     switch (tsk) {
645     case kNULLTASK:
646       break ;
647         case kRAW:
648       fgQA = new AliQAv1(tsk) ;
649       break ;
650         case kSIM:
651       fgQA = new AliQAv1(tsk) ;
652       break ;
653     case kREC:
654       AliInfoClass("fgQA = gAlice->GetQA()") ;
655       break ;
656     case kESD:
657       AliInfoClass("fgQA = static_cast<AliQAv1 *> (esdFile->Get(\"QA\")") ;
658       break ;
659     case kANA:
660       AliInfoClass("fgQA = static_cast<AliQAv1 *> (esdFile->Get(\"QA\")") ;
661       break ;
662     case kNTASK:
663       break ;
664     }
665   if (fgQA) 
666     fgQA->Set(tsk) ;
667   return fgQA ;
668 }
669
670 //_______________________________________________________________
671 AliQAv1 *  AliQAv1::Instance(const TASKINDEX_t tsk) 
672 {
673         // get an instance of the singleton.
674         ALITASK_t index = kNULLTASK ; 
675
676         if ( tsk == kRAWS )
677                 index = kRAW ;
678         else if (tsk < kDIGITS)
679                 index = kSIM ;
680         else if (tsk < kRECPARTICLES)
681                 index = kREC ; 
682         else if (tsk == kESDS) 
683                 index = kESD ; 
684
685         return Instance(index) ; 
686 }
687
688 //_______________________________________________________________
689 void AliQAv1::Merge(const TCollection * list) {
690         // Merge the QA resuls in the list into this single AliQAv1 object
691         
692         for (Int_t det = 0 ; det < kNDET ; det++) {
693                 Set(DETECTORINDEX_t(det)) ; 
694                 for (Int_t task = 0 ; task < kNTASK ; task++) {
695                         Set(ALITASK_t(task)) ; 
696                         for (Int_t bit = 0 ; bit < kNBIT ; bit++) {
697                                 TIter next(list) ;
698                                 AliQAv1 * qa ; 
699                                 while ( (qa = (AliQAv1*)next() ) ) {
700           for (Int_t es = 0 ; es < fNEventSpecies ; es++) {
701             if (qa->IsSet(DETECTORINDEX_t(det), ALITASK_t(task), es, QABIT_t(bit)))
702               Set(QABIT_t(bit), es) ; 
703           }
704                                 } // qa list
705                         } // bit
706                 } // task
707         } // detector
708 }
709
710 //_______________________________________________________________
711 ULong_t AliQAv1::Offset(ALITASK_t tsk) const
712 {
713   // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
714
715   CheckRange(tsk) ; 
716
717   ULong_t offset = 0 ;
718   switch (tsk) {
719   case kNULLTASK:
720     break ;
721   case kRAW:
722     offset+= 0 ;
723     break ;
724   case kSIM:
725     offset+= 4 ;
726     break ;
727   case kREC:
728     offset+= 8 ;
729     break ;
730   case kESD:
731     offset+= 12 ;
732     break ;
733   case kANA:
734     offset+= 16 ;
735     break ;
736   case kNTASK:
737     break ;
738   }
739
740   return offset ;
741 }
742
743 //_______________________________________________________________
744 void AliQAv1::Reset(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es)
745 {
746     // resets all the bits for a given tsk and event specie
747   CheckRange(det) ; 
748   CheckRange(tsk) ;
749   CheckRange(es) ;
750         
751   ULong_t offset = Offset(tsk) ;
752   ULong_t status = GetStatus(det, es) ;
753         for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
754                 offset+= bit ;
755                 status = status & ~1 << offset ;                
756         }  
757   SetStatus(det, es, status) ;
758 }
759
760 //_______________________________________________________________
761 void AliQAv1::ResetStatus(DETECTORINDEX_t det) 
762
763   // reset the status of det for all event specie
764   for (Int_t es = 0 ; es < fNEventSpecies ; es++)
765     fQA[det*fNdet+es] = 0 ; 
766 }
767
768 //_______________________________________________________________
769 void AliQAv1::Set(QABIT_t bit, Int_t ies)
770 {
771   // Set the status bit of the current detector in the current module and for the current event specie 
772    Set(bit, AliRecoParam::Convert(ies)) ;
773 }
774
775 //_______________________________________________________________
776 void AliQAv1::Set(QABIT_t bit, AliRecoParam::EventSpecie_t es)
777 {
778   // Set the status bit of the current detector in the current module and for the current event specie 
779   
780   SetStatusBit(fDet, fTask, es, bit) ;
781 }
782
783 //_____________________________________________________________________________
784 void AliQAv1::SetQARefStorage(const char * name)
785 {
786         // Set the root directory where the QA reference data are stored
787
788         fgQARefDirName = name ; 
789         if ( fgQARefDirName.Contains(fgkLabLocalFile) )
790                 fgQARefFileName =  fgkRefFileName ; 
791         else if ( fgQARefDirName.Contains(fgkLabLocalOCDB) )
792                 fgQARefFileName =  fgkQAName ; 
793         else if ( fgQARefDirName.Contains(fgkLabAliEnOCDB) )
794                 fgQARefFileName =  fgkQAName ; 
795
796   else {
797           AliErrorClass(Form("ERROR: %s is an invalid storage definition\n", name)) ; 
798           fgQARefDirName  = "" ; 
799           fgQARefFileName = "" ; 
800   }     
801         TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
802         AliInfoClass(Form("AliQAv1::SetQARefDir: QA references are in  %s\n", tmp.Data() )) ;
803 }
804
805 //_____________________________________________________________________________
806 void AliQAv1::SetQAResultDirName(const char * name)
807 {
808   // Set the root directory where to store the QA status object
809
810   fgQAResultDirName.Prepend(name) ; 
811   AliInfoClass(Form("AliQAv1::SetQAResultDirName: QA results are in  %s\n", fgQAResultDirName.Data())) ;
812   if ( fgQAResultDirName.Contains(fgkLabLocalFile)) 
813     fgQAResultDirName.ReplaceAll(fgkLabLocalFile, "") ;
814   fgQAResultFileName.Prepend(fgQAResultDirName) ;
815 }
816
817 //_______________________________________________________________
818 void AliQAv1::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
819 {
820  // Set the status bit for a given detector and a given task
821
822   CheckRange(det) ;
823   CheckRange(tsk) ;
824   CheckRange(bit) ;
825   CheckRange(es) ;
826   
827   Reset(det, tsk, es) ; 
828   
829   ULong_t offset = Offset(tsk) ;
830   ULong_t status = GetStatus(det, es) ;
831   offset+= bit ;
832   status = status | 1 << offset ;
833   SetStatus(det, es, status) ;
834 }
835
836 //_______________________________________________________________
837 void AliQAv1::Show(DETECTORINDEX_t det) const 
838
839   // dispplay the QA status word
840   if ( det == kNULLDET) 
841     det = fDet ;  
842   for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
843     if ( IsEventSpecieSet(ies) )
844       ShowStatus(det, kNULLTASK, AliRecoParam::ConvertIndex(ies)) ; 
845   }
846 }
847
848 //_______________________________________________________________
849 void AliQAv1::ShowAll() const 
850 {
851   // dispplay the QA status word
852   Int_t index ;
853   for (index = 0 ; index < kNDET ; index++) {
854                 for (Int_t tsk = kRAW ; tsk < kNTASK ; tsk++) {
855       for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
856         if ( IsEventSpecieSet(ies) )
857           ShowStatus(DETECTORINDEX_t(index), ALITASK_t(tsk), AliRecoParam::ConvertIndex(ies)) ;
858       }
859     }
860         }
861 }
862
863 //_______________________________________________________________
864 void AliQAv1::ShowStatus(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
865 {
866         // Prints the full QA status of a given detector
867         CheckRange(det) ;
868         CheckRange(es) ;
869         ULong_t status = GetStatus(det, es) ;
870         ULong_t tskStatus[kNTASK] ; 
871         tskStatus[kRAW] = status & 0x0000f ;
872         tskStatus[kSIM] = status & 0x000f0 ;
873         tskStatus[kREC] = status & 0x00f00 ;
874         tskStatus[kESD] = status & 0x0f000 ;
875         tskStatus[kANA] = status & 0xf0000 ;
876
877         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), 
878                                  tskStatus[kRAW], tskStatus[kSIM], tskStatus[kREC], tskStatus[kESD], tskStatus[kANA] )) ;
879         if (tsk == kNULLTASK) {
880                 for (Int_t itsk = kRAW ; itsk < kNTASK ; itsk++) {
881                         ShowASCIIStatus(es, det, ALITASK_t(itsk), tskStatus[itsk]) ; 
882                 } 
883         } else {
884                         ShowASCIIStatus(es, det, tsk, tskStatus[tsk]) ; 
885         }
886 }
887
888 //_______________________________________________________________
889 void AliQAv1::ShowASCIIStatus(AliRecoParam::EventSpecie_t es, DETECTORINDEX_t det, ALITASK_t tsk, const ULong_t status) const 
890 {
891         // print the QA status in human readable format
892   const QABIT_t bit = GetQAStatusBit(es, det, tsk) ; 
893   if ( bit != kNULLBit ) {
894           AliInfoClass(Form("           %8s %8s %4s  \n", AliRecoParam::GetEventSpecieName(es), GetDetName(det).Data(), GetAliTaskName(tsk))) ; 
895           AliInfoClass(Form("           %8s %8s %4s 0x%4lx, Problem signalled: %8s \n", AliRecoParam::GetEventSpecieName(es), GetDetName(det).Data(), GetAliTaskName(tsk), status, GetBitName(bit))) ; 
896   }
897 }
898
899 //_______________________________________________________________
900 void AliQAv1::UnSet(QABIT_t bit, Int_t ies)
901 {
902         // UnSet the status bit of the current detector in the current module
903                 UnSet(bit, AliRecoParam::Convert(ies)) ;
904 }
905
906 //_______________________________________________________________
907 void AliQAv1::UnSet(QABIT_t bit, AliRecoParam::EventSpecie_t es)
908 {
909         // UnSet the status bit of the current detector in the current module
910         
911         UnSetStatusBit(fDet, fTask, es, bit) ;
912 }
913
914 //_______________________________________________________________
915 void AliQAv1::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
916 {
917         // UnSet the status bit for a given detector and a given task
918         
919         CheckRange(det) ;
920         CheckRange(tsk) ;
921         CheckRange(bit) ;
922         CheckRange(es) ;
923         
924         ULong_t offset = Offset(tsk) ;
925         ULong_t status = GetStatus(det, es) ;
926         offset+= bit ;
927         status = status & 0 << offset ;
928         SetStatus(det, es, status) ;
929 }