]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQualAss.cxx
Introducing the notion of QA data acquisition cycle (needed by online)
[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  = "QAData" ;   
49   TString      AliQualAss::fgDetNames[]  = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
50                                         "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"} ;   
51   TString      AliQualAss::fgTaskNames[]  = {"Raws", "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(Int_t run, Int_t cycle) 
166 {
167   // opens the file to store the detectors Quality Assurance Data Maker results
168   char temp[100] ; 
169   sprintf(temp, "%s_%d_%d.root", fgDataName.Data(), run, cycle) ; 
170   TString opt ; 
171   if (! fgDataFile ) {     
172     if  (gSystem->AccessPathName(temp))
173       opt = "NEW" ;
174     else 
175       opt = "UPDATE" ; 
176     fgDataFile = TFile::Open(temp, opt.Data()) ;
177   } else {
178    if ( (strcmp(temp, fgDataFile->GetName()) != 0) ) {
179      if  (gSystem->AccessPathName(temp))
180       opt = "NEW" ;
181     else 
182       opt = "UPDATE" ; 
183     fgDataFile = TFile::Open(temp, opt.Data()) ;
184    }
185   }
186   return fgDataFile ; 
187
188
189 //_______________________________________________________________
190 const char * AliQualAss::GetDetName(Int_t det) 
191 {
192         // returns the detector name corresponding to a given index (needed in a loop)
193
194         if ( det >= 0 &&  det < kNDET) 
195                 return (fgDetNames[det]).Data() ; 
196         else 
197                 return NULL ; 
198 }
199
200 //_______________________________________________________________
201 const char * AliQualAss::GetAliTaskName(ALITASK tsk)
202 {
203   // returns the char name corresponding to module index
204   TString tskName ;
205   switch (tsk) {
206   case kNULLTASK:
207     break ; 
208   case kRAW:
209     tskName = "RAW" ;
210     break ;  
211   case kSIM:
212     tskName = "SIM" ;
213     break ;
214   case kREC:
215     tskName = "REC" ;
216     break ;
217   case kESD:
218     tskName = "ESD" ;
219     break ;
220   case kANA:
221     tskName = "ANA" ;
222     break ;
223   default:
224     tsk = kNULLTASK ; 
225     break ;
226   }
227   return tskName.Data() ;
228 }
229
230 //_______________________________________________________________
231 const Bool_t AliQualAss::CheckFatal() const
232 {
233   // check if any FATAL status is set
234   Bool_t rv = kFALSE ;
235   Int_t index ;
236   for (index = 0; index < kNDET ; index++)
237     rv = rv || IsSet(DETECTORINDEX(index), fTask, kFATAL) ;
238   return rv ;
239 }
240
241 //_______________________________________________________________
242 const Bool_t AliQualAss::IsSet(DETECTORINDEX det, ALITASK tsk, QABIT bit) const
243 {
244   // Checks is the requested bit is set
245
246   CheckRange(det) ; 
247   CheckRange(tsk) ;
248   CheckRange(bit) ;
249
250   ULong_t offset = Offset(tsk) ;
251   ULong_t status = GetStatus(det) ;
252   offset+= bit ;
253   status = (status & 1 << offset) != 0 ;
254   return status ;
255 }
256
257 //_______________________________________________________________
258 AliQualAss * AliQualAss::Instance()
259 {
260   // Get an instance of the singleton.
261   // Object must have been instantiated with Instance(ALITASK) first
262
263   return fgQA ;
264 }
265
266 //_______________________________________________________________
267 AliQualAss * AliQualAss::Instance(const DETECTORINDEX det)
268 {
269   // Get an instance of the singleton. The only authorized way to call the ctor
270   
271   if ( ! fgQA)
272     fgQA = new AliQualAss(det) ;
273   fgQA->Set(det) ;
274   return fgQA ;
275 }
276
277 //_______________________________________________________________
278 AliQualAss * AliQualAss::Instance(const ALITASK tsk)
279 {
280   // get an instance of the singleton.
281
282   if ( ! fgQA)
283     switch (tsk) {
284     case kNULLTASK:
285       break ;
286         case kRAW:
287       fgQA = new AliQualAss(tsk) ;
288       break ;
289         case kSIM:
290       fgQA = new AliQualAss(tsk) ;
291       break ;
292     case kREC:
293       printf("fgQA = gAlice->GetQA()") ;
294       break ;
295     case kESD:
296       printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
297       break ;
298     case kANA:
299       printf("fgQA = dynamic_cast<AliQA *> (esdFile->Get(\"QA\")") ;
300       break ;
301     case kNTASK:
302       break ;
303     }
304   if (fgQA) 
305     fgQA->Set(tsk) ;
306   return fgQA ;
307 }
308
309 //_______________________________________________________________
310 const ULong_t AliQualAss::Offset(ALITASK tsk) const
311 {
312   // Calculates the bit offset for a given module (SIM, REC, ESD, ANA)
313
314   CheckRange(tsk) ; 
315
316   ULong_t offset = 0 ;
317   switch (tsk) {
318   case kNULLTASK:
319     break ;
320   case kRAW:
321     offset+= 0 ;
322     break ;
323   case kSIM:
324     offset+= 4 ;
325     break ;
326   case kREC:
327     offset+= 8 ;
328     break ;
329   case kESD:
330     offset+= 12 ;
331     break ;
332   case kANA:
333     offset+= 16 ;
334     break ;
335   case kNTASK:
336     break ;
337   }
338
339   return offset ;
340 }
341
342 //_______________________________________________________________
343 void AliQualAss::Set(QABIT bit)
344 {
345   // Set the status bit of the current detector in the current module
346   
347   SetStatusBit(fDet, fTask, bit) ;
348 }
349
350 //_______________________________________________________________
351 void AliQualAss::SetStatusBit(DETECTORINDEX det, ALITASK tsk, QABIT bit)
352 {
353  // Set the status bit for a given detector and a given task
354
355   CheckRange(det) ;
356   CheckRange(tsk) ;
357   CheckRange(bit) ;
358
359   ULong_t offset = Offset(tsk) ;
360   ULong_t status = GetStatus(det) ;
361   offset+= bit ;
362   status = status | 1 << offset ;
363   SetStatus(det, status) ;
364 }
365
366 //_______________________________________________________________
367 void AliQualAss::ShowAll() const
368 {
369   // dispplay the QA status word
370   Int_t index ;
371   for (index = 0 ; index < kNDET ; index++)
372     ShowStatus(DETECTORINDEX(index)) ;
373 }
374
375 //_______________________________________________________________
376 void AliQualAss::ShowStatus(DETECTORINDEX det) const
377 {
378   // Prints the full QA status of a given detector
379   CheckRange(det) ;
380   ULong_t status = GetStatus(det) ;
381   ULong_t simStatus = status & 0x000f ;
382   ULong_t recStatus = status & 0x00f0 ;
383   ULong_t esdStatus = status & 0x0f00 ;
384   ULong_t anaStatus = status & 0xf000 ;
385
386   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 )) ;
387 }
388