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