]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQAChecker.cxx
Added another recoParam to the TOF recoParam object, i.e. time window to discriminate...
[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 =static_cast<TList *>(entry->GetObject()) ;
199         if ( strcmp(listDetQAD->ClassName(), "TList") != 0 ) {
200           AliError(Form("Expected a Tlist and found a %s for detector %s", listDetQAD->ClassName(), det)) ; 
201           continue ; 
202         }       
203         TIter next(listDetQAD) ;
204         TObjArray * ar ; 
205         while ( (ar = (TObjArray*)next()) )
206           if ( listDetQAD ) 
207           dirOCDB[specie] = static_cast<TObjArray *>(listDetQAD->FindObject(Form("%s/%s", task, AliRecoParam::GetEventSpecieName(specie)))) ; 
208       }
209     }
210   }
211 }
212
213 //_____________________________________________________________________________
214 AliQAChecker * AliQAChecker::Instance()
215 {
216         // returns unique instance of the checker
217   if ( ! fgQAChecker ) 
218    fgQAChecker = new AliQAChecker() ; 
219   return fgQAChecker ;  
220 }
221
222 //_____________________________________________________________________________
223 void AliQAChecker::LoadRunInfoFromGRP() 
224 {
225   AliCDBManager* man = AliCDBManager::Instance() ;
226   AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
227   AliGRPObject* grpObject = 0x0;
228   if (entry) {
229
230           TMap* m = static_cast<TMap*>(entry->GetObject());  // old GRP entry
231
232           if (m) {
233             AliDebug(AliQAv1::GetQADebugLevel(), "It is a map");
234             //m->Print();
235             grpObject = new AliGRPObject();
236                  grpObject->ReadValuesFromMap(m);
237     }
238
239     else {
240             AliDebug(AliQAv1::GetQADebugLevel(), "It is a new GRP object");
241         grpObject = static_cast<AliGRPObject*>(entry->GetObject());  // new GRP entry
242     }
243
244     entry->SetOwner(0);
245     AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
246   }
247
248   if (!grpObject) {
249      AliFatal("No GRP entry found in OCDB!");
250   }
251
252   TString lhcState = grpObject->GetLHCState();
253   if (lhcState==AliGRPObject::GetInvalidString()) {
254     AliError("GRP/GRP/Data entry:  missing value for the LHC state ! Using UNKNOWN");
255     lhcState = "UNKNOWN";
256   }
257
258   TString beamType = grpObject->GetBeamType();
259   if (beamType==AliGRPObject::GetInvalidString()) {
260     AliError("GRP/GRP/Data entry:  missing value for the beam type ! Using UNKNOWN");
261     beamType = "UNKNOWN";
262   }
263
264   Float_t beamEnergy = grpObject->GetBeamEnergy();
265   if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
266     AliError("GRP/GRP/Data entry:  missing value for the beam energy ! Using 0");
267     beamEnergy = 0;
268   }
269
270   TString runType = grpObject->GetRunType();
271   if (runType==AliGRPObject::GetInvalidString()) {
272     AliError("GRP/GRP/Data entry:  missing value for the run type ! Using UNKNOWN");
273     runType = "UNKNOWN";
274   }
275
276   Int_t activeDetectors = grpObject->GetDetectorMask();
277   if (activeDetectors==AliGRPObject::GetInvalidInt()) {
278     AliError("GRP/GRP/Data entry:  missing value for the detector mask ! Using 1074790399");
279     activeDetectors = 1074790399;
280   }
281
282   fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
283
284   fRunInfoOwner = kTRUE ; 
285
286   // set the event specie
287   fEventSpecie = AliRecoParam::kDefault ;
288   if (strcmp(runType,"PHYSICS")) {
289     // Not a physics run, the event specie is set to kCalib
290     fEventSpecie = AliRecoParam::kCalib ;
291     return;
292   }
293   if (strcmp(lhcState,"STABLE_BEAMS") == 0) {
294     // Heavy ion run (any beam tha is not pp, the event specie is set to kHighMult
295     fEventSpecie = AliRecoParam::kHighMult ;
296     if ((strcmp(beamType,"p-p") == 0) ||
297         (strcmp(beamType,"p-")  == 0) ||
298         (strcmp(beamType,"-p")  == 0) ||
299         (strcmp(beamType,"P-P") == 0) ||
300         (strcmp(beamType,"P-")  == 0) ||
301         (strcmp(beamType,"-P")  == 0)) {
302       // Proton run, the event specie is set to kLowMult
303       fEventSpecie = AliRecoParam::kLowMult ;
304     }
305     else if (strcmp(beamType,"-") == 0) {
306       // No beams, we assume cosmic data
307       fEventSpecie = AliRecoParam::kCosmic ;
308     }
309     else if (strcmp(beamType,"UNKNOWN") == 0) {
310       // No LHC beam information is available, we use the default event specie
311       fEventSpecie = AliRecoParam::kDefault ;
312     }
313   }
314 }
315
316 //_____________________________________________________________________________
317 Bool_t AliQAChecker::Run(const char * fileName)
318 {
319   // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, DigitsR, RecPoints, TrackSegments, RecParticles and ESDs
320   // starting from data in file  
321   TStopwatch stopwatch;
322   stopwatch.Start();
323
324   //search for all detectors QA directories
325   TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ; 
326   TIter nextd(detKeyList) ; 
327   TKey * detKey ; 
328   while ( (detKey = static_cast<TKey *>(nextd()) ) ) {
329     AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", detKey->GetName())) ;
330     //Check which detector
331     TString detName ; 
332     TString detNameQA(detKey->GetName()) ; 
333     Int_t det ; 
334     for ( det = 0; det < AliQAv1::kNDET ; det++) {
335       detName = AliQAv1::GetDetName(det) ; 
336       if (detNameQA.Contains(detName)) {
337         fFoundDetectors+=detName ; 
338         fFoundDetectors+="." ;          
339         break ; 
340       }
341     } 
342     TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ; 
343     TList * taskKeyList = detDir->GetListOfKeys() ;
344     TIter nextt(taskKeyList) ; 
345     TKey * taskKey ; 
346     // now search for the tasks dir
347     while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
348       TString taskName( taskKey->GetName() ) ; 
349       AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", taskName.Data())) ;
350       TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ; 
351       taskDir->cd() ; 
352       AliQACheckerBase * qac = GetDetQAChecker(det) ; 
353       if (qac)
354         AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", detName.Data())) ; 
355       if (!qac)
356         AliFatal(Form("QA checker not found for %s", detName.Data())) ; 
357       AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ; 
358       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kHITS) ) 
359         index = AliQAv1::kSIM ; 
360       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kSDIGITS) ) 
361         index = AliQAv1::kSIM ; 
362       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITS) ) 
363         index = AliQAv1::kSIM ; 
364       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITSR) ) 
365         index = AliQAv1::kREC ; 
366       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPOINTS) ) 
367         index = AliQAv1::kREC ; 
368       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kTRACKSEGMENTS) ) 
369         index = AliQAv1::kREC ; 
370       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPARTICLES) ) 
371         index = AliQAv1::kREC ; 
372       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kESDS) ) 
373         index = AliQAv1::kESD ; 
374       qac->Init(AliQAv1::DETECTORINDEX_t(det)) ; 
375       
376       TDirectory * refDir     = NULL ; 
377       TObjArray ** refOCDBDir = NULL ;  
378       GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
379                   qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
380                   qac->Run(index) ; 
381     }
382   }
383   AliInfo("QA performed for following detectors:") ; 
384   for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
385     if (fFoundDetectors.Contains(AliQAv1::GetDetName(det))) {
386       AliInfoClass(Form("%s, ",AliQAv1::GetDetName(det))) ; 
387       fFoundDetectors.ReplaceAll(AliQAv1::GetDetName(det), "") ; 
388     }   
389   }
390   printf("\n") ; 
391   return kTRUE ; 
392 }
393
394 //_____________________________________________________________________________
395 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TObjArray ** list)
396 {
397         // run the Quality Assurance Checker for detector det, for task task starting from data in list
398
399         AliQACheckerBase * qac = GetDetQAChecker(det) ; 
400         if (qac)
401                 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
402         if (!qac)
403                 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ; 
404   
405         AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ; 
406         if ( task == AliQAv1::kRAWS ) 
407                 index = AliQAv1::kRAW ; 
408         else if ( task == AliQAv1::kHITS ) 
409                 index = AliQAv1::kSIM ; 
410         else if ( task == AliQAv1::kSDIGITS ) 
411                 index = AliQAv1::kSIM ; 
412         else if ( task == AliQAv1::kDIGITS ) 
413                 index = AliQAv1::kSIM ; 
414         else if ( task == AliQAv1::kDIGITSR ) 
415                 index = AliQAv1::kREC ; 
416         else if ( task == AliQAv1::kRECPOINTS ) 
417                 index = AliQAv1::kREC ; 
418         else if ( task == AliQAv1::kTRACKSEGMENTS ) 
419                 index = AliQAv1::kREC ; 
420         else if ( task == AliQAv1::kRECPARTICLES ) 
421                 index = AliQAv1::kREC ; 
422         else if ( task == AliQAv1::kESDS ) 
423                 index = AliQAv1::kESD ; 
424
425         TDirectory * refDir     = NULL ; 
426         TObjArray ** refOCDBDir = NULL  ;       
427   qac->Init(det) ; 
428   GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
429   qac->SetRefandData(refDir, refOCDBDir) ; 
430   qac->Run(index, list) ; 
431         return kTRUE ; 
432 }
433
434 //_____________________________________________________________________________
435 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TNtupleD ** list)
436 {
437         // run the Quality Assurance Checker for detector det, for task task starting from data in list
438   
439         AliQACheckerBase * qac = GetDetQAChecker(det) ; 
440         if (qac)
441                 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
442         if (!qac)
443                 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ; 
444   
445         AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ; 
446         if ( task == AliQAv1::kRAWS ) 
447                 index = AliQAv1::kRAW ; 
448         else if ( task == AliQAv1::kHITS ) 
449                 index = AliQAv1::kSIM ; 
450         else if ( task == AliQAv1::kSDIGITS ) 
451                 index = AliQAv1::kSIM ; 
452         else if ( task == AliQAv1::kDIGITS ) 
453                 index = AliQAv1::kSIM ; 
454         else if ( task == AliQAv1::kDIGITSR ) 
455                 index = AliQAv1::kREC ; 
456         else if ( task == AliQAv1::kRECPOINTS ) 
457                 index = AliQAv1::kREC ; 
458         else if ( task == AliQAv1::kTRACKSEGMENTS ) 
459                 index = AliQAv1::kREC ; 
460         else if ( task == AliQAv1::kRECPARTICLES ) 
461                 index = AliQAv1::kREC ; 
462         else if ( task == AliQAv1::kESDS ) 
463                 index = AliQAv1::kESD ; 
464   
465         TDirectory * refDir     = NULL ; 
466         TObjArray ** refOCDBDir = NULL ;        
467   qac->Init(det) ; 
468   GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
469   qac->SetRefandData(refDir, refOCDBDir) ; 
470   qac->Run(index, list) ; 
471   return kTRUE ; 
472 }