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