Movin AliQA from STEER to STEERBase
[u/mrichter/AliRoot.git] / STEER / AliQA.cxx
CommitLineData
8661738e 1
421ab0fb 2/**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
7 * *
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 **************************************************************************/
16/* $Id$ */
17
18//////////////////////////////////////////////////////////////////////////////
19//
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)
29//
30//*-- Yves Schutz CERN, July 2007
31//////////////////////////////////////////////////////////////////////////////
32
33
34// --- ROOT system ---
35#include <TFile.h>
36#include <TSystem.h>
0d13dd63 37#include <TROOT.h>
421ab0fb 38
39// --- Standard library ---
40
41// --- AliRoot header files ---
42#include "AliLog.h"
2e42b4d4 43#include "AliQA.h"
9a223722 44#include "AliQAChecker.h"
421ab0fb 45
46
2e42b4d4 47ClassImp(AliQA)
f73f556a 48AliQA * AliQA::fgQA = 0x0 ;
49TFile * AliQA::fgQADataFile = 0x0 ;
50TString AliQA::fgQADataFileName = "QA" ; // will transform into Det.QA.run.cycle.root
51TFile * AliQA::fgQARefFile = 0x0 ;
52TString AliQA::fgQARefDirName = "" ;
53TString AliQA::fgQARefFileName = "QA.root" ;
54TFile * AliQA::fgQAResultFile = 0x0 ;
55TString AliQA::fgQAResultDirName = "" ;
56TString AliQA::fgQAResultFileName = "QA.root" ;
57TString AliQA::fgDetNames[] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
58 "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"} ;
59TString AliQA::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
60const TString AliQA::fkgLabLocalFile = "file://" ;
61const TString AliQA::fkgLabLocalOCDB = "local://" ;
62const TString AliQA::fkgLabAliEnOCDB = "alien://" ;
63const TString AliQA::fkgRefFileName = "QA.root" ;
64const TString AliQA::fkgQAOCDBDirName = "QA" ;
65const TString AliQA::fkgRefOCDBDirName = "Ref" ;
66const TString AliQA::fkgQARefOCDBDefault = "local://$ALICE_ROOT" ;
421ab0fb 67//____________________________________________________________________________
2e42b4d4 68AliQA::AliQA() :
421ab0fb 69 TNamed("", ""),
9a223722 70 fNdet(kNDET),
71 fQA(new ULong_t[fNdet]),
421ab0fb 72 fDet(kNULLDET),
73 fTask(kNULLTASK)
4edbc5bc 74
421ab0fb 75{
76 // default constructor
77 // beware singleton: not to be used
4ecde5fc 78
9a223722 79 for (Int_t index = 0 ; index < fNdet ; index++)
80 fQA[index] = 0 ;
421ab0fb 81}
82
83//____________________________________________________________________________
2e42b4d4 84AliQA::AliQA(const AliQA& qa) :
421ab0fb 85 TNamed(qa),
9a223722 86 fNdet(qa.fNdet),
421ab0fb 87 fQA(qa.fQA),
88 fDet(qa.fDet),
89 fTask(qa.fTask)
90{
91 // cpy ctor
92}
93
94//_____________________________________________________________________________
2e42b4d4 95AliQA& AliQA::operator = (const AliQA& qa)
421ab0fb 96{
97// assignment operator
98
2e42b4d4 99 this->~AliQA();
100 new(this) AliQA(qa);
421ab0fb 101 return *this;
102}
103
104//_______________________________________________________________
2e42b4d4 105AliQA::AliQA(const DETECTORINDEX det) :
9a223722 106 TNamed("QA", "Quality Assurance status"),
107 fNdet(kNDET),
108 fQA(new ULong_t[fNdet]),
a5fa6165 109 fDet(det),
4edbc5bc 110 fTask(kNULLTASK)
a5fa6165 111{
112 // constructor to be used
113 if (! CheckRange(det) ) {
114 fDet = kNULLDET ;
115 return ;
a4976ef3 116 }
a5fa6165 117 Int_t index ;
9a223722 118 for (index = 0; index < fNdet; index++)
a5fa6165 119 fQA[index] = 0 ;
120}
121
122//_______________________________________________________________
2e42b4d4 123AliQA::AliQA(const ALITASK tsk) :
421ab0fb 124 TNamed("QA", "Quality Assurance status"),
9a223722 125 fNdet(kNDET),
126 fQA(new ULong_t[fNdet]),
421ab0fb 127 fDet(kNULLDET),
128 fTask(tsk)
129{
130 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
131 if (! CheckRange(tsk) ) {
132 fTask = kNULLTASK ;
133 return ;
a4976ef3 134 }
a5fa6165 135 Int_t index ;
9a223722 136 for (index = 0; index < fNdet; index++)
a5fa6165 137 fQA[index] = 0 ;
421ab0fb 138}
139
140//____________________________________________________________________________
2e42b4d4 141AliQA::~AliQA()
421ab0fb 142{
143 // dtor
144 delete[] fQA ;
145}
146
46ca5304 147//_______________________________________________________________
148void AliQA::Close()
149{
150 // close the open files
151 if (fgQADataFile)
152 if (fgQADataFile->IsOpen())
153 fgQADataFile->Close() ;
154 if (fgQAResultFile)
155 if (fgQAResultFile->IsOpen())
156 fgQAResultFile->Close() ;
157 if (fgQARefFile)
158 if (fgQARefFile->IsOpen())
159 fgQARefFile->Close() ;
160}
161
4ecde5fc 162//_______________________________________________________________
163const Bool_t AliQA::CheckFatal() const
164{
165 // check if any FATAL status is set
166 Bool_t rv = kFALSE ;
167 Int_t index ;
168 for (index = 0; index < kNDET ; index++)
169 rv = rv || IsSet(DETECTORINDEX(index), fTask, kFATAL) ;
170 return rv ;
171}
172
421ab0fb 173//_______________________________________________________________
2e42b4d4 174const Bool_t AliQA::CheckRange(DETECTORINDEX det) const
421ab0fb 175{
a4976ef3 176 // check if detector is in given detector range: 0-kNDET
421ab0fb 177
a5fa6165 178 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
421ab0fb 179 if (!rv)
180 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
181 return rv ;
182}
183
184//_______________________________________________________________
2e42b4d4 185const Bool_t AliQA::CheckRange(ALITASK task) const
421ab0fb 186{
187 // check if task is given taskk range: 0:kNTASK
6c18591a 188 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
421ab0fb 189 if (!rv)
190 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
191 return rv ;
192}
193
194//_______________________________________________________________
2e42b4d4 195const Bool_t AliQA::CheckRange(QABIT bit) const
421ab0fb 196{
197 // check if bit is in given bit range: 0-kNBit
198
199 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
200 if (!rv)
201 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
202 return rv ;
203}
204
421ab0fb 205
4ecde5fc 206
a5fa6165 207//_______________________________________________________________
2e42b4d4 208const char * AliQA::GetAliTaskName(ALITASK tsk)
421ab0fb 209{
210 // returns the char name corresponding to module index
a5fa6165 211 TString tskName ;
421ab0fb 212 switch (tsk) {
213 case kNULLTASK:
214 break ;
6c18591a 215 case kRAW:
216 tskName = "RAW" ;
217 break ;
421ab0fb 218 case kSIM:
219 tskName = "SIM" ;
220 break ;
221 case kREC:
222 tskName = "REC" ;
223 break ;
224 case kESD:
225 tskName = "ESD" ;
226 break ;
227 case kANA:
228 tskName = "ANA" ;
229 break ;
230 default:
a5fa6165 231 tsk = kNULLTASK ;
421ab0fb 232 break ;
233 }
a5fa6165 234 return tskName.Data() ;
421ab0fb 235}
236
46ca5304 237//_______________________________________________________________
238const char * AliQA::GetDetName(Int_t det)
239{
240 // returns the detector name corresponding to a given index (needed in a loop)
241
242 if ( det >= 0 && det < kNDET)
243 return (fgDetNames[det]).Data() ;
244 else
245 return NULL ;
246}
247
248//_______________________________________________________________
249TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
250{
251 // opens the file to store the detectors Quality Assurance Data Maker results
0d13dd63 252 char temp[20] ;
46ca5304 253 sprintf(temp, "%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
254 TString opt ;
255 if (! fgQADataFile ) {
256 if (gSystem->AccessPathName(temp))
257 opt = "NEW" ;
258 else
259 opt = "UPDATE" ;
260 fgQADataFile = TFile::Open(temp, opt.Data()) ;
261 } else {
0d13dd63 262 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
263 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
264 if ( !fgQADataFile ) {
265 if (gSystem->AccessPathName(temp))
266 opt = "NEW" ;
267 else
268 opt = "UPDATE" ;
269 fgQADataFile = TFile::Open(temp, opt.Data()) ;
270 }
271 }
46ca5304 272 }
273 return fgQADataFile ;
274}
275
276//_____________________________________________________________________________
277TFile * AliQA::GetQADataFile(const char * fileName)
278{
279 // Open if necessary the Data file and return its pointer
280
281 if (!fgQADataFile)
282 if (!fileName)
283 fileName = AliQA::GetQADataFileName() ;
284 if (!gSystem->AccessPathName(fileName)) {
285 fgQADataFile = TFile::Open(fileName) ;
286 } else {
287 printf("File %s not found", fileName) ;
288 exit(1) ;
289 }
290 return fgQADataFile ;
291}
292
4ecde5fc 293//_______________________________________________________________
294TFile * AliQA::GetQAResultFile()
295{
296 // opens the file to store the Quality Assurance Data Checker results
297
46ca5304 298 if (!fgQAResultFile) {
1c0190ec 299 TString dirName(fgQAResultDirName) ;
4edbc5bc 300 if ( dirName.Contains(fkgLabLocalFile))
301 dirName.ReplaceAll(fkgLabLocalFile, "") ;
1c0190ec 302 TString fileName(dirName + fgQAResultFileName) ;
46ca5304 303 TString opt("") ;
304 if ( !gSystem->AccessPathName(fileName) )
305 opt = "UPDATE" ;
5bd22145 306 else {
1c0190ec 307 if ( gSystem->AccessPathName(dirName) )
308 gSystem->mkdir(dirName) ;
46ca5304 309 opt = "NEW" ;
5bd22145 310 }
46ca5304 311 fgQAResultFile = TFile::Open(fileName, opt) ;
312 }
313
314 return fgQAResultFile ;
421ab0fb 315}
316
317//_______________________________________________________________
2e42b4d4 318const Bool_t AliQA::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
421ab0fb 319{
320 // Checks is the requested bit is set
321
322 CheckRange(det) ;
323 CheckRange(tsk) ;
324 CheckRange(bit) ;
325
326 ULong_t offset = Offset(tsk) ;
327 ULong_t status = GetStatus(det) ;
328 offset+= bit ;
329 status = (status & 1 << offset) != 0 ;
330 return status ;
331}
332
333//_______________________________________________________________
2e42b4d4 334AliQA * AliQA::Instance()
421ab0fb 335{
336 // Get an instance of the singleton.
337 // Object must have been instantiated with Instance(ALITASK) first
338
339 return fgQA ;
340}
341
342//_______________________________________________________________
2e42b4d4 343AliQA * AliQA::Instance(const DETECTORINDEX det)
421ab0fb 344{
345 // Get an instance of the singleton. The only authorized way to call the ctor
346
9a223722 347 if ( ! fgQA) {
46ca5304 348 TFile * f = GetQAResultFile() ;
9a223722 349 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
350 if ( ! fgQA )
351 fgQA = new AliQA(det) ;
352 }
421ab0fb 353 fgQA->Set(det) ;
354 return fgQA ;
355}
356
357//_______________________________________________________________
2e42b4d4 358AliQA * AliQA::Instance(const ALITASK tsk)
421ab0fb 359{
360 // get an instance of the singleton.
361
362 if ( ! fgQA)
363 switch (tsk) {
364 case kNULLTASK:
365 break ;
6c18591a 366 case kRAW:
2e42b4d4 367 fgQA = new AliQA(tsk) ;
6c18591a 368 break ;
369 case kSIM:
2e42b4d4 370 fgQA = new AliQA(tsk) ;
421ab0fb 371 break ;
372 case kREC:
373 printf("fgQA = gAlice->GetQA()") ;
374 break ;
375 case kESD:
376 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
377 break ;
378 case kANA:
379 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
380 break ;
381 case kNTASK:
382 break ;
383 }
384 if (fgQA)
385 fgQA->Set(tsk) ;
386 return fgQA ;
387}
388
389//_______________________________________________________________
2e42b4d4 390const ULong_t AliQA::Offset(ALITASK tsk) const
421ab0fb 391{
392 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
393
394 CheckRange(tsk) ;
395
396 ULong_t offset = 0 ;
397 switch (tsk) {
398 case kNULLTASK:
399 break ;
6c18591a 400 case kRAW:
421ab0fb 401 offset+= 0 ;
402 break ;
6c18591a 403 case kSIM:
421ab0fb 404 offset+= 4 ;
405 break ;
6c18591a 406 case kREC:
421ab0fb 407 offset+= 8 ;
408 break ;
6c18591a 409 case kESD:
421ab0fb 410 offset+= 12 ;
411 break ;
6c18591a 412 case kANA:
413 offset+= 16 ;
414 break ;
421ab0fb 415 case kNTASK:
416 break ;
417 }
418
419 return offset ;
420}
421
422//_______________________________________________________________
2e42b4d4 423void AliQA::Set(QABIT bit)
421ab0fb 424{
425 // Set the status bit of the current detector in the current module
426
427 SetStatusBit(fDet, fTask, bit) ;
428}
429
4ecde5fc 430//_____________________________________________________________________________
4edbc5bc 431void AliQA::SetQARefStorage(const char * name)
4ecde5fc 432{
433 // Set the root directory where the QA reference data are stored
434
4edbc5bc 435 fgQARefDirName = name ;
436 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
437 fgQARefFileName = fkgRefFileName ;
438 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
f73f556a 439 fgQARefFileName = fkgQAOCDBDirName ;
4edbc5bc 440 else {
441 printf("ERROR: %s is an invalid storage definition\n", name) ;
442 fgQARefDirName = "" ;
443 fgQARefFileName = "" ;
444 }
445 TString tmp(fgQARefDirName + fgQARefFileName) ;
446 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
4ecde5fc 447}
448
449//_____________________________________________________________________________
450void AliQA::SetQAResultDirName(const char * name)
451{
452 // Set the root directory where to store the QA status object
453
454 fgQAResultDirName.Prepend(name) ;
455 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
4edbc5bc 456 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
457 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
4ecde5fc 458 fgQAResultFileName.Prepend(fgQAResultDirName) ;
459}
460
421ab0fb 461//_______________________________________________________________
2e42b4d4 462void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
421ab0fb 463{
464 // Set the status bit for a given detector and a given task
465
466 CheckRange(det) ;
467 CheckRange(tsk) ;
468 CheckRange(bit) ;
469
470 ULong_t offset = Offset(tsk) ;
471 ULong_t status = GetStatus(det) ;
472 offset+= bit ;
473 status = status | 1 << offset ;
474 SetStatus(det, status) ;
475}
476
477//_______________________________________________________________
2e42b4d4 478void AliQA::ShowAll() const
421ab0fb 479{
480 // dispplay the QA status word
481 Int_t index ;
482 for (index = 0 ; index < kNDET ; index++)
483 ShowStatus(DETECTORINDEX(index)) ;
484}
485
486//_______________________________________________________________
2e42b4d4 487void AliQA::ShowStatus(DETECTORINDEX det) const
421ab0fb 488{
489 // Prints the full QA status of a given detector
490 CheckRange(det) ;
491 ULong_t status = GetStatus(det) ;
a4976ef3 492 ULong_t rawStatus = status & 0x0000f ;
493 ULong_t simStatus = status & 0x000f0 ;
494 ULong_t recStatus = status & 0x00f00 ;
495 ULong_t esdStatus = status & 0x0f000 ;
496 ULong_t anaStatus = status & 0xf0000 ;
421ab0fb 497
a4976ef3 498 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 )) ;
421ab0fb 499}
500