Effective C++ warning removal (Marian)
[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"
421ab0fb 44
45
2e42b4d4 46ClassImp(AliQA)
f73f556a 47AliQA * AliQA::fgQA = 0x0 ;
48TFile * AliQA::fgQADataFile = 0x0 ;
49TString AliQA::fgQADataFileName = "QA" ; // will transform into Det.QA.run.cycle.root
50TFile * AliQA::fgQARefFile = 0x0 ;
51TString AliQA::fgQARefDirName = "" ;
52TString AliQA::fgQARefFileName = "QA.root" ;
53TFile * AliQA::fgQAResultFile = 0x0 ;
54TString AliQA::fgQAResultDirName = "" ;
55TString AliQA::fgQAResultFileName = "QA.root" ;
56TString AliQA::fgDetNames[] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
57 "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"} ;
58TString AliQA::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
59const TString AliQA::fkgLabLocalFile = "file://" ;
60const TString AliQA::fkgLabLocalOCDB = "local://" ;
61const TString AliQA::fkgLabAliEnOCDB = "alien://" ;
62const TString AliQA::fkgRefFileName = "QA.root" ;
63const TString AliQA::fkgQAOCDBDirName = "QA" ;
64const TString AliQA::fkgRefOCDBDirName = "Ref" ;
13c8b505 65const TString AliQA::fkgRefDataDirName = "Data" ;
66const TString AliQA::fkgQARefOCDBDefault = "alien://folder=/alice/QA/20" ;
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
2ba0b5f5 297 if (fgQAResultFile)
298 fgQAResultFile->Close() ;
299 fgQAResultFile = 0x0 ;
300// if (!fgQAResultFile) {
1c0190ec 301 TString dirName(fgQAResultDirName) ;
4edbc5bc 302 if ( dirName.Contains(fkgLabLocalFile))
303 dirName.ReplaceAll(fkgLabLocalFile, "") ;
1c0190ec 304 TString fileName(dirName + fgQAResultFileName) ;
46ca5304 305 TString opt("") ;
306 if ( !gSystem->AccessPathName(fileName) )
307 opt = "UPDATE" ;
5bd22145 308 else {
1c0190ec 309 if ( gSystem->AccessPathName(dirName) )
310 gSystem->mkdir(dirName) ;
46ca5304 311 opt = "NEW" ;
5bd22145 312 }
46ca5304 313 fgQAResultFile = TFile::Open(fileName, opt) ;
2ba0b5f5 314// }
46ca5304 315
316 return fgQAResultFile ;
421ab0fb 317}
318
319//_______________________________________________________________
2e42b4d4 320const Bool_t AliQA::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
421ab0fb 321{
322 // Checks is the requested bit is set
323
324 CheckRange(det) ;
325 CheckRange(tsk) ;
326 CheckRange(bit) ;
327
328 ULong_t offset = Offset(tsk) ;
329 ULong_t status = GetStatus(det) ;
330 offset+= bit ;
331 status = (status & 1 << offset) != 0 ;
332 return status ;
333}
334
335//_______________________________________________________________
2e42b4d4 336AliQA * AliQA::Instance()
421ab0fb 337{
338 // Get an instance of the singleton.
339 // Object must have been instantiated with Instance(ALITASK) first
340
341 return fgQA ;
342}
343
344//_______________________________________________________________
2e42b4d4 345AliQA * AliQA::Instance(const DETECTORINDEX det)
421ab0fb 346{
347 // Get an instance of the singleton. The only authorized way to call the ctor
348
9a223722 349 if ( ! fgQA) {
46ca5304 350 TFile * f = GetQAResultFile() ;
9a223722 351 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
352 if ( ! fgQA )
353 fgQA = new AliQA(det) ;
354 }
421ab0fb 355 fgQA->Set(det) ;
356 return fgQA ;
357}
358
359//_______________________________________________________________
2e42b4d4 360AliQA * AliQA::Instance(const ALITASK tsk)
421ab0fb 361{
362 // get an instance of the singleton.
363
364 if ( ! fgQA)
365 switch (tsk) {
366 case kNULLTASK:
367 break ;
6c18591a 368 case kRAW:
2e42b4d4 369 fgQA = new AliQA(tsk) ;
6c18591a 370 break ;
371 case kSIM:
2e42b4d4 372 fgQA = new AliQA(tsk) ;
421ab0fb 373 break ;
374 case kREC:
375 printf("fgQA = gAlice->GetQA()") ;
376 break ;
377 case kESD:
378 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
379 break ;
380 case kANA:
381 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
382 break ;
383 case kNTASK:
384 break ;
385 }
386 if (fgQA)
387 fgQA->Set(tsk) ;
388 return fgQA ;
389}
390
391//_______________________________________________________________
2e42b4d4 392const ULong_t AliQA::Offset(ALITASK tsk) const
421ab0fb 393{
394 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
395
396 CheckRange(tsk) ;
397
398 ULong_t offset = 0 ;
399 switch (tsk) {
400 case kNULLTASK:
401 break ;
6c18591a 402 case kRAW:
421ab0fb 403 offset+= 0 ;
404 break ;
6c18591a 405 case kSIM:
421ab0fb 406 offset+= 4 ;
407 break ;
6c18591a 408 case kREC:
421ab0fb 409 offset+= 8 ;
410 break ;
6c18591a 411 case kESD:
421ab0fb 412 offset+= 12 ;
413 break ;
6c18591a 414 case kANA:
415 offset+= 16 ;
416 break ;
421ab0fb 417 case kNTASK:
418 break ;
419 }
420
421 return offset ;
422}
423
424//_______________________________________________________________
2e42b4d4 425void AliQA::Set(QABIT bit)
421ab0fb 426{
427 // Set the status bit of the current detector in the current module
428
429 SetStatusBit(fDet, fTask, bit) ;
430}
431
4ecde5fc 432//_____________________________________________________________________________
4edbc5bc 433void AliQA::SetQARefStorage(const char * name)
4ecde5fc 434{
72c25501 435 // Set the root directory where the QA reference data are stored
436
437 fgQARefDirName = name ;
438 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
439 fgQARefFileName = fkgRefFileName ;
440 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
441 fgQARefFileName = fkgQAOCDBDirName ;
442 else if ( fgQARefDirName.Contains(fkgLabAliEnOCDB) )
443 fgQARefFileName = fkgQAOCDBDirName ;
4ecde5fc 444
4edbc5bc 445 else {
446 printf("ERROR: %s is an invalid storage definition\n", name) ;
447 fgQARefDirName = "" ;
448 fgQARefFileName = "" ;
449 }
72c25501 450 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
4edbc5bc 451 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
4ecde5fc 452}
453
454//_____________________________________________________________________________
455void AliQA::SetQAResultDirName(const char * name)
456{
457 // Set the root directory where to store the QA status object
458
459 fgQAResultDirName.Prepend(name) ;
460 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
4edbc5bc 461 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
462 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
4ecde5fc 463 fgQAResultFileName.Prepend(fgQAResultDirName) ;
464}
465
421ab0fb 466//_______________________________________________________________
2e42b4d4 467void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
421ab0fb 468{
469 // Set the status bit for a given detector and a given task
470
471 CheckRange(det) ;
472 CheckRange(tsk) ;
473 CheckRange(bit) ;
474
475 ULong_t offset = Offset(tsk) ;
476 ULong_t status = GetStatus(det) ;
477 offset+= bit ;
478 status = status | 1 << offset ;
479 SetStatus(det, status) ;
480}
481
482//_______________________________________________________________
2e42b4d4 483void AliQA::ShowAll() const
421ab0fb 484{
485 // dispplay the QA status word
486 Int_t index ;
487 for (index = 0 ; index < kNDET ; index++)
488 ShowStatus(DETECTORINDEX(index)) ;
489}
490
491//_______________________________________________________________
2e42b4d4 492void AliQA::ShowStatus(DETECTORINDEX det) const
421ab0fb 493{
494 // Prints the full QA status of a given detector
495 CheckRange(det) ;
496 ULong_t status = GetStatus(det) ;
a4976ef3 497 ULong_t rawStatus = status & 0x0000f ;
498 ULong_t simStatus = status & 0x000f0 ;
499 ULong_t recStatus = status & 0x00f00 ;
500 ULong_t esdStatus = status & 0x0f000 ;
501 ULong_t anaStatus = status & 0xf0000 ;
421ab0fb 502
2ba0b5f5 503 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 )) ;
421ab0fb 504}
505