1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for running the Quality Assurance Checker
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliCDBEntry.h"
25 #include "AliQAManager.h"
26 #include "AliCDBStorage.h"
27 #include "AliRunInfo.h"
29 #include "AliModule.h"
31 #include "AliQAChecker.h"
32 #include "AliQACheckerBase.h"
33 #include "AliCorrQAChecker.h"
34 #include "AliGlobalQAChecker.h"
35 #include "AliGRPObject.h"
38 #include <TObjArray.h>
39 #include <TObjString.h>
40 #include <TPluginManager.h>
42 #include <TStopwatch.h>
48 ClassImp(AliQAChecker)
49 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
51 //_____________________________________________________________________________
52 AliQAChecker::AliQAChecker(const char* name, const char* title) :
56 fRunInfoOwner(kFALSE),
59 fEventSpecie(AliRecoParam::kDefault),
62 // ctor: initialise checkers and open the data file
63 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
64 fCheckers[det] = NULL ;
67 //_____________________________________________________________________________
68 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
70 fDataFile(qac.fDataFile),
71 fRunInfo(qac.fRunInfo),
72 fRunInfoOwner(kFALSE),
73 fRefFile(qac.fRefFile),
74 fFoundDetectors(qac.fFoundDetectors),
75 fEventSpecie(qac.fEventSpecie),
80 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
81 fCheckers[det] = NULL ;
84 //_____________________________________________________________________________
85 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
87 // assignment operator
89 this->~AliQAChecker();
90 new(this) AliQAChecker(qac);
94 //_____________________________________________________________________________
95 AliQAChecker::~AliQAChecker()
100 delete [] fCheckers ;
104 //_____________________________________________________________________________
105 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
107 // Gets the Quality Assurance checker for the detector specified by its name
110 return fCheckers[det];
112 AliQACheckerBase * qac = NULL ;
114 TString detName(AliQAv1::GetDetName(det)) ;
116 if (det == AliQAv1::kGLOBAL) {
117 qac = new AliGlobalQAChecker() ;
118 } else if (det == AliQAv1::kCORR) {
119 qac = new AliCorrQAChecker() ;
121 AliDebugClass(AliQAv1::GetQADebugLevel(), Form("Retrieving QA checker for %s", detName.Data())) ;
122 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
123 TString qacName = "Ali" + detName + "QAChecker" ;
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();
132 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
133 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
135 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
137 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
139 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
140 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
145 fCheckers[det] = qac ;
150 //_____________________________________________________________________________
151 void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray **& dirOCDB)
153 // Opens and returns the file with the reference data
155 TString refStorage(AliQAv1::GetQARefStorage()) ;
156 // if (refStorage.Contains(AliQAv1::GetLabLocalFile())) {
157 // refStorage.ReplaceAll(AliQAv1::GetLabLocalFile(), "") ;
158 // refStorage += AliQAv1::GetQARefFileName() ;
160 // if ( fRefFile->IsOpen() )
161 // fRefFile->Close() ;
162 // fRefFile = TFile::Open(refStorage.Data()) ;
164 // AliError(Form("Cannot find reference file %s", refStorage.Data())) ;
167 // dirFile = fRefFile->GetDirectory(det) ;
169 // AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ;
171 // dirFile = dirFile->GetDirectory(task) ;
173 // AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ;
176 if (!refStorage.Contains(AliQAv1::GetLabLocalOCDB()) && !refStorage.Contains(AliQAv1::GetLabAliEnOCDB())) {
177 AliError(Form("%s is not a valid location for reference data", refStorage.Data())) ;
180 AliQAManager* manQA = AliQAManager::QAManager(AliQAv1::GetTaskIndex(task)) ;
181 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
182 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
184 //if ( strcmp(AliQAv1::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (EventSpecie)
185 // Get it from RunInfo
186 //if (!fRunInfo) // not yet set, get the info from GRP
187 // LoadRunInfoFromGRP() ;
188 AliQAv1::SetQARefDataDirName(specie) ;
190 if ( ! manQA->GetLock() ) {
191 manQA->SetDefaultStorage(AliQAv1::GetQARefStorage()) ;
192 manQA->SetSpecificStorage("*", AliQAv1::GetQARefStorage()) ;
193 manQA->SetRun(AliCDBManager::Instance()->GetRun()) ;
196 char * detOCDBDir = Form("%s/%s/%s", det, AliQAv1::GetRefOCDBDirName(), AliQAv1::GetRefDataDirName()) ;
197 AliCDBEntry * entry = manQA->Get(detOCDBDir, manQA->GetRun()) ;
199 dirOCDB = new TObjArray*[AliRecoParam::kNSpecies] ;
200 TList * listDetQAD =static_cast<TList *>(entry->GetObject()) ;
201 if ( strcmp(listDetQAD->ClassName(), "TList") != 0 ) {
202 AliError(Form("Expected a Tlist and found a %s for detector %s", listDetQAD->ClassName(), det)) ;
205 TIter next(listDetQAD) ;
207 while ( (ar = (TObjArray*)next()) )
209 dirOCDB[specie] = static_cast<TObjArray *>(listDetQAD->FindObject(Form("%s/%s", task, AliRecoParam::GetEventSpecieName(specie)))) ;
215 //_____________________________________________________________________________
216 AliQAChecker * AliQAChecker::Instance()
218 // returns unique instance of the checker
220 fgQAChecker = new AliQAChecker() ;
224 //_____________________________________________________________________________
225 void AliQAChecker::LoadRunInfoFromGRP()
227 AliCDBManager* man = AliCDBManager::Instance() ;
228 AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
229 AliGRPObject* grpObject = 0x0;
232 TMap* m = static_cast<TMap*>(entry->GetObject()); // old GRP entry
235 AliDebug(AliQAv1::GetQADebugLevel(), "It is a map");
237 grpObject = new AliGRPObject();
238 grpObject->ReadValuesFromMap(m);
242 AliDebug(AliQAv1::GetQADebugLevel(), "It is a new GRP object");
243 grpObject = static_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
247 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
251 AliFatal("No GRP entry found in OCDB!");
254 TString lhcState = grpObject->GetLHCState();
255 if (lhcState==AliGRPObject::GetInvalidString()) {
256 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
257 lhcState = "UNKNOWN";
260 TString beamType = grpObject->GetBeamType();
261 if (beamType==AliGRPObject::GetInvalidString()) {
262 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
263 beamType = "UNKNOWN";
266 Float_t beamEnergy = grpObject->GetBeamEnergy();
267 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
268 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
272 TString runType = grpObject->GetRunType();
273 if (runType==AliGRPObject::GetInvalidString()) {
274 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
278 Int_t activeDetectors = grpObject->GetDetectorMask();
279 if (activeDetectors==AliGRPObject::GetInvalidInt()) {
280 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
281 activeDetectors = 1074790399;
284 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
286 fRunInfoOwner = kTRUE ;
288 // set the event specie
289 fEventSpecie = AliRecoParam::kDefault ;
290 if (strcmp(runType,"PHYSICS")) {
291 // Not a physics run, the event specie is set to kCalib
292 fEventSpecie = AliRecoParam::kCalib ;
295 if (strcmp(lhcState,"STABLE_BEAMS") == 0) {
296 // Heavy ion run (any beam tha is not pp, the event specie is set to kHighMult
297 fEventSpecie = AliRecoParam::kHighMult ;
298 if ((strcmp(beamType,"p-p") == 0) ||
299 (strcmp(beamType,"p-") == 0) ||
300 (strcmp(beamType,"-p") == 0) ||
301 (strcmp(beamType,"P-P") == 0) ||
302 (strcmp(beamType,"P-") == 0) ||
303 (strcmp(beamType,"-P") == 0)) {
304 // Proton run, the event specie is set to kLowMult
305 fEventSpecie = AliRecoParam::kLowMult ;
307 else if (strcmp(beamType,"-") == 0) {
308 // No beams, we assume cosmic data
309 fEventSpecie = AliRecoParam::kCosmic ;
311 else if (strcmp(beamType,"UNKNOWN") == 0) {
312 // No LHC beam information is available, we use the default event specie
313 fEventSpecie = AliRecoParam::kDefault ;
318 //_____________________________________________________________________________
319 Bool_t AliQAChecker::Run(const char * fileName)
321 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, DigitsR, RecPoints, TrackSegments, RecParticles and ESDs
322 // starting from data in file
323 TStopwatch stopwatch;
326 //search for all detectors QA directories
327 TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ;
328 TIter nextd(detKeyList) ;
330 while ( (detKey = static_cast<TKey *>(nextd()) ) ) {
331 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", detKey->GetName())) ;
332 //Check which detector
334 TString detNameQA(detKey->GetName()) ;
336 for ( det = 0; det < AliQAv1::kNDET ; det++) {
337 detName = AliQAv1::GetDetName(det) ;
338 if (detNameQA.Contains(detName)) {
339 fFoundDetectors+=detName ;
340 fFoundDetectors+="." ;
344 TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
345 TList * taskKeyList = detDir->GetListOfKeys() ;
346 TIter nextt(taskKeyList) ;
348 // now search for the tasks dir
349 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
350 TString taskName( taskKey->GetName() ) ;
351 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", taskName.Data())) ;
352 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
354 AliQACheckerBase * qac = GetDetQAChecker(det) ;
356 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", detName.Data())) ;
358 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
359 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
360 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kHITS) )
361 index = AliQAv1::kSIM ;
362 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kSDIGITS) )
363 index = AliQAv1::kSIM ;
364 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITS) )
365 index = AliQAv1::kSIM ;
366 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITSR) )
367 index = AliQAv1::kREC ;
368 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPOINTS) )
369 index = AliQAv1::kREC ;
370 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kTRACKSEGMENTS) )
371 index = AliQAv1::kREC ;
372 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPARTICLES) )
373 index = AliQAv1::kREC ;
374 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kESDS) )
375 index = AliQAv1::kESD ;
376 qac->Init(AliQAv1::DETECTORINDEX_t(det)) ;
378 TDirectory * refDir = NULL ;
379 TObjArray ** refOCDBDir = NULL ;
380 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
381 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
385 AliInfo("QA performed for following detectors:") ;
386 for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
387 if (fFoundDetectors.Contains(AliQAv1::GetDetName(det))) {
388 AliInfoClass(Form("%s, ",AliQAv1::GetDetName(det))) ;
389 fFoundDetectors.ReplaceAll(AliQAv1::GetDetName(det), "") ;
396 //_____________________________________________________________________________
397 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TObjArray ** list)
399 // run the Quality Assurance Checker for detector det, for task task starting from data in list
401 AliQACheckerBase * qac = GetDetQAChecker(det) ;
403 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
405 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
407 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
408 if ( task == AliQAv1::kRAWS )
409 index = AliQAv1::kRAW ;
410 else if ( task == AliQAv1::kHITS )
411 index = AliQAv1::kSIM ;
412 else if ( task == AliQAv1::kSDIGITS )
413 index = AliQAv1::kSIM ;
414 else if ( task == AliQAv1::kDIGITS )
415 index = AliQAv1::kSIM ;
416 else if ( task == AliQAv1::kDIGITSR )
417 index = AliQAv1::kREC ;
418 else if ( task == AliQAv1::kRECPOINTS )
419 index = AliQAv1::kREC ;
420 else if ( task == AliQAv1::kTRACKSEGMENTS )
421 index = AliQAv1::kREC ;
422 else if ( task == AliQAv1::kRECPARTICLES )
423 index = AliQAv1::kREC ;
424 else if ( task == AliQAv1::kESDS )
425 index = AliQAv1::kESD ;
427 TDirectory * refDir = NULL ;
428 TObjArray ** refOCDBDir = NULL ;
430 GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
431 qac->SetRefandData(refDir, refOCDBDir) ;
432 qac->Run(index, list) ;
435 qac->MakeImage(list, task, AliQAv1::Mode(task)) ;
440 //_____________________________________________________________________________
441 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TNtupleD ** list)
443 // run the Quality Assurance Checker for detector det, for task task starting from data in list
445 AliQACheckerBase * qac = GetDetQAChecker(det) ;
447 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
449 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
451 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
452 if ( task == AliQAv1::kRAWS )
453 index = AliQAv1::kRAW ;
454 else if ( task == AliQAv1::kHITS )
455 index = AliQAv1::kSIM ;
456 else if ( task == AliQAv1::kSDIGITS )
457 index = AliQAv1::kSIM ;
458 else if ( task == AliQAv1::kDIGITS )
459 index = AliQAv1::kSIM ;
460 else if ( task == AliQAv1::kDIGITSR )
461 index = AliQAv1::kREC ;
462 else if ( task == AliQAv1::kRECPOINTS )
463 index = AliQAv1::kREC ;
464 else if ( task == AliQAv1::kTRACKSEGMENTS )
465 index = AliQAv1::kREC ;
466 else if ( task == AliQAv1::kRECPARTICLES )
467 index = AliQAv1::kREC ;
468 else if ( task == AliQAv1::kESDS )
469 index = AliQAv1::kESD ;
471 TDirectory * refDir = NULL ;
472 TObjArray ** refOCDBDir = NULL ;
474 GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
475 qac->SetRefandData(refDir, refOCDBDir) ;
476 qac->Run(index, list) ;