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"} ;
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::fkgQAOCDBDirName = "QA" ;
64 const TString AliQA::fkgRefOCDBDirName = "Ref" ;
65 const TString AliQA::fkgQARefOCDBDefault = "local://$ALICE_ROOT" ;
66 //____________________________________________________________________________
70 fQA(new ULong_t[fNdet]),
75 // default constructor
76 // beware singleton: not to be used
78 for (Int_t index = 0 ; index < fNdet ; index++)
82 //____________________________________________________________________________
83 AliQA::AliQA(const AliQA& qa) :
93 //_____________________________________________________________________________
94 AliQA& AliQA::operator = (const AliQA& qa)
96 // assignment operator
103 //_______________________________________________________________
104 AliQA::AliQA(const DETECTORINDEX det) :
105 TNamed("QA", "Quality Assurance status"),
107 fQA(new ULong_t[fNdet]),
111 // constructor to be used
112 if (! CheckRange(det) ) {
117 for (index = 0; index < fNdet; index++)
121 //_______________________________________________________________
122 AliQA::AliQA(const ALITASK tsk) :
123 TNamed("QA", "Quality Assurance status"),
125 fQA(new ULong_t[fNdet]),
129 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
130 if (! CheckRange(tsk) ) {
135 for (index = 0; index < fNdet; index++)
139 //____________________________________________________________________________
146 //_______________________________________________________________
149 // close the open files
151 if (fgQADataFile->IsOpen())
152 fgQADataFile->Close() ;
154 if (fgQAResultFile->IsOpen())
155 fgQAResultFile->Close() ;
157 if (fgQARefFile->IsOpen())
158 fgQARefFile->Close() ;
161 //_______________________________________________________________
162 const Bool_t AliQA::CheckFatal() const
164 // check if any FATAL status is set
167 for (index = 0; index < kNDET ; index++)
168 rv = rv || IsSet(DETECTORINDEX(index), fTask, kFATAL) ;
172 //_______________________________________________________________
173 const Bool_t AliQA::CheckRange(DETECTORINDEX det) const
175 // check if detector is in given detector range: 0-kNDET
177 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
179 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
183 //_______________________________________________________________
184 const Bool_t AliQA::CheckRange(ALITASK task) const
186 // check if task is given taskk range: 0:kNTASK
187 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
189 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
193 //_______________________________________________________________
194 const Bool_t AliQA::CheckRange(QABIT bit) const
196 // check if bit is in given bit range: 0-kNBit
198 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
200 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
206 //_______________________________________________________________
207 const char * AliQA::GetAliTaskName(ALITASK tsk)
209 // returns the char name corresponding to module index
233 return tskName.Data() ;
236 //_______________________________________________________________
237 const char * AliQA::GetDetName(Int_t det)
239 // returns the detector name corresponding to a given index (needed in a loop)
241 if ( det >= 0 && det < kNDET)
242 return (fgDetNames[det]).Data() ;
247 //_______________________________________________________________
248 TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
250 // opens the file to store the detectors Quality Assurance Data Maker results
252 sprintf(temp, "%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
254 if (! fgQADataFile ) {
255 if (gSystem->AccessPathName(temp))
259 fgQADataFile = TFile::Open(temp, opt.Data()) ;
261 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
262 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
263 if ( !fgQADataFile ) {
264 if (gSystem->AccessPathName(temp))
268 fgQADataFile = TFile::Open(temp, opt.Data()) ;
272 return fgQADataFile ;
275 //_____________________________________________________________________________
276 TFile * AliQA::GetQADataFile(const char * fileName)
278 // Open if necessary the Data file and return its pointer
282 fileName = AliQA::GetQADataFileName() ;
283 if (!gSystem->AccessPathName(fileName)) {
284 fgQADataFile = TFile::Open(fileName) ;
286 printf("File %s not found", fileName) ;
289 return fgQADataFile ;
292 //_______________________________________________________________
293 TFile * AliQA::GetQAResultFile()
295 // opens the file to store the Quality Assurance Data Checker results
297 if (!fgQAResultFile) {
298 TString dirName(fgQAResultDirName) ;
299 if ( dirName.Contains(fkgLabLocalFile))
300 dirName.ReplaceAll(fkgLabLocalFile, "") ;
301 TString fileName(dirName + fgQAResultFileName) ;
303 if ( !gSystem->AccessPathName(fileName) )
306 if ( gSystem->AccessPathName(dirName) )
307 gSystem->mkdir(dirName) ;
310 fgQAResultFile = TFile::Open(fileName, opt) ;
313 return fgQAResultFile ;
316 //_______________________________________________________________
317 const Bool_t AliQA::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
319 // Checks is the requested bit is set
325 ULong_t offset = Offset(tsk) ;
326 ULong_t status = GetStatus(det) ;
328 status = (status & 1 << offset) != 0 ;
332 //_______________________________________________________________
333 AliQA * AliQA::Instance()
335 // Get an instance of the singleton.
336 // Object must have been instantiated with Instance(ALITASK) first
341 //_______________________________________________________________
342 AliQA * AliQA::Instance(const DETECTORINDEX det)
344 // Get an instance of the singleton. The only authorized way to call the ctor
347 TFile * f = GetQAResultFile() ;
348 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
350 fgQA = new AliQA(det) ;
356 //_______________________________________________________________
357 AliQA * AliQA::Instance(const ALITASK tsk)
359 // get an instance of the singleton.
366 fgQA = new AliQA(tsk) ;
369 fgQA = new AliQA(tsk) ;
372 printf("fgQA = gAlice->GetQA()") ;
375 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
378 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
388 //_______________________________________________________________
389 const ULong_t AliQA::Offset(ALITASK tsk) const
391 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
421 //_______________________________________________________________
422 void AliQA::Set(QABIT bit)
424 // Set the status bit of the current detector in the current module
426 SetStatusBit(fDet, fTask, bit) ;
429 //_____________________________________________________________________________
430 void AliQA::SetQARefStorage(const char * name)
432 // Set the root directory where the QA reference data are stored
434 fgQARefDirName = name ;
435 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
436 fgQARefFileName = fkgRefFileName ;
437 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
438 fgQARefFileName = fkgQAOCDBDirName ;
440 printf("ERROR: %s is an invalid storage definition\n", name) ;
441 fgQARefDirName = "" ;
442 fgQARefFileName = "" ;
444 TString tmp(fgQARefDirName + fgQARefFileName) ;
445 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
448 //_____________________________________________________________________________
449 void AliQA::SetQAResultDirName(const char * name)
451 // Set the root directory where to store the QA status object
453 fgQAResultDirName.Prepend(name) ;
454 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
455 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
456 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
457 fgQAResultFileName.Prepend(fgQAResultDirName) ;
460 //_______________________________________________________________
461 void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
463 // Set the status bit for a given detector and a given task
469 ULong_t offset = Offset(tsk) ;
470 ULong_t status = GetStatus(det) ;
472 status = status | 1 << offset ;
473 SetStatus(det, status) ;
476 //_______________________________________________________________
477 void AliQA::ShowAll() const
479 // dispplay the QA status word
481 for (index = 0 ; index < kNDET ; index++)
482 ShowStatus(DETECTORINDEX(index)) ;
485 //_______________________________________________________________
486 void AliQA::ShowStatus(DETECTORINDEX det) const
488 // Prints the full QA status of a given detector
490 ULong_t status = GetStatus(det) ;
491 ULong_t rawStatus = status & 0x0000f ;
492 ULong_t simStatus = status & 0x000f0 ;
493 ULong_t recStatus = status & 0x00f00 ;
494 ULong_t esdStatus = status & 0x0f000 ;
495 ULong_t anaStatus = status & 0xf0000 ;
497 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 )) ;