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 ---
44 #include "AliQAChecker.h"
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"} ;
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::fkgQAOCDBDirName = "QA" ;
65 const TString AliQA::fkgRefOCDBDirName = "Ref" ;
66 const TString AliQA::fkgQARefOCDBDefault = "local://$ALICE_ROOT" ;
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 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 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(index), fTask, kFATAL) ;
173 //_______________________________________________________________
174 const Bool_t AliQA::CheckRange(DETECTORINDEX 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 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 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 tsk)
210 // returns the char name corresponding to module index
234 return tskName.Data() ;
237 //_______________________________________________________________
238 const char * AliQA::GetDetName(Int_t det)
240 // returns the detector name corresponding to a given index (needed in a loop)
242 if ( det >= 0 && det < kNDET)
243 return (fgDetNames[det]).Data() ;
248 //_______________________________________________________________
249 TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
251 // opens the file to store the detectors Quality Assurance Data Maker results
253 sprintf(temp, "%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
255 if (! fgQADataFile ) {
256 if (gSystem->AccessPathName(temp))
260 fgQADataFile = TFile::Open(temp, opt.Data()) ;
262 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
263 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
264 if ( !fgQADataFile ) {
265 if (gSystem->AccessPathName(temp))
269 fgQADataFile = TFile::Open(temp, opt.Data()) ;
273 return fgQADataFile ;
276 //_____________________________________________________________________________
277 TFile * AliQA::GetQADataFile(const char * fileName)
279 // Open if necessary the Data file and return its pointer
283 fileName = AliQA::GetQADataFileName() ;
284 if (!gSystem->AccessPathName(fileName)) {
285 fgQADataFile = TFile::Open(fileName) ;
287 printf("File %s not found", fileName) ;
290 return fgQADataFile ;
293 //_______________________________________________________________
294 TFile * AliQA::GetQAResultFile()
296 // opens the file to store the Quality Assurance Data Checker results
298 if (!fgQAResultFile) {
299 TString dirName(fgQAResultDirName) ;
300 if ( dirName.Contains(fkgLabLocalFile))
301 dirName.ReplaceAll(fkgLabLocalFile, "") ;
302 TString fileName(dirName + fgQAResultFileName) ;
304 if ( !gSystem->AccessPathName(fileName) )
307 if ( gSystem->AccessPathName(dirName) )
308 gSystem->mkdir(dirName) ;
311 fgQAResultFile = TFile::Open(fileName, opt) ;
314 return fgQAResultFile ;
317 //_______________________________________________________________
318 const Bool_t AliQA::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
320 // Checks is the requested bit is set
326 ULong_t offset = Offset(tsk) ;
327 ULong_t status = GetStatus(det) ;
329 status = (status & 1 << offset) != 0 ;
333 //_______________________________________________________________
334 AliQA * AliQA::Instance()
336 // Get an instance of the singleton.
337 // Object must have been instantiated with Instance(ALITASK) first
342 //_______________________________________________________________
343 AliQA * AliQA::Instance(const DETECTORINDEX det)
345 // Get an instance of the singleton. The only authorized way to call the ctor
348 TFile * f = GetQAResultFile() ;
349 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
351 fgQA = new AliQA(det) ;
357 //_______________________________________________________________
358 AliQA * AliQA::Instance(const ALITASK tsk)
360 // get an instance of the singleton.
367 fgQA = new AliQA(tsk) ;
370 fgQA = new AliQA(tsk) ;
373 printf("fgQA = gAlice->GetQA()") ;
376 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
379 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
389 //_______________________________________________________________
390 const ULong_t AliQA::Offset(ALITASK tsk) const
392 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
422 //_______________________________________________________________
423 void AliQA::Set(QABIT bit)
425 // Set the status bit of the current detector in the current module
427 SetStatusBit(fDet, fTask, bit) ;
430 //_____________________________________________________________________________
431 void AliQA::SetQARefStorage(const char * name)
433 // Set the root directory where the QA reference data are stored
435 fgQARefDirName = name ;
436 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
437 fgQARefFileName = fkgRefFileName ;
438 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
439 fgQARefFileName = fkgQAOCDBDirName ;
441 printf("ERROR: %s is an invalid storage definition\n", name) ;
442 fgQARefDirName = "" ;
443 fgQARefFileName = "" ;
445 TString tmp(fgQARefDirName + fgQARefFileName) ;
446 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
449 //_____________________________________________________________________________
450 void AliQA::SetQAResultDirName(const char * name)
452 // Set the root directory where to store the QA status object
454 fgQAResultDirName.Prepend(name) ;
455 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
456 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
457 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
458 fgQAResultFileName.Prepend(fgQAResultDirName) ;
461 //_______________________________________________________________
462 void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
464 // Set the status bit for a given detector and a given task
470 ULong_t offset = Offset(tsk) ;
471 ULong_t status = GetStatus(det) ;
473 status = status | 1 << offset ;
474 SetStatus(det, status) ;
477 //_______________________________________________________________
478 void AliQA::ShowAll() const
480 // dispplay the QA status word
482 for (index = 0 ; index < kNDET ; index++)
483 ShowStatus(DETECTORINDEX(index)) ;
486 //_______________________________________________________________
487 void AliQA::ShowStatus(DETECTORINDEX det) const
489 // Prints the full QA status of a given detector
491 ULong_t status = GetStatus(det) ;
492 ULong_t rawStatus = status & 0x0000f ;
493 ULong_t simStatus = status & 0x000f0 ;
494 ULong_t recStatus = status & 0x00f00 ;
495 ULong_t esdStatus = status & 0x0f000 ;
496 ULong_t anaStatus = status & 0xf0000 ;
498 AliInfo(Form("QA Status for %s raw =0x%x, sim=0x%x, rec=0x%x, esd=0x%x, ana=0x%x\n", GetDetName(det).Data(), rawStatus, simStatus, recStatus, esdStatus, anaStatus )) ;