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 ---
38 // --- Standard library ---
40 // --- AliRoot header files ---
41 #include "AliCDBManager.h"
42 #include "AliCDBMetaData.h"
43 #include "AliCDBEntry.h"
46 #include "AliQAChecker.h"
50 AliQA * AliQA::fgQA = 0x0 ;
51 TFile * AliQA::fgQADataFile = 0x0 ;
52 TString AliQA::fgQADataFileName = "QA" ; // will transform into Det.QA.run.cycle.root
53 TFile * AliQA::fgQARefFile = 0x0 ;
54 TString AliQA::fgQARefDirName = "local://Ref/" ;
55 TString AliQA::fgQARefFileName = "QA.root" ;
56 TFile * AliQA::fgQAResultFile = 0x0 ;
57 TString AliQA::fgQAResultDirName = "local://RUN/" ;
58 TString AliQA::fgQAResultFileName = "QA.root" ;
59 TString AliQA::fgDetNames[] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
60 "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"} ;
61 TString AliQA::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
63 //____________________________________________________________________________
67 fQA(new ULong_t[fNdet]),
71 // default constructor
72 // beware singleton: not to be used
74 for (Int_t index = 0 ; index < fNdet ; index++)
78 //____________________________________________________________________________
79 AliQA::AliQA(const AliQA& qa) :
89 //_____________________________________________________________________________
90 AliQA& AliQA::operator = (const AliQA& qa)
92 // assignment operator
99 //_______________________________________________________________
100 AliQA::AliQA(const DETECTORINDEX det) :
101 TNamed("QA", "Quality Assurance status"),
103 fQA(new ULong_t[fNdet]),
107 // constructor to be used
108 if (! CheckRange(det) ) {
113 for (index = 0; index < fNdet; index++)
117 //_______________________________________________________________
118 AliQA::AliQA(const ALITASK tsk) :
119 TNamed("QA", "Quality Assurance status"),
121 fQA(new ULong_t[fNdet]),
125 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
126 if (! CheckRange(tsk) ) {
131 for (index = 0; index < fNdet; index++)
135 //____________________________________________________________________________
142 //_______________________________________________________________
143 const Bool_t AliQA::AddQAData2CDB(const char * defSto) const
145 // loads the QA data into the OCDB
147 AliCDBManager* man = AliCDBManager::Instance() ;
148 man->SetDefaultStorage(defSto) ;
150 // loop over detectors
151 AliCDBId id("QA/Ref/PHOS",0,999999999) ;
157 //_______________________________________________________________
160 // close the open files
162 if (fgQADataFile->IsOpen())
163 fgQADataFile->Close() ;
165 if (fgQAResultFile->IsOpen())
166 fgQAResultFile->Close() ;
168 if (fgQARefFile->IsOpen())
169 fgQARefFile->Close() ;
172 //_______________________________________________________________
173 const Bool_t AliQA::CheckFatal() const
175 // check if any FATAL status is set
178 for (index = 0; index < kNDET ; index++)
179 rv = rv || IsSet(DETECTORINDEX(index), fTask, kFATAL) ;
183 //_______________________________________________________________
184 const Bool_t AliQA::CheckRange(DETECTORINDEX det) const
186 // check if detector is in given detector range: 0-kNDET
188 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
190 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
194 //_______________________________________________________________
195 const Bool_t AliQA::CheckRange(ALITASK task) const
197 // check if task is given taskk range: 0:kNTASK
198 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
200 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
204 //_______________________________________________________________
205 const Bool_t AliQA::CheckRange(QABIT bit) const
207 // check if bit is in given bit range: 0-kNBit
209 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
211 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
217 //_______________________________________________________________
218 const char * AliQA::GetAliTaskName(ALITASK tsk)
220 // returns the char name corresponding to module index
244 return tskName.Data() ;
247 //_______________________________________________________________
248 const char * AliQA::GetDetName(Int_t det)
250 // returns the detector name corresponding to a given index (needed in a loop)
252 if ( det >= 0 && det < kNDET)
253 return (fgDetNames[det]).Data() ;
258 //_______________________________________________________________
259 TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
261 // opens the file to store the detectors Quality Assurance Data Maker results
263 sprintf(temp, "%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
265 if (! fgQADataFile ) {
266 if (gSystem->AccessPathName(temp))
270 fgQADataFile = TFile::Open(temp, opt.Data()) ;
272 if ( (strcmp(temp, fgQADataFile->GetName()) != 0) ) {
273 if (gSystem->AccessPathName(temp))
277 fgQADataFile = TFile::Open(temp, opt.Data()) ;
280 return fgQADataFile ;
283 //_____________________________________________________________________________
284 TFile * AliQA::GetQADataFile(const char * fileName)
286 // Open if necessary the Data file and return its pointer
290 fileName = AliQA::GetQADataFileName() ;
291 if (!gSystem->AccessPathName(fileName)) {
292 fgQADataFile = TFile::Open(fileName) ;
294 printf("File %s not found", fileName) ;
297 return fgQADataFile ;
300 //_______________________________________________________________
301 TFile * AliQA::GetQARefFile()
303 // opens the file whwre Quality Assurance Reference Data are stored
306 TString fileName(fgQARefDirName + fgQARefFileName) ;
308 if ( fileName.Contains("local://"))
309 fileName.ReplaceAll("local://", "") ;
311 fgQARefFile = TFile::Open(fileName.Data(), "READ") ;
316 //_______________________________________________________________
317 TFile * AliQA::GetQAResultFile()
319 // opens the file to store the Quality Assurance Data Checker results
321 if (!fgQAResultFile) {
322 TString fileName(fgQAResultDirName + fgQAResultFileName) ;
323 if ( fileName.Contains("local://"))
324 fileName.ReplaceAll("local://", "") ;
326 if ( !gSystem->AccessPathName(fileName) )
331 fgQAResultFile = TFile::Open(fileName, opt) ;
334 return fgQAResultFile ;
337 //_______________________________________________________________
338 const Bool_t AliQA::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
340 // Checks is the requested bit is set
346 ULong_t offset = Offset(tsk) ;
347 ULong_t status = GetStatus(det) ;
349 status = (status & 1 << offset) != 0 ;
353 //_______________________________________________________________
354 AliQA * AliQA::Instance()
356 // Get an instance of the singleton.
357 // Object must have been instantiated with Instance(ALITASK) first
362 //_______________________________________________________________
363 AliQA * AliQA::Instance(const DETECTORINDEX det)
365 // Get an instance of the singleton. The only authorized way to call the ctor
368 TFile * f = GetQAResultFile() ;
369 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
371 fgQA = new AliQA(det) ;
377 //_______________________________________________________________
378 AliQA * AliQA::Instance(const ALITASK tsk)
380 // get an instance of the singleton.
387 fgQA = new AliQA(tsk) ;
390 fgQA = new AliQA(tsk) ;
393 printf("fgQA = gAlice->GetQA()") ;
396 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
399 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
409 //_______________________________________________________________
410 const ULong_t AliQA::Offset(ALITASK tsk) const
412 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
442 //_______________________________________________________________
443 void AliQA::Set(QABIT bit)
445 // Set the status bit of the current detector in the current module
447 SetStatusBit(fDet, fTask, bit) ;
450 //_____________________________________________________________________________
451 void AliQA::SetQARefDir(const char * name)
453 // Set the root directory where the QA reference data are stored
455 fgQARefDirName.Prepend(name) ;
456 printf("AliQA::SetQARefDir: QA references are in %s\n", fgQARefDirName.Data()) ;
457 if ( fgQARefDirName.Contains("local://"))
458 fgQARefDirName.ReplaceAll("local:/", "") ;
459 fgQARefFileName.Prepend(fgQARefDirName) ;
462 //_____________________________________________________________________________
463 void AliQA::SetQAResultDirName(const char * name)
465 // Set the root directory where to store the QA status object
467 fgQAResultDirName.Prepend(name) ;
468 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
469 if ( fgQAResultDirName.Contains("local://"))
470 fgQAResultDirName.ReplaceAll("local:/", "") ;
471 fgQAResultFileName.Prepend(fgQAResultDirName) ;
474 //_______________________________________________________________
475 void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
477 // Set the status bit for a given detector and a given task
483 ULong_t offset = Offset(tsk) ;
484 ULong_t status = GetStatus(det) ;
486 status = status | 1 << offset ;
487 SetStatus(det, status) ;
490 //_______________________________________________________________
491 void AliQA::ShowAll() const
493 // dispplay the QA status word
495 for (index = 0 ; index < kNDET ; index++)
496 ShowStatus(DETECTORINDEX(index)) ;
499 //_______________________________________________________________
500 void AliQA::ShowStatus(DETECTORINDEX det) const
502 // Prints the full QA status of a given detector
504 ULong_t status = GetStatus(det) ;
505 ULong_t rawStatus = status & 0x0000f ;
506 ULong_t simStatus = status & 0x000f0 ;
507 ULong_t recStatus = status & 0x00f00 ;
508 ULong_t esdStatus = status & 0x0f000 ;
509 ULong_t anaStatus = status & 0xf0000 ;
511 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 )) ;