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 < AliQAv1::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 < AliQAv1::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(AliQAv1::GetDetName(det)) ;
114 if (det == AliQAv1::kGLOBAL) {
115 qac = new AliGlobalQAChecker() ;
116 } else if (det == AliQAv1::kCORR) {
117 qac = new AliCorrQAChecker() ;
119 AliDebug(AliQAv1::GetQADebugLevel(), 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 //AliDebug(AliQAv1::GetQADebugLevel(), 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(AliQAv1::GetQARefStorage()) ;
154 // if (refStorage.Contains(AliQAv1::GetLabLocalFile())) {
155 // refStorage.ReplaceAll(AliQAv1::GetLabLocalFile(), "") ;
156 // refStorage += AliQAv1::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(AliQAv1::GetLabLocalOCDB()) && !refStorage.Contains(AliQAv1::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 ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
182 //if ( strcmp(AliQAv1::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 AliQAv1::SetQARefDataDirName(specie) ;
188 if ( ! manQA->GetLock() ) {
189 manQA->SetDefaultStorage(AliQAv1::GetQARefStorage()) ;
190 manQA->SetSpecificStorage("*", AliQAv1::GetQARefStorage()) ;
191 manQA->SetRun(AliCDBManager::Instance()->GetRun()) ;
194 char * detOCDBDir = Form("%s/%s/%s", det, AliQAv1::GetRefOCDBDirName(), AliQAv1::GetRefDataDirName()) ;
195 AliCDBEntry * entry = manQA->Get(detOCDBDir, manQA->GetRun()) ;
197 dirOCDB = new TObjArray*[AliRecoParam::kNSpecies] ;
198 TList * listDetQAD =static_cast<TList *>(entry->GetObject()) ;
199 if ( strcmp(listDetQAD->ClassName(), "TList") != 0 ) {
200 AliError(Form("Expected a Tlist and found a %s for detector %s", listDetQAD->ClassName(), det)) ;
203 TIter next(listDetQAD) ;
205 while ( (ar = (TObjArray*)next()) )
207 dirOCDB[specie] = static_cast<TObjArray *>(listDetQAD->FindObject(Form("%s/%s", task, AliRecoParam::GetEventSpecieName(specie)))) ;
213 //_____________________________________________________________________________
214 AliQAChecker * AliQAChecker::Instance()
216 // returns unique instance of the checker
218 fgQAChecker = new AliQAChecker() ;
222 //_____________________________________________________________________________
223 void AliQAChecker::LoadRunInfoFromGRP()
225 AliCDBManager* man = AliCDBManager::Instance() ;
226 AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
227 AliGRPObject* grpObject = 0x0;
230 TMap* m = static_cast<TMap*>(entry->GetObject()); // old GRP entry
233 AliDebug(AliQAv1::GetQADebugLevel(), "It is a map");
235 grpObject = new AliGRPObject();
236 grpObject->ReadValuesFromMap(m);
240 AliDebug(AliQAv1::GetQADebugLevel(), "It is a new GRP object");
241 grpObject = static_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
245 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
249 AliFatal("No GRP entry found in OCDB!");
252 TString lhcState = grpObject->GetLHCState();
253 if (lhcState==AliGRPObject::GetInvalidString()) {
254 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
255 lhcState = "UNKNOWN";
258 TString beamType = grpObject->GetBeamType();
259 if (beamType==AliGRPObject::GetInvalidString()) {
260 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
261 beamType = "UNKNOWN";
264 Float_t beamEnergy = grpObject->GetBeamEnergy();
265 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
266 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
270 TString runType = grpObject->GetRunType();
271 if (runType==AliGRPObject::GetInvalidString()) {
272 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
276 Int_t activeDetectors = grpObject->GetDetectorMask();
277 if (activeDetectors==AliGRPObject::GetInvalidInt()) {
278 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
279 activeDetectors = 1074790399;
282 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
284 fRunInfoOwner = kTRUE ;
286 // set the event specie
287 fEventSpecie = AliRecoParam::kDefault ;
288 if (strcmp(runType,"PHYSICS")) {
289 // Not a physics run, the event specie is set to kCalib
290 fEventSpecie = AliRecoParam::kCalib ;
293 if (strcmp(lhcState,"STABLE_BEAMS") == 0) {
294 // Heavy ion run (any beam tha is not pp, the event specie is set to kHighMult
295 fEventSpecie = AliRecoParam::kHighMult ;
296 if ((strcmp(beamType,"p-p") == 0) ||
297 (strcmp(beamType,"p-") == 0) ||
298 (strcmp(beamType,"-p") == 0) ||
299 (strcmp(beamType,"P-P") == 0) ||
300 (strcmp(beamType,"P-") == 0) ||
301 (strcmp(beamType,"-P") == 0)) {
302 // Proton run, the event specie is set to kLowMult
303 fEventSpecie = AliRecoParam::kLowMult ;
305 else if (strcmp(beamType,"-") == 0) {
306 // No beams, we assume cosmic data
307 fEventSpecie = AliRecoParam::kCosmic ;
309 else if (strcmp(beamType,"UNKNOWN") == 0) {
310 // No LHC beam information is available, we use the default event specie
311 fEventSpecie = AliRecoParam::kDefault ;
316 //_____________________________________________________________________________
317 Bool_t AliQAChecker::Run(const char * fileName)
319 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, DigitsR, RecPoints, TrackSegments, RecParticles and ESDs
320 // starting from data in file
321 TStopwatch stopwatch;
324 //search for all detectors QA directories
325 TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ;
326 TIter nextd(detKeyList) ;
328 while ( (detKey = static_cast<TKey *>(nextd()) ) ) {
329 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", detKey->GetName())) ;
330 //Check which detector
332 TString detNameQA(detKey->GetName()) ;
334 for ( det = 0; det < AliQAv1::kNDET ; det++) {
335 detName = AliQAv1::GetDetName(det) ;
336 if (detNameQA.Contains(detName)) {
337 fFoundDetectors+=detName ;
338 fFoundDetectors+="." ;
342 TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
343 TList * taskKeyList = detDir->GetListOfKeys() ;
344 TIter nextt(taskKeyList) ;
346 // now search for the tasks dir
347 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
348 TString taskName( taskKey->GetName() ) ;
349 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", taskName.Data())) ;
350 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
352 AliQACheckerBase * qac = GetDetQAChecker(det) ;
354 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", detName.Data())) ;
356 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
357 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
358 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kHITS) )
359 index = AliQAv1::kSIM ;
360 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kSDIGITS) )
361 index = AliQAv1::kSIM ;
362 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITS) )
363 index = AliQAv1::kSIM ;
364 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITSR) )
365 index = AliQAv1::kREC ;
366 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPOINTS) )
367 index = AliQAv1::kREC ;
368 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kTRACKSEGMENTS) )
369 index = AliQAv1::kREC ;
370 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPARTICLES) )
371 index = AliQAv1::kREC ;
372 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kESDS) )
373 index = AliQAv1::kESD ;
374 qac->Init(AliQAv1::DETECTORINDEX_t(det)) ;
376 TDirectory * refDir = NULL ;
377 TObjArray ** refOCDBDir = NULL ;
378 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
379 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
383 AliInfo("QA performed for following detectors:") ;
384 for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
385 if (fFoundDetectors.Contains(AliQAv1::GetDetName(det))) {
386 AliInfoClass(Form("%s, ",AliQAv1::GetDetName(det))) ;
387 fFoundDetectors.ReplaceAll(AliQAv1::GetDetName(det), "") ;
394 //_____________________________________________________________________________
395 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TObjArray ** list)
397 // run the Quality Assurance Checker for detector det, for task task starting from data in list
399 AliQACheckerBase * qac = GetDetQAChecker(det) ;
401 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
403 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
405 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
406 if ( task == AliQAv1::kRAWS )
407 index = AliQAv1::kRAW ;
408 else if ( task == AliQAv1::kHITS )
409 index = AliQAv1::kSIM ;
410 else if ( task == AliQAv1::kSDIGITS )
411 index = AliQAv1::kSIM ;
412 else if ( task == AliQAv1::kDIGITS )
413 index = AliQAv1::kSIM ;
414 else if ( task == AliQAv1::kDIGITSR )
415 index = AliQAv1::kREC ;
416 else if ( task == AliQAv1::kRECPOINTS )
417 index = AliQAv1::kREC ;
418 else if ( task == AliQAv1::kTRACKSEGMENTS )
419 index = AliQAv1::kREC ;
420 else if ( task == AliQAv1::kRECPARTICLES )
421 index = AliQAv1::kREC ;
422 else if ( task == AliQAv1::kESDS )
423 index = AliQAv1::kESD ;
425 TDirectory * refDir = NULL ;
426 TObjArray ** refOCDBDir = NULL ;
428 GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
429 qac->SetRefandData(refDir, refOCDBDir) ;
430 qac->Run(index, list) ;
434 //_____________________________________________________________________________
435 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TNtupleD ** list)
437 // run the Quality Assurance Checker for detector det, for task task starting from data in list
439 AliQACheckerBase * qac = GetDetQAChecker(det) ;
441 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
443 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
445 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
446 if ( task == AliQAv1::kRAWS )
447 index = AliQAv1::kRAW ;
448 else if ( task == AliQAv1::kHITS )
449 index = AliQAv1::kSIM ;
450 else if ( task == AliQAv1::kSDIGITS )
451 index = AliQAv1::kSIM ;
452 else if ( task == AliQAv1::kDIGITS )
453 index = AliQAv1::kSIM ;
454 else if ( task == AliQAv1::kDIGITSR )
455 index = AliQAv1::kREC ;
456 else if ( task == AliQAv1::kRECPOINTS )
457 index = AliQAv1::kREC ;
458 else if ( task == AliQAv1::kTRACKSEGMENTS )
459 index = AliQAv1::kREC ;
460 else if ( task == AliQAv1::kRECPARTICLES )
461 index = AliQAv1::kREC ;
462 else if ( task == AliQAv1::kESDS )
463 index = AliQAv1::kESD ;
465 TDirectory * refDir = NULL ;
466 TObjArray ** refOCDBDir = NULL ;
468 GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
469 qac->SetRefandData(refDir, refOCDBDir) ;
470 qac->Run(index, list) ;