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::fgRTNames[] = {"AUTO_TEST", "CALIBRATION", "CALIBRATION_PULSER", "CHANNEL_DELAY_TUNING", "COSMIC",
60 "COSMICS", "DAQ_FO_UNIF_SCAN", "DAQ_GEN_DAC_SCAN", "DAQ_MEAN_TH_SCAN", "DAQ_MIN_TH_SCAN",
61 "DAQ_NOISY_PIX_SCAN", "DAQ_PIX_DELAY_SCAN", "DAQ_UNIFORMITY_SCAN", "DCS_FO_UNIF_SCAN",
62 "DCS_MEAN_TH_SCAN", "DCS_MIN_TH_SCAN", "DCS_PIX_DELAY_SCAN", "DCS_UNIFORMITY_SCAN",
63 "DDL_TEST", "GAIN", "PEDESTAL", "INJECTOR", "LASER", "MONTECARLO", "NOISE", "NOISY_PIX_SCAN",
64 "PHYSICS", "PULSER", "STANDALONE", "STANDALONE_BC", "STANDALONE_CENTRAL", "STANDALONE_COSMIC",
65 "STANDALONE_EMD", "STANDALONE_LASER", "STANDALONE_MB", "STANDALONE_PEDESTAL",
66 "STANDALONE_SEMICENTRAL", "STANDALONE_PULSER" } ;
67 TString AliQA::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
68 const TString AliQA::fkgLabLocalFile = "file://" ;
69 const TString AliQA::fkgLabLocalOCDB = "local://" ;
70 const TString AliQA::fkgLabAliEnOCDB = "alien://" ;
71 const TString AliQA::fkgRefFileName = "QA.root" ;
72 const TString AliQA::fkgQAName = "QA" ;
73 const TString AliQA::fkgRefOCDBDirName = "Ref" ;
74 TString AliQA::fkgRefDataDirName = "" ;
75 const TString AliQA::fkgQARefOCDBDefault = "alien://folder=/alice/QA/20" ;
76 //____________________________________________________________________________
80 fQA(new ULong_t[fNdet]),
85 // default constructor
86 // beware singleton: not to be used
88 for (Int_t index = 0 ; index < fNdet ; index++)
92 //____________________________________________________________________________
93 AliQA::AliQA(const AliQA& qa) :
103 //_____________________________________________________________________________
104 AliQA& AliQA::operator = (const AliQA& qa)
106 // assignment operator
113 //_______________________________________________________________
114 AliQA::AliQA(const DETECTORINDEX_t det) :
115 TNamed("QA", "Quality Assurance status"),
117 fQA(new ULong_t[fNdet]),
121 // constructor to be used
122 if (! CheckRange(det) ) {
127 for (index = 0; index < fNdet; index++)
131 //_______________________________________________________________
132 AliQA::AliQA(const ALITASK_t tsk) :
133 TNamed("QA", "Quality Assurance status"),
135 fQA(new ULong_t[fNdet]),
139 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
140 if (! CheckRange(tsk) ) {
145 for (index = 0; index < fNdet; index++)
149 //____________________________________________________________________________
156 //_______________________________________________________________
159 // close the open files
161 if (fgQADataFile->IsOpen())
162 fgQADataFile->Close() ;
164 if (fgQAResultFile->IsOpen())
165 fgQAResultFile->Close() ;
167 if (fgQARefFile->IsOpen())
168 fgQARefFile->Close() ;
171 //_______________________________________________________________
172 const Bool_t AliQA::CheckFatal() const
174 // check if any FATAL status is set
177 for (index = 0; index < kNDET ; index++)
178 rv = rv || IsSet(DETECTORINDEX_t(index), fTask, kFATAL) ;
182 //_______________________________________________________________
183 const Bool_t AliQA::CheckRange(DETECTORINDEX_t det) const
185 // check if detector is in given detector range: 0-kNDET
187 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
189 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
193 //_______________________________________________________________
194 const Bool_t AliQA::CheckRange(ALITASK_t task) const
196 // check if task is given taskk range: 0:kNTASK
197 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
199 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
203 //_______________________________________________________________
204 const Bool_t AliQA::CheckRange(QABIT_t bit) const
206 // check if bit is in given bit range: 0-kNBit
208 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
210 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
216 //_______________________________________________________________
217 const char * AliQA::GetAliTaskName(ALITASK_t tsk)
219 // returns the char name corresponding to module index
243 return tskName.Data() ;
245 //_______________________________________________________________
246 const char * AliQA::GetBitName(QABIT_t bit) const
248 // returns the char name corresponding to bit
257 bitName = "WARNING" ;
269 return bitName.Data() ;
272 //_______________________________________________________________
273 const AliQA::DETECTORINDEX_t AliQA::GetDetIndex(const char * name)
275 // returns the detector index corresponding to a given name
276 TString sname(name) ;
277 DETECTORINDEX_t rv = kNULLDET ;
278 for (Int_t det = 0; det < kNDET ; det++) {
279 if ( GetDetName(det) == sname ) {
280 rv = DETECTORINDEX_t(det) ;
287 //_______________________________________________________________
288 const char * AliQA::GetDetName(Int_t det)
290 // returns the detector name corresponding to a given index (needed in a loop)
292 if ( det >= 0 && det < kNDET)
293 return (fgDetNames[det]).Data() ;
298 //_______________________________________________________________
299 TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
301 // opens the file to store the detectors Quality Assurance Data Maker results
302 const char * temp = Form("%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
304 if (! fgQADataFile ) {
305 if (gSystem->AccessPathName(temp))
309 fgQADataFile = TFile::Open(temp, opt.Data()) ;
311 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
312 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
313 if ( !fgQADataFile ) {
314 if (gSystem->AccessPathName(temp))
318 fgQADataFile = TFile::Open(temp, opt.Data()) ;
322 return fgQADataFile ;
325 //_____________________________________________________________________________
326 TFile * AliQA::GetQADataFile(const char * fileName)
328 // Open if necessary the Data file and return its pointer
332 fileName = AliQA::GetQADataFileName() ;
333 if (!gSystem->AccessPathName(fileName)) {
334 fgQADataFile = TFile::Open(fileName) ;
336 printf("File %s not found", fileName) ;
339 return fgQADataFile ;
342 //_______________________________________________________________
343 TFile * AliQA::GetQAResultFile()
345 // opens the file to store the Quality Assurance Data Checker results
347 fgQAResultFile->Close() ;
348 fgQAResultFile = 0x0 ;
349 // if (!fgQAResultFile) {
350 TString dirName(fgQAResultDirName) ;
351 if ( dirName.Contains(fkgLabLocalFile))
352 dirName.ReplaceAll(fkgLabLocalFile, "") ;
353 TString fileName(dirName + fgQAResultFileName) ;
355 if ( !gSystem->AccessPathName(fileName) )
358 if ( gSystem->AccessPathName(dirName) )
359 gSystem->mkdir(dirName) ;
362 fgQAResultFile = TFile::Open(fileName, opt) ;
365 return fgQAResultFile ;
368 //_______________________________________________________________
369 const TString AliQA::GetRunTypeName(RUNTYPE_t rt)
371 TString rv("Invalid Run Type") ;
372 if ( rt == kNULLTYPE ) {
373 rv = "Known RUN_TYPE are: \n" ;
374 for (Int_t index = 0 ; index < kNTYPE; index++) {
375 rv += Form("%2d -- %s\n", index, fgRTNames[index].Data()) ;
377 printf("%s", rv.Data()) ;
381 if ( rt > kNULLTYPE && rt < kNTYPE )
387 //_______________________________________________________________
388 const Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit) const
390 // Checks is the requested bit is set
396 ULong_t offset = Offset(tsk) ;
397 ULong_t status = GetStatus(det) ;
399 status = (status & 1 << offset) != 0 ;
403 //_______________________________________________________________
404 AliQA * AliQA::Instance()
406 // Get an instance of the singleton.
407 // Object must have been instantiated with Instance(ALITASK) first
412 //_______________________________________________________________
413 AliQA * AliQA::Instance(const DETECTORINDEX_t det)
415 // Get an instance of the singleton. The only authorized way to call the ctor
418 TFile * f = GetQAResultFile() ;
419 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
421 fgQA = new AliQA(det) ;
427 //_______________________________________________________________
428 AliQA * AliQA::Instance(const ALITASK_t tsk)
430 // get an instance of the singleton.
437 fgQA = new AliQA(tsk) ;
440 fgQA = new AliQA(tsk) ;
443 printf("fgQA = gAlice->GetQA()") ;
446 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
449 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
459 //_______________________________________________________________
460 AliQA * AliQA::Instance(const TASKINDEX_t tsk)
462 // get an instance of the singleton.
464 ALITASK_t index = kNULLTASK ;
468 else if (tsk < kDIGITS)
470 else if (tsk < kRECPARTICLES)
472 else if (tsk == kESDS)
475 return Instance(index) ;
478 //_______________________________________________________________
479 const ULong_t AliQA::Offset(ALITASK_t tsk) const
481 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
511 //_______________________________________________________________
512 void AliQA::Set(QABIT_t bit)
514 // Set the status bit of the current detector in the current module
516 SetStatusBit(fDet, fTask, bit) ;
519 //_____________________________________________________________________________
520 void AliQA::SetQARefStorage(const char * name)
522 // Set the root directory where the QA reference data are stored
524 fgQARefDirName = name ;
525 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
526 fgQARefFileName = fkgRefFileName ;
527 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
528 fgQARefFileName = fkgQAName ;
529 else if ( fgQARefDirName.Contains(fkgLabAliEnOCDB) )
530 fgQARefFileName = fkgQAName ;
533 printf("ERROR: %s is an invalid storage definition\n", name) ;
534 fgQARefDirName = "" ;
535 fgQARefFileName = "" ;
537 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
538 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
541 //_____________________________________________________________________________
542 void AliQA::SetQAResultDirName(const char * name)
544 // Set the root directory where to store the QA status object
546 fgQAResultDirName.Prepend(name) ;
547 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
548 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
549 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
550 fgQAResultFileName.Prepend(fgQAResultDirName) ;
553 //_______________________________________________________________
554 void AliQA::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
556 // Set the status bit for a given detector and a given task
562 ULong_t offset = Offset(tsk) ;
563 ULong_t status = GetStatus(det) ;
565 status = status | 1 << offset ;
566 SetStatus(det, status) ;
569 //_______________________________________________________________
570 void AliQA::ShowAll() const
572 // dispplay the QA status word
574 for (index = 0 ; index < kNDET ; index++)
575 ShowStatus(DETECTORINDEX_t(index)) ;
578 //_______________________________________________________________
579 void AliQA::ShowStatus(DETECTORINDEX_t det) const
581 // Prints the full QA status of a given detector
583 ULong_t status = GetStatus(det) ;
584 ULong_t tskStatus[kNTASK] ;
585 tskStatus[kRAW] = status & 0x0000f ;
586 tskStatus[kSIM] = status & 0x000f0 ;
587 tskStatus[kREC] = status & 0x00f00 ;
588 tskStatus[kESD] = status & 0x0f000 ;
589 tskStatus[kANA] = status & 0xf0000 ;
591 AliInfo(Form("====> QA Status for %8s raw =0x%x, sim=0x%x, rec=0x%x, esd=0x%x, ana=0x%x", GetDetName(det).Data(),
592 tskStatus[kRAW], tskStatus[kSIM], tskStatus[kREC], tskStatus[kESD], tskStatus[kANA] )) ;
593 for (Int_t tsk = kRAW ; tsk < kNTASK ; tsk++) {
594 ShowASCIIStatus(det, ALITASK_t(tsk), tskStatus[tsk]) ;
598 //_______________________________________________________________
599 void AliQA::ShowASCIIStatus(DETECTORINDEX_t det, ALITASK_t tsk, const ULong_t status) const
601 // print the QA status in human readable format
603 for (Int_t bit = kINFO ; bit < kNBIT ; bit++) {
604 if (IsSet(det, tsk, QABIT_t(bit))) {
605 text = GetBitName(QABIT_t(bit)) ;
610 printf(" %8s %4s 0x%4x, Problem signalled: %8s \n", GetDetName(det).Data(), GetAliTaskName(tsk), status, text.Data()) ;
613 //_______________________________________________________________
614 void AliQA::UnSet(QABIT_t bit)
616 // UnSet the status bit of the current detector in the current module
618 UnSetStatusBit(fDet, fTask, bit) ;
621 //_______________________________________________________________
622 void AliQA::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
624 // UnSet the status bit for a given detector and a given task
630 ULong_t offset = Offset(tsk) ;
631 ULong_t status = GetStatus(det) ;
633 status = status & 0 << offset ;
634 SetStatus(det, status) ;