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