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