]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQAChecker.cxx
removed the gcc4.3 warnings
[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 "AliRunInfo.h" 
28 #include "AliLog.h"
29 #include "AliModule.h" 
30 #include "AliQA.h"
31 #include "AliQAChecker.h"
32 #include "AliQACheckerBase.h"
33 #include "AliCorrQAChecker.h"
34 #include "AliGlobalQAChecker.h"
35 #include "AliGRPObject.h"
36
37 #include <TKey.h>
38 #include <TObjArray.h>
39 #include <TObjString.h>
40 #include <TPluginManager.h> 
41 #include <TROOT.h>
42 #include <TStopwatch.h> 
43 #include <TString.h> 
44 #include <TSystem.h> 
45 #include <TList.h>
46 #include <TNtupleD.h>
47
48 ClassImp(AliQAChecker)
49   AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
50
51 //_____________________________________________________________________________
52 AliQAChecker::AliQAChecker(const char* name, const char* title) :
53   TNamed(name, title),
54   fDataFile(0x0), 
55   fRunInfo(0x0), 
56   fRunInfoOwner(kFALSE), 
57   fRefFile(0x0), 
58   fFoundDetectors(".")
59 {
60   // ctor: initialise checkers and open the data file   
61   for (Int_t det = 0 ; det < AliQA::kNDET ; det++) 
62     fCheckers[det] = NULL ; 
63 }
64
65 //_____________________________________________________________________________
66 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
67   TNamed(qac),
68   fDataFile(qac.fDataFile), 
69   fRunInfo(qac.fRunInfo), 
70   fRunInfoOwner(kFALSE),   
71   fRefFile(qac.fRefFile), 
72   fFoundDetectors(qac.fFoundDetectors)
73 {
74   // copy constructor
75   
76   for (Int_t det = 0 ; det < AliQA::kNDET ; det++) 
77     fCheckers[det] = NULL ; 
78 }
79
80 //_____________________________________________________________________________
81 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
82 {
83 // assignment operator
84
85   this->~AliQAChecker();
86   new(this) AliQAChecker(qac);
87   return *this;
88 }
89
90 //_____________________________________________________________________________
91 AliQAChecker::~AliQAChecker()
92 {
93 // clean up
94   if (fRunInfo)
95     delete fRunInfo ; 
96   delete [] fCheckers ; 
97   AliQA::Close() ; 
98 }
99
100 //_____________________________________________________________________________
101   AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
102 {
103         // Gets the Quality Assurance checker for the detector specified by its name
104         
105         if (fCheckers[det]) 
106     return fCheckers[det];
107
108         AliQACheckerBase * qac = NULL ;
109
110         TString detName(AliQA::GetDetName(det)) ; 
111         
112         if (det == AliQA::kGLOBAL) {
113                 qac = new AliGlobalQAChecker() ; 
114         } else if (det == AliQA::kCORR) {
115                 qac = new AliCorrQAChecker() ; 
116         } else {
117                 AliDebug(1, Form("Retrieving QA checker for %s", detName.Data())) ; 
118                 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
119                 TString qacName = "Ali" + detName + "QAChecker" ;
120
121                 // first check if a plugin is defined for the quality assurance checker
122                 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
123                 // if not, add a plugin for it
124                 if (!pluginHandler) {
125                         //AliInfo(Form("defining plugin for %s", qacName.Data()));
126                         TString libs = gSystem->GetLibraries();
127                 
128                         if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
129                                 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
130                         else 
131                                 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
132
133                         pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);    
134
135                         if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) 
136                                 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
137   
138                 }
139         }
140         if (qac) 
141                 fCheckers[det] = qac ;
142         
143         return qac ; 
144 }
145  
146 //_____________________________________________________________________________
147 void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray *& dirOCDB)     
148
149   // Opens and returns the file with the reference data 
150         
151   dirFile = NULL ; 
152   dirOCDB = NULL ; 
153   TString refStorage(AliQA::GetQARefStorage()) ; 
154   //refStorage += AliQA::GetQARefFileName() ;
155   if (refStorage.Contains(AliQA::GetLabLocalFile())) {  
156     refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ; 
157     if ( fRefFile ) 
158       if ( fRefFile->IsOpen() ) 
159                                         fRefFile->Close() ; 
160     fRefFile = TFile::Open(refStorage.Data()) ; 
161     if (!fRefFile) { 
162       AliError(Form("Cannot find reference file %s", refStorage.Data())) ; 
163       dirFile = NULL ; 
164     }
165     dirFile = fRefFile->GetDirectory(det) ; 
166     if (!dirFile) {
167       AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ; 
168     } else {
169                         dirFile = dirFile->GetDirectory(task) ; 
170       if (!dirFile) 
171                                 AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ; 
172     }  
173   } else if (refStorage.Contains(AliQA::GetLabLocalOCDB()) || refStorage.Contains(AliQA::GetLabAliEnOCDB())) {  
174     AliCDBManager* man = AliCDBManager::Instance() ;
175     if ( strcmp(AliQA::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (RUNTYPE)
176       // Get it from RunInfo
177       if (!fRunInfo)  // not yet set, get the info from GRP
178                                 LoadRunInfoFromGRP() ; 
179       AliQA::SetQARefDataDirName(fRunInfo->GetRunType()) ;
180     }
181     if ( ! man->GetLock() ) { 
182       man->SetDefaultStorage(AliQA::GetQARefStorage()) ; 
183       man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
184     }
185     char * detOCDBDir = Form("%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ; 
186     AliInfo(Form("Reference QA data are taken from %s", detOCDBDir)) ;
187     AliCDBEntry * entry = man->Get(detOCDBDir, man->GetRun()) ;
188     if (entry) {
189       TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
190       if ( listDetQAD ) 
191                                 dirOCDB = dynamic_cast<TObjArray *>(listDetQAD->FindObject(task)) ; 
192     }
193   }
194 }
195
196 //_____________________________________________________________________________
197 AliQAChecker * AliQAChecker::Instance()
198 {
199         // returns unique instance of the checker
200   if ( ! fgQAChecker ) 
201    fgQAChecker = new AliQAChecker() ; 
202   return fgQAChecker ;  
203 }
204
205 //_____________________________________________________________________________
206 void AliQAChecker::LoadRunInfoFromGRP() 
207 {
208   AliCDBManager* man = AliCDBManager::Instance() ;
209   AliCDBEntry* entry = man->Get(AliQA::GetGRPPath().Data());
210   AliGRPObject* grpObject = 0x0;
211   if (entry) {
212
213           TMap* m = dynamic_cast<TMap*>(entry->GetObject());  // old GRP entry
214
215           if (m) {
216             AliInfo("It is a map");
217             //m->Print();
218             grpObject = new AliGRPObject();
219                  grpObject->ReadValuesFromMap(m);
220     }
221
222     else {
223             AliInfo("It is a new GRP object");
224         grpObject = dynamic_cast<AliGRPObject*>(entry->GetObject());  // new GRP entry
225     }
226
227     entry->SetOwner(0);
228     AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
229   }
230
231   if (!grpObject) {
232      AliFatal("No GRP entry found in OCDB!");
233   }
234
235   TString lhcState = grpObject->GetLHCState();
236   if (lhcState==AliGRPObject::GetInvalidString()) {
237     AliError("GRP/GRP/Data entry:  missing value for the LHC state ! Using UNKNOWN");
238     lhcState = "UNKNOWN";
239   }
240
241   TString beamType = grpObject->GetBeamType();
242   if (beamType==AliGRPObject::GetInvalidString()) {
243     AliError("GRP/GRP/Data entry:  missing value for the beam type ! Using UNKNOWN");
244     beamType = "UNKNOWN";
245   }
246
247   Float_t beamEnergy = grpObject->GetBeamEnergy();
248   if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
249     AliError("GRP/GRP/Data entry:  missing value for the beam energy ! Using 0");
250     beamEnergy = 0;
251   }
252
253   TString runType = grpObject->GetRunType();
254   if (runType==AliGRPObject::GetInvalidString()) {
255     AliError("GRP/GRP/Data entry:  missing value for the run type ! Using UNKNOWN");
256     runType = "UNKNOWN";
257   }
258
259   Int_t activeDetectors = grpObject->GetDetectorMask();
260   if (activeDetectors==AliGRPObject::GetInvalidInt()) {
261     AliError("GRP/GRP/Data entry:  missing value for the detector mask ! Using 1074790399");
262     activeDetectors = 1074790399;
263   }
264
265   fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
266
267   fRunInfoOwner = kTRUE ; 
268 }
269
270 //_____________________________________________________________________________
271 Bool_t AliQAChecker::Run(const char * fileName)
272 {
273   // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
274   // starting from data in file
275
276   Bool_t rv = kFALSE ; 
277   
278   TStopwatch stopwatch;
279   stopwatch.Start();
280
281   //search for all detectors QA directories
282   TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ; 
283   TIter nextd(detKeyList) ; 
284   TKey * detKey ; 
285   while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
286     AliDebug(1, Form("Found %s", detKey->GetName())) ;
287     //Check which detector
288     TString detName ; 
289     TString detNameQA(detKey->GetName()) ; 
290     Int_t det ; 
291     for ( det = 0; det < AliQA::kNDET ; det++) {
292       detName = AliQA::GetDetName(det) ; 
293       if (detNameQA.Contains(detName)) {
294         fFoundDetectors+=detName ; 
295         fFoundDetectors+="." ;          
296         break ; 
297       }
298     } 
299     TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ; 
300     TList * taskKeyList = detDir->GetListOfKeys() ;
301     TIter nextt(taskKeyList) ; 
302     TKey * taskKey ; 
303     // now search for the tasks dir
304     while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
305       TString taskName( taskKey->GetName() ) ; 
306       AliInfo(Form("Found %s", taskName.Data())) ;
307       TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ; 
308       taskDir->cd() ; 
309       AliQACheckerBase * qac = GetDetQAChecker(det) ; 
310       if (qac)
311                 AliInfo(Form("QA checker found for %s", detName.Data())) ; 
312       if (!qac)
313                 AliFatal(Form("QA checker not found for %s", detName.Data())) ; 
314       AliQA::ALITASK_t index = AliQA::kNULLTASK ; 
315       if ( taskName == AliQA::GetTaskName(AliQA::kHITS) ) 
316                 index = AliQA::kSIM ; 
317       if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) ) 
318                 index = AliQA::kSIM ; 
319       if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) ) 
320                 index = AliQA::kSIM ; 
321       if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) ) 
322                 index = AliQA::kREC ; 
323       if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) ) 
324                 index = AliQA::kREC ; 
325       if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) ) 
326                 index = AliQA::kREC ; 
327       if ( taskName == AliQA::GetTaskName(AliQA::kESDS) ) 
328                 index = AliQA::kESD ; 
329       qac->Init(AliQA::DETECTORINDEX_t(det)) ; 
330
331           TDirectory * refDir    = NULL ; 
332           TObjArray * refOCDBDir = NULL ;       
333           GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
334           if ( refDir || refOCDBDir) {
335                   qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
336                   qac->Run(index) ; 
337           }
338         }
339   }
340   AliInfo("QA performed for following detectors:") ; 
341   for ( Int_t det = 0; det < AliQA::kNDET; det++) {
342     if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
343       printf("%s, ",AliQA::GetDetName(det)) ; 
344       fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ; 
345     }   
346   }
347   printf("\n") ; 
348   rv = kTRUE ; 
349
350   return rv ; 
351   
352 }
353
354 //_____________________________________________________________________________
355 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObject * obj)
356 {
357         // run the Quality Assurance Checker for detector det, for task task starting from data in list
358
359         AliQACheckerBase * qac = GetDetQAChecker(det) ; 
360         if (qac)
361                 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
362         if (!qac)
363                 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ; 
364   
365         AliQA::ALITASK_t index = AliQA::kNULLTASK ; 
366         if ( task == AliQA::kRAWS ) 
367                 index = AliQA::kRAW ; 
368         else if ( task == AliQA::kHITS ) 
369                 index = AliQA::kSIM ; 
370         else if ( task == AliQA::kSDIGITS ) 
371                 index = AliQA::kSIM ; 
372         else if ( task == AliQA::kDIGITS ) 
373                 index = AliQA::kSIM ; 
374         else if ( task == AliQA::kRECPOINTS ) 
375                 index = AliQA::kREC ; 
376         else if ( task == AliQA::kTRACKSEGMENTS ) 
377                 index = AliQA::kREC ; 
378         else if ( task == AliQA::kRECPARTICLES ) 
379                 index = AliQA::kREC ; 
380         else if ( task == AliQA::kESDS ) 
381                 index = AliQA::kESD ; 
382
383         TDirectory * refDir    = NULL ; 
384         TObjArray * refOCDBDir = NULL ; 
385         qac->Init(det) ; 
386         GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
387         if ( refDir || refOCDBDir)  // references found
388           qac->SetRefandData(refDir, refOCDBDir) ; 
389         
390   TString className(obj->ClassName()) ; 
391   if (className.Contains(TObjArray::Class()->GetName())) {
392     qac->Run(index, static_cast<TObjArray *>(obj)) ; 
393   } else if (className.Contains(TNtupleD::Class()->GetName())) {
394     qac->Run(index, static_cast<TNtupleD *>(obj)) ; 
395   } else {
396     AliError(Form("%s class not implemented", className.Data())) ; 
397     return kFALSE ; 
398   }
399         return kTRUE ; 
400 }