2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //////////////////////////////////////////////////////////////////////////////
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)
31 //*-- Yves Schutz CERN, July 2007
32 //////////////////////////////////////////////////////////////////////////////
36 // --- ROOT system ---
41 // --- Standard library ---
43 // --- AliRoot header files ---
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 ;
75 //____________________________________________________________________________
79 fNEventSpecies(AliRecoParam::kNSpecies),
80 fLengthQA(fNdet*fNEventSpecies),
81 fQA(new ULong_t[fLengthQA]),
84 fEventSpecie(AliRecoParam::kDefault),
85 fEventSpecies(new Bool_t[fNEventSpecies])
87 // default constructor
88 memset(fQA,0,fLengthQA);
89 memset(fEventSpecies,kFALSE,fNEventSpecies);
92 //____________________________________________________________________________
93 AliQA::AliQA(const AliQA& qa) :
96 fNEventSpecies(qa.fNEventSpecies),
97 fLengthQA(qa.fLengthQA),
98 fQA(new ULong_t[fLengthQA]),
101 fEventSpecie(qa.fEventSpecie),
102 fEventSpecies(new Bool_t[fNEventSpecies])
105 memcpy(fQA,qa.fQA,fLengthQA*sizeof(ULong_t));
106 memcpy(fEventSpecies,qa.fEventSpecies,fNEventSpecies*sizeof(Bool_t));
109 //_____________________________________________________________________________
110 AliQA& AliQA::operator = (const AliQA& qa)
112 // assignment operator
114 TNamed::operator=(qa);
116 fNEventSpecies = qa.fNEventSpecies;
117 fLengthQA = qa.fLengthQA;
119 if(fQA) delete [] fQA;
120 fQA = new ULong_t[fLengthQA];
121 memcpy(fQA,qa.fQA,fLengthQA*sizeof(ULong_t));
125 fEventSpecie = qa.fEventSpecie;
126 if(fEventSpecies) delete [] fEventSpecies;
127 fEventSpecies = new Bool_t[fNEventSpecies];
128 memcpy(fEventSpecies,qa.fEventSpecies,fNEventSpecies*sizeof(Bool_t));
133 //_______________________________________________________________
134 AliQA::AliQA(const DETECTORINDEX_t det) :
135 TNamed("QA", "Quality Assurance status"),
137 fNEventSpecies(AliRecoParam::kNSpecies),
138 fLengthQA(fNdet*fNEventSpecies),
139 fQA(new ULong_t[fLengthQA]),
142 fEventSpecie(AliRecoParam::kDefault),
143 fEventSpecies(new Bool_t[fNEventSpecies])
145 // constructor to be used
146 if (! CheckRange(det) ) fDet = kNULLDET ;
147 memset(fQA,0,fLengthQA);
148 memset(fEventSpecies,kFALSE,fNEventSpecies);
151 //_______________________________________________________________
152 AliQA::AliQA(const ALITASK_t tsk) :
153 TNamed("QA", "Quality Assurance status"),
155 fNEventSpecies(AliRecoParam::kNSpecies),
156 fLengthQA(fNdet*fNEventSpecies),
157 fQA(new ULong_t[fLengthQA]),
160 fEventSpecie(AliRecoParam::kDefault),
161 fEventSpecies(new Bool_t[fNEventSpecies])
163 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
164 if (! CheckRange(tsk) ) fTask = kNULLTASK ;
165 memset(fQA,0,fLengthQA);
166 memset(fEventSpecies,kFALSE,fNEventSpecies);
169 //____________________________________________________________________________
174 delete [] fEventSpecies;
177 //_______________________________________________________________
180 // close the open files
182 if (fgQADataFile->IsOpen())
183 fgQADataFile->Close() ;
185 if (fgQAResultFile->IsOpen())
186 fgQAResultFile->Close() ;
188 if (fgQARefFile->IsOpen())
189 fgQARefFile->Close() ;
192 //_______________________________________________________________
193 Bool_t AliQA::CheckFatal() const
195 // check if any FATAL status is set
198 for (index = 0; index < kNDET ; index++)
199 rv = rv || IsSet(DETECTORINDEX_t(index), fTask, fEventSpecie, kFATAL) ;
203 //_______________________________________________________________
204 Bool_t AliQA::CheckRange(DETECTORINDEX_t det) const
206 // check if detector is in given detector range: 0-kNDET
208 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
210 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
214 //_______________________________________________________________
215 Bool_t AliQA::CheckRange(ALITASK_t task) const
217 // check if task is given taskk range: 0:kNTASK
218 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
220 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
224 //_______________________________________________________________
225 Bool_t AliQA::CheckRange(QABIT_t bit) const
227 // check if bit is in given bit range: 0-kNBit
229 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
231 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
235 //_______________________________________________________________
236 Bool_t AliQA::CheckRange(AliRecoParam::EventSpecie_t es) const
238 // check if bit is in given bit range: 0-kNBit
241 case AliRecoParam::kDefault:
244 case AliRecoParam::kLowMult:
247 case AliRecoParam::kHighMult:
250 case AliRecoParam::kCosmic:
253 case AliRecoParam::kCalib:
258 AliFatal(Form("Event Specie %d is not valid", es)) ;
262 //_______________________________________________________________
263 const char * AliQA::GetAliTaskName(ALITASK_t tsk)
265 // returns the char name corresponding to module index
289 return tskName.Data() ;
292 //_______________________________________________________________
293 const char * AliQA::GetBitName(QABIT_t bit) const
295 // returns the char name corresponding to bit
304 bitName = "WARNING" ;
316 return bitName.Data() ;
319 //_______________________________________________________________
320 AliQA::DETECTORINDEX_t AliQA::GetDetIndex(const char * name)
322 // returns the detector index corresponding to a given name
323 TString sname(name) ;
324 DETECTORINDEX_t rv = kNULLDET ;
325 for (Int_t det = 0; det < kNDET ; det++) {
326 if ( GetDetName(det) == sname ) {
327 rv = DETECTORINDEX_t(det) ;
334 //_______________________________________________________________
335 const char * AliQA::GetDetName(Int_t det)
337 // returns the detector name corresponding to a given index (needed in a loop)
339 if ( det >= 0 && det < kNDET)
340 return (fgDetNames[det]).Data() ;
345 //_______________________________________________________________
346 TFile * AliQA::GetQADataFile(const char * name, Int_t run)
348 // opens the file to store the detectors Quality Assurance Data Maker results
349 const char * temp = Form("%s.%s.%d.root", name, fgQADataFileName.Data(), run) ;
351 if (! fgQADataFile ) {
352 if (gSystem->AccessPathName(temp))
356 fgQADataFile = TFile::Open(temp, opt.Data()) ;
358 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
359 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
360 if ( !fgQADataFile ) {
361 if (gSystem->AccessPathName(temp))
365 fgQADataFile = TFile::Open(temp, opt.Data()) ;
369 return fgQADataFile ;
372 //_____________________________________________________________________________
373 TFile * AliQA::GetQADataFile(const char * fileName)
375 // Open if necessary the Data file and return its pointer
379 fileName = AliQA::GetQADataFileName() ;
380 if (!gSystem->AccessPathName(fileName)) {
381 fgQADataFile = TFile::Open(fileName) ;
383 printf("File %s not found", fileName) ;
386 return fgQADataFile ;
389 //_______________________________________________________________
390 TFile * AliQA::GetQAResultFile()
392 // opens the file to store the Quality Assurance Data Checker results
394 fgQAResultFile->Close() ;
395 fgQAResultFile = 0x0 ;
396 // if (!fgQAResultFile) {
397 TString dirName(fgQAResultDirName) ;
398 if ( dirName.Contains(fgkLabLocalFile))
399 dirName.ReplaceAll(fgkLabLocalFile, "") ;
400 TString fileName(dirName + fgQAResultFileName) ;
402 if ( !gSystem->AccessPathName(fileName) )
405 if ( gSystem->AccessPathName(dirName) )
406 gSystem->mkdir(dirName) ;
409 fgQAResultFile = TFile::Open(fileName, opt) ;
412 return fgQAResultFile ;
415 //_______________________________________________________________
416 AliQA::TASKINDEX_t AliQA::GetTaskIndex(const char * name)
418 // returns the detector index corresponding to a given name
419 TString sname(name) ;
420 TASKINDEX_t rv = kNULLTASKINDEX ;
421 for (Int_t tsk = 0; tsk < kNTASKINDEX ; tsk++) {
422 if ( GetTaskName(tsk) == sname ) {
423 rv = TASKINDEX_t(tsk) ;
430 //_______________________________________________________________
431 Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, Int_t ies, QABIT_t bit) const
433 // Checks is the requested bit is set
435 const AliRecoParam::EventSpecie_t es = AliRecoParam::Convert(ies) ;
436 return IsSet(det, tsk, es, bit) ;
440 //_______________________________________________________________
441 Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit) const
443 // Checks is the requested bit is set
450 ULong_t offset = Offset(tsk) ;
451 ULong_t status = GetStatus(det, es) ;
453 status = (status & 1 << offset) != 0 ;
457 //_______________________________________________________________
458 Bool_t AliQA::IsSetAny(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
460 // Checks is the requested bit is set
466 ULong_t offset = Offset(tsk) ;
467 ULong_t status = GetStatus(det, es) ;
469 for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
471 st += (status & 1 << offset) != 0 ;
478 //_______________________________________________________________
479 Bool_t AliQA::IsSetAny(DETECTORINDEX_t det, AliRecoParam::EventSpecie_t es) const
481 // Checks is the requested bit is set
486 ULong_t status = GetStatus(det, es) ;
488 for ( Int_t tsk = 0 ; tsk < kNTASK ; tsk++) {
489 ULong_t offset = Offset(ALITASK_t(tsk)) ;
490 for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
492 st += (status & 1 << offset) != 0 ;
501 //_______________________________________________________________
502 AliQA * AliQA::Instance()
504 // Get an instance of the singleton. The only authorized way to call the ctor
507 TFile * f = GetQAResultFile() ;
508 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
515 //_______________________________________________________________
516 AliQA * AliQA::Instance(const DETECTORINDEX_t det)
518 // Get an instance of the singleton. The only authorized way to call the ctor
521 TFile * f = GetQAResultFile() ;
522 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
524 fgQA = new AliQA(det) ;
530 //_______________________________________________________________
531 AliQA * AliQA::Instance(const ALITASK_t tsk)
533 // Get an instance of the singleton. The only authorized way to call the ctor
540 fgQA = new AliQA(tsk) ;
543 fgQA = new AliQA(tsk) ;
546 printf("fgQA = gAlice->GetQA()") ;
549 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
552 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
562 //_______________________________________________________________
563 AliQA * AliQA::Instance(const TASKINDEX_t tsk)
565 // get an instance of the singleton.
567 ALITASK_t index = kNULLTASK ;
571 else if (tsk < kDIGITS)
573 else if (tsk < kRECPARTICLES)
575 else if (tsk == kESDS)
578 return Instance(index) ;
581 //_______________________________________________________________
582 void AliQA::Merge(TCollection * list) {
583 // Merge the QA resuls in the list into this single AliQA object
585 for (Int_t det = 0 ; det < kNDET ; det++) {
586 Set(DETECTORINDEX_t(det)) ;
587 for (Int_t task = 0 ; task < kNTASK ; task++) {
588 Set(ALITASK_t(task)) ;
589 for (Int_t bit = 0 ; bit < kNBIT ; bit++) {
592 while ( (qa = (AliQA*)next() ) ) {
593 for (Int_t es = 0 ; es < fNEventSpecies ; es++) {
594 if (qa->IsSet(DETECTORINDEX_t(det), ALITASK_t(task), es, QABIT_t(bit)))
595 Set(QABIT_t(bit), es) ;
603 //_______________________________________________________________
604 ULong_t AliQA::Offset(ALITASK_t tsk) const
606 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
636 //_______________________________________________________________
637 void AliQA::ResetStatus(DETECTORINDEX_t det)
639 // reset the status of det for all event specie
640 for (Int_t es = 0 ; es < fNEventSpecies ; es++)
641 fQA[det*fNdet+es] = 0 ;
644 //_______________________________________________________________
645 void AliQA::Set(QABIT_t bit, Int_t ies)
647 // Set the status bit of the current detector in the current module and for the current event specie
648 Set(bit, AliRecoParam::Convert(ies)) ;
651 //_______________________________________________________________
652 void AliQA::Set(QABIT_t bit, AliRecoParam::EventSpecie_t es)
654 // Set the status bit of the current detector in the current module and for the current event specie
656 SetStatusBit(fDet, fTask, es, bit) ;
659 //_____________________________________________________________________________
660 void AliQA::SetQARefStorage(const char * name)
662 // Set the root directory where the QA reference data are stored
664 fgQARefDirName = name ;
665 if ( fgQARefDirName.Contains(fgkLabLocalFile) )
666 fgQARefFileName = fgkRefFileName ;
667 else if ( fgQARefDirName.Contains(fgkLabLocalOCDB) )
668 fgQARefFileName = fgkQAName ;
669 else if ( fgQARefDirName.Contains(fgkLabAliEnOCDB) )
670 fgQARefFileName = fgkQAName ;
673 printf("ERROR: %s is an invalid storage definition\n", name) ;
674 fgQARefDirName = "" ;
675 fgQARefFileName = "" ;
677 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
678 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
681 //_____________________________________________________________________________
682 void AliQA::SetQAResultDirName(const char * name)
684 // Set the root directory where to store the QA status object
686 fgQAResultDirName.Prepend(name) ;
687 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
688 if ( fgQAResultDirName.Contains(fgkLabLocalFile))
689 fgQAResultDirName.ReplaceAll(fgkLabLocalFile, "") ;
690 fgQAResultFileName.Prepend(fgQAResultDirName) ;
693 //_______________________________________________________________
694 void AliQA::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
696 // Set the status bit for a given detector and a given task
703 ULong_t offset = Offset(tsk) ;
704 ULong_t status = GetStatus(det, es) ;
706 status = status | 1 << offset ;
707 SetStatus(det, es, status) ;
710 //_______________________________________________________________
711 void AliQA::Show() const
713 // dispplay the QA status word
715 for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
716 const Bool_t what = IsEventSpecieSet(ies) ;
718 ShowStatus(fDet, fTask, AliRecoParam::Convert(ies)) ;
722 //_______________________________________________________________
723 void AliQA::Show(DETECTORINDEX_t det) const
725 // dispplay the QA status word
727 for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
728 const Bool_t what = IsEventSpecieSet(ies) ;
730 ShowStatus(fDet, kNULLTASK, AliRecoParam::Convert(ies)) ;
734 //_______________________________________________________________
735 void AliQA::ShowAll() const
737 // dispplay the QA status word
739 for (index = 0 ; index < kNDET ; index++) {
740 for (Int_t tsk = kRAW ; tsk < kNTASK ; tsk++) {
741 for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
742 const Bool_t what = IsEventSpecieSet(ies) ;
744 ShowStatus(DETECTORINDEX_t(index), ALITASK_t(tsk), AliRecoParam::Convert(ies)) ;
750 //_______________________________________________________________
751 void AliQA::ShowStatus(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
753 // Prints the full QA status of a given detector
756 ULong_t status = GetStatus(det, es) ;
757 ULong_t tskStatus[kNTASK] ;
758 tskStatus[kRAW] = status & 0x0000f ;
759 tskStatus[kSIM] = status & 0x000f0 ;
760 tskStatus[kREC] = status & 0x00f00 ;
761 tskStatus[kESD] = status & 0x0f000 ;
762 tskStatus[kANA] = status & 0xf0000 ;
764 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),
765 tskStatus[kRAW], tskStatus[kSIM], tskStatus[kREC], tskStatus[kESD], tskStatus[kANA] )) ;
766 if (tsk == kNULLTASK) {
767 for (Int_t itsk = kRAW ; itsk < kNTASK ; itsk++) {
768 ShowASCIIStatus(es, det, ALITASK_t(itsk), tskStatus[itsk]) ;
771 ShowASCIIStatus(es, det, tsk, tskStatus[tsk]) ;
775 //_______________________________________________________________
776 void AliQA::ShowASCIIStatus(AliRecoParam::EventSpecie_t es, DETECTORINDEX_t det, ALITASK_t tsk, const ULong_t status) const
778 // print the QA status in human readable format
780 for (Int_t bit = kINFO ; bit < kNBIT ; bit++) {
781 if (IsSet(det, tsk, es, QABIT_t(bit))) {
782 text = GetBitName(QABIT_t(bit)) ;
787 printf(" %8s %8s %4s 0x%4lx, Problem signalled: %8s \n", AliRecoParam::GetEventSpecieName(es), GetDetName(det).Data(), GetAliTaskName(tsk), status, text.Data()) ;
790 //_______________________________________________________________
791 void AliQA::UnSet(QABIT_t bit, Int_t ies)
793 // UnSet the status bit of the current detector in the current module
794 UnSet(bit, AliRecoParam::Convert(ies)) ;
797 //_______________________________________________________________
798 void AliQA::UnSet(QABIT_t bit, AliRecoParam::EventSpecie_t es)
800 // UnSet the status bit of the current detector in the current module
802 UnSetStatusBit(fDet, fTask, es, bit) ;
805 //_______________________________________________________________
806 void AliQA::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
808 // UnSet the status bit for a given detector and a given task
815 ULong_t offset = Offset(tsk) ;
816 ULong_t status = GetStatus(det, es) ;
818 status = status & 0 << offset ;
819 SetStatus(det, es, status) ;