]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQAChecker.cxx
22173614a260677a7571065e2b962d790a6c779b
[u/mrichter/AliRoot.git] / STEER / AliQAChecker.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
16 /* $Id: */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // class for running the Quality Assurance Checker
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include "AliLog.h"
25 #include "AliModule.h" 
26 #include "AliQA.h"
27 #include "AliQAChecker.h"
28 #include "AliQACheckerBase.h"
29
30 #include <TKey.h>
31 #include <TObjArray.h>
32 #include <TPluginManager.h> 
33 #include <TROOT.h>
34 #include <TStopwatch.h> 
35 #include <TString.h> 
36 #include <TSystem.h> 
37 #include <TList.h>
38
39 ClassImp(AliQAChecker)
40   AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
41   TFile   * AliQAChecker::fgQAResultFile        = 0x0 ;  
42 //  TString   AliQAChecker::fgQAResultDirName     = "local://RUN/";  
43 //  TString   AliQAChecker::fgQAResultFileName    = "QA.root" ; 
44
45 //_____________________________________________________________________________
46 AliQAChecker::AliQAChecker(const char* name, const char* title) :
47   TNamed(name, title),
48   fDataFile(0x0), 
49 //  fRefDirName("./Ref/"), 
50 //  fRefName("QA.root"), 
51   fFoundDetectors(".")
52 {
53   // ctor: initialise checkers and open the data file   
54   for (Int_t det = 0 ; det < AliQA::kNDET ; det++) 
55     fCheckers[det] = NULL ; 
56   
57 //  fRefDirName.Append(fRefName) ; 
58 }
59
60 //_____________________________________________________________________________
61 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
62   TNamed(qac),
63   fDataFile(qac.fDataFile), 
64 //  fRefDirName(qac.fRefDirName), 
65 //  fRefName(qac.fRefName), 
66   fFoundDetectors(qac.fFoundDetectors)
67 {
68   // copy constructor
69   
70   for (Int_t det = 0 ; det < AliQA::kNDET ; det++) 
71     fCheckers[det] = NULL ; 
72 }
73
74 //_____________________________________________________________________________
75 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
76 {
77 // assignment operator
78
79   this->~AliQAChecker();
80   new(this) AliQAChecker(qac);
81   return *this;
82 }
83
84 //_____________________________________________________________________________
85 AliQAChecker::~AliQAChecker()
86 {
87 // clean up
88   delete [] fCheckers ; 
89   fgQAResultFile->Close() ; 
90 }
91
92 //_____________________________________________________________________________
93 TFile * AliQAChecker:: GetDataFile(const char * fileName)
94 {
95   // Open if necessary the Data file and return its pointer
96
97   if (!fDataFile) 
98         if (!fileName) 
99                 fileName = AliQA::GetDataName() ; 
100         if  (!gSystem->AccessPathName(fileName)) {
101                 fDataFile =  TFile::Open(fileName) ;
102         } else {
103                 AliFatal(Form("File %s not found", fileName)) ; 
104         }
105   return fDataFile ; 
106 }
107
108 //_____________________________________________________________________________
109 TFile * AliQAChecker:: GetQAResultFile() 
110 {
111   // Check if file to store QA exists, if not create it
112
113   if (fgQAResultFile) { 
114     if (fgQAResultFile->IsOpen()){
115       fgQAResultFile->Close() ; 
116       fgQAResultFile = 0x0 ; 
117     }
118   }   
119 //  if ( fgQAResultFileName.Contains("local://")) 
120 //    fgQAResultFileName.ReplaceAll("local:/", "") ;
121 //  
122 //  TString opt("") ; 
123 //  if ( !gSystem->AccessPathName(fgQAResultFileName) )
124 //    opt = "UPDATE" ; 
125 //  else 
126 //    opt = "NEW" ; 
127 //  fgQAResultFile = TFile::Open(fgQAResultFileName, opt) ;   
128 //      
129   fgQAResultFile = AliQA::GetQAResultFile() ; 
130   return fgQAResultFile ; 
131 }
132
133 //_____________________________________________________________________________
134   AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
135 {
136   // Gets the Quality Assurance checker for the detector specified by its name
137   
138   if (fCheckers[det]) 
139     return fCheckers[det];
140
141  TString detName(AliQA::GetDetName(det)) ; 
142
143   AliInfo(Form("Retrieving QA checker for %s", detName.Data())) ; 
144   TPluginManager* pluginManager = gROOT->GetPluginManager() ;
145   TString qacName = "Ali" + detName + "QAChecker" ;
146
147   AliQACheckerBase * qac = NULL ;
148   // first check if a plugin is defined for the quality assurance checker
149   TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
150   // if not, add a plugin for it
151   if (!pluginHandler) {
152     //AliInfo(Form("defining plugin for %s", qacName.Data()));
153     TString libs = gSystem->GetLibraries();
154  
155    if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
156       pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
157     else 
158       pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
159
160    pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
161
162   if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) 
163     qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
164   
165   if (qac) 
166     fCheckers[det] = qac ; 
167   }
168
169  return qac ; 
170 }
171
172
173 //_____________________________________________________________________________
174 TDirectory * AliQAChecker::GetRefSubDir(const char * det, const char * task)     
175
176   // Opens and returns the file with the reference data 
177   TFile * f = AliQA::GetQARefFile() ; //TFile::Open(fRefDirName, "READ") ;
178   TDirectory * rv = NULL ; 
179   if (!f) { 
180     AliError(Form("Cannot find reference file %s", (AliQA::GetQARefFileName()))) ; 
181     return rv ; 
182   }
183   rv = f->GetDirectory(det) ; 
184   if (!rv) {
185     AliWarning(Form("Directory %s not found in %d", det, (AliQA::GetQARefFileName()))) ; 
186   } else {
187     rv = rv->GetDirectory(task) ; 
188     if (!rv) 
189       AliWarning(Form("Directory %s/%s not found in %s", det, task, (AliQA::GetQARefFileName()))) ; 
190   }  
191   return rv ; 
192 }
193
194 //_____________________________________________________________________________
195 AliQAChecker * AliQAChecker::Instance()
196 {
197         // returns unique instance of the checker
198   if ( ! fgQAChecker ) 
199    fgQAChecker = new AliQAChecker() ; 
200   return fgQAChecker ;  
201 }
202
203 //_____________________________________________________________________________
204 Bool_t AliQAChecker::Run(const char * fileName)
205 {
206   // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
207   // starting from data in file
208
209   Bool_t rv = kFALSE ; 
210   
211   TStopwatch stopwatch;
212   stopwatch.Start();
213
214   //search for all detectors QA directories
215   TList * detKeyList = GetDataFile(fileName)->GetListOfKeys() ; 
216   TIter nextd(detKeyList) ; 
217   TKey * detKey ; 
218   while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
219     AliInfo(Form("Found %s", detKey->GetName())) ;
220     //Check which detector
221     TString detName ; 
222     TString detNameQA(detKey->GetName()) ; 
223     Int_t det ; 
224     for ( det = 0; det < AliQA::kNDET ; det++) {
225       detName = AliQA::GetDetName(det) ; 
226       if (detNameQA.Contains(detName)) {
227         fFoundDetectors+=detName ; 
228         fFoundDetectors+="." ;          
229         break ; 
230       }
231     } 
232     TDirectory * detDir = GetDataFile(fileName)->GetDirectory(detKey->GetName()) ; 
233     TList * taskKeyList = detDir->GetListOfKeys() ;
234     TIter nextt(taskKeyList) ; 
235     TKey * taskKey ; 
236     // now search for the tasks dir
237     while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
238       TString taskName( taskKey->GetName() ) ; 
239       AliInfo(Form("Found %s", taskName.Data())) ;
240       TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ; 
241       taskDir->cd() ; 
242       AliQACheckerBase * qac = GetDetQAChecker(det) ; 
243       if (qac)
244                 AliInfo(Form("QA checker found for %s", detName.Data())) ; 
245       if (!qac)
246                 AliFatal(Form("QA checker not found for %s", detName.Data())) ; 
247       AliQA::ALITASK index = AliQA::kNULLTASK ; 
248       if ( taskName == AliQA::GetTaskName(AliQA::kHITS) ) 
249                 index = AliQA::kSIM ; 
250       if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) ) 
251                 index = AliQA::kSIM ; 
252       if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) ) 
253                 index = AliQA::kSIM ; 
254       if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) ) 
255                 index = AliQA::kREC ; 
256       if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) ) 
257                 index = AliQA::kREC ; 
258       if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) ) 
259                 index = AliQA::kREC ; 
260       if ( taskName == AliQA::GetTaskName(AliQA::kESDS) ) 
261                 index = AliQA::kESD ; 
262       qac->Init(AliQA::DETECTORINDEX(det)) ; 
263
264           TDirectory * refDir = GetRefSubDir(detNameQA.Data(), taskName.Data()) ;
265           if ( refDir ) { 
266                 qac->SetRefandData(refDir, taskDir) ; 
267                 qac->Run(index) ; 
268           }
269     }
270  }
271   AliInfo("QA performed for following detectors:") ; 
272   for ( Int_t det = 0; det < AliQA::kNDET; det++) {
273     if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
274       printf("%s, ",AliQA::GetDetName(det)) ; 
275       fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ; 
276     }   
277   }
278   printf("\n") ; 
279   rv = kTRUE ; 
280
281   return rv ; 
282   
283 }
284
285 //_____________________________________________________________________________
286 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX det, AliQA::TASKINDEX task, TList * list)
287 {
288   // run the Quality Assurance Checker for detector det, for task task starting from data in list
289
290   AliQACheckerBase * qac = GetDetQAChecker(det) ; 
291   if (qac)
292     AliInfo(Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
293   if (!qac)
294         AliFatal(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ; 
295   
296   AliQA::ALITASK index = AliQA::kNULLTASK ; 
297   if ( task == AliQA::kRAWS ) 
298                 index = AliQA::kRAW ; 
299   else if ( task == AliQA::kHITS ) 
300                 index = AliQA::kSIM ; 
301   else if ( task == AliQA::kSDIGITS ) 
302                 index = AliQA::kSIM ; 
303   else if ( task == AliQA::kDIGITS ) 
304                 index = AliQA::kSIM ; 
305   else if ( task == AliQA::kRECPOINTS ) 
306                 index = AliQA::kREC ; 
307   else if ( task == AliQA::kTRACKSEGMENTS ) 
308                 index = AliQA::kREC ; 
309   else if ( task == AliQA::kRECPARTICLES ) 
310                 index = AliQA::kREC ; 
311   else if ( task == AliQA::kESDS ) 
312                 index = AliQA::kESD ; 
313
314   TDirectory * refDir = GetRefSubDir(AliQA::GetDetName(det).Data(), AliQA::GetTaskName(task).Data()) ;
315   if ( refDir ) { 
316         qac->Init(det) ; 
317         qac->SetRefandData(refDir) ; 
318         qac->Run(index, list) ; 
319   }
320   return kTRUE ; 
321   
322 }
323
324 //_____________________________________________________________________________
325 //void AliQAChecker::SetQAResultDirName(const char * name)
326 //{
327 //  // Set the root directory where to store the QA status object
328 //
329 //  fgQAResultDirName.Prepend(name) ; 
330 //  AliInfo(Form("QA results are in  %s", fgQAResultDirName.Data())) ;
331 //  if ( fgQAResultDirName.Contains("local://")) 
332 //    fgQAResultDirName.ReplaceAll("local:/", "") ;
333 //  fgQAResultFileName.Prepend(fgQAResultDirName) ;
334 //}
335
336 //_____________________________________________________________________________
337 //void AliQAChecker::SetRefDirName(const char * name)
338 //{
339 //  // Set the root directory of reference data
340 //
341 //  fRefDirName.Prepend(name) ; 
342 //  fRefDirName.Append(fRefName) ; 
343 //  AliInfo(Form("Reference data are taken from %s", fRefDirName.Data())) ;
344 //  if ( fRefDirName.Contains("local://")) 
345 //    fRefDirName.ReplaceAll("local:/", "") ; 
346 //}
347 //
348
349
350
351