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