]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQAChecker.cxx
ALL QA naming conventions and files in AliQA
[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
42 //_____________________________________________________________________________
43 AliQAChecker::AliQAChecker(const char* name, const char* title) :
44   TNamed(name, title),
45   fDataFile(0x0), 
46   fFoundDetectors(".")
47 {
48   // ctor: initialise checkers and open the data file   
49   for (Int_t det = 0 ; det < AliQA::kNDET ; det++) 
50     fCheckers[det] = NULL ; 
51 }
52
53 //_____________________________________________________________________________
54 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
55   TNamed(qac),
56   fDataFile(qac.fDataFile), 
57   fFoundDetectors(qac.fFoundDetectors)
58 {
59   // copy constructor
60   
61   for (Int_t det = 0 ; det < AliQA::kNDET ; det++) 
62     fCheckers[det] = NULL ; 
63 }
64
65 //_____________________________________________________________________________
66 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
67 {
68 // assignment operator
69
70   this->~AliQAChecker();
71   new(this) AliQAChecker(qac);
72   return *this;
73 }
74
75 //_____________________________________________________________________________
76 AliQAChecker::~AliQAChecker()
77 {
78 // clean up
79   delete [] fCheckers ; 
80   AliQA::Close() ; 
81 }
82
83 //_____________________________________________________________________________
84   AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
85 {
86   // Gets the Quality Assurance checker for the detector specified by its name
87   
88   if (fCheckers[det]) 
89     return fCheckers[det];
90
91  TString detName(AliQA::GetDetName(det)) ; 
92
93   AliInfo(Form("Retrieving QA checker for %s", detName.Data())) ; 
94   TPluginManager* pluginManager = gROOT->GetPluginManager() ;
95   TString qacName = "Ali" + detName + "QAChecker" ;
96
97   AliQACheckerBase * qac = NULL ;
98   // first check if a plugin is defined for the quality assurance checker
99   TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
100   // if not, add a plugin for it
101   if (!pluginHandler) {
102     //AliInfo(Form("defining plugin for %s", qacName.Data()));
103     TString libs = gSystem->GetLibraries();
104  
105    if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
106       pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
107     else 
108       pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
109
110    pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
111
112   if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) 
113     qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
114   
115   if (qac) 
116     fCheckers[det] = qac ; 
117   }
118
119  return qac ; 
120 }
121
122
123 //_____________________________________________________________________________
124 TDirectory * AliQAChecker::GetRefSubDir(const char * det, const char * task)     
125
126   // Opens and returns the file with the reference data 
127   TFile * f = AliQA::GetQARefFile() ; //TFile::Open(fRefDirName, "READ") ;
128   TDirectory * rv = NULL ; 
129   if (!f) { 
130     AliError(Form("Cannot find reference file %s", (AliQA::GetQARefFileName()))) ; 
131     return rv ; 
132   }
133   rv = f->GetDirectory(det) ; 
134   if (!rv) {
135     AliWarning(Form("Directory %s not found in %d", det, (AliQA::GetQARefFileName()))) ; 
136   } else {
137     rv = rv->GetDirectory(task) ; 
138     if (!rv) 
139       AliWarning(Form("Directory %s/%s not found in %s", det, task, (AliQA::GetQARefFileName()))) ; 
140   }  
141   return rv ; 
142 }
143
144 //_____________________________________________________________________________
145 AliQAChecker * AliQAChecker::Instance()
146 {
147         // returns unique instance of the checker
148   if ( ! fgQAChecker ) 
149    fgQAChecker = new AliQAChecker() ; 
150   return fgQAChecker ;  
151 }
152
153 //_____________________________________________________________________________
154 Bool_t AliQAChecker::Run(const char * fileName)
155 {
156   // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
157   // starting from data in file
158
159   Bool_t rv = kFALSE ; 
160   
161   TStopwatch stopwatch;
162   stopwatch.Start();
163
164   //search for all detectors QA directories
165   TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ; 
166   TIter nextd(detKeyList) ; 
167   TKey * detKey ; 
168   while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
169     AliInfo(Form("Found %s", detKey->GetName())) ;
170     //Check which detector
171     TString detName ; 
172     TString detNameQA(detKey->GetName()) ; 
173     Int_t det ; 
174     for ( det = 0; det < AliQA::kNDET ; det++) {
175       detName = AliQA::GetDetName(det) ; 
176       if (detNameQA.Contains(detName)) {
177         fFoundDetectors+=detName ; 
178         fFoundDetectors+="." ;          
179         break ; 
180       }
181     } 
182     TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ; 
183     TList * taskKeyList = detDir->GetListOfKeys() ;
184     TIter nextt(taskKeyList) ; 
185     TKey * taskKey ; 
186     // now search for the tasks dir
187     while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
188       TString taskName( taskKey->GetName() ) ; 
189       AliInfo(Form("Found %s", taskName.Data())) ;
190       TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ; 
191       taskDir->cd() ; 
192       AliQACheckerBase * qac = GetDetQAChecker(det) ; 
193       if (qac)
194                 AliInfo(Form("QA checker found for %s", detName.Data())) ; 
195       if (!qac)
196                 AliFatal(Form("QA checker not found for %s", detName.Data())) ; 
197       AliQA::ALITASK index = AliQA::kNULLTASK ; 
198       if ( taskName == AliQA::GetTaskName(AliQA::kHITS) ) 
199                 index = AliQA::kSIM ; 
200       if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) ) 
201                 index = AliQA::kSIM ; 
202       if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) ) 
203                 index = AliQA::kSIM ; 
204       if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) ) 
205                 index = AliQA::kREC ; 
206       if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) ) 
207                 index = AliQA::kREC ; 
208       if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) ) 
209                 index = AliQA::kREC ; 
210       if ( taskName == AliQA::GetTaskName(AliQA::kESDS) ) 
211                 index = AliQA::kESD ; 
212       qac->Init(AliQA::DETECTORINDEX(det)) ; 
213
214           TDirectory * refDir = GetRefSubDir(detNameQA.Data(), taskName.Data()) ;
215           if ( refDir ) { 
216                 qac->SetRefandData(refDir, taskDir) ; 
217                 qac->Run(index) ; 
218           }
219     }
220  }
221   AliInfo("QA performed for following detectors:") ; 
222   for ( Int_t det = 0; det < AliQA::kNDET; det++) {
223     if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
224       printf("%s, ",AliQA::GetDetName(det)) ; 
225       fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ; 
226     }   
227   }
228   printf("\n") ; 
229   rv = kTRUE ; 
230
231   return rv ; 
232   
233 }
234
235 //_____________________________________________________________________________
236 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX det, AliQA::TASKINDEX task, TList * list)
237 {
238   // run the Quality Assurance Checker for detector det, for task task starting from data in list
239
240   AliQACheckerBase * qac = GetDetQAChecker(det) ; 
241   if (qac)
242     AliInfo(Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
243   if (!qac)
244         AliFatal(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ; 
245   
246   AliQA::ALITASK index = AliQA::kNULLTASK ; 
247   if ( task == AliQA::kRAWS ) 
248                 index = AliQA::kRAW ; 
249   else if ( task == AliQA::kHITS ) 
250                 index = AliQA::kSIM ; 
251   else if ( task == AliQA::kSDIGITS ) 
252                 index = AliQA::kSIM ; 
253   else if ( task == AliQA::kDIGITS ) 
254                 index = AliQA::kSIM ; 
255   else if ( task == AliQA::kRECPOINTS ) 
256                 index = AliQA::kREC ; 
257   else if ( task == AliQA::kTRACKSEGMENTS ) 
258                 index = AliQA::kREC ; 
259   else if ( task == AliQA::kRECPARTICLES ) 
260                 index = AliQA::kREC ; 
261   else if ( task == AliQA::kESDS ) 
262                 index = AliQA::kESD ; 
263   TDirectory * refDir = GetRefSubDir(AliQA::GetDetName(det).Data(), AliQA::GetTaskName(task).Data()) ;
264   if ( refDir ) { 
265         qac->Init(det) ; 
266         qac->SetRefandData(refDir) ; 
267         qac->Run(index, list) ; 
268   }
269   return kTRUE ; 
270   
271 }
272
273
274