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 = "local://Ref/" ;
56 TString AliQA::fgQARefFileName = "QA.root" ;
57 TFile * AliQA::fgQAResultFile = 0x0 ;
58 TString AliQA::fgQAResultDirName = "local://RUN/" ;
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"} ;
64 //____________________________________________________________________________
68 fQA(new ULong_t[fNdet]),
72 // default constructor
73 // beware singleton: not to be used
75 for (Int_t index = 0 ; index < fNdet ; index++)
79 //____________________________________________________________________________
80 AliQA::AliQA(const AliQA& qa) :
90 //_____________________________________________________________________________
91 AliQA& AliQA::operator = (const AliQA& qa)
93 // assignment operator
100 //_______________________________________________________________
101 AliQA::AliQA(const DETECTORINDEX det) :
102 TNamed("QA", "Quality Assurance status"),
104 fQA(new ULong_t[fNdet]),
108 // constructor to be used
109 if (! CheckRange(det) ) {
114 for (index = 0; index < fNdet; index++)
118 //_______________________________________________________________
119 AliQA::AliQA(const ALITASK tsk) :
120 TNamed("QA", "Quality Assurance status"),
122 fQA(new ULong_t[fNdet]),
126 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
127 if (! CheckRange(tsk) ) {
132 for (index = 0; index < fNdet; index++)
136 //____________________________________________________________________________
143 //_______________________________________________________________
144 const Bool_t AliQA::AddQAData2CDB(const char * defSto) const
146 // loads the QA data into the OCDB
148 AliCDBManager* man = AliCDBManager::Instance() ;
149 man->SetDefaultStorage(defSto) ;
151 // loop over detectors
152 AliCDBId id("QA/Ref/PHOS",0,999999999) ;
158 //_______________________________________________________________
161 // close the open files
163 if (fgQADataFile->IsOpen())
164 fgQADataFile->Close() ;
166 if (fgQAResultFile->IsOpen())
167 fgQAResultFile->Close() ;
169 if (fgQARefFile->IsOpen())
170 fgQARefFile->Close() ;
173 //_______________________________________________________________
174 const Bool_t AliQA::CheckFatal() const
176 // check if any FATAL status is set
179 for (index = 0; index < kNDET ; index++)
180 rv = rv || IsSet(DETECTORINDEX(index), fTask, kFATAL) ;
184 //_______________________________________________________________
185 const Bool_t AliQA::CheckRange(DETECTORINDEX det) const
187 // check if detector is in given detector range: 0-kNDET
189 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
191 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
195 //_______________________________________________________________
196 const Bool_t AliQA::CheckRange(ALITASK task) const
198 // check if task is given taskk range: 0:kNTASK
199 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
201 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
205 //_______________________________________________________________
206 const Bool_t AliQA::CheckRange(QABIT bit) const
208 // check if bit is in given bit range: 0-kNBit
210 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
212 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
218 //_______________________________________________________________
219 const char * AliQA::GetAliTaskName(ALITASK tsk)
221 // returns the char name corresponding to module index
245 return tskName.Data() ;
248 //_______________________________________________________________
249 const char * AliQA::GetDetName(Int_t det)
251 // returns the detector name corresponding to a given index (needed in a loop)
253 if ( det >= 0 && det < kNDET)
254 return (fgDetNames[det]).Data() ;
259 //_______________________________________________________________
260 TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
262 // opens the file to store the detectors Quality Assurance Data Maker results
264 sprintf(temp, "%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
266 if (! fgQADataFile ) {
267 if (gSystem->AccessPathName(temp))
271 fgQADataFile = TFile::Open(temp, opt.Data()) ;
273 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
274 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
275 if ( !fgQADataFile ) {
276 if (gSystem->AccessPathName(temp))
280 fgQADataFile = TFile::Open(temp, opt.Data()) ;
284 return fgQADataFile ;
287 //_____________________________________________________________________________
288 TFile * AliQA::GetQADataFile(const char * fileName)
290 // Open if necessary the Data file and return its pointer
294 fileName = AliQA::GetQADataFileName() ;
295 if (!gSystem->AccessPathName(fileName)) {
296 fgQADataFile = TFile::Open(fileName) ;
298 printf("File %s not found", fileName) ;
301 return fgQADataFile ;
304 //_______________________________________________________________
305 TFile * AliQA::GetQARefFile()
307 // opens the file whwre Quality Assurance Reference Data are stored
310 TString fileName(fgQARefDirName + fgQARefFileName) ;
312 if ( fileName.Contains("local://"))
313 fileName.ReplaceAll("local://", "") ;
315 fgQARefFile = TFile::Open(fileName.Data(), "READ") ;
320 //_______________________________________________________________
321 TFile * AliQA::GetQAResultFile()
323 // opens the file to store the Quality Assurance Data Checker results
325 if (!fgQAResultFile) {
326 TString dirName(fgQAResultDirName) ;
327 if ( dirName.Contains("local://"))
328 dirName.ReplaceAll("local://", "") ;
329 TString fileName(dirName + fgQAResultFileName) ;
331 if ( !gSystem->AccessPathName(fileName) )
334 if ( gSystem->AccessPathName(dirName) )
335 gSystem->mkdir(dirName) ;
338 fgQAResultFile = TFile::Open(fileName, opt) ;
341 return fgQAResultFile ;
344 //_______________________________________________________________
345 const Bool_t AliQA::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
347 // Checks is the requested bit is set
353 ULong_t offset = Offset(tsk) ;
354 ULong_t status = GetStatus(det) ;
356 status = (status & 1 << offset) != 0 ;
360 //_______________________________________________________________
361 AliQA * AliQA::Instance()
363 // Get an instance of the singleton.
364 // Object must have been instantiated with Instance(ALITASK) first
369 //_______________________________________________________________
370 AliQA * AliQA::Instance(const DETECTORINDEX det)
372 // Get an instance of the singleton. The only authorized way to call the ctor
375 TFile * f = GetQAResultFile() ;
376 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
378 fgQA = new AliQA(det) ;
384 //_______________________________________________________________
385 AliQA * AliQA::Instance(const ALITASK tsk)
387 // get an instance of the singleton.
394 fgQA = new AliQA(tsk) ;
397 fgQA = new AliQA(tsk) ;
400 printf("fgQA = gAlice->GetQA()") ;
403 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
406 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
416 //_______________________________________________________________
417 const ULong_t AliQA::Offset(ALITASK tsk) const
419 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
449 //_______________________________________________________________
450 void AliQA::Set(QABIT bit)
452 // Set the status bit of the current detector in the current module
454 SetStatusBit(fDet, fTask, bit) ;
457 //_____________________________________________________________________________
458 void AliQA::SetQARefDir(const char * name)
460 // Set the root directory where the QA reference data are stored
462 fgQARefDirName.Prepend(name) ;
463 printf("AliQA::SetQARefDir: QA references are in %s\n", fgQARefDirName.Data()) ;
464 if ( fgQARefDirName.Contains("local://"))
465 fgQARefDirName.ReplaceAll("local:/", "") ;
466 fgQARefFileName.Prepend(fgQARefDirName) ;
469 //_____________________________________________________________________________
470 void AliQA::SetQAResultDirName(const char * name)
472 // Set the root directory where to store the QA status object
474 fgQAResultDirName.Prepend(name) ;
475 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
476 if ( fgQAResultDirName.Contains("local://"))
477 fgQAResultDirName.ReplaceAll("local:/", "") ;
478 fgQAResultFileName.Prepend(fgQAResultDirName) ;
481 //_______________________________________________________________
482 void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
484 // Set the status bit for a given detector and a given task
490 ULong_t offset = Offset(tsk) ;
491 ULong_t status = GetStatus(det) ;
493 status = status | 1 << offset ;
494 SetStatus(det, status) ;
497 //_______________________________________________________________
498 void AliQA::ShowAll() const
500 // dispplay the QA status word
502 for (index = 0 ; index < kNDET ; index++)
503 ShowStatus(DETECTORINDEX(index)) ;
506 //_______________________________________________________________
507 void AliQA::ShowStatus(DETECTORINDEX det) const
509 // Prints the full QA status of a given detector
511 ULong_t status = GetStatus(det) ;
512 ULong_t rawStatus = status & 0x0000f ;
513 ULong_t simStatus = status & 0x000f0 ;
514 ULong_t recStatus = status & 0x00f00 ;
515 ULong_t esdStatus = status & 0x0f000 ;
516 ULong_t anaStatus = status & 0xf0000 ;
518 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 )) ;