]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQualAss.cxx
Introducing Raw data QA and replacing the QA data histograms by a Tlist of histograms
[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 < kRAW || 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 kRAW:
201     tskName = "RAW" ;
202     break ;  
203   case kSIM:
204     tskName = "SIM" ;
205     break ;
206   case kREC:
207     tskName = "REC" ;
208     break ;
209   case kESD:
210     tskName = "ESD" ;
211     break ;
212   case kANA:
213     tskName = "ANA" ;
214     break ;
215   default:
216     tsk = kNULLTASK ; 
217     break ;
218   }
219   return tskName.Data() ;
220 }
221
222 //_______________________________________________________________
223 const Bool_t AliQualAss::CheckFatal() const
224 {
225   // check if any FATAL status is set
226   Bool_t rv = kFALSE ;
227   Int_t index ;
228   for (index = 0; index < kNDET ; index++)
229     rv = rv || IsSet(DETECTORINDEX(index), fTask, kFATAL) ;
230   return rv ;
231 }
232
233 //_______________________________________________________________
234 const Bool_t AliQualAss::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
235 {
236   // Checks is the requested bit is set
237
238   CheckRange(det) ; 
239   CheckRange(tsk) ;
240   CheckRange(bit) ;
241
242   ULong_t offset = Offset(tsk) ;
243   ULong_t status = GetStatus(det) ;
244   offset+= bit ;
245   status = (status & 1 << offset) != 0 ;
246   return status ;
247 }
248
249 //_______________________________________________________________
250 AliQualAss * AliQualAss::Instance()
251 {
252   // Get an instance of the singleton.
253   // Object must have been instantiated with Instance(ALITASK) first
254
255   return fgQA ;
256 }
257
258 //_______________________________________________________________
259 AliQualAss * AliQualAss::Instance(const DETECTORINDEX det)
260 {
261   // Get an instance of the singleton. The only authorized way to call the ctor
262   
263   if ( ! fgQA)
264     fgQA = new AliQualAss(det) ;
265   fgQA->Set(det) ;
266   return fgQA ;
267 }
268
269 //_______________________________________________________________
270 AliQualAss * AliQualAss::Instance(const ALITASK tsk)
271 {
272   // get an instance of the singleton.
273
274   if ( ! fgQA)
275     switch (tsk) {
276     case kNULLTASK:
277       break ;
278         case kRAW:
279       fgQA = new AliQualAss(tsk) ;
280       break ;
281         case kSIM:
282       fgQA = new AliQualAss(tsk) ;
283       break ;
284     case kREC:
285       printf("fgQA = gAlice->GetQA()") ;
286       break ;
287     case kESD:
288       printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
289       break ;
290     case kANA:
291       printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
292       break ;
293     case kNTASK:
294       break ;
295     }
296   if (fgQA) 
297     fgQA->Set(tsk) ;
298   return fgQA ;
299 }
300
301 //_______________________________________________________________
302 const ULong_t AliQualAss::Offset(ALITASK tsk) const
303 {
304   // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
305
306   CheckRange(tsk) ; 
307
308   ULong_t offset = 0 ;
309   switch (tsk) {
310   case kNULLTASK:
311     break ;
312   case kRAW:
313     offset+= 0 ;
314     break ;
315   case kSIM:
316     offset+= 4 ;
317     break ;
318   case kREC:
319     offset+= 8 ;
320     break ;
321   case kESD:
322     offset+= 12 ;
323     break ;
324   case kANA:
325     offset+= 16 ;
326     break ;
327   case kNTASK:
328     break ;
329   }
330
331   return offset ;
332 }
333
334 //_______________________________________________________________
335 void AliQualAss::Set(QABIT bit)
336 {
337   // Set the status bit of the current detector in the current module
338   
339   SetStatusBit(fDet, fTask, bit) ;
340 }
341
342 //_______________________________________________________________
343 void AliQualAss::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
344 {
345  // Set the status bit for a given detector and a given task
346
347   CheckRange(det) ;
348   CheckRange(tsk) ;
349   CheckRange(bit) ;
350
351   ULong_t offset = Offset(tsk) ;
352   ULong_t status = GetStatus(det) ;
353   offset+= bit ;
354   status = status | 1 << offset ;
355   SetStatus(det, status) ;
356 }
357
358 //_______________________________________________________________
359 void AliQualAss::ShowAll() const
360 {
361   // dispplay the QA status word
362   Int_t index ;
363   for (index = 0 ; index < kNDET ; index++)
364     ShowStatus(DETECTORINDEX(index)) ;
365 }
366
367 //_______________________________________________________________
368 void AliQualAss::ShowStatus(DETECTORINDEX det) const
369 {
370   // Prints the full QA status of a given detector
371   CheckRange(det) ;
372   ULong_t status = GetStatus(det) ;
373   ULong_t simStatus = status & 0x000f ;
374   ULong_t recStatus = status & 0x00f0 ;
375   ULong_t esdStatus = status & 0x0f00 ;
376   ULong_t anaStatus = status & 0xf000 ;
377
378   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 )) ;
379 }
380