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