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"
48 AliQA * AliQA::fgQA = 0x0 ;
49 TFile * AliQA::fgQADataFile = 0x0 ;
50 TString AliQA::fgQADataFileName = "QA" ; // will transform into Det.QA.run.cycle.root
51 TFile * AliQA::fgQARefFile = 0x0 ;
52 TString AliQA::fgQARefDirName = "" ;
53 TString AliQA::fgQARefFileName = "QA.root" ;
54 TFile * AliQA::fgQAResultFile = 0x0 ;
55 TString AliQA::fgQAResultDirName = "" ;
56 TString AliQA::fgQAResultFileName = "QA.root" ;
57 TString AliQA::fgDetNames[] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
58 "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT", "Global"} ;
59 TString AliQA::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
60 const TString AliQA::fkgLabLocalFile = "file://" ;
61 const TString AliQA::fkgLabLocalOCDB = "local://" ;
62 const TString AliQA::fkgLabAliEnOCDB = "alien://" ;
63 const TString AliQA::fkgRefFileName = "QA.root" ;
64 const TString AliQA::fkgQAName = "QA" ;
65 const TString AliQA::fkgRefOCDBDirName = "Ref" ;
66 TString AliQA::fkgRefDataDirName = "Data" ;
67 const TString AliQA::fkgQARefOCDBDefault = "alien://folder=/alice/QA/20" ;
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_t 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_t 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 //_______________________________________________________________
151 // close the open files
153 if (fgQADataFile->IsOpen())
154 fgQADataFile->Close() ;
156 if (fgQAResultFile->IsOpen())
157 fgQAResultFile->Close() ;
159 if (fgQARefFile->IsOpen())
160 fgQARefFile->Close() ;
163 //_______________________________________________________________
164 const Bool_t AliQA::CheckFatal() const
166 // check if any FATAL status is set
169 for (index = 0; index < kNDET ; index++)
170 rv = rv || IsSet(DETECTORINDEX_t(index), fTask, kFATAL) ;
174 //_______________________________________________________________
175 const Bool_t AliQA::CheckRange(DETECTORINDEX_t det) const
177 // check if detector is in given detector range: 0-kNDET
179 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
181 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
185 //_______________________________________________________________
186 const Bool_t AliQA::CheckRange(ALITASK_t task) const
188 // check if task is given taskk range: 0:kNTASK
189 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
191 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
195 //_______________________________________________________________
196 const Bool_t AliQA::CheckRange(QABIT_t bit) const
198 // check if bit is in given bit range: 0-kNBit
200 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
202 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
208 //_______________________________________________________________
209 const char * AliQA::GetAliTaskName(ALITASK_t tsk)
211 // returns the char name corresponding to module index
235 return tskName.Data() ;
238 //_______________________________________________________________
239 const AliQA::DETECTORINDEX_t AliQA::GetDetIndex(const char * name)
241 // returns the detector index corresponding to a given name
242 TString sname(name) ;
243 DETECTORINDEX_t rv = kNULLDET ;
244 for (Int_t det = 0; det < kNDET ; det++) {
245 if ( GetDetName(det) == sname ) {
246 rv = DETECTORINDEX_t(det) ;
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
268 const char * temp = Form("%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
270 if (! fgQADataFile ) {
271 if (gSystem->AccessPathName(temp))
275 fgQADataFile = TFile::Open(temp, opt.Data()) ;
277 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
278 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
279 if ( !fgQADataFile ) {
280 if (gSystem->AccessPathName(temp))
284 fgQADataFile = TFile::Open(temp, opt.Data()) ;
288 return fgQADataFile ;
291 //_____________________________________________________________________________
292 TFile * AliQA::GetQADataFile(const char * fileName)
294 // Open if necessary the Data file and return its pointer
298 fileName = AliQA::GetQADataFileName() ;
299 if (!gSystem->AccessPathName(fileName)) {
300 fgQADataFile = TFile::Open(fileName) ;
302 printf("File %s not found", fileName) ;
305 return fgQADataFile ;
308 //_______________________________________________________________
309 TFile * AliQA::GetQAResultFile()
311 // opens the file to store the Quality Assurance Data Checker results
313 fgQAResultFile->Close() ;
314 fgQAResultFile = 0x0 ;
315 // if (!fgQAResultFile) {
316 TString dirName(fgQAResultDirName) ;
317 if ( dirName.Contains(fkgLabLocalFile))
318 dirName.ReplaceAll(fkgLabLocalFile, "") ;
319 TString fileName(dirName + fgQAResultFileName) ;
321 if ( !gSystem->AccessPathName(fileName) )
324 if ( gSystem->AccessPathName(dirName) )
325 gSystem->mkdir(dirName) ;
328 fgQAResultFile = TFile::Open(fileName, opt) ;
331 return fgQAResultFile ;
334 //_______________________________________________________________
335 const Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit) const
337 // Checks is the requested bit is set
343 ULong_t offset = Offset(tsk) ;
344 ULong_t status = GetStatus(det) ;
346 status = (status & 1 << offset) != 0 ;
350 //_______________________________________________________________
351 AliQA * AliQA::Instance()
353 // Get an instance of the singleton.
354 // Object must have been instantiated with Instance(ALITASK) first
359 //_______________________________________________________________
360 AliQA * AliQA::Instance(const DETECTORINDEX_t det)
362 // Get an instance of the singleton. The only authorized way to call the ctor
365 TFile * f = GetQAResultFile() ;
366 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
368 fgQA = new AliQA(det) ;
374 //_______________________________________________________________
375 AliQA * AliQA::Instance(const ALITASK_t tsk)
377 // get an instance of the singleton.
384 fgQA = new AliQA(tsk) ;
387 fgQA = new AliQA(tsk) ;
390 printf("fgQA = gAlice->GetQA()") ;
393 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
396 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
406 //_______________________________________________________________
407 AliQA * AliQA::Instance(const TASKINDEX_t tsk)
409 // get an instance of the singleton.
411 ALITASK_t index = kNULLTASK ;
415 else if (tsk < kDIGITS)
417 else if (tsk < kRECPARTICLES)
419 else if (tsk == kESDS)
422 return Instance(index) ;
425 //_______________________________________________________________
426 const ULong_t AliQA::Offset(ALITASK_t tsk) const
428 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
458 //_______________________________________________________________
459 void AliQA::Set(QABIT_t bit)
461 // Set the status bit of the current detector in the current module
463 SetStatusBit(fDet, fTask, bit) ;
466 //_____________________________________________________________________________
467 void AliQA::SetQARefStorage(const char * name)
469 // Set the root directory where the QA reference data are stored
471 fgQARefDirName = name ;
472 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
473 fgQARefFileName = fkgRefFileName ;
474 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
475 fgQARefFileName = fkgQAName ;
476 else if ( fgQARefDirName.Contains(fkgLabAliEnOCDB) )
477 fgQARefFileName = fkgQAName ;
480 printf("ERROR: %s is an invalid storage definition\n", name) ;
481 fgQARefDirName = "" ;
482 fgQARefFileName = "" ;
484 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
485 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
487 AliCDBManager* man = AliCDBManager::Instance() ;
488 if ( ! man->IsDefaultStorageSet() ) {
489 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
490 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
494 //_____________________________________________________________________________
495 void AliQA::SetQAResultDirName(const char * name)
497 // Set the root directory where to store the QA status object
499 fgQAResultDirName.Prepend(name) ;
500 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
501 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
502 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
503 fgQAResultFileName.Prepend(fgQAResultDirName) ;
506 //_______________________________________________________________
507 void AliQA::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
509 // Set the status bit for a given detector and a given task
515 ULong_t offset = Offset(tsk) ;
516 ULong_t status = GetStatus(det) ;
518 status = status | 1 << offset ;
519 SetStatus(det, status) ;
522 //_______________________________________________________________
523 void AliQA::ShowAll() const
525 // dispplay the QA status word
527 for (index = 0 ; index < kNDET ; index++)
528 ShowStatus(DETECTORINDEX_t(index)) ;
531 //_______________________________________________________________
532 void AliQA::ShowStatus(DETECTORINDEX_t det) const
534 // Prints the full QA status of a given detector
536 ULong_t status = GetStatus(det) ;
537 ULong_t rawStatus = status & 0x0000f ;
538 ULong_t simStatus = status & 0x000f0 ;
539 ULong_t recStatus = status & 0x00f00 ;
540 ULong_t esdStatus = status & 0x0f000 ;
541 ULong_t anaStatus = status & 0xf0000 ;
543 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 )) ;
546 //_______________________________________________________________
547 void AliQA::UnSet(QABIT_t bit)
549 // UnSet the status bit of the current detector in the current module
551 UnSetStatusBit(fDet, fTask, bit) ;
554 //_______________________________________________________________
555 void AliQA::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
557 // UnSet the status bit for a given detector and a given task
563 ULong_t offset = Offset(tsk) ;
564 ULong_t status = GetStatus(det) ;
566 status = status & 0 << offset ;
567 SetStatus(det, status) ;