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 ---
42 #include "AliCDBManager.h"
43 #include "AliCDBMetaData.h"
44 #include "AliCDBEntry.h"
47 #include "AliQAChecker.h"
51 AliQA * AliQA::fgQA = 0x0 ;
52 TFile * AliQA::fgQADataFile = 0x0 ;
53 TString AliQA::fgQADataFileName = "QA" ; // will transform into Det.QA.run.cycle.root
54 TFile * AliQA::fgQARefFile = 0x0 ;
55 TString AliQA::fgQARefDirName = "" ;
56 TString AliQA::fgQARefFileName = "QA.root" ;
57 TFile * AliQA::fgQAResultFile = 0x0 ;
58 TString AliQA::fgQAResultDirName = "" ;
59 TString AliQA::fgQAResultFileName = "QA.root" ;
60 TString AliQA::fgDetNames[] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
61 "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"} ;
62 TString AliQA::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
63 const TString AliQA::fkgLabLocalFile = "file://" ;
64 const TString AliQA::fkgLabLocalOCDB = "local://" ;
65 const TString AliQA::fkgLabAliEnOCDB = "alien://" ;
66 const TString AliQA::fkgRefFileName = "QA.root" ;
67 const TString AliQA::fkgRefOCDBDirName = "QA/Ref" ;
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 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 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 //_______________________________________________________________
149 const Bool_t AliQA::AddQAData2CDB(const char * defSto) const
151 // loads the QA data into the OCDB
153 AliCDBManager* man = AliCDBManager::Instance() ;
154 man->SetDefaultStorage(defSto) ;
156 // loop over detectors
157 AliCDBId id("QA/Ref/PHOS",0,999999999) ;
163 //_______________________________________________________________
166 // close the open files
168 if (fgQADataFile->IsOpen())
169 fgQADataFile->Close() ;
171 if (fgQAResultFile->IsOpen())
172 fgQAResultFile->Close() ;
174 if (fgQARefFile->IsOpen())
175 fgQARefFile->Close() ;
178 //_______________________________________________________________
179 const Bool_t AliQA::CheckFatal() const
181 // check if any FATAL status is set
184 for (index = 0; index < kNDET ; index++)
185 rv = rv || IsSet(DETECTORINDEX(index), fTask, kFATAL) ;
189 //_______________________________________________________________
190 const Bool_t AliQA::CheckRange(DETECTORINDEX det) const
192 // check if detector is in given detector range: 0-kNDET
194 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
196 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
200 //_______________________________________________________________
201 const Bool_t AliQA::CheckRange(ALITASK task) const
203 // check if task is given taskk range: 0:kNTASK
204 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
206 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
210 //_______________________________________________________________
211 const Bool_t AliQA::CheckRange(QABIT bit) const
213 // check if bit is in given bit range: 0-kNBit
215 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
217 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
223 //_______________________________________________________________
224 const char * AliQA::GetAliTaskName(ALITASK tsk)
226 // returns the char name corresponding to module index
250 return tskName.Data() ;
253 //_______________________________________________________________
254 const char * AliQA::GetDetName(Int_t det)
256 // returns the detector name corresponding to a given index (needed in a loop)
258 if ( det >= 0 && det < kNDET)
259 return (fgDetNames[det]).Data() ;
264 //_______________________________________________________________
265 TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
267 // opens the file to store the detectors Quality Assurance Data Maker results
269 sprintf(temp, "%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
271 if (! fgQADataFile ) {
272 if (gSystem->AccessPathName(temp))
276 fgQADataFile = TFile::Open(temp, opt.Data()) ;
278 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
279 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
280 if ( !fgQADataFile ) {
281 if (gSystem->AccessPathName(temp))
285 fgQADataFile = TFile::Open(temp, opt.Data()) ;
289 return fgQADataFile ;
292 //_____________________________________________________________________________
293 TFile * AliQA::GetQADataFile(const char * fileName)
295 // Open if necessary the Data file and return its pointer
299 fileName = AliQA::GetQADataFileName() ;
300 if (!gSystem->AccessPathName(fileName)) {
301 fgQADataFile = TFile::Open(fileName) ;
303 printf("File %s not found", fileName) ;
306 return fgQADataFile ;
309 //_______________________________________________________________
310 TFile * AliQA::GetQAResultFile()
312 // opens the file to store the Quality Assurance Data Checker results
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 det, ALITASK tsk, QABIT 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 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 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 const ULong_t AliQA::Offset(ALITASK tsk) const
408 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
438 //_______________________________________________________________
439 void AliQA::Set(QABIT bit)
441 // Set the status bit of the current detector in the current module
443 SetStatusBit(fDet, fTask, bit) ;
446 //_____________________________________________________________________________
447 void AliQA::SetQARefStorage(const char * name)
449 // Set the root directory where the QA reference data are stored
451 fgQARefDirName = name ;
452 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
453 fgQARefFileName = fkgRefFileName ;
454 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
455 fgQARefFileName = fkgRefOCDBDirName ;
457 printf("ERROR: %s is an invalid storage definition\n", name) ;
458 fgQARefDirName = "" ;
459 fgQARefFileName = "" ;
461 TString tmp(fgQARefDirName + fgQARefFileName) ;
462 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
465 //_____________________________________________________________________________
466 void AliQA::SetQAResultDirName(const char * name)
468 // Set the root directory where to store the QA status object
470 fgQAResultDirName.Prepend(name) ;
471 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
472 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
473 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
474 fgQAResultFileName.Prepend(fgQAResultDirName) ;
477 //_______________________________________________________________
478 void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
480 // Set the status bit for a given detector and a given task
486 ULong_t offset = Offset(tsk) ;
487 ULong_t status = GetStatus(det) ;
489 status = status | 1 << offset ;
490 SetStatus(det, status) ;
493 //_______________________________________________________________
494 void AliQA::ShowAll() const
496 // dispplay the QA status word
498 for (index = 0 ; index < kNDET ; index++)
499 ShowStatus(DETECTORINDEX(index)) ;
502 //_______________________________________________________________
503 void AliQA::ShowStatus(DETECTORINDEX det) const
505 // Prints the full QA status of a given detector
507 ULong_t status = GetStatus(det) ;
508 ULong_t rawStatus = status & 0x0000f ;
509 ULong_t simStatus = status & 0x000f0 ;
510 ULong_t recStatus = status & 0x00f00 ;
511 ULong_t esdStatus = status & 0x0f000 ;
512 ULong_t anaStatus = status & 0xf0000 ;
514 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 )) ;