]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQAChecker.cxx
Fixes for bug #49914: Compilation breaks in trunk, and bug #48629: Trunk cannot read...
[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"
b03591ab 25#include "AliQAManager.h"
96d67a8d 26#include "AliCDBStorage.h"
1aaf4118 27#include "AliRunInfo.h"
421ab0fb 28#include "AliLog.h"
29#include "AliModule.h"
4e25ac79 30#include "AliQAv1.h"
2e42b4d4 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
4e25ac79 62 for (Int_t det = 0 ; det < AliQAv1::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
4e25ac79 78 for (Int_t det = 0 ; det < AliQAv1::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 ;
4e25ac79 99 AliQAv1::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
4e25ac79 112 TString detName(AliQAv1::GetDetName(det)) ;
401b84d6 113
4e25ac79 114 if (det == AliQAv1::kGLOBAL) {
401b84d6 115 qac = new AliGlobalQAChecker() ;
4e25ac79 116 } else if (det == AliQAv1::kCORR) {
a2b64fbd 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
cbae8032 152 dirFile = NULL ;
4e25ac79 153 TString refStorage(AliQAv1::GetQARefStorage()) ;
154// if (refStorage.Contains(AliQAv1::GetLabLocalFile())) {
155// refStorage.ReplaceAll(AliQAv1::GetLabLocalFile(), "") ;
156// refStorage += AliQAv1::GetQARefFileName() ;
cf13d879 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
4e25ac79 174 if (!refStorage.Contains(AliQAv1::GetLabLocalOCDB()) && !refStorage.Contains(AliQAv1::GetLabAliEnOCDB())) {
cf13d879 175 AliError(Form("%s is not a valid location for reference data", refStorage.Data())) ;
176 return ;
177 } else {
b03591ab 178 AliQAManager* manQA = AliQAManager::QAManager() ;
57acd2d2 179 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
4e25ac79 180 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
57acd2d2 181 continue ;
4e25ac79 182 //if ( strcmp(AliQAv1::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (EventSpecie)
57acd2d2 183 // Get it from RunInfo
184 //if (!fRunInfo) // not yet set, get the info from GRP
185 // LoadRunInfoFromGRP() ;
4e25ac79 186 AliQAv1::SetQARefDataDirName(specie) ;
57acd2d2 187 //}
b03591ab 188 if ( ! manQA->GetLock() ) {
4e25ac79 189 manQA->SetDefaultStorage(AliQAv1::GetQARefStorage()) ;
190 manQA->SetSpecificStorage("*", AliQAv1::GetQARefStorage()) ;
b03591ab 191 manQA->SetRun(AliCDBManager::Instance()->GetRun()) ;
192 manQA->SetLock() ;
57acd2d2 193 }
4e25ac79 194 char * detOCDBDir = Form("%s/%s/%s", det, AliQAv1::GetRefOCDBDirName(), AliQAv1::GetRefDataDirName()) ;
b03591ab 195 AliCDBEntry * entry = manQA->Get(detOCDBDir, manQA->GetRun()) ;
57acd2d2 196 if (entry) {
197 dirOCDB = new TObjArray*[AliRecoParam::kNSpecies] ;
198 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
199 TIter next(listDetQAD) ;
200 TObjArray * ar ;
cf13d879 201 while ( (ar = (TObjArray*)next()) )
57acd2d2 202 if ( listDetQAD )
203 dirOCDB[specie] = dynamic_cast<TObjArray *>(listDetQAD->FindObject(Form("%s/%s", task, AliRecoParam::GetEventSpecieName(specie)))) ;
204 }
cbae8032 205 }
206 }
421ab0fb 207}
208
a4976ef3 209//_____________________________________________________________________________
2e42b4d4 210AliQAChecker * AliQAChecker::Instance()
a4976ef3 211{
212 // returns unique instance of the checker
213 if ( ! fgQAChecker )
2e42b4d4 214 fgQAChecker = new AliQAChecker() ;
a4976ef3 215 return fgQAChecker ;
216}
217
cbae8032 218//_____________________________________________________________________________
7e88424f 219void AliQAChecker::LoadRunInfoFromGRP()
cbae8032 220{
221 AliCDBManager* man = AliCDBManager::Instance() ;
4e25ac79 222 AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
44e45fac 223 AliGRPObject* grpObject = 0x0;
224 if (entry) {
225
226 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
227
228 if (m) {
229 AliInfo("It is a map");
230 //m->Print();
231 grpObject = new AliGRPObject();
232 grpObject->ReadValuesFromMap(m);
233 }
234
235 else {
236 AliInfo("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!");
cbae8032 246 }
44e45fac 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";
cbae8032 258 }
44e45fac 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;
cbae8032 264 }
44e45fac 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";
7e88424f 270 }
44e45fac 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;
cbae8032 276 }
44e45fac 277
278 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
279
7e88424f 280 fRunInfoOwner = kTRUE ;
57acd2d2 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 }
cbae8032 310}
311
421ab0fb 312//_____________________________________________________________________________
808b7099 313Bool_t AliQAChecker::Run(const char * fileName)
421ab0fb 314{
a5fa6165 315 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
57acd2d2 316 // starting from data in file
421ab0fb 317 TStopwatch stopwatch;
318 stopwatch.Start();
319
a5fa6165 320 //search for all detectors QA directories
4e25ac79 321 TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ;
a5fa6165 322 TIter nextd(detKeyList) ;
323 TKey * detKey ;
324 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
54a7f3ac 325 AliDebug(1, Form("Found %s", detKey->GetName())) ;
a5fa6165 326 //Check which detector
327 TString detName ;
328 TString detNameQA(detKey->GetName()) ;
329 Int_t det ;
4e25ac79 330 for ( det = 0; det < AliQAv1::kNDET ; det++) {
331 detName = AliQAv1::GetDetName(det) ;
a5fa6165 332 if (detNameQA.Contains(detName)) {
57acd2d2 333 fFoundDetectors+=detName ;
334 fFoundDetectors+="." ;
335 break ;
a5fa6165 336 }
337 }
4e25ac79 338 TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
a5fa6165 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 AliInfo(Form("Found %s", taskName.Data())) ;
346 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
347 taskDir->cd() ;
2e42b4d4 348 AliQACheckerBase * qac = GetDetQAChecker(det) ;
a5fa6165 349 if (qac)
57acd2d2 350 AliInfo(Form("QA checker found for %s", detName.Data())) ;
a5fa6165 351 if (!qac)
57acd2d2 352 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
4e25ac79 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)) ;
57acd2d2 369
370 TDirectory * refDir = NULL ;
371 TObjArray ** refOCDBDir = NULL ;
372 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
4edbc5bc 373 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
374 qac->Run(index) ;
57acd2d2 375 }
4edbc5bc 376 }
a5fa6165 377 AliInfo("QA performed for following detectors:") ;
4e25ac79 378 for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
379 if (fFoundDetectors.Contains(AliQAv1::GetDetName(det))) {
380 printf("%s, ",AliQAv1::GetDetName(det)) ;
381 fFoundDetectors.ReplaceAll(AliQAv1::GetDetName(det), "") ;
a5fa6165 382 }
421ab0fb 383 }
a5fa6165 384 printf("\n") ;
57acd2d2 385 return kTRUE ;
421ab0fb 386}
387
a4976ef3 388//_____________________________________________________________________________
4e25ac79 389Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TObjArray ** list)
a4976ef3 390{
d6372ce8 391 // run the Quality Assurance Checker for detector det, for task task starting from data in list
a4976ef3 392
d6372ce8 393 AliQACheckerBase * qac = GetDetQAChecker(det) ;
394 if (qac)
4e25ac79 395 AliDebug(1, Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
d6372ce8 396 if (!qac)
4e25ac79 397 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
a4976ef3 398
4e25ac79 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 ;
4edbc5bc 416
57acd2d2 417 TDirectory * refDir = NULL ;
418 TObjArray ** refOCDBDir = NULL ;
419 qac->Init(det) ;
4e25ac79 420 GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
57acd2d2 421 qac->SetRefandData(refDir, refOCDBDir) ;
422 qac->Run(index, list) ;
d6372ce8 423 return kTRUE ;
31316597 424}
57acd2d2 425
426//_____________________________________________________________________________
4e25ac79 427Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TNtupleD ** list)
57acd2d2 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)
4e25ac79 433 AliDebug(1, Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
57acd2d2 434 if (!qac)
4e25ac79 435 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
57acd2d2 436
4e25ac79 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 ;
57acd2d2 454
455 TDirectory * refDir = NULL ;
456 TObjArray ** refOCDBDir = NULL ;
457 qac->Init(det) ;
4e25ac79 458 GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
57acd2d2 459 qac->SetRefandData(refDir, refOCDBDir) ;
460 qac->Run(index, list) ;
461 return kTRUE ;
462}