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::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
60 const TString AliQA::fkgLabLocalFile = "file://" ;
61 const TString AliQA::fkgLabLocalOCDB = "local://" ;
62 const TString AliQA::fkgLabAliEnOCDB = "alien://" ;
63 const TString AliQA::fkgRefFileName = "QA.root" ;
64 const TString AliQA::fkgQAName = "QA" ;
65 const TString AliQA::fkgRefOCDBDirName = "Ref" ;
66 TString AliQA::fkgRefDataDirName = "Data" ;
67 const TString AliQA::fkgQARefOCDBDefault = "alien://folder=/alice/QA/20" ;
68 //____________________________________________________________________________
72 fQA(new ULong_t[fNdet]),
77 // default constructor
78 // beware singleton: not to be used
80 for (Int_t index = 0 ; index < fNdet ; index++)
84 //____________________________________________________________________________
85 AliQA::AliQA(const AliQA& qa) :
95 //_____________________________________________________________________________
96 AliQA& AliQA::operator = (const AliQA& qa)
98 // assignment operator
105 //_______________________________________________________________
106 AliQA::AliQA(const DETECTORINDEX_t det) :
107 TNamed("QA", "Quality Assurance status"),
109 fQA(new ULong_t[fNdet]),
113 // constructor to be used
114 if (! CheckRange(det) ) {
119 for (index = 0; index < fNdet; index++)
123 //_______________________________________________________________
124 AliQA::AliQA(const ALITASK_t tsk) :
125 TNamed("QA", "Quality Assurance status"),
127 fQA(new ULong_t[fNdet]),
131 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
132 if (! CheckRange(tsk) ) {
137 for (index = 0; index < fNdet; index++)
141 //____________________________________________________________________________
148 //_______________________________________________________________
151 // close the open files
153 if (fgQADataFile->IsOpen())
154 fgQADataFile->Close() ;
156 if (fgQAResultFile->IsOpen())
157 fgQAResultFile->Close() ;
159 if (fgQARefFile->IsOpen())
160 fgQARefFile->Close() ;
163 //_______________________________________________________________
164 const Bool_t AliQA::CheckFatal() const
166 // check if any FATAL status is set
169 for (index = 0; index < kNDET ; index++)
170 rv = rv || IsSet(DETECTORINDEX_t(index), fTask, kFATAL) ;
174 //_______________________________________________________________
175 const Bool_t AliQA::CheckRange(DETECTORINDEX_t det) const
177 // check if detector is in given detector range: 0-kNDET
179 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
181 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
185 //_______________________________________________________________
186 const Bool_t AliQA::CheckRange(ALITASK_t task) const
188 // check if task is given taskk range: 0:kNTASK
189 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
191 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
195 //_______________________________________________________________
196 const Bool_t AliQA::CheckRange(QABIT_t bit) const
198 // check if bit is in given bit range: 0-kNBit
200 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
202 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
208 //_______________________________________________________________
209 const char * AliQA::GetAliTaskName(ALITASK_t tsk)
211 // returns the char name corresponding to module index
235 return tskName.Data() ;
237 //_______________________________________________________________
238 const char * AliQA::GetBitName(QABIT_t bit) const
240 // returns the char name corresponding to bit
249 bitName = "WARNING" ;
261 return bitName.Data() ;
264 //_______________________________________________________________
265 const AliQA::DETECTORINDEX_t AliQA::GetDetIndex(const char * name)
267 // returns the detector index corresponding to a given name
268 TString sname(name) ;
269 DETECTORINDEX_t rv = kNULLDET ;
270 for (Int_t det = 0; det < kNDET ; det++) {
271 if ( GetDetName(det) == sname ) {
272 rv = DETECTORINDEX_t(det) ;
279 //_______________________________________________________________
280 const char * AliQA::GetDetName(Int_t det)
282 // returns the detector name corresponding to a given index (needed in a loop)
284 if ( det >= 0 && det < kNDET)
285 return (fgDetNames[det]).Data() ;
290 //_______________________________________________________________
291 TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
293 // opens the file to store the detectors Quality Assurance Data Maker results
294 const char * temp = Form("%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
296 if (! fgQADataFile ) {
297 if (gSystem->AccessPathName(temp))
301 fgQADataFile = TFile::Open(temp, opt.Data()) ;
303 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
304 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
305 if ( !fgQADataFile ) {
306 if (gSystem->AccessPathName(temp))
310 fgQADataFile = TFile::Open(temp, opt.Data()) ;
314 return fgQADataFile ;
317 //_____________________________________________________________________________
318 TFile * AliQA::GetQADataFile(const char * fileName)
320 // Open if necessary the Data file and return its pointer
324 fileName = AliQA::GetQADataFileName() ;
325 if (!gSystem->AccessPathName(fileName)) {
326 fgQADataFile = TFile::Open(fileName) ;
328 printf("File %s not found", fileName) ;
331 return fgQADataFile ;
334 //_______________________________________________________________
335 TFile * AliQA::GetQAResultFile()
337 // opens the file to store the Quality Assurance Data Checker results
339 fgQAResultFile->Close() ;
340 fgQAResultFile = 0x0 ;
341 // if (!fgQAResultFile) {
342 TString dirName(fgQAResultDirName) ;
343 if ( dirName.Contains(fkgLabLocalFile))
344 dirName.ReplaceAll(fkgLabLocalFile, "") ;
345 TString fileName(dirName + fgQAResultFileName) ;
347 if ( !gSystem->AccessPathName(fileName) )
350 if ( gSystem->AccessPathName(dirName) )
351 gSystem->mkdir(dirName) ;
354 fgQAResultFile = TFile::Open(fileName, opt) ;
357 return fgQAResultFile ;
360 //_______________________________________________________________
361 const Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit) const
363 // Checks is the requested bit is set
369 ULong_t offset = Offset(tsk) ;
370 ULong_t status = GetStatus(det) ;
372 status = (status & 1 << offset) != 0 ;
376 //_______________________________________________________________
377 AliQA * AliQA::Instance()
379 // Get an instance of the singleton.
380 // Object must have been instantiated with Instance(ALITASK) first
385 //_______________________________________________________________
386 AliQA * AliQA::Instance(const DETECTORINDEX_t det)
388 // Get an instance of the singleton. The only authorized way to call the ctor
391 TFile * f = GetQAResultFile() ;
392 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
394 fgQA = new AliQA(det) ;
400 //_______________________________________________________________
401 AliQA * AliQA::Instance(const ALITASK_t tsk)
403 // get an instance of the singleton.
410 fgQA = new AliQA(tsk) ;
413 fgQA = new AliQA(tsk) ;
416 printf("fgQA = gAlice->GetQA()") ;
419 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
422 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
432 //_______________________________________________________________
433 AliQA * AliQA::Instance(const TASKINDEX_t tsk)
435 // get an instance of the singleton.
437 ALITASK_t index = kNULLTASK ;
441 else if (tsk < kDIGITS)
443 else if (tsk < kRECPARTICLES)
445 else if (tsk == kESDS)
448 return Instance(index) ;
451 //_______________________________________________________________
452 const ULong_t AliQA::Offset(ALITASK_t tsk) const
454 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
484 //_______________________________________________________________
485 void AliQA::Set(QABIT_t bit)
487 // Set the status bit of the current detector in the current module
489 SetStatusBit(fDet, fTask, bit) ;
492 //_____________________________________________________________________________
493 void AliQA::SetQARefStorage(const char * name)
495 // Set the root directory where the QA reference data are stored
497 fgQARefDirName = name ;
498 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
499 fgQARefFileName = fkgRefFileName ;
500 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
501 fgQARefFileName = fkgQAName ;
502 else if ( fgQARefDirName.Contains(fkgLabAliEnOCDB) )
503 fgQARefFileName = fkgQAName ;
506 printf("ERROR: %s is an invalid storage definition\n", name) ;
507 fgQARefDirName = "" ;
508 fgQARefFileName = "" ;
510 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
511 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
514 //_____________________________________________________________________________
515 void AliQA::SetQAResultDirName(const char * name)
517 // Set the root directory where to store the QA status object
519 fgQAResultDirName.Prepend(name) ;
520 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
521 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
522 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
523 fgQAResultFileName.Prepend(fgQAResultDirName) ;
526 //_______________________________________________________________
527 void AliQA::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
529 // Set the status bit for a given detector and a given task
535 ULong_t offset = Offset(tsk) ;
536 ULong_t status = GetStatus(det) ;
538 status = status | 1 << offset ;
539 SetStatus(det, status) ;
542 //_______________________________________________________________
543 void AliQA::ShowAll() const
545 // dispplay the QA status word
547 for (index = 0 ; index < kNDET ; index++)
548 ShowStatus(DETECTORINDEX_t(index)) ;
551 //_______________________________________________________________
552 void AliQA::ShowStatus(DETECTORINDEX_t det) const
554 // Prints the full QA status of a given detector
556 ULong_t status = GetStatus(det) ;
557 ULong_t tskStatus[kNTASK] ;
558 tskStatus[kRAW] = status & 0x0000f ;
559 tskStatus[kSIM] = status & 0x000f0 ;
560 tskStatus[kREC] = status & 0x00f00 ;
561 tskStatus[kESD] = status & 0x0f000 ;
562 tskStatus[kANA] = status & 0xf0000 ;
564 AliInfo(Form("====> QA Status for %8s raw =0x%x, sim=0x%x, rec=0x%x, esd=0x%x, ana=0x%x", GetDetName(det).Data(),
565 tskStatus[kRAW], tskStatus[kSIM], tskStatus[kREC], tskStatus[kESD], tskStatus[kANA] )) ;
566 for (Int_t tsk = kRAW ; tsk < kNTASK ; tsk++) {
567 ShowASCIIStatus(det, ALITASK_t(tsk), tskStatus[tsk]) ;
571 //_______________________________________________________________
572 void AliQA::ShowASCIIStatus(DETECTORINDEX_t det, ALITASK_t tsk, const ULong_t status) const
574 // print the QA status in human readable format
576 for (Int_t bit = kINFO ; bit < kNBIT ; bit++) {
577 if (IsSet(det, tsk, QABIT_t(bit))) {
578 text = GetBitName(QABIT_t(bit)) ;
583 printf(" %8s %4s 0x%4x, Problem signalled: %8s \n", GetDetName(det).Data(), GetAliTaskName(tsk), status, text.Data()) ;
586 //_______________________________________________________________
587 void AliQA::UnSet(QABIT_t bit)
589 // UnSet the status bit of the current detector in the current module
591 UnSetStatusBit(fDet, fTask, bit) ;
594 //_______________________________________________________________
595 void AliQA::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
597 // UnSet the status bit for a given detector and a given task
603 ULong_t offset = Offset(tsk) ;
604 ULong_t status = GetStatus(det) ;
606 status = status & 0 << offset ;
607 SetStatus(det, status) ;