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 //////////////////////////////////////////////////////////////////////////////
34 // --- ROOT system ---
39 // --- Standard library ---
41 // --- AliRoot header files ---
47 AliQA * AliQA::fgQA = 0x0 ;
48 TFile * AliQA::fgQADataFile = 0x0 ;
49 TString AliQA::fgQADataFileName = "QA" ; // will transform into Det.QA.run.cycle.root
50 TFile * AliQA::fgQARefFile = 0x0 ;
51 TString AliQA::fgQARefDirName = "" ;
52 TString AliQA::fgQARefFileName = "QA.root" ;
53 TFile * AliQA::fgQAResultFile = 0x0 ;
54 TString AliQA::fgQAResultDirName = "" ;
55 TString AliQA::fgQAResultFileName = "QA.root" ;
56 TString AliQA::fgDetNames[] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
57 "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT", "Global"} ;
58 TString AliQA::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
59 const TString AliQA::fkgLabLocalFile = "file://" ;
60 const TString AliQA::fkgLabLocalOCDB = "local://" ;
61 const TString AliQA::fkgLabAliEnOCDB = "alien://" ;
62 const TString AliQA::fkgRefFileName = "QA.root" ;
63 const TString AliQA::fkgQAName = "QA" ;
64 const TString AliQA::fkgRefOCDBDirName = "Ref" ;
65 TString AliQA::fkgRefDataDirName = "Data" ;
66 const TString AliQA::fkgQARefOCDBDefault = "alien://folder=/alice/QA/20" ;
67 //____________________________________________________________________________
71 fQA(new ULong_t[fNdet]),
76 // default constructor
77 // beware singleton: not to be used
79 for (Int_t index = 0 ; index < fNdet ; index++)
83 //____________________________________________________________________________
84 AliQA::AliQA(const AliQA& qa) :
94 //_____________________________________________________________________________
95 AliQA& AliQA::operator = (const AliQA& qa)
97 // assignment operator
104 //_______________________________________________________________
105 AliQA::AliQA(const DETECTORINDEX_t det) :
106 TNamed("QA", "Quality Assurance status"),
108 fQA(new ULong_t[fNdet]),
112 // constructor to be used
113 if (! CheckRange(det) ) {
118 for (index = 0; index < fNdet; index++)
122 //_______________________________________________________________
123 AliQA::AliQA(const ALITASK_t tsk) :
124 TNamed("QA", "Quality Assurance status"),
126 fQA(new ULong_t[fNdet]),
130 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
131 if (! CheckRange(tsk) ) {
136 for (index = 0; index < fNdet; index++)
140 //____________________________________________________________________________
147 //_______________________________________________________________
150 // close the open files
152 if (fgQADataFile->IsOpen())
153 fgQADataFile->Close() ;
155 if (fgQAResultFile->IsOpen())
156 fgQAResultFile->Close() ;
158 if (fgQARefFile->IsOpen())
159 fgQARefFile->Close() ;
162 //_______________________________________________________________
163 const Bool_t AliQA::CheckFatal() const
165 // check if any FATAL status is set
168 for (index = 0; index < kNDET ; index++)
169 rv = rv || IsSet(DETECTORINDEX_t(index), fTask, kFATAL) ;
173 //_______________________________________________________________
174 const Bool_t AliQA::CheckRange(DETECTORINDEX_t det) const
176 // check if detector is in given detector range: 0-kNDET
178 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
180 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
184 //_______________________________________________________________
185 const Bool_t AliQA::CheckRange(ALITASK_t task) const
187 // check if task is given taskk range: 0:kNTASK
188 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
190 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
194 //_______________________________________________________________
195 const Bool_t AliQA::CheckRange(QABIT_t bit) const
197 // check if bit is in given bit range: 0-kNBit
199 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
201 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
207 //_______________________________________________________________
208 const char * AliQA::GetAliTaskName(ALITASK_t tsk)
210 // returns the char name corresponding to module index
234 return tskName.Data() ;
237 //_______________________________________________________________
238 const AliQA::DETECTORINDEX_t AliQA::GetDetIndex(const char * name)
240 // returns the detector index corresponding to a given name
241 TString sname(name) ;
242 DETECTORINDEX_t rv = kNULLDET ;
243 for (Int_t det = 0; det < kNDET ; det++) {
244 if ( GetDetName(det) == sname ) {
245 rv = DETECTORINDEX_t(det) ;
252 //_______________________________________________________________
253 const char * AliQA::GetDetName(Int_t det)
255 // returns the detector name corresponding to a given index (needed in a loop)
257 if ( det >= 0 && det < kNDET)
258 return (fgDetNames[det]).Data() ;
263 //_______________________________________________________________
264 TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
266 // opens the file to store the detectors Quality Assurance Data Maker results
267 const char * temp = Form("%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
269 if (! fgQADataFile ) {
270 if (gSystem->AccessPathName(temp))
274 fgQADataFile = TFile::Open(temp, opt.Data()) ;
276 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
277 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
278 if ( !fgQADataFile ) {
279 if (gSystem->AccessPathName(temp))
283 fgQADataFile = TFile::Open(temp, opt.Data()) ;
287 return fgQADataFile ;
290 //_____________________________________________________________________________
291 TFile * AliQA::GetQADataFile(const char * fileName)
293 // Open if necessary the Data file and return its pointer
297 fileName = AliQA::GetQADataFileName() ;
298 if (!gSystem->AccessPathName(fileName)) {
299 fgQADataFile = TFile::Open(fileName) ;
301 printf("File %s not found", fileName) ;
304 return fgQADataFile ;
307 //_______________________________________________________________
308 TFile * AliQA::GetQAResultFile()
310 // opens the file to store the Quality Assurance Data Checker results
312 fgQAResultFile->Close() ;
313 fgQAResultFile = 0x0 ;
314 // if (!fgQAResultFile) {
315 TString dirName(fgQAResultDirName) ;
316 if ( dirName.Contains(fkgLabLocalFile))
317 dirName.ReplaceAll(fkgLabLocalFile, "") ;
318 TString fileName(dirName + fgQAResultFileName) ;
320 if ( !gSystem->AccessPathName(fileName) )
323 if ( gSystem->AccessPathName(dirName) )
324 gSystem->mkdir(dirName) ;
327 fgQAResultFile = TFile::Open(fileName, opt) ;
330 return fgQAResultFile ;
333 //_______________________________________________________________
334 const Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit) const
336 // Checks is the requested bit is set
342 ULong_t offset = Offset(tsk) ;
343 ULong_t status = GetStatus(det) ;
345 status = (status & 1 << offset) != 0 ;
349 //_______________________________________________________________
350 AliQA * AliQA::Instance()
352 // Get an instance of the singleton.
353 // Object must have been instantiated with Instance(ALITASK) first
358 //_______________________________________________________________
359 AliQA * AliQA::Instance(const DETECTORINDEX_t det)
361 // Get an instance of the singleton. The only authorized way to call the ctor
364 TFile * f = GetQAResultFile() ;
365 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
367 fgQA = new AliQA(det) ;
373 //_______________________________________________________________
374 AliQA * AliQA::Instance(const ALITASK_t tsk)
376 // get an instance of the singleton.
383 fgQA = new AliQA(tsk) ;
386 fgQA = new AliQA(tsk) ;
389 printf("fgQA = gAlice->GetQA()") ;
392 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
395 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
405 //_______________________________________________________________
406 AliQA * AliQA::Instance(const TASKINDEX_t tsk)
408 // get an instance of the singleton.
410 ALITASK_t index = kNULLTASK ;
414 else if (tsk < kDIGITS)
416 else if (tsk < kRECPARTICLES)
418 else if (tsk == kESDS)
421 return Instance(index) ;
424 //_______________________________________________________________
425 const ULong_t AliQA::Offset(ALITASK_t tsk) const
427 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
457 //_______________________________________________________________
458 void AliQA::Set(QABIT_t bit)
460 // Set the status bit of the current detector in the current module
462 SetStatusBit(fDet, fTask, bit) ;
465 //_____________________________________________________________________________
466 void AliQA::SetQARefStorage(const char * name)
468 // Set the root directory where the QA reference data are stored
470 fgQARefDirName = name ;
471 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
472 fgQARefFileName = fkgRefFileName ;
473 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
474 fgQARefFileName = fkgQAName ;
475 else if ( fgQARefDirName.Contains(fkgLabAliEnOCDB) )
476 fgQARefFileName = fkgQAName ;
479 printf("ERROR: %s is an invalid storage definition\n", name) ;
480 fgQARefDirName = "" ;
481 fgQARefFileName = "" ;
483 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
484 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
487 //_____________________________________________________________________________
488 void AliQA::SetQAResultDirName(const char * name)
490 // Set the root directory where to store the QA status object
492 fgQAResultDirName.Prepend(name) ;
493 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
494 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
495 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
496 fgQAResultFileName.Prepend(fgQAResultDirName) ;
499 //_______________________________________________________________
500 void AliQA::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
502 // Set the status bit for a given detector and a given task
508 ULong_t offset = Offset(tsk) ;
509 ULong_t status = GetStatus(det) ;
511 status = status | 1 << offset ;
512 SetStatus(det, status) ;
515 //_______________________________________________________________
516 void AliQA::ShowAll() const
518 // dispplay the QA status word
520 for (index = 0 ; index < kNDET ; index++)
521 ShowStatus(DETECTORINDEX_t(index)) ;
524 //_______________________________________________________________
525 void AliQA::ShowStatus(DETECTORINDEX_t det) const
527 // Prints the full QA status of a given detector
529 ULong_t status = GetStatus(det) ;
530 ULong_t rawStatus = status & 0x0000f ;
531 ULong_t simStatus = status & 0x000f0 ;
532 ULong_t recStatus = status & 0x00f00 ;
533 ULong_t esdStatus = status & 0x0f000 ;
534 ULong_t anaStatus = status & 0xf0000 ;
536 AliInfo(Form("QA Status for %8s raw =0x%x, sim=0x%x, rec=0x%x, esd=0x%x, ana=0x%x\n", GetDetName(det).Data(), rawStatus, simStatus, recStatus, esdStatus, anaStatus )) ;
539 //_______________________________________________________________
540 void AliQA::UnSet(QABIT_t bit)
542 // UnSet the status bit of the current detector in the current module
544 UnSetStatusBit(fDet, fTask, bit) ;
547 //_______________________________________________________________
548 void AliQA::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
550 // UnSet the status bit for a given detector and a given task
556 ULong_t offset = Offset(tsk) ;
557 ULong_t status = GetStatus(det) ;
559 status = status & 0 << offset ;
560 SetStatus(det, status) ;