]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQAChecker.cxx
addapt array of histograms for different SM combinations to new EMCAL SM
[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   fRun(0)
61 {
62   // ctor: initialise checkers and open the data file   
63   for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) 
64     fCheckers[det] = NULL ; 
65 }
66
67 //_____________________________________________________________________________
68 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
69   TNamed(qac),
70   fDataFile(qac.fDataFile), 
71   fRunInfo(qac.fRunInfo), 
72   fRunInfoOwner(kFALSE),   
73   fRefFile(qac.fRefFile), 
74   fFoundDetectors(qac.fFoundDetectors),
75   fEventSpecie(qac.fEventSpecie),
76   fRun(qac.fRun)
77 {
78   // copy constructor
79   
80   for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) 
81     fCheckers[det] = NULL ; 
82 }
83
84 //_____________________________________________________________________________
85 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
86 {
87 // assignment operator
88
89   this->~AliQAChecker();
90   new(this) AliQAChecker(qac);
91   return *this;
92 }
93
94 //_____________________________________________________________________________
95 AliQAChecker::~AliQAChecker()
96 {
97 // clean up
98   if (fRunInfo)
99     delete fRunInfo ; 
100   for (Int_t det=0; det<AliQAv1::kNDET; det++)
101     delete fCheckers[det] ; 
102   AliQAv1::Close() ; 
103 }
104
105 //_____________________________________________________________________________
106   AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
107 {
108         // Gets the Quality Assurance checker for the detector specified by its name
109         
110         if (fCheckers[det]) 
111     return fCheckers[det];
112
113         AliQACheckerBase * qac = NULL ;
114
115         TString detName(AliQAv1::GetDetName(det)) ; 
116         
117         if (det == AliQAv1::kGLOBAL) {
118                 qac = new AliGlobalQAChecker() ; 
119         } else if (det == AliQAv1::kCORR) {
120                 qac = new AliCorrQAChecker() ; 
121         } else {
122                 AliDebugClass(AliQAv1::GetQADebugLevel(), Form("Retrieving QA checker for %s", detName.Data())) ; 
123                 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
124                 TString qacName = "Ali" + detName + "QAChecker" ;
125
126                 // first check if a plugin is defined for the quality assurance checker
127                 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
128                 // if not, add a plugin for it
129                 if (!pluginHandler) {
130                         //AliDebug(AliQAv1::GetQADebugLevel(), Form("defining plugin for %s", qacName.Data()));
131                         TString libs = gSystem->GetLibraries();
132                 
133                         if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
134                                 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
135                         else 
136                                 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
137
138                         pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);    
139
140                         if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) 
141                                 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
142   
143                 }
144         }
145         if (qac) 
146                 fCheckers[det] = qac ;
147         
148         return qac ; 
149 }
150
151 //_____________________________________________________________________________
152 AliQAChecker * AliQAChecker::Instance()
153 {
154         // returns unique instance of the checker
155   if ( ! fgQAChecker ) 
156    fgQAChecker = new AliQAChecker() ; 
157   return fgQAChecker ;  
158 }
159
160 //_____________________________________________________________________________
161 void AliQAChecker::LoadRunInfoFromGRP() 
162 {
163   AliCDBManager* man = AliCDBManager::Instance() ;
164   AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
165   AliGRPObject* grpObject = 0x0;
166   if (entry) {
167
168           TMap* m = static_cast<TMap*>(entry->GetObject());  // old GRP entry
169
170           if (m) {
171             AliDebug(AliQAv1::GetQADebugLevel(), "It is a map");
172             //m->Print();
173             grpObject = new AliGRPObject();
174                  grpObject->ReadValuesFromMap(m);
175     }
176
177     else {
178             AliDebug(AliQAv1::GetQADebugLevel(), "It is a new GRP object");
179         grpObject = static_cast<AliGRPObject*>(entry->GetObject());  // new GRP entry
180     }
181
182     entry->SetOwner(0);
183     AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
184   }
185
186   if (!grpObject) {
187      AliFatal("No GRP entry found in OCDB!");
188   }
189
190   TString lhcState = grpObject->GetLHCState();
191   if (lhcState==AliGRPObject::GetInvalidString()) {
192     AliError("GRP/GRP/Data entry:  missing value for the LHC state ! Using UNKNOWN");
193     lhcState = "UNKNOWN";
194   }
195
196   TString beamType = grpObject->GetBeamType();
197   if (beamType==AliGRPObject::GetInvalidString()) {
198     AliError("GRP/GRP/Data entry:  missing value for the beam type ! Using UNKNOWN");
199     beamType = "UNKNOWN";
200   }
201
202   Float_t beamEnergy = grpObject->GetBeamEnergy();
203   if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
204     AliError("GRP/GRP/Data entry:  missing value for the beam energy ! Using 0");
205     beamEnergy = 0;
206   }
207
208   TString runType = grpObject->GetRunType();
209   if (runType==AliGRPObject::GetInvalidString()) {
210     AliError("GRP/GRP/Data entry:  missing value for the run type ! Using UNKNOWN");
211     runType = "UNKNOWN";
212   }
213
214   Int_t activeDetectors = grpObject->GetDetectorMask();
215   if (activeDetectors==AliGRPObject::GetInvalidInt()) {
216     AliError("GRP/GRP/Data entry:  missing value for the detector mask ! Using 1074790399");
217     activeDetectors = 1074790399;
218   }
219
220   fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
221
222   fRunInfoOwner = kTRUE ; 
223
224   // set the event specie
225   fEventSpecie = AliRecoParam::kDefault ;
226   if (strcmp(runType,"PHYSICS")) {
227     // Not a physics run, the event specie is set to kCalib
228     fEventSpecie = AliRecoParam::kCalib ;
229     return;
230   }
231   if (strcmp(lhcState,"STABLE_BEAMS") == 0) {
232     // Heavy ion run (any beam tha is not pp, the event specie is set to kHighMult
233     fEventSpecie = AliRecoParam::kHighMult ;
234     if ((strcmp(beamType,"p-p") == 0) ||
235         (strcmp(beamType,"p-")  == 0) ||
236         (strcmp(beamType,"-p")  == 0) ||
237         (strcmp(beamType,"P-P") == 0) ||
238         (strcmp(beamType,"P-")  == 0) ||
239         (strcmp(beamType,"-P")  == 0)) {
240       // Proton run, the event specie is set to kLowMult
241       fEventSpecie = AliRecoParam::kLowMult ;
242     }
243     else if (strcmp(beamType,"-") == 0) {
244       // No beams, we assume cosmic data
245       fEventSpecie = AliRecoParam::kCosmic ;
246     }
247     else if (strcmp(beamType,"UNKNOWN") == 0) {
248       // No LHC beam information is available, we use the default event specie
249       fEventSpecie = AliRecoParam::kDefault ;
250     }
251   }
252 }
253
254 //_____________________________________________________________________________
255 Bool_t AliQAChecker::Run(const char * fileName, AliDetectorRecoParam * recoParam)
256 {
257   // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, DigitsR, RecPoints, TrackSegments, RecParticles and ESDs
258   // starting from data in file  
259   TStopwatch stopwatch;
260   stopwatch.Start();
261   
262   //search for all detectors QA directories
263   TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ; 
264   TIter nextd(detKeyList) ; 
265   TKey * detKey ; 
266   while ( (detKey = static_cast<TKey *>(nextd()) ) ) {
267     AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", detKey->GetName())) ;
268     //Check which detector
269     TString detName ; 
270     TString detNameQA(detKey->GetName()) ; 
271     Int_t det ; 
272     for ( det = 0; det < AliQAv1::kNDET ; det++) {
273       detName = AliQAv1::GetDetName(det) ; 
274       if (detNameQA.Contains(detName)) {
275         fFoundDetectors+=detName ; 
276         fFoundDetectors+="." ;          
277         break ; 
278       }
279     } 
280     TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ; 
281     TList * taskKeyList = detDir->GetListOfKeys() ;
282     TIter nextt(taskKeyList) ; 
283     TKey * taskKey ; 
284     // now search for the tasks dir
285     while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
286       TString taskName( taskKey->GetName() ) ; 
287       AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", taskName.Data())) ;
288       TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ; 
289       taskDir->cd() ; 
290       AliQACheckerBase * qac = GetDetQAChecker(det) ; 
291       if (qac)
292         AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", detName.Data())) ; 
293       if (!qac)
294         AliFatal(Form("QA checker not found for %s", detName.Data())) ; 
295       AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ; 
296       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kHITS) ) 
297         index = AliQAv1::kSIM ; 
298       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kSDIGITS) ) 
299         index = AliQAv1::kSIM ; 
300       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITS) ) 
301         index = AliQAv1::kSIM ; 
302       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRAWS) ) 
303         index = AliQAv1::kRAW ;       
304       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITSR) ) 
305         index = AliQAv1::kREC ; 
306       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPOINTS) ) 
307         index = AliQAv1::kREC ; 
308       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kTRACKSEGMENTS) ) 
309         index = AliQAv1::kREC ; 
310       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPARTICLES) ) 
311         index = AliQAv1::kREC ; 
312       if ( taskName == AliQAv1::GetTaskName(AliQAv1::kESDS) ) 
313         index = AliQAv1::kESD ; 
314       qac->Init(AliQAv1::DETECTORINDEX_t(det)) ; 
315                   qac->Run(index, recoParam) ; 
316     }
317   }
318   TString detList ; 
319   for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
320     if (fFoundDetectors.Contains(AliQAv1::GetDetName(det))) {
321       detList += AliQAv1::GetDetName(det) ; 
322       detList += " " ; 
323       fFoundDetectors.ReplaceAll(AliQAv1::GetDetName(det), "") ; 
324       AliQAv1::Instance()->Show(AliQAv1::GetDetIndex(AliQAv1::GetDetName(det))) ; 
325     }   
326   }
327   AliInfo(Form("QA performed for following detectors: %s", detList.Data())) ; 
328   return kTRUE ; 
329 }
330
331 //_____________________________________________________________________________
332 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TObjArray ** list, AliDetectorRecoParam * recoParam)
333 {
334         // run the Quality Assurance Checker for detector det, for task task starting from data in list
335
336         AliQACheckerBase * qac = GetDetQAChecker(det) ; 
337         if (qac)
338                 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
339         if (!qac)
340                 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ; 
341   
342         AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ; 
343         if ( task == AliQAv1::kRAWS ) 
344                 index = AliQAv1::kRAW ; 
345         else if ( task == AliQAv1::kHITS ) 
346                 index = AliQAv1::kSIM ; 
347         else if ( task == AliQAv1::kSDIGITS ) 
348                 index = AliQAv1::kSIM ; 
349         else if ( task == AliQAv1::kDIGITS ) 
350                 index = AliQAv1::kSIM ; 
351         else if ( task == AliQAv1::kDIGITSR ) 
352                 index = AliQAv1::kREC ; 
353         else if ( task == AliQAv1::kRECPOINTS ) 
354                 index = AliQAv1::kREC ; 
355         else if ( task == AliQAv1::kTRACKSEGMENTS ) 
356                 index = AliQAv1::kREC ; 
357         else if ( task == AliQAv1::kRECPARTICLES ) 
358                 index = AliQAv1::kREC ; 
359         else if ( task == AliQAv1::kESDS ) 
360                 index = AliQAv1::kESD ; 
361
362   qac->Init(det) ; 
363   qac->Run(index, list, recoParam) ; 
364   
365   // make the image 
366   qac->MakeImage(list, task, AliQAv1::Mode(task)) ; 
367   
368         return kTRUE ; 
369 }
370
371 //_____________________________________________________________________________
372 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TNtupleD ** list, AliDetectorRecoParam * recoParam)
373 {
374         // run the Quality Assurance Checker for detector det, for task task starting from data in list
375   
376         AliQACheckerBase * qac = GetDetQAChecker(det) ; 
377         if (qac)
378                 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
379         if (!qac)
380                 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ; 
381   
382         AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ; 
383         if ( task == AliQAv1::kRAWS ) 
384                 index = AliQAv1::kRAW ; 
385         else if ( task == AliQAv1::kHITS ) 
386                 index = AliQAv1::kSIM ; 
387         else if ( task == AliQAv1::kSDIGITS ) 
388                 index = AliQAv1::kSIM ; 
389         else if ( task == AliQAv1::kDIGITS ) 
390                 index = AliQAv1::kSIM ; 
391         else if ( task == AliQAv1::kDIGITSR ) 
392                 index = AliQAv1::kREC ; 
393         else if ( task == AliQAv1::kRECPOINTS ) 
394                 index = AliQAv1::kREC ; 
395         else if ( task == AliQAv1::kTRACKSEGMENTS ) 
396                 index = AliQAv1::kREC ; 
397         else if ( task == AliQAv1::kRECPARTICLES ) 
398                 index = AliQAv1::kREC ; 
399         else if ( task == AliQAv1::kESDS ) 
400                 index = AliQAv1::kESD ; 
401   
402   qac->Init(det) ; 
403   qac->Run(index, list, recoParam) ; 
404
405   return kTRUE ; 
406 }