]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQA.cxx
set as default configuration the geometry with PHOS holes
[u/mrichter/AliRoot.git] / STEER / AliQA.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 "AliQA.h"
42
43
44 ClassImp(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",
49                                         "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"} ;   
50   TString      AliQA::fgTaskNames[]  = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;   
51
52 //____________________________________________________________________________
53 AliQA::AliQA() : 
54   TNamed("", ""), 
55   fQA(0x0), 
56   fDet(kNULLDET),
57   fTask(kNULLTASK)
58 {
59   // default constructor
60   // beware singleton: not to be used
61 }
62
63 //____________________________________________________________________________
64 AliQA::AliQA(const AliQA& qa) :
65   TNamed(qa),
66   fQA(qa.fQA), 
67   fDet(qa.fDet),
68   fTask(qa.fTask)
69
70   // cpy ctor
71 }
72
73 //_____________________________________________________________________________
74 AliQA& AliQA::operator = (const AliQA& qa)
75 {
76 // assignment operator
77
78   this->~AliQA();
79   new(this) AliQA(qa);
80   return *this;
81 }
82
83 //_______________________________________________________________
84 AliQA::AliQA(const DETECTORINDEX det) :
85   TNamed("QA", "Quality Assurance status"), 
86   fQA(new ULong_t[kNDET]), 
87   fDet(det),
88   fTask(kNULLTASK)
89 {
90   // constructor to be used
91   if (! CheckRange(det) ) {
92     fDet = kNULLDET ; 
93     return ;
94   } 
95   Int_t index ; 
96   for (index = 0; index < kNDET; index++) 
97     fQA[index] = 0 ; 
98 }
99   
100 //_______________________________________________________________
101 AliQA::AliQA(const ALITASK tsk) :
102   TNamed("QA", "Quality Assurance status"), 
103   fQA(new ULong_t[kNDET]), 
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 ;
111   } 
112   Int_t index ; 
113   for (index = 0; index < kNDET; index++) 
114     fQA[index] = 0 ; 
115 }
116
117 //____________________________________________________________________________
118 AliQA::~AliQA() 
119 {
120   // dtor  
121   delete[] fQA ;
122 }
123
124 //_______________________________________________________________
125 const Bool_t AliQA::CheckRange(DETECTORINDEX det) const
126
127   // check if detector is in given detector range: 0-kNDET
128
129   Bool_t rv = ( det < 0 || det > kNDET )  ? kFALSE : kTRUE ;
130   if (!rv)
131     AliFatal(Form("Detector index %d is out of range: 0 <= index <= %d", det, kNDET)) ;
132   return rv ;
133 }
134
135 //_______________________________________________________________
136 const Bool_t AliQA::CheckRange(ALITASK task) const
137
138   // check if task is given taskk range: 0:kNTASK
139   Bool_t rv = ( task < kRAW || task > kNTASK )  ? kFALSE : kTRUE ;
140   if (!rv)
141     AliFatal(Form("Module index %d is out of range: 0 <= index <= %d", task, kNTASK)) ;
142   return rv ;
143 }
144
145 //_______________________________________________________________
146 const Bool_t AliQA::CheckRange(QABIT bit) const
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
156
157 //_______________________________________________________________
158 TFile * AliQA::GetQADMOutFile(const char * name, const Int_t run, const Int_t cycle) 
159 {
160   // opens the file to store the detectors Quality Assurance Data Maker results
161   char temp[100] ; 
162   sprintf(temp, "%s.%s.%d.%d.root", name, fgDataName.Data(), run, cycle) ; 
163   TString opt ; 
164   if (! fgDataFile ) {     
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))
173       opt = "NEW" ;
174     else 
175       opt = "UPDATE" ; 
176     fgDataFile = TFile::Open(temp, opt.Data()) ;
177    }
178   }
179   return fgDataFile ; 
180
181
182 //_______________________________________________________________
183 const char * AliQA::GetDetName(Int_t det) 
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 //_______________________________________________________________
194 const char * AliQA::GetAliTaskName(ALITASK tsk)
195 {
196   // returns the char name corresponding to module index
197   TString tskName ;
198   switch (tsk) {
199   case kNULLTASK:
200     break ; 
201   case kRAW:
202     tskName = "RAW" ;
203     break ;  
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:
217     tsk = kNULLTASK ; 
218     break ;
219   }
220   return tskName.Data() ;
221 }
222
223 //_______________________________________________________________
224 const Bool_t AliQA::CheckFatal() const
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 //_______________________________________________________________
235 const Bool_t AliQA::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
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 //_______________________________________________________________
251 AliQA * AliQA::Instance()
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 //_______________________________________________________________
260 AliQA * AliQA::Instance(const DETECTORINDEX det)
261 {
262   // Get an instance of the singleton. The only authorized way to call the ctor
263   
264   if ( ! fgQA)
265     fgQA = new AliQA(det) ;
266   fgQA->Set(det) ;
267   return fgQA ;
268 }
269
270 //_______________________________________________________________
271 AliQA * AliQA::Instance(const ALITASK tsk)
272 {
273   // get an instance of the singleton.
274
275   if ( ! fgQA)
276     switch (tsk) {
277     case kNULLTASK:
278       break ;
279         case kRAW:
280       fgQA = new AliQA(tsk) ;
281       break ;
282         case kSIM:
283       fgQA = new AliQA(tsk) ;
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 //_______________________________________________________________
303 const ULong_t AliQA::Offset(ALITASK tsk) const
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 ;
313   case kRAW:
314     offset+= 0 ;
315     break ;
316   case kSIM:
317     offset+= 4 ;
318     break ;
319   case kREC:
320     offset+= 8 ;
321     break ;
322   case kESD:
323     offset+= 12 ;
324     break ;
325   case kANA:
326     offset+= 16 ;
327     break ;
328   case kNTASK:
329     break ;
330   }
331
332   return offset ;
333 }
334
335 //_______________________________________________________________
336 void AliQA::Set(QABIT bit)
337 {
338   // Set the status bit of the current detector in the current module
339   
340   SetStatusBit(fDet, fTask, bit) ;
341 }
342
343 //_______________________________________________________________
344 void AliQA::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
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 //_______________________________________________________________
360 void AliQA::ShowAll() const
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 //_______________________________________________________________
369 void AliQA::ShowStatus(DETECTORINDEX det) const
370 {
371   // Prints the full QA status of a given detector
372   CheckRange(det) ;
373   ULong_t status = GetStatus(det) ;
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 ;
379
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 )) ;
381 }
382