]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQAChecker.cxx
Debug printout removed.
[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 "AliQAManager.h"
26 #include "AliCDBStorage.h"
27 #include "AliRunInfo.h" 
28 #include "AliLog.h"
29 #include "AliModule.h" 
30 #include "AliQAv1.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   fEventSpecie(AliRecoParam::kDefault) 
60 {
61   // ctor: initialise checkers and open the data file   
62   for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) 
63     fCheckers[det] = NULL ; 
64 }
65
66 //_____________________________________________________________________________
67 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
68   TNamed(qac),
69   fDataFile(qac.fDataFile), 
70   fRunInfo(qac.fRunInfo), 
71   fRunInfoOwner(kFALSE),   
72   fRefFile(qac.fRefFile), 
73   fFoundDetectors(qac.fFoundDetectors),
74   fEventSpecie(qac.fEventSpecie)
75 {
76   // copy constructor
77   
78   for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) 
79     fCheckers[det] = NULL ; 
80 }
81
82 //_____________________________________________________________________________
83 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
84 {
85 // assignment operator
86
87   this->~AliQAChecker();
88   new(this) AliQAChecker(qac);
89   return *this;
90 }
91
92 //_____________________________________________________________________________
93 AliQAChecker::~AliQAChecker()
94 {
95 // clean up
96   if (fRunInfo)
97     delete fRunInfo ; 
98   delete [] fCheckers ; 
99   AliQAv1::Close() ; 
100 }
101
102 //_____________________________________________________________________________
103   AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
104 {
105         // Gets the Quality Assurance checker for the detector specified by its name
106         
107         if (fCheckers[det]) 
108     return fCheckers[det];
109
110         AliQACheckerBase * qac = NULL ;
111
112         TString detName(AliQAv1::GetDetName(det)) ; 
113         
114         if (det == AliQAv1::kGLOBAL) {
115                 qac = new AliGlobalQAChecker() ; 
116         } else if (det == AliQAv1::kCORR) {
117                 qac = new AliCorrQAChecker() ; 
118         } else {
119                 AliDebug(AliQAv1::GetQADebugLevel(), Form("Retrieving QA checker for %s", detName.Data())) ; 
120                 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
121                 TString qacName = "Ali" + detName + "QAChecker" ;
122
123                 // first check if a plugin is defined for the quality assurance checker
124                 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
125                 // if not, add a plugin for it
126                 if (!pluginHandler) {
127                         //AliDebug(AliQAv1::GetQADebugLevel(), Form("defining plugin for %s", qacName.Data()));
128                         TString libs = gSystem->GetLibraries();
129                 
130                         if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
131                                 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
132                         else 
133                                 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
134
135                         pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);    
136
137                         if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) 
138                                 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
139   
140                 }
141         }
142         if (qac) 
143                 fCheckers[det] = qac ;
144         
145         return qac ; 
146 }
147  
148 //_____________________________________________________________________________
149 void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray **& dirOCDB)     
150
151   // Opens and returns the file with the reference data 
152   dirFile = NULL ; 
153   TString refStorage(AliQAv1::GetQARefStorage()) ;
154 //  if (refStorage.Contains(AliQAv1::GetLabLocalFile())) {      
155 //    refStorage.ReplaceAll(AliQAv1::GetLabLocalFile(), "") ; 
156 //    refStorage += AliQAv1::GetQARefFileName() ;
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 
174   if (!refStorage.Contains(AliQAv1::GetLabLocalOCDB()) && !refStorage.Contains(AliQAv1::GetLabAliEnOCDB())) {
175     AliError(Form("%s is not a valid location for reference data", refStorage.Data())) ; 
176     return ; 
177   } else {
178     AliQAManager* manQA = AliQAManager::QAManager() ;
179     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
180       if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) ) 
181         continue ; 
182       //if ( strcmp(AliQAv1::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (EventSpecie)
183         // Get it from RunInfo
184         //if (!fRunInfo)  // not yet set, get the info from GRP
185         //  LoadRunInfoFromGRP() ; 
186       AliQAv1::SetQARefDataDirName(specie) ;
187       //}
188       if ( ! manQA->GetLock() ) { 
189         manQA->SetDefaultStorage(AliQAv1::GetQARefStorage()) ; 
190         manQA->SetSpecificStorage("*", AliQAv1::GetQARefStorage()) ;
191         manQA->SetRun(AliCDBManager::Instance()->GetRun()) ; 
192         manQA->SetLock() ; 
193       }
194       char * detOCDBDir = Form("%s/%s/%s", det, AliQAv1::GetRefOCDBDirName(), AliQAv1::GetRefDataDirName()) ; 
195       AliCDBEntry * entry = manQA->Get(detOCDBDir, manQA->GetRun()) ;
196       if (entry) {
197         dirOCDB = new TObjArray*[AliRecoParam::kNSpecies] ;     
198         TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
199         TIter next(listDetQAD) ;
200         TObjArray * ar ; 
201         while ( (ar = (TObjArray*)next()) )
202           if ( listDetQAD ) 
203           dirOCDB[specie] = dynamic_cast<TObjArray *>(listDetQAD->FindObject(Form("%s/%s", task, AliRecoParam::GetEventSpecieName(specie)))) ; 
204       }
205     }
206   }
207 }
208
209 //_____________________________________________________________________________
210 AliQAChecker * AliQAChecker::Instance()
211 {
212         // returns unique instance of the checker
213   if ( ! fgQAChecker ) 
214    fgQAChecker = new AliQAChecker() ; 
215   return fgQAChecker ;  
216 }
217
218 //_____________________________________________________________________________
219 void AliQAChecker::LoadRunInfoFromGRP() 
220 {
221   AliCDBManager* man = AliCDBManager::Instance() ;
222   AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
223   AliGRPObject* grpObject = 0x0;
224   if (entry) {
225
226           TMap* m = dynamic_cast<TMap*>(entry->GetObject());  // old GRP entry
227
228           if (m) {
229             AliDebug(AliQAv1::GetQADebugLevel(), "It is a map");
230             //m->Print();
231             grpObject = new AliGRPObject();
232                  grpObject->ReadValuesFromMap(m);
233     }
234
235     else {
236             AliDebug(AliQAv1::GetQADebugLevel(), "It is a new GRP object");
237         grpObject = dynamic_cast<AliGRPObject*>(entry->GetObject());  // new GRP entry
238     }
239
240     entry->SetOwner(0);
241     AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
242   }
243
244   if (!grpObject) {
245      AliFatal("No GRP entry found in OCDB!");
246   }
247
248   TString lhcState = grpObject->GetLHCState();
249   if (lhcState==AliGRPObject::GetInvalidString()) {
250     AliError("GRP/GRP/Data entry:  missing value for the LHC state ! Using UNKNOWN");
251     lhcState = "UNKNOWN";
252   }
253
254   TString beamType = grpObject->GetBeamType();
255   if (beamType==AliGRPObject::GetInvalidString()) {
256     AliError("GRP/GRP/Data entry:  missing value for the beam type ! Using UNKNOWN");
257     beamType = "UNKNOWN";
258   }
259
260   Float_t beamEnergy = grpObject->GetBeamEnergy();
261   if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
262     AliError("GRP/GRP/Data entry:  missing value for the beam energy ! Using 0");
263     beamEnergy = 0;
264   }
265
266   TString runType = grpObject->GetRunType();
267   if (runType==AliGRPObject::GetInvalidString()) {
268     AliError("GRP/GRP/Data entry:  missing value for the run type ! Using UNKNOWN");
269     runType = "UNKNOWN";
270   }
271
272   Int_t activeDetectors = grpObject->GetDetectorMask();
273   if (activeDetectors==AliGRPObject::GetInvalidInt()) {
274     AliError("GRP/GRP/Data entry:  missing value for the detector mask ! Using 1074790399");
275     activeDetectors = 1074790399;
276   }
277
278   fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
279
280   fRunInfoOwner = kTRUE ; 
281
282   // set the event specie
283   fEventSpecie = AliRecoParam::kDefault ;
284   if (strcmp(runType,"PHYSICS")) {
285     // Not a physics run, the event specie is set to kCalib
286     fEventSpecie = AliRecoParam::kCalib ;
287     return;
288   }
289   if (strcmp(lhcState,"STABLE_BEAMS") == 0) {
290     // Heavy ion run (any beam tha is not pp, the event specie is set to kHighMult
291     fEventSpecie = AliRecoParam::kHighMult ;
292     if ((strcmp(beamType,"p-p") == 0) ||
293         (strcmp(beamType,"p-")  == 0) ||
294         (strcmp(beamType,"-p")  == 0) ||
295         (strcmp(beamType,"P-P") == 0) ||
296         (strcmp(beamType,"P-")  == 0) ||
297         (strcmp(beamType,"-P")  == 0)) {
298       // Proton run, the event specie is set to kLowMult
299       fEventSpecie = AliRecoParam::kLowMult ;
300     }
301     else if (strcmp(beamType,"-") == 0) {
302       // No beams, we assume cosmic data
303       fEventSpecie = AliRecoParam::kCosmic ;
304     }
305     else if (strcmp(beamType,"UNKNOWN") == 0) {
306       // No LHC beam information is available, we use the default event specie
307       fEventSpecie = AliRecoParam::kDefault ;
308     }
309   }
310 }
311
312 //_____________________________________________________________________________
313 Bool_t AliQAChecker::Run(const char * fileName)
314 {
315   // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
316   // starting from data in file  
317   TStopwatch stopwatch;
318   stopwatch.Start();
319
320   //search for all detectors QA directories
321   TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ; 
322   TIter nextd(detKeyList) ; 
323   TKey * detKey ; 
324   while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
325     AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", detKey->GetName())) ;
326     //Check which detector
327     TString detName ; 
328     TString detNameQA(detKey->GetName()) ; 
329     Int_t det ; 
330     for ( det = 0; det < AliQAv1::kNDET ; det++) {
331       detName = AliQAv1::GetDetName(det) ; 
332       if (detNameQA.Contains(detName)) {
333         fFoundDetectors+=detName ; 
334         fFoundDetectors+="." ;          
335         break ; 
336       }
337     } 
338     TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ; 
339     TList * taskKeyList = detDir->GetListOfKeys() ;
340     TIter nextt(taskKeyList) ; 
341     TKey * taskKey ; 
342     // now search for the tasks dir
343     while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
344       TString taskName( taskKey->GetName() ) ; 
345       AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", taskName.Data())) ;
346       TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ; 
347       taskDir->cd() ; 
348       AliQACheckerBase * qac = GetDetQAChecker(det) ; 
349       if (qac)
350         AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", detName.Data())) ; 
351       if (!qac)
352         AliFatal(Form("QA checker not found for %s", detName.Data())) ; 
353       AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ; 
354       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kHITS) ) 
355         index = AliQAv1::kSIM ; 
356       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kSDIGITS) ) 
357         index = AliQAv1::kSIM ; 
358       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITS) ) 
359         index = AliQAv1::kSIM ; 
360       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPOINTS) ) 
361         index = AliQAv1::kREC ; 
362       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kTRACKSEGMENTS) ) 
363         index = AliQAv1::kREC ; 
364       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPARTICLES) ) 
365         index = AliQAv1::kREC ; 
366       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kESDS) ) 
367         index = AliQAv1::kESD ; 
368       qac->Init(AliQAv1::DETECTORINDEX_t(det)) ; 
369       
370       TDirectory * refDir     = NULL ; 
371       TObjArray ** refOCDBDir = NULL ;  
372       GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
373                   qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
374                   qac->Run(index) ; 
375     }
376   }
377   AliInfo("QA performed for following detectors:") ; 
378   for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
379     if (fFoundDetectors.Contains(AliQAv1::GetDetName(det))) {
380       AliInfoClass(Form("%s, ",AliQAv1::GetDetName(det))) ; 
381       fFoundDetectors.ReplaceAll(AliQAv1::GetDetName(det), "") ; 
382     }   
383   }
384   printf("\n") ; 
385   return kTRUE ; 
386 }
387
388 //_____________________________________________________________________________
389 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TObjArray ** list)
390 {
391         // run the Quality Assurance Checker for detector det, for task task starting from data in list
392
393         AliQACheckerBase * qac = GetDetQAChecker(det) ; 
394         if (qac)
395                 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
396         if (!qac)
397                 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ; 
398   
399         AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ; 
400         if ( task == AliQAv1::kRAWS ) 
401                 index = AliQAv1::kRAW ; 
402         else if ( task == AliQAv1::kHITS ) 
403                 index = AliQAv1::kSIM ; 
404         else if ( task == AliQAv1::kSDIGITS ) 
405                 index = AliQAv1::kSIM ; 
406         else if ( task == AliQAv1::kDIGITS ) 
407                 index = AliQAv1::kSIM ; 
408         else if ( task == AliQAv1::kRECPOINTS ) 
409                 index = AliQAv1::kREC ; 
410         else if ( task == AliQAv1::kTRACKSEGMENTS ) 
411                 index = AliQAv1::kREC ; 
412         else if ( task == AliQAv1::kRECPARTICLES ) 
413                 index = AliQAv1::kREC ; 
414         else if ( task == AliQAv1::kESDS ) 
415                 index = AliQAv1::kESD ; 
416
417         TDirectory * refDir     = NULL ; 
418         TObjArray ** refOCDBDir = NULL  ;       
419   qac->Init(det) ; 
420   GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
421   qac->SetRefandData(refDir, refOCDBDir) ; 
422   qac->Run(index, list) ; 
423         return kTRUE ; 
424 }
425
426 //_____________________________________________________________________________
427 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TNtupleD ** list)
428 {
429         // run the Quality Assurance Checker for detector det, for task task starting from data in list
430   
431         AliQACheckerBase * qac = GetDetQAChecker(det) ; 
432         if (qac)
433                 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
434         if (!qac)
435                 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ; 
436   
437         AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ; 
438         if ( task == AliQAv1::kRAWS ) 
439                 index = AliQAv1::kRAW ; 
440         else if ( task == AliQAv1::kHITS ) 
441                 index = AliQAv1::kSIM ; 
442         else if ( task == AliQAv1::kSDIGITS ) 
443                 index = AliQAv1::kSIM ; 
444         else if ( task == AliQAv1::kDIGITS ) 
445                 index = AliQAv1::kSIM ; 
446         else if ( task == AliQAv1::kRECPOINTS ) 
447                 index = AliQAv1::kREC ; 
448         else if ( task == AliQAv1::kTRACKSEGMENTS ) 
449                 index = AliQAv1::kREC ; 
450         else if ( task == AliQAv1::kRECPARTICLES ) 
451                 index = AliQAv1::kREC ; 
452         else if ( task == AliQAv1::kESDS ) 
453                 index = AliQAv1::kESD ; 
454   
455         TDirectory * refDir     = NULL ; 
456         TObjArray ** refOCDBDir = NULL ;        
457   qac->Init(det) ; 
458   GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
459   qac->SetRefandData(refDir, refOCDBDir) ; 
460   qac->Run(index, list) ; 
461   return kTRUE ; 
462 }