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*sizeof(ULong_t));
89 memset(fEventSpecies,kFALSE,fNEventSpecies*sizeof(Bool_t));
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 Int_t qalength, ULong_t * qa, const Int_t eslength, Bool_t * es) :
135 TNamed("QA", "Quality Assurance status"),
137 fNEventSpecies(eslength),
139 fQA(new ULong_t[fLengthQA]),
142 fEventSpecie(AliRecoParam::kDefault),
143 fEventSpecies(new Bool_t[fNEventSpecies])
145 // constructor to be used
146 memcpy(fQA, qa, fLengthQA*sizeof(ULong_t));
147 memcpy(fEventSpecies, es, fNEventSpecies*sizeof(Bool_t));
150 //_______________________________________________________________
151 AliQA::AliQA(const DETECTORINDEX_t det) :
152 TNamed("QA", "Quality Assurance status"),
154 fNEventSpecies(AliRecoParam::kNSpecies),
155 fLengthQA(fNdet*fNEventSpecies),
156 fQA(new ULong_t[fLengthQA]),
159 fEventSpecie(AliRecoParam::kDefault),
160 fEventSpecies(new Bool_t[fNEventSpecies])
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));
168 //_______________________________________________________________
169 AliQA::AliQA(const ALITASK_t tsk) :
170 TNamed("QA", "Quality Assurance status"),
172 fNEventSpecies(AliRecoParam::kNSpecies),
173 fLengthQA(fNdet*fNEventSpecies),
174 fQA(new ULong_t[fLengthQA]),
177 fEventSpecie(AliRecoParam::kDefault),
178 fEventSpecies(new Bool_t[fNEventSpecies])
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));
186 //____________________________________________________________________________
191 delete [] fEventSpecies;
194 //_______________________________________________________________
197 // close the open files
199 if (fgQADataFile->IsOpen())
200 fgQADataFile->Close() ;
202 if (fgQAResultFile->IsOpen())
203 fgQAResultFile->Close() ;
205 if (fgQARefFile->IsOpen())
206 fgQARefFile->Close() ;
209 //_______________________________________________________________
210 Bool_t AliQA::CheckFatal() const
212 // check if any FATAL status is set
215 for (index = 0; index < kNDET ; index++)
216 rv = rv || IsSet(DETECTORINDEX_t(index), fTask, fEventSpecie, kFATAL) ;
220 //_______________________________________________________________
221 Bool_t AliQA::CheckRange(DETECTORINDEX_t det) const
223 // check if detector is in given detector range: 0-kNDET
225 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
227 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
231 //_______________________________________________________________
232 Bool_t AliQA::CheckRange(ALITASK_t task) const
234 // check if task is given taskk range: 0:kNTASK
235 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
237 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
241 //_______________________________________________________________
242 Bool_t AliQA::CheckRange(QABIT_t bit) const
244 // check if bit is in given bit range: 0-kNBit
246 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
248 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
252 //_______________________________________________________________
253 Bool_t AliQA::CheckRange(AliRecoParam::EventSpecie_t es) const
255 // check if bit is in given bit range: 0-kNBit
258 case AliRecoParam::kDefault:
261 case AliRecoParam::kLowMult:
264 case AliRecoParam::kHighMult:
267 case AliRecoParam::kCosmic:
270 case AliRecoParam::kCalib:
275 AliFatal(Form("Event Specie %d is not valid", es)) ;
279 //_______________________________________________________________
280 const char * AliQA::GetAliTaskName(ALITASK_t tsk)
282 // returns the char name corresponding to module index
306 return tskName.Data() ;
309 //_______________________________________________________________
310 const char * AliQA::GetBitName(QABIT_t bit) const
312 // returns the char name corresponding to bit
321 bitName = "WARNING" ;
333 return bitName.Data() ;
336 //_______________________________________________________________
337 AliQA::DETECTORINDEX_t AliQA::GetDetIndex(const char * name)
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) ;
351 //_______________________________________________________________
352 const char * AliQA::GetDetName(Int_t det)
354 // returns the detector name corresponding to a given index (needed in a loop)
356 if ( det >= 0 && det < kNDET)
357 return (fgDetNames[det]).Data() ;
362 //_______________________________________________________________
363 TFile * AliQA::GetQADataFile(const char * name, Int_t run)
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) ;
368 if (! fgQADataFile ) {
369 if (gSystem->AccessPathName(temp))
373 fgQADataFile = TFile::Open(temp, opt.Data()) ;
375 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
376 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
377 if ( !fgQADataFile ) {
378 if (gSystem->AccessPathName(temp))
382 fgQADataFile = TFile::Open(temp, opt.Data()) ;
386 return fgQADataFile ;
389 //_____________________________________________________________________________
390 TFile * AliQA::GetQADataFile(const char * fileName)
392 // Open if necessary the Data file and return its pointer
396 fileName = AliQA::GetQADataFileName() ;
397 if (!gSystem->AccessPathName(fileName)) {
398 fgQADataFile = TFile::Open(fileName) ;
400 printf("File %s not found", fileName) ;
403 return fgQADataFile ;
406 //_______________________________________________________________
407 TFile * AliQA::GetQAResultFile()
409 // opens the file to store the Quality Assurance Data Checker results
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) ;
419 if ( !gSystem->AccessPathName(fileName) )
422 if ( gSystem->AccessPathName(dirName) )
423 gSystem->mkdir(dirName) ;
426 fgQAResultFile = TFile::Open(fileName, opt) ;
429 return fgQAResultFile ;
432 //_______________________________________________________________
433 AliQA::TASKINDEX_t AliQA::GetTaskIndex(const char * name)
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) ;
447 //_______________________________________________________________
448 Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, Int_t ies, QABIT_t bit) const
450 // Checks is the requested bit is set
452 const AliRecoParam::EventSpecie_t es = AliRecoParam::Convert(ies) ;
453 return IsSet(det, tsk, es, bit) ;
457 //_______________________________________________________________
458 Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit) const
460 // Checks is the requested bit is set
467 ULong_t offset = Offset(tsk) ;
468 ULong_t status = GetStatus(det, es) ;
470 status = (status & 1 << offset) != 0 ;
474 //_______________________________________________________________
475 Bool_t AliQA::IsSetAny(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
477 // Checks is the requested bit is set
483 ULong_t offset = Offset(tsk) ;
484 ULong_t status = GetStatus(det, es) ;
486 for ( Int_t bit = 0 ; bit < kNBIT ; bit++) {
488 st += (status & 1 << offset) != 0 ;
495 //_______________________________________________________________
496 Bool_t AliQA::IsSetAny(DETECTORINDEX_t det, AliRecoParam::EventSpecie_t es) const
498 // Checks is the requested bit is set
503 ULong_t status = GetStatus(det, es) ;
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++) {
509 st += (status & 1 << offset) != 0 ;
518 //_______________________________________________________________
519 AliQA * AliQA::Instance()
521 // Get an instance of the singleton. The only authorized way to call the ctor
524 TFile * f = GetQAResultFile() ;
525 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
532 //_______________________________________________________________
533 AliQA * AliQA::Instance(const Int_t qalength, ULong_t * qa, const Int_t eslength, Bool_t * es)
535 // Get an instance of the singleton. The only authorized way to call the ctor
538 fgQA = new AliQA(qalength, qa, eslength, es) ;
542 //_______________________________________________________________
543 AliQA * AliQA::Instance(const DETECTORINDEX_t det)
545 // Get an instance of the singleton. The only authorized way to call the ctor
548 TFile * f = GetQAResultFile() ;
549 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
551 fgQA = new AliQA(det) ;
557 //_______________________________________________________________
558 AliQA * AliQA::Instance(const ALITASK_t tsk)
560 // Get an instance of the singleton. The only authorized way to call the ctor
567 fgQA = new AliQA(tsk) ;
570 fgQA = new AliQA(tsk) ;
573 printf("fgQA = gAlice->GetQA()") ;
576 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
579 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
589 //_______________________________________________________________
590 AliQA * AliQA::Instance(const TASKINDEX_t tsk)
592 // get an instance of the singleton.
594 ALITASK_t index = kNULLTASK ;
598 else if (tsk < kDIGITS)
600 else if (tsk < kRECPARTICLES)
602 else if (tsk == kESDS)
605 return Instance(index) ;
608 //_______________________________________________________________
609 void AliQA::Merge(TCollection * list) {
610 // Merge the QA resuls in the list into this single AliQA object
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++) {
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) ;
630 //_______________________________________________________________
631 ULong_t AliQA::Offset(ALITASK_t tsk) const
633 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
663 //_______________________________________________________________
664 void AliQA::ResetStatus(DETECTORINDEX_t det)
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 ;
671 //_______________________________________________________________
672 void AliQA::Set(QABIT_t bit, Int_t ies)
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)) ;
678 //_______________________________________________________________
679 void AliQA::Set(QABIT_t bit, AliRecoParam::EventSpecie_t es)
681 // Set the status bit of the current detector in the current module and for the current event specie
683 SetStatusBit(fDet, fTask, es, bit) ;
686 //_____________________________________________________________________________
687 void AliQA::SetQARefStorage(const char * name)
689 // Set the root directory where the QA reference data are stored
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 ;
700 printf("ERROR: %s is an invalid storage definition\n", name) ;
701 fgQARefDirName = "" ;
702 fgQARefFileName = "" ;
704 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
705 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
708 //_____________________________________________________________________________
709 void AliQA::SetQAResultDirName(const char * name)
711 // Set the root directory where to store the QA status object
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) ;
720 //_______________________________________________________________
721 void AliQA::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
723 // Set the status bit for a given detector and a given task
730 ULong_t offset = Offset(tsk) ;
731 ULong_t status = GetStatus(det, es) ;
733 status = status | 1 << offset ;
734 SetStatus(det, es, status) ;
737 //_______________________________________________________________
738 void AliQA::Show() const
740 // dispplay the QA status word
742 for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
743 const Bool_t what = IsEventSpecieSet(ies) ;
745 ShowStatus(fDet, fTask, AliRecoParam::Convert(ies)) ;
749 //_______________________________________________________________
750 void AliQA::Show(DETECTORINDEX_t det) const
752 // dispplay the QA status word
754 for (Int_t ies = 0 ; ies < fNEventSpecies ; ies++) {
755 const Bool_t what = IsEventSpecieSet(ies) ;
757 ShowStatus(fDet, kNULLTASK, AliRecoParam::Convert(ies)) ;
761 //_______________________________________________________________
762 void AliQA::ShowAll() const
764 // dispplay the QA status word
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) ;
771 ShowStatus(DETECTORINDEX_t(index), ALITASK_t(tsk), AliRecoParam::Convert(ies)) ;
777 //_______________________________________________________________
778 void AliQA::ShowStatus(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es) const
780 // Prints the full QA status of a given detector
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 ;
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]) ;
798 ShowASCIIStatus(es, det, tsk, tskStatus[tsk]) ;
802 //_______________________________________________________________
803 void AliQA::ShowASCIIStatus(AliRecoParam::EventSpecie_t es, DETECTORINDEX_t det, ALITASK_t tsk, const ULong_t status) const
805 // print the QA status in human readable format
807 for (Int_t bit = kINFO ; bit < kNBIT ; bit++) {
808 if (IsSet(det, tsk, es, QABIT_t(bit))) {
809 text = GetBitName(QABIT_t(bit)) ;
814 printf(" %8s %8s %4s 0x%4lx, Problem signalled: %8s \n", AliRecoParam::GetEventSpecieName(es), GetDetName(det).Data(), GetAliTaskName(tsk), status, text.Data()) ;
817 //_______________________________________________________________
818 void AliQA::UnSet(QABIT_t bit, Int_t ies)
820 // UnSet the status bit of the current detector in the current module
821 UnSet(bit, AliRecoParam::Convert(ies)) ;
824 //_______________________________________________________________
825 void AliQA::UnSet(QABIT_t bit, AliRecoParam::EventSpecie_t es)
827 // UnSet the status bit of the current detector in the current module
829 UnSetStatusBit(fDet, fTask, es, bit) ;
832 //_______________________________________________________________
833 void AliQA::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, AliRecoParam::EventSpecie_t es, QABIT_t bit)
835 // UnSet the status bit for a given detector and a given task
842 ULong_t offset = Offset(tsk) ;
843 ULong_t status = GetStatus(det, es) ;
845 status = status & 0 << offset ;
846 SetStatus(det, es, status) ;