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 "AliCDBManager.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
154 TString refStorage(AliQA::GetQARefStorage()) ;
155 if (refStorage.Contains(AliQA::GetLabLocalFile())) {
156 refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ;
157 refStorage += AliQA::GetQARefFileName() ;
159 if ( fRefFile->IsOpen() )
161 fRefFile = TFile::Open(refStorage.Data()) ;
163 AliError(Form("Cannot find reference file %s", refStorage.Data())) ;
166 dirFile = fRefFile->GetDirectory(det) ;
168 AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ;
170 dirFile = dirFile->GetDirectory(task) ;
172 AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ;
174 } else if (refStorage.Contains(AliQA::GetLabLocalOCDB()) || refStorage.Contains(AliQA::GetLabAliEnOCDB())) {
175 AliCDBManager* man = AliCDBManager::Instance() ;
176 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
177 if ( !AliQA::Instance()->IsEventSpecieSet(specie) )
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) ;
185 if ( ! man->GetLock() ) {
186 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
187 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
189 char * detOCDBDir = Form("%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ;
190 AliCDBEntry * entry = man->Get(detOCDBDir, man->GetRun()) ;
192 dirOCDB = new TObjArray*[AliRecoParam::kNSpecies] ;
193 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
194 TIter next(listDetQAD) ;
196 while ( ar = (TObjArray*)next() )
198 dirOCDB[specie] = dynamic_cast<TObjArray *>(listDetQAD->FindObject(Form("%s/%s", task, AliRecoParam::GetEventSpecieName(specie)))) ;
204 //_____________________________________________________________________________
205 AliQAChecker * AliQAChecker::Instance()
207 // returns unique instance of the checker
209 fgQAChecker = new AliQAChecker() ;
213 //_____________________________________________________________________________
214 void AliQAChecker::LoadRunInfoFromGRP()
216 AliCDBManager* man = AliCDBManager::Instance() ;
217 AliCDBEntry* entry = man->Get(AliQA::GetGRPPath().Data());
218 AliGRPObject* grpObject = 0x0;
221 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
224 AliInfo("It is a map");
226 grpObject = new AliGRPObject();
227 grpObject->ReadValuesFromMap(m);
231 AliInfo("It is a new GRP object");
232 grpObject = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
236 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
240 AliFatal("No GRP entry found in OCDB!");
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";
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";
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");
261 TString runType = grpObject->GetRunType();
262 if (runType==AliGRPObject::GetInvalidString()) {
263 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
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;
273 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
275 fRunInfoOwner = kTRUE ;
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 ;
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 ;
296 else if (strcmp(beamType,"-") == 0) {
297 // No beams, we assume cosmic data
298 fEventSpecie = AliRecoParam::kCosmic ;
300 else if (strcmp(beamType,"UNKNOWN") == 0) {
301 // No LHC beam information is available, we use the default event specie
302 fEventSpecie = AliRecoParam::kDefault ;
307 //_____________________________________________________________________________
308 Bool_t AliQAChecker::Run(const char * fileName)
310 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
311 // starting from data in file
312 TStopwatch stopwatch;
315 //search for all detectors QA directories
316 TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ;
317 TIter nextd(detKeyList) ;
319 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
320 AliDebug(1, Form("Found %s", detKey->GetName())) ;
321 //Check which detector
323 TString detNameQA(detKey->GetName()) ;
325 for ( det = 0; det < AliQA::kNDET ; det++) {
326 detName = AliQA::GetDetName(det) ;
327 if (detNameQA.Contains(detName)) {
328 fFoundDetectors+=detName ;
329 fFoundDetectors+="." ;
333 TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
334 TList * taskKeyList = detDir->GetListOfKeys() ;
335 TIter nextt(taskKeyList) ;
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()) ;
343 AliQACheckerBase * qac = GetDetQAChecker(det) ;
345 AliInfo(Form("QA checker found for %s", detName.Data())) ;
347 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
348 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
349 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
350 index = AliQA::kSIM ;
351 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
352 index = AliQA::kSIM ;
353 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
354 index = AliQA::kSIM ;
355 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
356 index = AliQA::kREC ;
357 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
358 index = AliQA::kREC ;
359 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
360 index = AliQA::kREC ;
361 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
362 index = AliQA::kESD ;
363 qac->Init(AliQA::DETECTORINDEX_t(det)) ;
365 TDirectory * refDir = NULL ;
366 TObjArray ** refOCDBDir = NULL ;
367 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
368 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
372 AliInfo("QA performed for following detectors:") ;
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), "") ;
383 //_____________________________________________________________________________
384 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObjArray ** list)
386 // run the Quality Assurance Checker for detector det, for task task starting from data in list
388 AliQACheckerBase * qac = GetDetQAChecker(det) ;
390 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
392 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
394 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
395 if ( task == AliQA::kRAWS )
396 index = AliQA::kRAW ;
397 else if ( task == AliQA::kHITS )
398 index = AliQA::kSIM ;
399 else if ( task == AliQA::kSDIGITS )
400 index = AliQA::kSIM ;
401 else if ( task == AliQA::kDIGITS )
402 index = AliQA::kSIM ;
403 else if ( task == AliQA::kRECPOINTS )
404 index = AliQA::kREC ;
405 else if ( task == AliQA::kTRACKSEGMENTS )
406 index = AliQA::kREC ;
407 else if ( task == AliQA::kRECPARTICLES )
408 index = AliQA::kREC ;
409 else if ( task == AliQA::kESDS )
410 index = AliQA::kESD ;
412 TDirectory * refDir = NULL ;
413 TObjArray ** refOCDBDir = NULL ;
415 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
416 qac->SetRefandData(refDir, refOCDBDir) ;
417 qac->Run(index, list) ;
421 //_____________________________________________________________________________
422 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TNtupleD ** list)
424 // run the Quality Assurance Checker for detector det, for task task starting from data in list
426 AliQACheckerBase * qac = GetDetQAChecker(det) ;
428 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
430 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
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 ;
450 TDirectory * refDir = NULL ;
451 TObjArray ** refOCDBDir = NULL ;
453 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
454 qac->SetRefandData(refDir, refOCDBDir) ;
455 qac->Run(index, list) ;