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::GetLabLocalOCDB()) && !refStorage.Contains(AliQAv1::GetLabAliEnOCDB())) {
157 AliError(Form("%s is not a valid location for reference data", refStorage.Data())) ;
160 AliQAManager* manQA = AliQAManager::QAManager(AliQAv1::GetTaskIndex(task)) ;
161 dirOCDB = new TObjArray*[AliRecoParam::kNSpecies] ;
162 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
163 dirOCDB[specie] = NULL ;
164 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) )
166 AliQAv1::SetQARefDataDirName(specie) ;
167 if ( ! manQA->GetLock() ) {
168 manQA->SetDefaultStorage(AliQAv1::GetQARefStorage()) ;
169 manQA->SetSpecificStorage("*", AliQAv1::GetQARefStorage()) ;
170 manQA->SetRun(AliCDBManager::Instance()->GetRun()) ;
173 char * detOCDBDir = Form("%s/%s/%s", det, AliQAv1::GetRefOCDBDirName(), AliQAv1::GetRefDataDirName()) ;
174 AliCDBEntry * entry = manQA->Get(detOCDBDir, manQA->GetRun()) ;
176 TList * listDetQAD =static_cast<TList *>(entry->GetObject()) ;
177 if ( strcmp(listDetQAD->ClassName(), "TList") != 0 ) {
178 AliError(Form("Expected a Tlist and found a %s for detector %s", listDetQAD->ClassName(), det)) ;
181 TIter next(listDetQAD) ;
183 while ( (ar = (TObjArray*)next()) )
185 dirOCDB[specie] = static_cast<TObjArray *>(listDetQAD->FindObject(Form("%s/%s", task, AliRecoParam::GetEventSpecieName(specie)))) ;
191 //_____________________________________________________________________________
192 AliQAChecker * AliQAChecker::Instance()
194 // returns unique instance of the checker
196 fgQAChecker = new AliQAChecker() ;
200 //_____________________________________________________________________________
201 void AliQAChecker::LoadRunInfoFromGRP()
203 AliCDBManager* man = AliCDBManager::Instance() ;
204 AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
205 AliGRPObject* grpObject = 0x0;
208 TMap* m = static_cast<TMap*>(entry->GetObject()); // old GRP entry
211 AliDebug(AliQAv1::GetQADebugLevel(), "It is a map");
213 grpObject = new AliGRPObject();
214 grpObject->ReadValuesFromMap(m);
218 AliDebug(AliQAv1::GetQADebugLevel(), "It is a new GRP object");
219 grpObject = static_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
223 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
227 AliFatal("No GRP entry found in OCDB!");
230 TString lhcState = grpObject->GetLHCState();
231 if (lhcState==AliGRPObject::GetInvalidString()) {
232 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
233 lhcState = "UNKNOWN";
236 TString beamType = grpObject->GetBeamType();
237 if (beamType==AliGRPObject::GetInvalidString()) {
238 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
239 beamType = "UNKNOWN";
242 Float_t beamEnergy = grpObject->GetBeamEnergy();
243 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
244 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
248 TString runType = grpObject->GetRunType();
249 if (runType==AliGRPObject::GetInvalidString()) {
250 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
254 Int_t activeDetectors = grpObject->GetDetectorMask();
255 if (activeDetectors==AliGRPObject::GetInvalidInt()) {
256 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
257 activeDetectors = 1074790399;
260 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
262 fRunInfoOwner = kTRUE ;
264 // set the event specie
265 fEventSpecie = AliRecoParam::kDefault ;
266 if (strcmp(runType,"PHYSICS")) {
267 // Not a physics run, the event specie is set to kCalib
268 fEventSpecie = AliRecoParam::kCalib ;
271 if (strcmp(lhcState,"STABLE_BEAMS") == 0) {
272 // Heavy ion run (any beam tha is not pp, the event specie is set to kHighMult
273 fEventSpecie = AliRecoParam::kHighMult ;
274 if ((strcmp(beamType,"p-p") == 0) ||
275 (strcmp(beamType,"p-") == 0) ||
276 (strcmp(beamType,"-p") == 0) ||
277 (strcmp(beamType,"P-P") == 0) ||
278 (strcmp(beamType,"P-") == 0) ||
279 (strcmp(beamType,"-P") == 0)) {
280 // Proton run, the event specie is set to kLowMult
281 fEventSpecie = AliRecoParam::kLowMult ;
283 else if (strcmp(beamType,"-") == 0) {
284 // No beams, we assume cosmic data
285 fEventSpecie = AliRecoParam::kCosmic ;
287 else if (strcmp(beamType,"UNKNOWN") == 0) {
288 // No LHC beam information is available, we use the default event specie
289 fEventSpecie = AliRecoParam::kDefault ;
294 //_____________________________________________________________________________
295 Bool_t AliQAChecker::Run(const char * fileName, Int_t runnumber)
297 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, DigitsR, RecPoints, TrackSegments, RecParticles and ESDs
298 // starting from data in file
299 TStopwatch stopwatch;
302 // set the run number
303 AliCDBManager::Instance()->SetRun(runnumber) ;
304 // search and set the event species
305 AliQAv1 * qa = AliQAv1::Instance() ;
306 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
307 if ( AliQAv1::GetQADataFile(fileName)->FindObjectAny(AliRecoParam::GetEventSpecieName(specie)) )
308 qa->SetEventSpecie(AliRecoParam::ConvertIndex(specie)) ;
310 //search for all detectors QA directories
311 TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ;
312 TIter nextd(detKeyList) ;
314 while ( (detKey = static_cast<TKey *>(nextd()) ) ) {
315 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", detKey->GetName())) ;
316 //Check which detector
318 TString detNameQA(detKey->GetName()) ;
320 for ( det = 0; det < AliQAv1::kNDET ; det++) {
321 detName = AliQAv1::GetDetName(det) ;
322 if (detNameQA.Contains(detName)) {
323 fFoundDetectors+=detName ;
324 fFoundDetectors+="." ;
328 TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
329 TList * taskKeyList = detDir->GetListOfKeys() ;
330 TIter nextt(taskKeyList) ;
332 // now search for the tasks dir
333 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
334 TString taskName( taskKey->GetName() ) ;
335 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", taskName.Data())) ;
336 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
338 AliQACheckerBase * qac = GetDetQAChecker(det) ;
340 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", detName.Data())) ;
342 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
343 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
344 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kHITS) )
345 index = AliQAv1::kSIM ;
346 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kSDIGITS) )
347 index = AliQAv1::kSIM ;
348 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITS) )
349 index = AliQAv1::kSIM ;
350 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITSR) )
351 index = AliQAv1::kREC ;
352 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPOINTS) )
353 index = AliQAv1::kREC ;
354 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kTRACKSEGMENTS) )
355 index = AliQAv1::kREC ;
356 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPARTICLES) )
357 index = AliQAv1::kREC ;
358 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kESDS) )
359 index = AliQAv1::kESD ;
360 qac->Init(AliQAv1::DETECTORINDEX_t(det)) ;
362 TDirectory * refDir = NULL ;
363 TObjArray ** refOCDBDir = NULL ;
364 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
365 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
370 for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
371 if (fFoundDetectors.Contains(qa->GetDetName(det))) {
372 detList += qa->GetDetName(det) ;
374 fFoundDetectors.ReplaceAll(qa->GetDetName(det), "") ;
375 qa->Show(qa->GetDetIndex(qa->GetDetName(det))) ;
378 AliInfo(Form("QA performed for following detectors: %s", detList.Data())) ;
382 //_____________________________________________________________________________
383 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TObjArray ** list)
385 // run the Quality Assurance Checker for detector det, for task task starting from data in list
387 AliQACheckerBase * qac = GetDetQAChecker(det) ;
389 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
391 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
393 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
394 if ( task == AliQAv1::kRAWS )
395 index = AliQAv1::kRAW ;
396 else if ( task == AliQAv1::kHITS )
397 index = AliQAv1::kSIM ;
398 else if ( task == AliQAv1::kSDIGITS )
399 index = AliQAv1::kSIM ;
400 else if ( task == AliQAv1::kDIGITS )
401 index = AliQAv1::kSIM ;
402 else if ( task == AliQAv1::kDIGITSR )
403 index = AliQAv1::kREC ;
404 else if ( task == AliQAv1::kRECPOINTS )
405 index = AliQAv1::kREC ;
406 else if ( task == AliQAv1::kTRACKSEGMENTS )
407 index = AliQAv1::kREC ;
408 else if ( task == AliQAv1::kRECPARTICLES )
409 index = AliQAv1::kREC ;
410 else if ( task == AliQAv1::kESDS )
411 index = AliQAv1::kESD ;
413 TDirectory * refDir = NULL ;
414 TObjArray ** refOCDBDir = NULL ;
416 GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
417 qac->SetRefandData(refDir, refOCDBDir) ;
418 qac->Run(index, list) ;
421 qac->MakeImage(list, task, AliQAv1::Mode(task)) ;
426 //_____________________________________________________________________________
427 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::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(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
435 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
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::kDIGITSR )
447 index = AliQAv1::kREC ;
448 else if ( task == AliQAv1::kRECPOINTS )
449 index = AliQAv1::kREC ;
450 else if ( task == AliQAv1::kTRACKSEGMENTS )
451 index = AliQAv1::kREC ;
452 else if ( task == AliQAv1::kRECPARTICLES )
453 index = AliQAv1::kREC ;
454 else if ( task == AliQAv1::kESDS )
455 index = AliQAv1::kESD ;
457 TDirectory * refDir = NULL ;
458 TObjArray ** refOCDBDir = NULL ;
460 GetRefSubDir(AliQAv1::GetDetName(det), AliQAv1::GetTaskName(task), refDir, refOCDBDir) ;
461 qac->SetRefandData(refDir, refOCDBDir) ;
462 qac->Run(index, list) ;