set as default configuration the geometry with PHOS holes
[u/mrichter/AliRoot.git] / STEER / AliQA.cxx
CommitLineData
421ab0fb 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15/* $Id$ */
16
17//////////////////////////////////////////////////////////////////////////////
18//
19// Quality Assurance Object//_________________________________________________________________________
20// Quality Assurance object. The QA status is held in one word per detector,
21// each bit corresponds to a different status.
22// bit 0-3 : QA raised during simulation (SIM)
23// bit 4-7 : QA raised during reconstruction (REC)
24// bit 8-11 : QA raised during ESD checking (ESD)
25// bit 12-15: QA raised during analysis (ANA)
26// Each of the 4 bits corresponds to a severity level of increasing importance
27// from lower to higher bit (INFO, WARNING, ERROR, FATAL)
28//
29//*-- Yves Schutz CERN, July 2007
30//////////////////////////////////////////////////////////////////////////////
31
32
33// --- ROOT system ---
34#include <TFile.h>
35#include <TSystem.h>
36
37// --- Standard library ---
38
39// --- AliRoot header files ---
40#include "AliLog.h"
2e42b4d4 41#include "AliQA.h"
421ab0fb 42
43
2e42b4d4 44ClassImp(AliQA)
45 AliQA * AliQA::fgQA = 0x0 ;
46 TFile * AliQA::fgDataFile = 0x0 ;
47 TString AliQA::fgDataName = "QA" ;
48 TString AliQA::fgDetNames[] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
a5fa6165 49 "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"} ;
2e42b4d4 50 TString AliQA::fgTaskNames[] = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;
421ab0fb 51
52//____________________________________________________________________________
2e42b4d4 53AliQA::AliQA() :
421ab0fb 54 TNamed("", ""),
421ab0fb 55 fQA(0x0),
56 fDet(kNULLDET),
57 fTask(kNULLTASK)
58{
59 // default constructor
60 // beware singleton: not to be used
61}
62
63//____________________________________________________________________________
2e42b4d4 64AliQA::AliQA(const AliQA& qa) :
421ab0fb 65 TNamed(qa),
421ab0fb 66 fQA(qa.fQA),
67 fDet(qa.fDet),
68 fTask(qa.fTask)
69{
70 // cpy ctor
71}
72
73//_____________________________________________________________________________
2e42b4d4 74AliQA& AliQA::operator = (const AliQA& qa)
421ab0fb 75{
76// assignment operator
77
2e42b4d4 78 this->~AliQA();
79 new(this) AliQA(qa);
421ab0fb 80 return *this;
81}
82
83//_______________________________________________________________
2e42b4d4 84AliQA::AliQA(const DETECTORINDEX det) :
a5fa6165 85 TNamed("QA", "Quality Assurance status"),
a4976ef3 86 fQA(new ULong_t[kNDET]),
a5fa6165 87 fDet(det),
88 fTask(kNULLTASK)
89{
90 // constructor to be used
91 if (! CheckRange(det) ) {
92 fDet = kNULLDET ;
93 return ;
a4976ef3 94 }
a5fa6165 95 Int_t index ;
96 for (index = 0; index < kNDET; index++)
97 fQA[index] = 0 ;
98}
99
100//_______________________________________________________________
2e42b4d4 101AliQA::AliQA(const ALITASK tsk) :
421ab0fb 102 TNamed("QA", "Quality Assurance status"),
a4976ef3 103 fQA(new ULong_t[kNDET]),
421ab0fb 104 fDet(kNULLDET),
105 fTask(tsk)
106{
107 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
108 if (! CheckRange(tsk) ) {
109 fTask = kNULLTASK ;
110 return ;
a4976ef3 111 }
a5fa6165 112 Int_t index ;
113 for (index = 0; index < kNDET; index++)
114 fQA[index] = 0 ;
421ab0fb 115}
116
117//____________________________________________________________________________
2e42b4d4 118AliQA::~AliQA()
421ab0fb 119{
120 // dtor
121 delete[] fQA ;
122}
123
124//_______________________________________________________________
2e42b4d4 125const Bool_t AliQA::CheckRange(DETECTORINDEX det) const
421ab0fb 126{
a4976ef3 127 // check if detector is in given detector range: 0-kNDET
421ab0fb 128
a5fa6165 129 Bool_t rv = ( det < 0 || det > kNDET ) ? kFALSE : kTRUE ;
421ab0fb 130 if (!rv)
131 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
132 return rv ;
133}
134
135//_______________________________________________________________
2e42b4d4 136const Bool_t AliQA::CheckRange(ALITASK task) const
421ab0fb 137{
138 // check if task is given taskk range: 0:kNTASK
6c18591a 139 Bool_t rv = ( task < kRAW || task > kNTASK ) ? kFALSE : kTRUE ;
421ab0fb 140 if (!rv)
141 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
142 return rv ;
143}
144
145//_______________________________________________________________
2e42b4d4 146const Bool_t AliQA::CheckRange(QABIT bit) const
421ab0fb 147{
148 // check if bit is in given bit range: 0-kNBit
149
150 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
151 if (!rv)
152 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
153 return rv ;
154}
155
421ab0fb 156
157//_______________________________________________________________
2e42b4d4 158TFile * AliQA::GetQADMOutFile(const char * name, const Int_t run, const Int_t cycle)
421ab0fb 159{
160 // opens the file to store the detectors Quality Assurance Data Maker results
5b188f2f 161 char temp[100] ;
d62f9368 162 sprintf(temp, "%s.%s.%d.%d.root", name, fgDataName.Data(), run, cycle) ;
5b188f2f 163 TString opt ;
a5fa6165 164 if (! fgDataFile ) {
5b188f2f 165 if (gSystem->AccessPathName(temp))
166 opt = "NEW" ;
167 else
168 opt = "UPDATE" ;
169 fgDataFile = TFile::Open(temp, opt.Data()) ;
170 } else {
171 if ( (strcmp(temp, fgDataFile->GetName()) != 0) ) {
172 if (gSystem->AccessPathName(temp))
a5fa6165 173 opt = "NEW" ;
174 else
175 opt = "UPDATE" ;
5b188f2f 176 fgDataFile = TFile::Open(temp, opt.Data()) ;
177 }
421ab0fb 178 }
a5fa6165 179 return fgDataFile ;
421ab0fb 180}
181
182//_______________________________________________________________
2e42b4d4 183const char * AliQA::GetDetName(Int_t det)
a5fa6165 184{
185 // returns the detector name corresponding to a given index (needed in a loop)
186
187 if ( det >= 0 && det < kNDET)
188 return (fgDetNames[det]).Data() ;
189 else
190 return NULL ;
191}
192
193//_______________________________________________________________
2e42b4d4 194const char * AliQA::GetAliTaskName(ALITASK tsk)
421ab0fb 195{
196 // returns the char name corresponding to module index
a5fa6165 197 TString tskName ;
421ab0fb 198 switch (tsk) {
199 case kNULLTASK:
200 break ;
6c18591a 201 case kRAW:
202 tskName = "RAW" ;
203 break ;
421ab0fb 204 case kSIM:
205 tskName = "SIM" ;
206 break ;
207 case kREC:
208 tskName = "REC" ;
209 break ;
210 case kESD:
211 tskName = "ESD" ;
212 break ;
213 case kANA:
214 tskName = "ANA" ;
215 break ;
216 default:
a5fa6165 217 tsk = kNULLTASK ;
421ab0fb 218 break ;
219 }
a5fa6165 220 return tskName.Data() ;
421ab0fb 221}
222
223//_______________________________________________________________
2e42b4d4 224const Bool_t AliQA::CheckFatal() const
421ab0fb 225{
226 // check if any FATAL status is set
227 Bool_t rv = kFALSE ;
228 Int_t index ;
229 for (index = 0; index < kNDET ; index++)
230 rv = rv || IsSet(DETECTORINDEX(index), fTask, kFATAL) ;
231 return rv ;
232}
233
234//_______________________________________________________________
2e42b4d4 235const Bool_t AliQA::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
421ab0fb 236{
237 // Checks is the requested bit is set
238
239 CheckRange(det) ;
240 CheckRange(tsk) ;
241 CheckRange(bit) ;
242
243 ULong_t offset = Offset(tsk) ;
244 ULong_t status = GetStatus(det) ;
245 offset+= bit ;
246 status = (status & 1 << offset) != 0 ;
247 return status ;
248}
249
250//_______________________________________________________________
2e42b4d4 251AliQA * AliQA::Instance()
421ab0fb 252{
253 // Get an instance of the singleton.
254 // Object must have been instantiated with Instance(ALITASK) first
255
256 return fgQA ;
257}
258
259//_______________________________________________________________
2e42b4d4 260AliQA * AliQA::Instance(const DETECTORINDEX det)
421ab0fb 261{
262 // Get an instance of the singleton. The only authorized way to call the ctor
263
a5fa6165 264 if ( ! fgQA)
2e42b4d4 265 fgQA = new AliQA(det) ;
421ab0fb 266 fgQA->Set(det) ;
267 return fgQA ;
268}
269
270//_______________________________________________________________
2e42b4d4 271AliQA * AliQA::Instance(const ALITASK tsk)
421ab0fb 272{
273 // get an instance of the singleton.
274
275 if ( ! fgQA)
276 switch (tsk) {
277 case kNULLTASK:
278 break ;
6c18591a 279 case kRAW:
2e42b4d4 280 fgQA = new AliQA(tsk) ;
6c18591a 281 break ;
282 case kSIM:
2e42b4d4 283 fgQA = new AliQA(tsk) ;
421ab0fb 284 break ;
285 case kREC:
286 printf("fgQA = gAlice->GetQA()") ;
287 break ;
288 case kESD:
289 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
290 break ;
291 case kANA:
292 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
293 break ;
294 case kNTASK:
295 break ;
296 }
297 if (fgQA)
298 fgQA->Set(tsk) ;
299 return fgQA ;
300}
301
302//_______________________________________________________________
2e42b4d4 303const ULong_t AliQA::Offset(ALITASK tsk) const
421ab0fb 304{
305 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
306
307 CheckRange(tsk) ;
308
309 ULong_t offset = 0 ;
310 switch (tsk) {
311 case kNULLTASK:
312 break ;
6c18591a 313 case kRAW:
421ab0fb 314 offset+= 0 ;
315 break ;
6c18591a 316 case kSIM:
421ab0fb 317 offset+= 4 ;
318 break ;
6c18591a 319 case kREC:
421ab0fb 320 offset+= 8 ;
321 break ;
6c18591a 322 case kESD:
421ab0fb 323 offset+= 12 ;
324 break ;
6c18591a 325 case kANA:
326 offset+= 16 ;
327 break ;
421ab0fb 328 case kNTASK:
329 break ;
330 }
331
332 return offset ;
333}
334
335//_______________________________________________________________
2e42b4d4 336void AliQA::Set(QABIT bit)
421ab0fb 337{
338 // Set the status bit of the current detector in the current module
339
340 SetStatusBit(fDet, fTask, bit) ;
341}
342
343//_______________________________________________________________
2e42b4d4 344void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
421ab0fb 345{
346 // Set the status bit for a given detector and a given task
347
348 CheckRange(det) ;
349 CheckRange(tsk) ;
350 CheckRange(bit) ;
351
352 ULong_t offset = Offset(tsk) ;
353 ULong_t status = GetStatus(det) ;
354 offset+= bit ;
355 status = status | 1 << offset ;
356 SetStatus(det, status) ;
357}
358
359//_______________________________________________________________
2e42b4d4 360void AliQA::ShowAll() const
421ab0fb 361{
362 // dispplay the QA status word
363 Int_t index ;
364 for (index = 0 ; index < kNDET ; index++)
365 ShowStatus(DETECTORINDEX(index)) ;
366}
367
368//_______________________________________________________________
2e42b4d4 369void AliQA::ShowStatus(DETECTORINDEX det) const
421ab0fb 370{
371 // Prints the full QA status of a given detector
372 CheckRange(det) ;
373 ULong_t status = GetStatus(det) ;
a4976ef3 374 ULong_t rawStatus = status & 0x0000f ;
375 ULong_t simStatus = status & 0x000f0 ;
376 ULong_t recStatus = status & 0x00f00 ;
377 ULong_t esdStatus = status & 0x0f000 ;
378 ULong_t anaStatus = status & 0xf0000 ;
421ab0fb 379
a4976ef3 380 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 381}
382