force raw QA only for selected detectors
[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
b09247a2 34#include <cstdlib>
421ab0fb 35// --- ROOT system ---
36#include <TFile.h>
37#include <TSystem.h>
0d13dd63 38#include <TROOT.h>
421ab0fb 39
40// --- Standard library ---
41
42// --- AliRoot header files ---
43#include "AliLog.h"
2e42b4d4 44#include "AliQA.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",
7c002d48 58 "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT", "Global"} ;
f73f556a 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" ;
96d67a8d 64const TString AliQA::fkgQAName = "QA" ;
f73f556a 65const TString AliQA::fkgRefOCDBDirName = "Ref" ;
96d67a8d 66TString AliQA::fkgRefDataDirName = "Data" ;
13c8b505 67const TString AliQA::fkgQARefOCDBDefault = "alien://folder=/alice/QA/20" ;
421ab0fb 68//____________________________________________________________________________
2e42b4d4 69AliQA::AliQA() :
421ab0fb 70 TNamed("", ""),
9a223722 71 fNdet(kNDET),
72 fQA(new ULong_t[fNdet]),
421ab0fb 73 fDet(kNULLDET),
74 fTask(kNULLTASK)
4edbc5bc 75
421ab0fb 76{
77 // default constructor
78 // beware singleton: not to be used
4ecde5fc 79
9a223722 80 for (Int_t index = 0 ; index < fNdet ; index++)
81 fQA[index] = 0 ;
421ab0fb 82}
83
84//____________________________________________________________________________
2e42b4d4 85AliQA::AliQA(const AliQA& qa) :
421ab0fb 86 TNamed(qa),
9a223722 87 fNdet(qa.fNdet),
421ab0fb 88 fQA(qa.fQA),
89 fDet(qa.fDet),
90 fTask(qa.fTask)
91{
92 // cpy ctor
93}
94
95//_____________________________________________________________________________
2e42b4d4 96AliQA& AliQA::operator = (const AliQA& qa)
421ab0fb 97{
98// assignment operator
99
2e42b4d4 100 this->~AliQA();
101 new(this) AliQA(qa);
421ab0fb 102 return *this;
103}
104
105//_______________________________________________________________
96d67a8d 106AliQA::AliQA(const DETECTORINDEX_t det) :
9a223722 107 TNamed("QA", "Quality Assurance status"),
108 fNdet(kNDET),
109 fQA(new ULong_t[fNdet]),
a5fa6165 110 fDet(det),
4edbc5bc 111 fTask(kNULLTASK)
a5fa6165 112{
113 // constructor to be used
114 if (! CheckRange(det) ) {
115 fDet = kNULLDET ;
116 return ;
a4976ef3 117 }
a5fa6165 118 Int_t index ;
9a223722 119 for (index = 0; index < fNdet; index++)
a5fa6165 120 fQA[index] = 0 ;
121}
122
123//_______________________________________________________________
96d67a8d 124AliQA::AliQA(const ALITASK_t tsk) :
421ab0fb 125 TNamed("QA", "Quality Assurance status"),
9a223722 126 fNdet(kNDET),
127 fQA(new ULong_t[fNdet]),
421ab0fb 128 fDet(kNULLDET),
129 fTask(tsk)
130{
131 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
132 if (! CheckRange(tsk) ) {
133 fTask = kNULLTASK ;
134 return ;
a4976ef3 135 }
a5fa6165 136 Int_t index ;
9a223722 137 for (index = 0; index < fNdet; index++)
a5fa6165 138 fQA[index] = 0 ;
421ab0fb 139}
140
141//____________________________________________________________________________
2e42b4d4 142AliQA::~AliQA()
421ab0fb 143{
144 // dtor
145 delete[] fQA ;
146}
147
46ca5304 148//_______________________________________________________________
149void AliQA::Close()
150{
151 // close the open files
152 if (fgQADataFile)
153 if (fgQADataFile->IsOpen())
154 fgQADataFile->Close() ;
155 if (fgQAResultFile)
156 if (fgQAResultFile->IsOpen())
157 fgQAResultFile->Close() ;
158 if (fgQARefFile)
159 if (fgQARefFile->IsOpen())
160 fgQARefFile->Close() ;
161}
162
4ecde5fc 163//_______________________________________________________________
164const Bool_t AliQA::CheckFatal() const
165{
166 // check if any FATAL status is set
167 Bool_t rv = kFALSE ;
168 Int_t index ;
169 for (index = 0; index < kNDET ; index++)
96d67a8d 170 rv = rv || IsSet(DETECTORINDEX_t(index), fTask, kFATAL) ;
4ecde5fc 171 return rv ;
172}
173
421ab0fb 174//_______________________________________________________________
96d67a8d 175const Bool_t AliQA::CheckRange(DETECTORINDEX_t det) const
421ab0fb 176{
a4976ef3 177 // check if detector is in given detector range: 0-kNDET
421ab0fb 178
a5fa6165 179 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
421ab0fb 180 if (!rv)
181 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
182 return rv ;
183}
184
185//_______________________________________________________________
96d67a8d 186const Bool_t AliQA::CheckRange(ALITASK_t task) const
421ab0fb 187{
188 // check if task is given taskk range: 0:kNTASK
6c18591a 189 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
421ab0fb 190 if (!rv)
191 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
192 return rv ;
193}
194
195//_______________________________________________________________
96d67a8d 196const Bool_t AliQA::CheckRange(QABIT_t bit) const
421ab0fb 197{
198 // check if bit is in given bit range: 0-kNBit
199
200 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
201 if (!rv)
202 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
203 return rv ;
204}
205
421ab0fb 206
4ecde5fc 207
a5fa6165 208//_______________________________________________________________
96d67a8d 209const char * AliQA::GetAliTaskName(ALITASK_t tsk)
421ab0fb 210{
0b96c27c 211 // returns the char name corresponding to module index
212 TString tskName ;
213 switch (tsk) {
214 case kNULLTASK:
215 break ;
216 case kRAW:
217 tskName = "RAW" ;
218 break ;
219 case kSIM:
220 tskName = "SIM" ;
221 break ;
222 case kREC:
223 tskName = "REC" ;
224 break ;
225 case kESD:
226 tskName = "ESD" ;
227 break ;
228 case kANA:
229 tskName = "ANA" ;
230 break ;
231 default:
232 tsk = kNULLTASK ;
233 break ;
234 }
235 return tskName.Data() ;
236}
237//_______________________________________________________________
238const char * AliQA::GetBitName(QABIT_t bit) const
239{
240 // returns the char name corresponding to bit
241 TString bitName ;
242 switch (bit) {
243 case kNULLBit:
244 break ;
245 case kINFO:
246 bitName = "INFO" ;
247 break ;
248 case kWARNING:
249 bitName = "WARNING" ;
250 break ;
251 case kERROR:
252 bitName = "ERROR" ;
253 break ;
254 case kFATAL:
255 bitName = "FATAL" ;
256 break ;
257 default:
258 bit = kNULLBit ;
259 break ;
260 }
261 return bitName.Data() ;
421ab0fb 262}
263
46ca5304 264//_______________________________________________________________
7c002d48 265const AliQA::DETECTORINDEX_t AliQA::GetDetIndex(const char * name)
96d67a8d 266{
267 // returns the detector index corresponding to a given name
268 TString sname(name) ;
269 DETECTORINDEX_t rv = kNULLDET ;
270 for (Int_t det = 0; det < kNDET ; det++) {
271 if ( GetDetName(det) == sname ) {
272 rv = DETECTORINDEX_t(det) ;
273 break ;
274 }
275 }
276 return rv ;
277}
278
7c002d48 279//_______________________________________________________________
280const char * AliQA::GetDetName(Int_t det)
281{
282 // returns the detector name corresponding to a given index (needed in a loop)
283
284 if ( det >= 0 && det < kNDET)
285 return (fgDetNames[det]).Data() ;
286 else
287 return NULL ;
288}
289
46ca5304 290//_______________________________________________________________
291TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
292{
293 // opens the file to store the detectors Quality Assurance Data Maker results
96d67a8d 294 const char * temp = Form("%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
295 TString opt ;
296 if (! fgQADataFile ) {
297 if (gSystem->AccessPathName(temp))
298 opt = "NEW" ;
299 else
300 opt = "UPDATE" ;
301 fgQADataFile = TFile::Open(temp, opt.Data()) ;
302 } else {
303 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
304 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
305 if ( !fgQADataFile ) {
306 if (gSystem->AccessPathName(temp))
307 opt = "NEW" ;
308 else
309 opt = "UPDATE" ;
310 fgQADataFile = TFile::Open(temp, opt.Data()) ;
311 }
312 }
46ca5304 313 }
96d67a8d 314 return fgQADataFile ;
46ca5304 315}
316
317//_____________________________________________________________________________
318TFile * AliQA::GetQADataFile(const char * fileName)
319{
320 // Open if necessary the Data file and return its pointer
321
322 if (!fgQADataFile)
323 if (!fileName)
324 fileName = AliQA::GetQADataFileName() ;
325 if (!gSystem->AccessPathName(fileName)) {
326 fgQADataFile = TFile::Open(fileName) ;
327 } else {
328 printf("File %s not found", fileName) ;
329 exit(1) ;
330 }
331 return fgQADataFile ;
332}
333
4ecde5fc 334//_______________________________________________________________
335TFile * AliQA::GetQAResultFile()
336{
337 // opens the file to store the Quality Assurance Data Checker results
2ba0b5f5 338 if (fgQAResultFile)
339 fgQAResultFile->Close() ;
340 fgQAResultFile = 0x0 ;
341// if (!fgQAResultFile) {
1c0190ec 342 TString dirName(fgQAResultDirName) ;
4edbc5bc 343 if ( dirName.Contains(fkgLabLocalFile))
344 dirName.ReplaceAll(fkgLabLocalFile, "") ;
1c0190ec 345 TString fileName(dirName + fgQAResultFileName) ;
46ca5304 346 TString opt("") ;
347 if ( !gSystem->AccessPathName(fileName) )
348 opt = "UPDATE" ;
5bd22145 349 else {
1c0190ec 350 if ( gSystem->AccessPathName(dirName) )
351 gSystem->mkdir(dirName) ;
46ca5304 352 opt = "NEW" ;
5bd22145 353 }
46ca5304 354 fgQAResultFile = TFile::Open(fileName, opt) ;
2ba0b5f5 355// }
46ca5304 356
357 return fgQAResultFile ;
421ab0fb 358}
359
360//_______________________________________________________________
96d67a8d 361const Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit) const
421ab0fb 362{
363 // Checks is the requested bit is set
364
365 CheckRange(det) ;
366 CheckRange(tsk) ;
367 CheckRange(bit) ;
368
369 ULong_t offset = Offset(tsk) ;
370 ULong_t status = GetStatus(det) ;
371 offset+= bit ;
372 status = (status & 1 << offset) != 0 ;
373 return status ;
374}
375
376//_______________________________________________________________
2e42b4d4 377AliQA * AliQA::Instance()
421ab0fb 378{
379 // Get an instance of the singleton.
380 // Object must have been instantiated with Instance(ALITASK) first
381
382 return fgQA ;
383}
384
385//_______________________________________________________________
96d67a8d 386AliQA * AliQA::Instance(const DETECTORINDEX_t det)
421ab0fb 387{
388 // Get an instance of the singleton. The only authorized way to call the ctor
389
9a223722 390 if ( ! fgQA) {
46ca5304 391 TFile * f = GetQAResultFile() ;
9a223722 392 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
393 if ( ! fgQA )
394 fgQA = new AliQA(det) ;
395 }
421ab0fb 396 fgQA->Set(det) ;
397 return fgQA ;
398}
399
400//_______________________________________________________________
96d67a8d 401AliQA * AliQA::Instance(const ALITASK_t tsk)
421ab0fb 402{
403 // get an instance of the singleton.
404
405 if ( ! fgQA)
406 switch (tsk) {
407 case kNULLTASK:
408 break ;
6c18591a 409 case kRAW:
2e42b4d4 410 fgQA = new AliQA(tsk) ;
6c18591a 411 break ;
412 case kSIM:
2e42b4d4 413 fgQA = new AliQA(tsk) ;
421ab0fb 414 break ;
415 case kREC:
416 printf("fgQA = gAlice->GetQA()") ;
417 break ;
418 case kESD:
419 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
420 break ;
421 case kANA:
422 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
423 break ;
424 case kNTASK:
425 break ;
426 }
427 if (fgQA)
428 fgQA->Set(tsk) ;
429 return fgQA ;
430}
431
432//_______________________________________________________________
96d67a8d 433AliQA * AliQA::Instance(const TASKINDEX_t tsk)
434{
435 // get an instance of the singleton.
436
437 ALITASK_t index = kNULLTASK ;
438
439 if ( tsk == kRAWS )
440 index = kRAW ;
441 else if (tsk < kDIGITS)
442 index = kSIM ;
443 else if (tsk < kRECPARTICLES)
444 index = kREC ;
445 else if (tsk == kESDS)
446 index = kESD ;
447
448 return Instance(index) ;
449}
450
451//_______________________________________________________________
452const ULong_t AliQA::Offset(ALITASK_t tsk) const
421ab0fb 453{
454 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
455
456 CheckRange(tsk) ;
457
458 ULong_t offset = 0 ;
459 switch (tsk) {
460 case kNULLTASK:
461 break ;
6c18591a 462 case kRAW:
421ab0fb 463 offset+= 0 ;
464 break ;
6c18591a 465 case kSIM:
421ab0fb 466 offset+= 4 ;
467 break ;
6c18591a 468 case kREC:
421ab0fb 469 offset+= 8 ;
470 break ;
6c18591a 471 case kESD:
421ab0fb 472 offset+= 12 ;
473 break ;
6c18591a 474 case kANA:
475 offset+= 16 ;
476 break ;
421ab0fb 477 case kNTASK:
478 break ;
479 }
480
481 return offset ;
482}
483
484//_______________________________________________________________
96d67a8d 485void AliQA::Set(QABIT_t bit)
421ab0fb 486{
487 // Set the status bit of the current detector in the current module
488
489 SetStatusBit(fDet, fTask, bit) ;
490}
491
4ecde5fc 492//_____________________________________________________________________________
4edbc5bc 493void AliQA::SetQARefStorage(const char * name)
4ecde5fc 494{
72c25501 495 // Set the root directory where the QA reference data are stored
496
497 fgQARefDirName = name ;
498 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
499 fgQARefFileName = fkgRefFileName ;
500 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
96d67a8d 501 fgQARefFileName = fkgQAName ;
72c25501 502 else if ( fgQARefDirName.Contains(fkgLabAliEnOCDB) )
96d67a8d 503 fgQARefFileName = fkgQAName ;
4ecde5fc 504
4edbc5bc 505 else {
506 printf("ERROR: %s is an invalid storage definition\n", name) ;
507 fgQARefDirName = "" ;
508 fgQARefFileName = "" ;
509 }
72c25501 510 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
4edbc5bc 511 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
4ecde5fc 512}
513
514//_____________________________________________________________________________
515void AliQA::SetQAResultDirName(const char * name)
516{
517 // Set the root directory where to store the QA status object
518
519 fgQAResultDirName.Prepend(name) ;
520 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
4edbc5bc 521 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
522 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
4ecde5fc 523 fgQAResultFileName.Prepend(fgQAResultDirName) ;
524}
525
421ab0fb 526//_______________________________________________________________
96d67a8d 527void AliQA::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
421ab0fb 528{
529 // Set the status bit for a given detector and a given task
530
531 CheckRange(det) ;
532 CheckRange(tsk) ;
533 CheckRange(bit) ;
534
535 ULong_t offset = Offset(tsk) ;
536 ULong_t status = GetStatus(det) ;
537 offset+= bit ;
538 status = status | 1 << offset ;
539 SetStatus(det, status) ;
540}
541
542//_______________________________________________________________
2e42b4d4 543void AliQA::ShowAll() const
421ab0fb 544{
545 // dispplay the QA status word
546 Int_t index ;
547 for (index = 0 ; index < kNDET ; index++)
96d67a8d 548 ShowStatus(DETECTORINDEX_t(index)) ;
421ab0fb 549}
550
551//_______________________________________________________________
96d67a8d 552void AliQA::ShowStatus(DETECTORINDEX_t det) const
421ab0fb 553{
0b96c27c 554 // Prints the full QA status of a given detector
555 CheckRange(det) ;
556 ULong_t status = GetStatus(det) ;
557 ULong_t tskStatus[kNTASK] ;
558 tskStatus[kRAW] = status & 0x0000f ;
559 tskStatus[kSIM] = status & 0x000f0 ;
560 tskStatus[kREC] = status & 0x00f00 ;
561 tskStatus[kESD] = status & 0x0f000 ;
562 tskStatus[kANA] = status & 0xf0000 ;
563
564 AliInfo(Form("====> QA Status for %8s raw =0x%x, sim=0x%x, rec=0x%x, esd=0x%x, ana=0x%x", GetDetName(det).Data(),
565 tskStatus[kRAW], tskStatus[kSIM], tskStatus[kREC], tskStatus[kESD], tskStatus[kANA] )) ;
566 for (Int_t tsk = kRAW ; tsk < kNTASK ; tsk++) {
567 ShowASCIIStatus(det, ALITASK_t(tsk), tskStatus[tsk]) ;
568 }
569}
421ab0fb 570
0b96c27c 571//_______________________________________________________________
572void AliQA::ShowASCIIStatus(DETECTORINDEX_t det, ALITASK_t tsk, const ULong_t status) const
573{
574 // print the QA status in human readable format
575 TString text;
576 for (Int_t bit = kINFO ; bit < kNBIT ; bit++) {
577 if (IsSet(det, tsk, QABIT_t(bit))) {
578 text = GetBitName(QABIT_t(bit)) ;
579 text += " " ;
580 }
581 }
582 if (! text.IsNull())
583 printf(" %8s %4s 0x%4x, Problem signalled: %8s \n", GetDetName(det).Data(), GetAliTaskName(tsk), status, text.Data()) ;
421ab0fb 584}
585
96d67a8d 586//_______________________________________________________________
587void AliQA::UnSet(QABIT_t bit)
588{
589 // UnSet the status bit of the current detector in the current module
590
591 UnSetStatusBit(fDet, fTask, bit) ;
592}
593
594//_______________________________________________________________
595void AliQA::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
596{
597 // UnSet the status bit for a given detector and a given task
598
599 CheckRange(det) ;
600 CheckRange(tsk) ;
601 CheckRange(bit) ;
602
603 ULong_t offset = Offset(tsk) ;
604 ULong_t status = GetStatus(det) ;
605 offset+= bit ;
606 status = status & 0 << offset ;
607 SetStatus(det, status) ;
92a357bf 608}