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