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 fgQAResultFile->Close() ;
298 fgQAResultFile = 0x0 ;
299 // if (!fgQAResultFile) {
300 TString dirName(fgQAResultDirName) ;
301 if ( dirName.Contains(fkgLabLocalFile))
302 dirName.ReplaceAll(fkgLabLocalFile, "") ;
303 TString fileName(dirName + fgQAResultFileName) ;
305 if ( !gSystem->AccessPathName(fileName) )
308 if ( gSystem->AccessPathName(dirName) )
309 gSystem->mkdir(dirName) ;
312 fgQAResultFile = TFile::Open(fileName, opt) ;
315 return fgQAResultFile ;
318 //_______________________________________________________________
319 const Bool_t AliQA::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
321 // Checks is the requested bit is set
327 ULong_t offset = Offset(tsk) ;
328 ULong_t status = GetStatus(det) ;
330 status = (status & 1 << offset) != 0 ;
334 //_______________________________________________________________
335 AliQA * AliQA::Instance()
337 // Get an instance of the singleton.
338 // Object must have been instantiated with Instance(ALITASK) first
343 //_______________________________________________________________
344 AliQA * AliQA::Instance(const DETECTORINDEX det)
346 // Get an instance of the singleton. The only authorized way to call the ctor
349 TFile * f = GetQAResultFile() ;
350 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
352 fgQA = new AliQA(det) ;
358 //_______________________________________________________________
359 AliQA * AliQA::Instance(const ALITASK tsk)
361 // get an instance of the singleton.
368 fgQA = new AliQA(tsk) ;
371 fgQA = new AliQA(tsk) ;
374 printf("fgQA = gAlice->GetQA()") ;
377 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
380 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
390 //_______________________________________________________________
391 const ULong_t AliQA::Offset(ALITASK tsk) const
393 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
423 //_______________________________________________________________
424 void AliQA::Set(QABIT bit)
426 // Set the status bit of the current detector in the current module
428 SetStatusBit(fDet, fTask, bit) ;
431 //_____________________________________________________________________________
432 void AliQA::SetQARefStorage(const char * name)
434 // Set the root directory where the QA reference data are stored
436 fgQARefDirName = name ;
437 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
438 fgQARefFileName = fkgRefFileName ;
439 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
440 fgQARefFileName = fkgQAOCDBDirName ;
442 printf("ERROR: %s is an invalid storage definition\n", name) ;
443 fgQARefDirName = "" ;
444 fgQARefFileName = "" ;
446 TString tmp(fgQARefDirName + fgQARefFileName) ;
447 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
450 //_____________________________________________________________________________
451 void AliQA::SetQAResultDirName(const char * name)
453 // Set the root directory where to store the QA status object
455 fgQAResultDirName.Prepend(name) ;
456 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
457 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
458 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
459 fgQAResultFileName.Prepend(fgQAResultDirName) ;
462 //_______________________________________________________________
463 void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
465 // Set the status bit for a given detector and a given task
471 ULong_t offset = Offset(tsk) ;
472 ULong_t status = GetStatus(det) ;
474 status = status | 1 << offset ;
475 SetStatus(det, status) ;
478 //_______________________________________________________________
479 void AliQA::ShowAll() const
481 // dispplay the QA status word
483 for (index = 0 ; index < kNDET ; index++)
484 ShowStatus(DETECTORINDEX(index)) ;
487 //_______________________________________________________________
488 void AliQA::ShowStatus(DETECTORINDEX det) const
490 // Prints the full QA status of a given detector
492 ULong_t status = GetStatus(det) ;
493 ULong_t rawStatus = status & 0x0000f ;
494 ULong_t simStatus = status & 0x000f0 ;
495 ULong_t recStatus = status & 0x00f00 ;
496 ULong_t esdStatus = status & 0x0f000 ;
497 ULong_t anaStatus = status & 0xf0000 ;
499 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 )) ;