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