New QA classes (Yves)
[u/mrichter/AliRoot.git] / STEER / AliQualAss.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"
41#include "AliQualAss.h"
42
43
44ClassImp(AliQualAss)
45
46 AliQualAss * AliQualAss::fgQA = 0x0 ;
47 TFile * AliQualAss::fgOutput = 0x0 ;
48 TString AliQualAss::fgOutputName = "QA.root" ;
49
50//____________________________________________________________________________
51AliQualAss::AliQualAss() :
52 TNamed("", ""),
53 fNdet(12),
54 fQA(0x0),
55 fDet(kNULLDET),
56 fTask(kNULLTASK)
57{
58 // default constructor
59 // beware singleton: not to be used
60}
61
62//____________________________________________________________________________
63AliQualAss::AliQualAss(const AliQualAss& qa) :
64 TNamed(qa),
65 fNdet(qa.fNdet),
66 fQA(qa.fQA),
67 fDet(qa.fDet),
68 fTask(qa.fTask)
69{
70 // cpy ctor
71}
72
73//_____________________________________________________________________________
74AliQualAss& AliQualAss::operator = (const AliQualAss& qa)
75{
76// assignment operator
77
78 this->~AliQualAss();
79 new(this) AliQualAss(qa);
80 return *this;
81}
82
83//_______________________________________________________________
84AliQualAss::AliQualAss(ALITASK tsk) :
85 TNamed("QA", "Quality Assurance status"),
86 fNdet(12),
87 fQA(0x0),
88 fDet(kNULLDET),
89 fTask(tsk)
90{
91 // constructor to be used in the AliRoot module (SIM, REC, ESD or ANA)
92 if (! CheckRange(tsk) ) {
93 fTask = kNULLTASK ;
94 return ;
95 } else {
96 fQA = new ULong_t[fNdet] ;
97 Int_t index ;
98 for ( index = 0 ; index <= fNdet ; index++)
99 ResetStatus(DETECTORINDEX(index)) ;
100 }
101}
102
103//____________________________________________________________________________
104AliQualAss::~AliQualAss()
105{
106 // dtor
107 delete[] fQA ;
108}
109
110//_______________________________________________________________
111const Bool_t AliQualAss::CheckRange(DETECTORINDEX det) const
112{
113 // check if detector is in given detector range: 0-fNdet
114
115 Bool_t rv = ( det < 0 || det > fNdet ) ? kFALSE : kTRUE ;
116 if (!rv)
117 AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
118 return rv ;
119}
120
121//_______________________________________________________________
122const Bool_t AliQualAss::CheckRange(ALITASK task) const
123{
124 // check if task is given taskk range: 0:kNTASK
125 Bool_t rv = ( task < kSIM || task > kNTASK ) ? kFALSE : kTRUE ;
126 if (!rv)
127 AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
128 return rv ;
129}
130
131//_______________________________________________________________
132const Bool_t AliQualAss::CheckRange(QABIT bit) const
133{
134 // check if bit is in given bit range: 0-kNBit
135
136 Bool_t rv = ( bit < 0 || bit > kNBIT ) ? kFALSE : kTRUE ;
137 if (!rv)
138 AliFatal(Form("Status bit %d is out of range: 0 <= bit <= %d", bit, kNBIT)) ;
139 return rv ;
140}
141
142//_______________________________________________________________
143const char * AliQualAss::GetDetectorName(DETECTORINDEX det) const
144{
145 // returns the char name corresponding to detector index
146
147 char * detName = "";
148 switch (det) {
149 case kNULLDET:
150 break ;
151 case kITS:
152 detName = "ITS" ;
153 break ;
154 case kTPC:
155 detName = "TPC" ;
156 break ;
157 case kTRD:
158 detName = "TRD" ;
159 break ;
160 case kTOF:
161 detName = "TOF" ;
162 break ;
163 case kPHOS:
164 detName = "PHOS" ;
165 break ;
166 case kHMPID:
167 detName = "HMPID" ;
168 break ;
169 case kEMCAL:
170 detName = "EMCAL" ;
171 break ;
172 case kMUON:
173 detName = "MUON" ;
174 break ;
175 case kFMD:
176 detName = "FMD" ;
177 break ;
178 case kZDC:
179 detName = "ZDC" ;
180 break ;
181 case kPMD:
182 detName = "PMD" ;
183 break ;
184 case kT0:
185 detName = "TO" ;
186 break ;
187 case kVZERO:
188 detName = "VZERO" ;
189 break ;
190 case kACORDE:
191 detName = "ACORDE" ;
192 break ;
193 case kHLT:
194 detName = "HLT" ;
195 break ;
196 default:
197 AliError(Form("%d is not a valid detector index %d <= index <= %d\n", det, 0, kNDET-1)) ;
198 break ;
199 }
200 return detName ;
201}
202
203//_______________________________________________________________
204TFile * AliQualAss::GetQADMOutFile()
205{
206 // opens the file to store the detectors Quality Assurance Data Maker results
207
208 if (! fgOutput ) {
209 char opt[6] ;
210 if (gSystem->AccessPathName(fgOutputName.Data()))
211 sprintf(opt, "%s", "NEW") ;
212 else
213 sprintf(opt, "%s", "UPDATE") ;
214
215 fgOutput = TFile::Open(fgOutputName.Data(), opt) ;
216 }
217 return fgOutput ;
218}
219
220//_______________________________________________________________
221const char * AliQualAss::GetTaskName(ALITASK tsk) const
222{
223 // returns the char name corresponding to module index
224 char * tskName = "" ;
225 switch (tsk) {
226 case kNULLTASK:
227 break ;
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:
241 AliError(Form("%d is not a valid module index %d <= index <= %d\n", tsk, 0, kNTASK-1)) ;
242 break ;
243 }
244 return tskName ;
245}
246
247//_______________________________________________________________
248const Bool_t AliQualAss::CheckFatal() const
249{
250 // check if any FATAL status is set
251 Bool_t rv = kFALSE ;
252 Int_t index ;
253 for (index = 0; index < kNDET ; index++)
254 rv = rv || IsSet(DETECTORINDEX(index), fTask, kFATAL) ;
255 return rv ;
256}
257
258//_______________________________________________________________
259const Bool_t AliQualAss::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
260{
261 // Checks is the requested bit is set
262
263 CheckRange(det) ;
264 CheckRange(tsk) ;
265 CheckRange(bit) ;
266
267 ULong_t offset = Offset(tsk) ;
268 ULong_t status = GetStatus(det) ;
269 offset+= bit ;
270 status = (status & 1 << offset) != 0 ;
271 return status ;
272}
273
274//_______________________________________________________________
275AliQualAss * AliQualAss::Instance()
276{
277 // Get an instance of the singleton.
278 // Object must have been instantiated with Instance(ALITASK) first
279
280 return fgQA ;
281}
282
283//_______________________________________________________________
284AliQualAss * AliQualAss::Instance(DETECTORINDEX det)
285{
286 // Get an instance of the singleton. The only authorized way to call the ctor
287
288 fgQA->Set(det) ;
289 return fgQA ;
290}
291
292//_______________________________________________________________
293AliQualAss * AliQualAss::Instance(ALITASK tsk)
294{
295 // get an instance of the singleton.
296
297 if ( ! fgQA)
298 switch (tsk) {
299 case kNULLTASK:
300 break ;
301 case kSIM:
302 fgQA = new AliQualAss(tsk) ;
303 break ;
304 case kREC:
305 printf("fgQA = gAlice->GetQA()") ;
306 break ;
307 case kESD:
308 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
309 break ;
310 case kANA:
311 printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
312 break ;
313 case kNTASK:
314 break ;
315 }
316 if (fgQA)
317 fgQA->Set(tsk) ;
318 return fgQA ;
319}
320
321//_______________________________________________________________
322const ULong_t AliQualAss::Offset(ALITASK tsk) const
323{
324 // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
325
326 CheckRange(tsk) ;
327
328 ULong_t offset = 0 ;
329 switch (tsk) {
330 case kNULLTASK:
331 break ;
332 case kSIM:
333 offset+= 0 ;
334 break ;
335 case kREC:
336 offset+= 4 ;
337 break ;
338 case kESD:
339 offset+= 8 ;
340 break ;
341 case kANA:
342 offset+= 12 ;
343 break ;
344 case kNTASK:
345 break ;
346 }
347
348 return offset ;
349}
350
351//_______________________________________________________________
352void AliQualAss::Set(QABIT bit)
353{
354 // Set the status bit of the current detector in the current module
355
356 SetStatusBit(fDet, fTask, bit) ;
357}
358
359//_______________________________________________________________
360void AliQualAss::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
361{
362 // Set the status bit for a given detector and a given task
363
364 CheckRange(det) ;
365 CheckRange(tsk) ;
366 CheckRange(bit) ;
367
368 ULong_t offset = Offset(tsk) ;
369 ULong_t status = GetStatus(det) ;
370 offset+= bit ;
371 status = status | 1 << offset ;
372 SetStatus(det, status) ;
373}
374
375//_______________________________________________________________
376void AliQualAss::ShowAll() const
377{
378 // dispplay the QA status word
379 Int_t index ;
380 for (index = 0 ; index < kNDET ; index++)
381 ShowStatus(DETECTORINDEX(index)) ;
382}
383
384//_______________________________________________________________
385void AliQualAss::ShowStatus(DETECTORINDEX det) const
386{
387 // Prints the full QA status of a given detector
388 CheckRange(det) ;
389 ULong_t status = GetStatus(det) ;
390 ULong_t simStatus = status & 0x000f ;
391 ULong_t recStatus = status & 0x00f0 ;
392 ULong_t esdStatus = status & 0x0f00 ;
393 ULong_t anaStatus = status & 0xf000 ;
394
395 AliInfo(Form("QA Status for %s sim=0x%x, rec=0x%x, esd=0x%x, ana=0x%x\n", GetDetectorName(det), simStatus, recStatus, esdStatus, anaStatus )) ;
396}
397