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