]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQA.cxx
Reduce memory used by SDD calibration objects in OCDB (F. Prino)
[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{
211 // returns the char name corresponding to module index
a5fa6165 212 TString tskName ;
421ab0fb 213 switch (tsk) {
214 case kNULLTASK:
215 break ;
6c18591a 216 case kRAW:
217 tskName = "RAW" ;
218 break ;
421ab0fb 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:
a5fa6165 232 tsk = kNULLTASK ;
421ab0fb 233 break ;
234 }
a5fa6165 235 return tskName.Data() ;
421ab0fb 236}
237
46ca5304 238//_______________________________________________________________
7c002d48 239const AliQA::DETECTORINDEX_t AliQA::GetDetIndex(const char * name)
96d67a8d 240{
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) ;
247 break ;
248 }
249 }
250 return rv ;
251}
252
7c002d48 253//_______________________________________________________________
254const char * AliQA::GetDetName(Int_t det)
255{
256 // returns the detector name corresponding to a given index (needed in a loop)
257
258 if ( det >= 0 && det < kNDET)
259 return (fgDetNames[det]).Data() ;
260 else
261 return NULL ;
262}
263
46ca5304 264//_______________________________________________________________
265TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle)
266{
267 // opens the file to store the detectors Quality Assurance Data Maker results
96d67a8d 268 const char * temp = Form("%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ;
269 TString opt ;
270 if (! fgQADataFile ) {
271 if (gSystem->AccessPathName(temp))
272 opt = "NEW" ;
273 else
274 opt = "UPDATE" ;
275 fgQADataFile = TFile::Open(temp, opt.Data()) ;
276 } else {
277 if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
278 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ;
279 if ( !fgQADataFile ) {
280 if (gSystem->AccessPathName(temp))
281 opt = "NEW" ;
282 else
283 opt = "UPDATE" ;
284 fgQADataFile = TFile::Open(temp, opt.Data()) ;
285 }
286 }
46ca5304 287 }
96d67a8d 288 return fgQADataFile ;
46ca5304 289}
290
291//_____________________________________________________________________________
292TFile * AliQA::GetQADataFile(const char * fileName)
293{
294 // Open if necessary the Data file and return its pointer
295
296 if (!fgQADataFile)
297 if (!fileName)
298 fileName = AliQA::GetQADataFileName() ;
299 if (!gSystem->AccessPathName(fileName)) {
300 fgQADataFile = TFile::Open(fileName) ;
301 } else {
302 printf("File %s not found", fileName) ;
303 exit(1) ;
304 }
305 return fgQADataFile ;
306}
307
4ecde5fc 308//_______________________________________________________________
309TFile * AliQA::GetQAResultFile()
310{
311 // opens the file to store the Quality Assurance Data Checker results
2ba0b5f5 312 if (fgQAResultFile)
313 fgQAResultFile->Close() ;
314 fgQAResultFile = 0x0 ;
315// if (!fgQAResultFile) {
1c0190ec 316 TString dirName(fgQAResultDirName) ;
4edbc5bc 317 if ( dirName.Contains(fkgLabLocalFile))
318 dirName.ReplaceAll(fkgLabLocalFile, "") ;
1c0190ec 319 TString fileName(dirName + fgQAResultFileName) ;
46ca5304 320 TString opt("") ;
321 if ( !gSystem->AccessPathName(fileName) )
322 opt = "UPDATE" ;
5bd22145 323 else {
1c0190ec 324 if ( gSystem->AccessPathName(dirName) )
325 gSystem->mkdir(dirName) ;
46ca5304 326 opt = "NEW" ;
5bd22145 327 }
46ca5304 328 fgQAResultFile = TFile::Open(fileName, opt) ;
2ba0b5f5 329// }
46ca5304 330
331 return fgQAResultFile ;
421ab0fb 332}
333
334//_______________________________________________________________
96d67a8d 335const Bool_t AliQA::IsSet(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit) const
421ab0fb 336{
337 // Checks is the requested bit is set
338
339 CheckRange(det) ;
340 CheckRange(tsk) ;
341 CheckRange(bit) ;
342
343 ULong_t offset = Offset(tsk) ;
344 ULong_t status = GetStatus(det) ;
345 offset+= bit ;
346 status = (status & 1 << offset) != 0 ;
347 return status ;
348}
349
350//_______________________________________________________________
2e42b4d4 351AliQA * AliQA::Instance()
421ab0fb 352{
353 // Get an instance of the singleton.
354 // Object must have been instantiated with Instance(ALITASK) first
355
356 return fgQA ;
357}
358
359//_______________________________________________________________
96d67a8d 360AliQA * AliQA::Instance(const DETECTORINDEX_t det)
421ab0fb 361{
362 // Get an instance of the singleton. The only authorized way to call the ctor
363
9a223722 364 if ( ! fgQA) {
46ca5304 365 TFile * f = GetQAResultFile() ;
9a223722 366 fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ;
367 if ( ! fgQA )
368 fgQA = new AliQA(det) ;
369 }
421ab0fb 370 fgQA->Set(det) ;
371 return fgQA ;
372}
373
374//_______________________________________________________________
96d67a8d 375AliQA * AliQA::Instance(const ALITASK_t tsk)
421ab0fb 376{
377 // get an instance of the singleton.
378
379 if ( ! fgQA)
380 switch (tsk) {
381 case kNULLTASK:
382 break ;
6c18591a 383 case kRAW:
2e42b4d4 384 fgQA = new AliQA(tsk) ;
6c18591a 385 break ;
386 case kSIM:
2e42b4d4 387 fgQA = new AliQA(tsk) ;
421ab0fb 388 break ;
389 case kREC:
390 printf("fgQA = gAlice->GetQA()") ;
391 break ;
392 case kESD:
393 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
394 break ;
395 case kANA:
396 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
397 break ;
398 case kNTASK:
399 break ;
400 }
401 if (fgQA)
402 fgQA->Set(tsk) ;
403 return fgQA ;
404}
405
406//_______________________________________________________________
96d67a8d 407AliQA * AliQA::Instance(const TASKINDEX_t tsk)
408{
409 // get an instance of the singleton.
410
411 ALITASK_t index = kNULLTASK ;
412
413 if ( tsk == kRAWS )
414 index = kRAW ;
415 else if (tsk < kDIGITS)
416 index = kSIM ;
417 else if (tsk < kRECPARTICLES)
418 index = kREC ;
419 else if (tsk == kESDS)
420 index = kESD ;
421
422 return Instance(index) ;
423}
424
425//_______________________________________________________________
426const ULong_t AliQA::Offset(ALITASK_t tsk) const
421ab0fb 427{
428 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
429
430 CheckRange(tsk) ;
431
432 ULong_t offset = 0 ;
433 switch (tsk) {
434 case kNULLTASK:
435 break ;
6c18591a 436 case kRAW:
421ab0fb 437 offset+= 0 ;
438 break ;
6c18591a 439 case kSIM:
421ab0fb 440 offset+= 4 ;
441 break ;
6c18591a 442 case kREC:
421ab0fb 443 offset+= 8 ;
444 break ;
6c18591a 445 case kESD:
421ab0fb 446 offset+= 12 ;
447 break ;
6c18591a 448 case kANA:
449 offset+= 16 ;
450 break ;
421ab0fb 451 case kNTASK:
452 break ;
453 }
454
455 return offset ;
456}
457
458//_______________________________________________________________
96d67a8d 459void AliQA::Set(QABIT_t bit)
421ab0fb 460{
461 // Set the status bit of the current detector in the current module
462
463 SetStatusBit(fDet, fTask, bit) ;
464}
465
4ecde5fc 466//_____________________________________________________________________________
4edbc5bc 467void AliQA::SetQARefStorage(const char * name)
4ecde5fc 468{
72c25501 469 // Set the root directory where the QA reference data are stored
470
471 fgQARefDirName = name ;
472 if ( fgQARefDirName.Contains(fkgLabLocalFile) )
473 fgQARefFileName = fkgRefFileName ;
474 else if ( fgQARefDirName.Contains(fkgLabLocalOCDB) )
96d67a8d 475 fgQARefFileName = fkgQAName ;
72c25501 476 else if ( fgQARefDirName.Contains(fkgLabAliEnOCDB) )
96d67a8d 477 fgQARefFileName = fkgQAName ;
4ecde5fc 478
4edbc5bc 479 else {
480 printf("ERROR: %s is an invalid storage definition\n", name) ;
481 fgQARefDirName = "" ;
482 fgQARefFileName = "" ;
483 }
72c25501 484 TString tmp(fgQARefDirName) ; // + fgQARefFileName) ;
4edbc5bc 485 printf("AliQA::SetQARefDir: QA references are in %s\n", tmp.Data() ) ;
4ecde5fc 486}
487
488//_____________________________________________________________________________
489void AliQA::SetQAResultDirName(const char * name)
490{
491 // Set the root directory where to store the QA status object
492
493 fgQAResultDirName.Prepend(name) ;
494 printf("AliQA::SetQAResultDirName: QA results are in %s\n", fgQAResultDirName.Data()) ;
4edbc5bc 495 if ( fgQAResultDirName.Contains(fkgLabLocalFile))
496 fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
4ecde5fc 497 fgQAResultFileName.Prepend(fgQAResultDirName) ;
498}
499
421ab0fb 500//_______________________________________________________________
96d67a8d 501void AliQA::SetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
421ab0fb 502{
503 // Set the status bit for a given detector and a given task
504
505 CheckRange(det) ;
506 CheckRange(tsk) ;
507 CheckRange(bit) ;
508
509 ULong_t offset = Offset(tsk) ;
510 ULong_t status = GetStatus(det) ;
511 offset+= bit ;
512 status = status | 1 << offset ;
513 SetStatus(det, status) ;
514}
515
516//_______________________________________________________________
2e42b4d4 517void AliQA::ShowAll() const
421ab0fb 518{
519 // dispplay the QA status word
520 Int_t index ;
521 for (index = 0 ; index < kNDET ; index++)
96d67a8d 522 ShowStatus(DETECTORINDEX_t(index)) ;
421ab0fb 523}
524
525//_______________________________________________________________
96d67a8d 526void AliQA::ShowStatus(DETECTORINDEX_t det) const
421ab0fb 527{
528 // Prints the full QA status of a given detector
529 CheckRange(det) ;
530 ULong_t status = GetStatus(det) ;
a4976ef3 531 ULong_t rawStatus = status & 0x0000f ;
532 ULong_t simStatus = status & 0x000f0 ;
533 ULong_t recStatus = status & 0x00f00 ;
534 ULong_t esdStatus = status & 0x0f000 ;
535 ULong_t anaStatus = status & 0xf0000 ;
421ab0fb 536
2ba0b5f5 537 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 538}
539
96d67a8d 540//_______________________________________________________________
541void AliQA::UnSet(QABIT_t bit)
542{
543 // UnSet the status bit of the current detector in the current module
544
545 UnSetStatusBit(fDet, fTask, bit) ;
546}
547
548//_______________________________________________________________
549void AliQA::UnSetStatusBit(DETECTORINDEX_t det, ALITASK_t tsk, QABIT_t bit)
550{
551 // UnSet the status bit for a given detector and a given task
552
553 CheckRange(det) ;
554 CheckRange(tsk) ;
555 CheckRange(bit) ;
556
557 ULong_t offset = Offset(tsk) ;
558 ULong_t status = GetStatus(det) ;
559 offset+= bit ;
560 status = status & 0 << offset ;
561 SetStatus(det, status) ;
92a357bf 562}