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 (SIM)
24 // bit 4-7 : QA raised during reconstruction (REC)
25 // bit 8-11 : QA raised during ESD checking (ESD)
26 // bit 12-15: 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)
30 //*-- Yves Schutz CERN, July 2007
31 //////////////////////////////////////////////////////////////////////////////
35 // --- ROOT system ---
40 // --- Standard library ---
42 // --- AliRoot header files ---
48 AliQA * AliQA::fgQA = 0x0 ;
49 TFile * AliQA::fgQADataFile = 0x0 ;
50 TString AliQA::fgQADataFileName = "QA" ; // will transform into Det.QA.run.cycle.root
51 TFile * AliQA::fgQARefFile = 0x0 ;
52 TString AliQA::fgQARefDirName = "" ;
53 TString AliQA::fgQARefFileName = "QA.root" ;
54 TFile * AliQA::fgQAResultFile = 0x0 ;
55 TString AliQA::fgQAResultDirName = "" ;
56 TString AliQA::fgQAResultFileName = "QA.root" ;
57 TString AliQA::fgDetNames[] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
58 "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT", "Global"} ;
59 TString AliQA::fgGRPPath = "GRP/GRP/Data" ;
60 TString AliQA::fgRTNames[] = {"UNKNOWN", "AUTO_TEST", "CALIBRATION", "CALIBRATION_PULSER", "CHANNEL_DELAY_TUNING", "COSMIC",
61 "COSMICS", "DAQ_FO_UNIF_SCAN", "DAQ_GEN_DAC_SCAN", "DAQ_MEAN_TH_SCAN", "DAQ_MIN_TH_SCAN",
62 "DAQ_NOISY_PIX_SCAN", "DAQ_PIX_DELAY_SCAN", "DAQ_UNIFORMITY_SCAN", "DCS_FO_UNIF_SCAN",
63 "DCS_MEAN_TH_SCAN", "DCS_MIN_TH_SCAN", "DCS_PIX_DELAY_SCAN", "DCS_UNIFORMITY_SCAN",
64 "DDL_TEST", "GAIN", "PEDESTAL", "INJECTOR", "LASER", "MONTECARLO", "NOISE", "NOISY_PIX_SCAN",
65 "PHYSICS", "PULSER", "STANDALONE", "STANDALONE_BC", "STANDALONE_CENTRAL", "STANDALONE_COSMIC",
66 "STANDALONE_EMD", "STANDALONE_LASER", "STANDALONE_MB", "STANDALONE_PEDESTAL",
67 "STANDALONE_SEMICENTRAL", "STANDALONE_PULSER" } ;
68 TString AliQA::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
69 const TString AliQA::fkgLabLocalFile = "file://" ;
70 const TString AliQA::fkgLabLocalOCDB = "local://" ;
71 const TString AliQA::fkgLabAliEnOCDB = "alien://" ;
72 const TString AliQA::fkgRefFileName = "QA.root" ;
73 const TString AliQA::fkgQAName = "QA" ;
74 const TString AliQA::fkgRefOCDBDirName = "Ref" ;
75 TString AliQA::fkgRefDataDirName = "" ;
76 const TString AliQA::fkgQARefOCDBDefault = "alien://folder=/alice/QA/20" ;
77 //____________________________________________________________________________
81 fQA(new ULong_t[fNdet]),
86 // default constructor
87 // beware singleton: not to be used
89 for (Int_t index = 0 ; index < fNdet ; index++)
93 //____________________________________________________________________________
94 AliQA::AliQA(const AliQA& qa) :
104 //_____________________________________________________________________________
105 AliQA& AliQA::operator = (const AliQA& qa)
107 // assignment operator
114 //_______________________________________________________________
115 AliQA::AliQA(const DETECTORINDEX_t det) :
116 TNamed("QA", "Quality Assurance status"),
118 fQA(new ULong_t[fNdet]),
122 // constructor to be used
123 if (! CheckRange(det) ) {
128 for (index = 0; index < fNdet; index++)
132 //_______________________________________________________________
133 AliQA::AliQA(const ALITASK_t tsk) :
134 TNamed("QA", "Quality Assurance status"),
136 fQA(new ULong_t[fNdet]),
140 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
141 if (! CheckRange(tsk) ) {
146 for (index = 0; index < fNdet; index++)
150 //____________________________________________________________________________
157 //_______________________________________________________________
160 // close the open files
162 if (fgQADataFile->IsOpen())
163 fgQADataFile->Close() ;
165 if (fgQAResultFile->IsOpen())
166 fgQAResultFile->Close() ;
168 if (fgQARefFile->IsOpen())
169 fgQARefFile->Close() ;
172 //_______________________________________________________________
173 const Bool_t AliQA::CheckFatal() const
175 // check if any FATAL status is set
178 for (index = 0; index < kNDET ; index++)
179 rv = rv || IsSet(DETECTORINDEX_t(index), fTask, kFATAL) ;
183 //_______________________________________________________________
184 const Bool_t AliQA::CheckRange(DETECTORINDEX_t det) const
186 // check if detector is in given detector range: 0-kNDET
188 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
190 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
194 //_______________________________________________________________
195 const Bool_t AliQA::CheckRange(ALITASK_t task) const
197 // check if task is given taskk range: 0:kNTASK
198 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
200 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
204 //_______________________________________________________________
205 const Bool_t AliQA::CheckRange(QABIT_t bit) const
207 // check if bit is in given bit range: 0-kNBit
209 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
211 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
217 //_______________________________________________________________
218 const char * AliQA::GetAliTaskName(ALITASK_t tsk)
220 // returns the char name corresponding to module index
244 return tskName.Data() ;
246 //_______________________________________________________________
247 const char * AliQA::GetBitName(QABIT_t bit) const
249 // returns the char name corresponding to bit
258 bitName = "WARNING" ;
270 return bitName.Data() ;
273 //_______________________________________________________________
274 const AliQA::DETECTORINDEX_t AliQA::GetDetIndex(const char * name)
276 // returns the detector index corresponding to a given name
277 TString sname(name) ;
278 DETECTORINDEX_t rv = kNULLDET ;
279 for (Int_t det = 0; det < kNDET ; det++) {
280 if ( GetDetName(det) == sname ) {
281 rv = DETECTORINDEX_t(det) ;
288 //_______________________________________________________________
289 const char * AliQA::GetDetName(Int_t det)
291 // returns the detector name corresponding to a given index (needed in a loop)
293 if ( det >= 0 && det < kNDET)
294 return (fgDetNames[det]).Data() ;
299 //_______________________________________________________________
300 TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
302 // opens the file to store the detectors Quality Assurance Data Maker results
303 const char * temp = Form("%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
305 if (! fgQADataFile ) {
306 if (gSystem->AccessPathName(temp))
310 fgQADataFile = TFile::Open(temp, opt.Data()) ;
312 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
313 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
314 if ( !fgQADataFile ) {
315 if (gSystem->AccessPathName(temp))
319 fgQADataFile = TFile::Open(temp, opt.Data()) ;
323 return fgQADataFile ;
326 //_____________________________________________________________________________
327 TFile * AliQA::GetQADataFile(const char * fileName)
329 // Open if necessary the Data file and return its pointer
333 fileName = AliQA::GetQADataFileName() ;
334 if (!gSystem->AccessPathName(fileName)) {
335 fgQADataFile = TFile::Open(fileName) ;
337 printf("File %s not found", fileName) ;
340 return fgQADataFile ;
343 //_______________________________________________________________
344 TFile * AliQA::GetQAResultFile()
346 // opens the file to store the Quality Assurance Data Checker results
348 fgQAResultFile->Close() ;
349 fgQAResultFile = 0x0 ;
350 // if (!fgQAResultFile) {
351 TString dirName(fgQAResultDirName) ;
352 if ( dirName.Contains(fkgLabLocalFile))
353 dirName.ReplaceAll(fkgLabLocalFile, "") ;
354 TString fileName(dirName + fgQAResultFileName) ;
356 if ( !gSystem->AccessPathName(fileName) )
359 if ( gSystem->AccessPathName(dirName) )
360 gSystem->mkdir(dirName) ;
363 fgQAResultFile = TFile::Open(fileName, opt) ;
366 return fgQAResultFile ;
369 //_______________________________________________________________
370 const TString AliQA::GetRunTypeName(RUNTYPE_t rt)
372 TString rv("Invalid Run Type") ;
373 if ( rt == kNULLTYPE ) {
374 rv = "Known RUN_TYPE are: \n" ;
375 for (Int_t index = 0 ; index < kNTYPE; index++) {
376 rv += Form("%2d -- %s\n", index, fgRTNames[index].Data()) ;
378 printf("%s", rv.Data()) ;
382 if ( rt > kNULLTYPE && rt < kNTYPE )
388 //_______________________________________________________________
389 const Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit) const
391 // Checks is the requested bit is set
397 ULong_t offset = Offset(tsk) ;
398 ULong_t status = GetStatus(det) ;
400 status = (status & 1 << offset) != 0 ;
404 //_______________________________________________________________
405 AliQA * AliQA::Instance()
407 // Get an instance of the singleton.
408 // Object must have been instantiated with Instance(ALITASK) first
413 //_______________________________________________________________
414 AliQA * AliQA::Instance(const DETECTORINDEX_t det)
416 // Get an instance of the singleton. The only authorized way to call the ctor
419 TFile * f = GetQAResultFile() ;
420 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
422 fgQA = new AliQA(det) ;
428 //_______________________________________________________________
429 AliQA * AliQA::Instance(const ALITASK_t tsk)
431 // get an instance of the singleton.
438 fgQA = new AliQA(tsk) ;
441 fgQA = new AliQA(tsk) ;
444 printf("fgQA = gAlice->GetQA()") ;
447 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
450 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
460 //_______________________________________________________________
461 AliQA * AliQA::Instance(const TASKINDEX_t tsk)
463 // get an instance of the singleton.
465 ALITASK_t index = kNULLTASK ;
469 else if (tsk < kDIGITS)
471 else if (tsk < kRECPARTICLES)
473 else if (tsk == kESDS)
476 return Instance(index) ;
479 //_______________________________________________________________
480 const ULong_t AliQA::Offset(ALITASK_t tsk) const
482 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
512 //_______________________________________________________________
513 void AliQA::Set(QABIT_t bit)
515 // Set the status bit of the current detector in the current module
517 SetStatusBit(fDet, fTask, bit) ;
520 //_____________________________________________________________________________
521 void AliQA::SetQARefStorage(const char * name)
523 // Set the root directory where the QA reference data are stored
525 fgQARefDirName = name ;
526 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
527 fgQARefFileName = fkgRefFileName ;
528 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
529 fgQARefFileName = fkgQAName ;
530 else if ( fgQARefDirName.Contains(fkgLabAliEnOCDB) )
531 fgQARefFileName = fkgQAName ;
534 printf("ERROR: %s is an invalid storage definition\n", name) ;
535 fgQARefDirName = "" ;
536 fgQARefFileName = "" ;
538 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
539 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
542 //_____________________________________________________________________________
543 void AliQA::SetQARefDataDirName(const char * name)
545 // Set the lower level directory name where reference data are found
548 for (Int_t index = 0; index < AliQA::kNTYPE; index++) {
549 if (test == fgRTNames[index]) {
550 rt = (RUNTYPE_t) index ;
553 printf("AliQA::SetQARefDataDirName: %s is an unknown RUN TYPE name\n", name) ;
557 SetQARefDataDirName(rt) ;
560 //_____________________________________________________________________________
561 void AliQA::SetQAResultDirName(const char * name)
563 // Set the root directory where to store the QA status object
565 fgQAResultDirName.Prepend(name) ;
566 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
567 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
568 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
569 fgQAResultFileName.Prepend(fgQAResultDirName) ;
572 //_______________________________________________________________
573 void AliQA::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
575 // Set the status bit for a given detector and a given task
581 ULong_t offset = Offset(tsk) ;
582 ULong_t status = GetStatus(det) ;
584 status = status | 1 << offset ;
585 SetStatus(det, status) ;
588 //_______________________________________________________________
589 void AliQA::ShowAll() const
591 // dispplay the QA status word
593 for (index = 0 ; index < kNDET ; index++)
594 ShowStatus(DETECTORINDEX_t(index)) ;
597 //_______________________________________________________________
598 void AliQA::ShowStatus(DETECTORINDEX_t det) const
600 // Prints the full QA status of a given detector
602 ULong_t status = GetStatus(det) ;
603 ULong_t tskStatus[kNTASK] ;
604 tskStatus[kRAW] = status & 0x0000f ;
605 tskStatus[kSIM] = status & 0x000f0 ;
606 tskStatus[kREC] = status & 0x00f00 ;
607 tskStatus[kESD] = status & 0x0f000 ;
608 tskStatus[kANA] = status & 0xf0000 ;
610 AliInfo(Form("====> QA Status for %8s raw =0x%x, sim=0x%x, rec=0x%x, esd=0x%x, ana=0x%x", GetDetName(det).Data(),
611 tskStatus[kRAW], tskStatus[kSIM], tskStatus[kREC], tskStatus[kESD], tskStatus[kANA] )) ;
612 for (Int_t tsk = kRAW ; tsk < kNTASK ; tsk++) {
613 ShowASCIIStatus(det, ALITASK_t(tsk), tskStatus[tsk]) ;
617 //_______________________________________________________________
618 void AliQA::ShowASCIIStatus(DETECTORINDEX_t det, ALITASK_t tsk, const ULong_t status) const
620 // print the QA status in human readable format
622 for (Int_t bit = kINFO ; bit < kNBIT ; bit++) {
623 if (IsSet(det, tsk, QABIT_t(bit))) {
624 text = GetBitName(QABIT_t(bit)) ;
629 printf(" %8s %4s 0x%4x, Problem signalled: %8s \n", GetDetName(det).Data(), GetAliTaskName(tsk), status, text.Data()) ;
632 //_______________________________________________________________
633 void AliQA::UnSet(QABIT_t bit)
635 // UnSet the status bit of the current detector in the current module
637 UnSetStatusBit(fDet, fTask, bit) ;
640 //_______________________________________________________________
641 void AliQA::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
643 // UnSet the status bit for a given detector and a given task
649 ULong_t offset = Offset(tsk) ;
650 ULong_t status = GetStatus(det) ;
652 status = status & 0 << offset ;
653 SetStatus(det, status) ;