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)
61 // ctor: initialise checkers and open the data file
62 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
63 fCheckers[det] = NULL ;
66 //_____________________________________________________________________________
67 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
69 fDataFile(qac.fDataFile),
70 fRunInfo(qac.fRunInfo),
71 fRunInfoOwner(kFALSE),
72 fRefFile(qac.fRefFile),
73 fFoundDetectors(qac.fFoundDetectors),
74 fEventSpecie(qac.fEventSpecie)
78 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
79 fCheckers[det] = NULL ;
82 //_____________________________________________________________________________
83 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
85 // assignment operator
87 this->~AliQAChecker();
88 new(this) AliQAChecker(qac);
92 //_____________________________________________________________________________
93 AliQAChecker::~AliQAChecker()
102 //_____________________________________________________________________________
103 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
105 // Gets the Quality Assurance checker for the detector specified by its name
108 return fCheckers[det];
110 AliQACheckerBase * qac = NULL ;
112 TString detName(AliQA::GetDetName(det)) ;
114 if (det == AliQA::kGLOBAL) {
115 qac = new AliGlobalQAChecker() ;
116 } else if (det == AliQA::kCORR) {
117 qac = new AliCorrQAChecker() ;
119 AliDebug(1, Form("Retrieving QA checker for %s", detName.Data())) ;
120 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
121 TString qacName = "Ali" + detName + "QAChecker" ;
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();
130 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
131 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
133 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
135 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
137 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
138 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
143 fCheckers[det] = qac ;
148 //_____________________________________________________________________________
149 void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray **& dirOCDB)
151 // Opens and returns the file with the reference data
153 TString refStorage(AliQA::GetQARefStorage()) ;
154 // if (refStorage.Contains(AliQA::GetLabLocalFile())) {
155 // refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ;
156 // refStorage += AliQA::GetQARefFileName() ;
158 // if ( fRefFile->IsOpen() )
159 // fRefFile->Close() ;
160 // fRefFile = TFile::Open(refStorage.Data()) ;
162 // AliError(Form("Cannot find reference file %s", refStorage.Data())) ;
165 // dirFile = fRefFile->GetDirectory(det) ;
167 // AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ;
169 // dirFile = dirFile->GetDirectory(task) ;
171 // AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ;
174 if (!refStorage.Contains(AliQA::GetLabLocalOCDB()) && !refStorage.Contains(AliQA::GetLabAliEnOCDB())) {
175 AliError(Form("%s is not a valid location for reference data", refStorage.Data())) ;
178 AliQAManager* manQA = AliQAManager::QAManager() ;
179 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
180 if ( !AliQA::Instance()->IsEventSpecieSet(specie) )
182 //if ( strcmp(AliQA::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (EventSpecie)
183 // Get it from RunInfo
184 //if (!fRunInfo) // not yet set, get the info from GRP
185 // LoadRunInfoFromGRP() ;
186 AliQA::SetQARefDataDirName(specie) ;
188 if ( ! manQA->GetLock() ) {
189 manQA->SetDefaultStorage(AliQA::GetQARefStorage()) ;
190 manQA->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
191 manQA->SetRun(AliCDBManager::Instance()->GetRun()) ;
194 char * detOCDBDir = Form("%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ;
195 AliCDBEntry * entry = manQA->Get(detOCDBDir, manQA->GetRun()) ;
197 dirOCDB = new TObjArray*[AliRecoParam::kNSpecies] ;
198 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
199 TIter next(listDetQAD) ;
201 while ( (ar = (TObjArray*)next()) )
203 dirOCDB[specie] = dynamic_cast<TObjArray *>(listDetQAD->FindObject(Form("%s/%s", task, AliRecoParam::GetEventSpecieName(specie)))) ;
209 //_____________________________________________________________________________
210 AliQAChecker * AliQAChecker::Instance()
212 // returns unique instance of the checker
214 fgQAChecker = new AliQAChecker() ;
218 //_____________________________________________________________________________
219 void AliQAChecker::LoadRunInfoFromGRP()
221 AliCDBManager* man = AliCDBManager::Instance() ;
222 AliCDBEntry* entry = man->Get(AliQA::GetGRPPath().Data());
223 AliGRPObject* grpObject = 0x0;
226 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
229 AliInfo("It is a map");
231 grpObject = new AliGRPObject();
232 grpObject->ReadValuesFromMap(m);
236 AliInfo("It is a new GRP object");
237 grpObject = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
241 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
245 AliFatal("No GRP entry found in OCDB!");
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";
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";
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");
266 TString runType = grpObject->GetRunType();
267 if (runType==AliGRPObject::GetInvalidString()) {
268 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
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;
278 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
280 fRunInfoOwner = kTRUE ;
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 ;
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 ;
301 else if (strcmp(beamType,"-") == 0) {
302 // No beams, we assume cosmic data
303 fEventSpecie = AliRecoParam::kCosmic ;
305 else if (strcmp(beamType,"UNKNOWN") == 0) {
306 // No LHC beam information is available, we use the default event specie
307 fEventSpecie = AliRecoParam::kDefault ;
312 //_____________________________________________________________________________
313 Bool_t AliQAChecker::Run(const char * fileName)
315 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
316 // starting from data in file
317 TStopwatch stopwatch;
320 //search for all detectors QA directories
321 TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ;
322 TIter nextd(detKeyList) ;
324 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
325 AliDebug(1, Form("Found %s", detKey->GetName())) ;
326 //Check which detector
328 TString detNameQA(detKey->GetName()) ;
330 for ( det = 0; det < AliQA::kNDET ; det++) {
331 detName = AliQA::GetDetName(det) ;
332 if (detNameQA.Contains(detName)) {
333 fFoundDetectors+=detName ;
334 fFoundDetectors+="." ;
338 TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
339 TList * taskKeyList = detDir->GetListOfKeys() ;
340 TIter nextt(taskKeyList) ;
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()) ;
348 AliQACheckerBase * qac = GetDetQAChecker(det) ;
350 AliInfo(Form("QA checker found for %s", detName.Data())) ;
352 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
353 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
354 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
355 index = AliQA::kSIM ;
356 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
357 index = AliQA::kSIM ;
358 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
359 index = AliQA::kSIM ;
360 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
361 index = AliQA::kREC ;
362 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
363 index = AliQA::kREC ;
364 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
365 index = AliQA::kREC ;
366 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
367 index = AliQA::kESD ;
368 qac->Init(AliQA::DETECTORINDEX_t(det)) ;
370 TDirectory * refDir = NULL ;
371 TObjArray ** refOCDBDir = NULL ;
372 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
373 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
377 AliInfo("QA performed for following detectors:") ;
378 for ( Int_t det = 0; det < AliQA::kNDET; det++) {
379 if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
380 printf("%s, ",AliQA::GetDetName(det)) ;
381 fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ;
388 //_____________________________________________________________________________
389 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObjArray ** list)
391 // run the Quality Assurance Checker for detector det, for task task starting from data in list
393 AliQACheckerBase * qac = GetDetQAChecker(det) ;
395 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
397 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
399 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
400 if ( task == AliQA::kRAWS )
401 index = AliQA::kRAW ;
402 else if ( task == AliQA::kHITS )
403 index = AliQA::kSIM ;
404 else if ( task == AliQA::kSDIGITS )
405 index = AliQA::kSIM ;
406 else if ( task == AliQA::kDIGITS )
407 index = AliQA::kSIM ;
408 else if ( task == AliQA::kRECPOINTS )
409 index = AliQA::kREC ;
410 else if ( task == AliQA::kTRACKSEGMENTS )
411 index = AliQA::kREC ;
412 else if ( task == AliQA::kRECPARTICLES )
413 index = AliQA::kREC ;
414 else if ( task == AliQA::kESDS )
415 index = AliQA::kESD ;
417 TDirectory * refDir = NULL ;
418 TObjArray ** refOCDBDir = NULL ;
420 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
421 qac->SetRefandData(refDir, refOCDBDir) ;
422 qac->Run(index, list) ;
426 //_____________________________________________________________________________
427 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TNtupleD ** list)
429 // run the Quality Assurance Checker for detector det, for task task starting from data in list
431 AliQACheckerBase * qac = GetDetQAChecker(det) ;
433 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
435 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
437 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
438 if ( task == AliQA::kRAWS )
439 index = AliQA::kRAW ;
440 else if ( task == AliQA::kHITS )
441 index = AliQA::kSIM ;
442 else if ( task == AliQA::kSDIGITS )
443 index = AliQA::kSIM ;
444 else if ( task == AliQA::kDIGITS )
445 index = AliQA::kSIM ;
446 else if ( task == AliQA::kRECPOINTS )
447 index = AliQA::kREC ;
448 else if ( task == AliQA::kTRACKSEGMENTS )
449 index = AliQA::kREC ;
450 else if ( task == AliQA::kRECPARTICLES )
451 index = AliQA::kREC ;
452 else if ( task == AliQA::kESDS )
453 index = AliQA::kESD ;
455 TDirectory * refDir = NULL ;
456 TObjArray ** refOCDBDir = NULL ;
458 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
459 qac->SetRefandData(refDir, refOCDBDir) ;
460 qac->Run(index, list) ;