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