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),
60 // ctor: initialise checkers and open the data file
61 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
62 fCheckers[det] = NULL ;
65 //_____________________________________________________________________________
66 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
68 fDataFile(qac.fDataFile),
69 fRunInfo(qac.fRunInfo),
70 fRunInfoOwner(kFALSE),
71 fRefFile(qac.fRefFile),
72 fFoundDetectors(qac.fFoundDetectors)
76 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
77 fCheckers[det] = NULL ;
80 //_____________________________________________________________________________
81 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
83 // assignment operator
85 this->~AliQAChecker();
86 new(this) AliQAChecker(qac);
90 //_____________________________________________________________________________
91 AliQAChecker::~AliQAChecker()
100 //_____________________________________________________________________________
101 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
103 // Gets the Quality Assurance checker for the detector specified by its name
106 return fCheckers[det];
108 AliQACheckerBase * qac = NULL ;
110 TString detName(AliQA::GetDetName(det)) ;
112 if (det == AliQA::kGLOBAL) {
113 qac = new AliGlobalQAChecker() ;
114 } else if (det == AliQA::kCORR) {
115 qac = new AliCorrQAChecker() ;
117 AliDebug(1, Form("Retrieving QA checker for %s", detName.Data())) ;
118 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
119 TString qacName = "Ali" + detName + "QAChecker" ;
121 // first check if a plugin is defined for the quality assurance checker
122 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
123 // if not, add a plugin for it
124 if (!pluginHandler) {
125 //AliInfo(Form("defining plugin for %s", qacName.Data()));
126 TString libs = gSystem->GetLibraries();
128 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
129 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
131 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
133 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
135 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
136 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
141 fCheckers[det] = qac ;
146 //_____________________________________________________________________________
147 void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray *& dirOCDB)
149 // Opens and returns the file with the reference data
153 TString refStorage(AliQA::GetQARefStorage()) ;
154 //refStorage += AliQA::GetQARefFileName() ;
155 if (refStorage.Contains(AliQA::GetLabLocalFile())) {
156 refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ;
158 if ( fRefFile->IsOpen() )
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())) ;
173 } else if (refStorage.Contains(AliQA::GetLabLocalOCDB()) || refStorage.Contains(AliQA::GetLabAliEnOCDB())) {
174 AliCDBManager* man = AliCDBManager::Instance() ;
175 if ( strcmp(AliQA::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (RUNTYPE)
176 // Get it from RunInfo
177 if (!fRunInfo) // not yet set, get the info from GRP
178 LoadRunInfoFromGRP() ;
179 AliQA::SetQARefDataDirName(fRunInfo->GetRunType()) ;
181 if ( ! man->GetLock() ) {
182 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
183 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
185 char * detOCDBDir = Form("%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ;
186 AliInfo(Form("Reference QA data are taken from %s", detOCDBDir)) ;
187 AliCDBEntry * entry = man->Get(detOCDBDir, man->GetRun()) ;
189 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
191 dirOCDB = dynamic_cast<TObjArray *>(listDetQAD->FindObject(task)) ;
196 //_____________________________________________________________________________
197 AliQAChecker * AliQAChecker::Instance()
199 // returns unique instance of the checker
201 fgQAChecker = new AliQAChecker() ;
205 //_____________________________________________________________________________
206 void AliQAChecker::LoadRunInfoFromGRP()
208 AliCDBManager* man = AliCDBManager::Instance() ;
209 AliCDBEntry* entry = man->Get(AliQA::GetGRPPath().Data());
210 AliGRPObject* grpObject = 0x0;
213 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
216 AliInfo("It is a map");
218 grpObject = new AliGRPObject();
219 grpObject->ReadValuesFromMap(m);
223 AliInfo("It is a new GRP object");
224 grpObject = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
228 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
232 AliFatal("No GRP entry found in OCDB!");
235 TString lhcState = grpObject->GetLHCState();
236 if (lhcState==AliGRPObject::GetInvalidString()) {
237 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
238 lhcState = "UNKNOWN";
241 TString beamType = grpObject->GetBeamType();
242 if (beamType==AliGRPObject::GetInvalidString()) {
243 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
244 beamType = "UNKNOWN";
247 Float_t beamEnergy = grpObject->GetBeamEnergy();
248 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
249 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
253 TString runType = grpObject->GetRunType();
254 if (runType==AliGRPObject::GetInvalidString()) {
255 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
259 Int_t activeDetectors = grpObject->GetDetectorMask();
260 if (activeDetectors==AliGRPObject::GetInvalidInt()) {
261 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
262 activeDetectors = 1074790399;
265 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
267 fRunInfoOwner = kTRUE ;
270 //_____________________________________________________________________________
271 Bool_t AliQAChecker::Run(const char * fileName)
273 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
274 // starting from data in file
278 TStopwatch stopwatch;
281 //search for all detectors QA directories
282 TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ;
283 TIter nextd(detKeyList) ;
285 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
286 AliDebug(1, Form("Found %s", detKey->GetName())) ;
287 //Check which detector
289 TString detNameQA(detKey->GetName()) ;
291 for ( det = 0; det < AliQA::kNDET ; det++) {
292 detName = AliQA::GetDetName(det) ;
293 if (detNameQA.Contains(detName)) {
294 fFoundDetectors+=detName ;
295 fFoundDetectors+="." ;
299 TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
300 TList * taskKeyList = detDir->GetListOfKeys() ;
301 TIter nextt(taskKeyList) ;
303 // now search for the tasks dir
304 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
305 TString taskName( taskKey->GetName() ) ;
306 AliInfo(Form("Found %s", taskName.Data())) ;
307 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
309 AliQACheckerBase * qac = GetDetQAChecker(det) ;
311 AliInfo(Form("QA checker found for %s", detName.Data())) ;
313 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
314 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
315 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
316 index = AliQA::kSIM ;
317 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
318 index = AliQA::kSIM ;
319 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
320 index = AliQA::kSIM ;
321 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
322 index = AliQA::kREC ;
323 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
324 index = AliQA::kREC ;
325 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
326 index = AliQA::kREC ;
327 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
328 index = AliQA::kESD ;
329 qac->Init(AliQA::DETECTORINDEX_t(det)) ;
331 TDirectory * refDir = NULL ;
332 TObjArray * refOCDBDir = NULL ;
333 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
334 if ( refDir || refOCDBDir) {
335 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
340 AliInfo("QA performed for following detectors:") ;
341 for ( Int_t det = 0; det < AliQA::kNDET; det++) {
342 if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
343 printf("%s, ",AliQA::GetDetName(det)) ;
344 fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ;
354 //_____________________________________________________________________________
355 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObject * obj)
357 // run the Quality Assurance Checker for detector det, for task task starting from data in list
359 AliQACheckerBase * qac = GetDetQAChecker(det) ;
361 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
363 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
365 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
366 if ( task == AliQA::kRAWS )
367 index = AliQA::kRAW ;
368 else if ( task == AliQA::kHITS )
369 index = AliQA::kSIM ;
370 else if ( task == AliQA::kSDIGITS )
371 index = AliQA::kSIM ;
372 else if ( task == AliQA::kDIGITS )
373 index = AliQA::kSIM ;
374 else if ( task == AliQA::kRECPOINTS )
375 index = AliQA::kREC ;
376 else if ( task == AliQA::kTRACKSEGMENTS )
377 index = AliQA::kREC ;
378 else if ( task == AliQA::kRECPARTICLES )
379 index = AliQA::kREC ;
380 else if ( task == AliQA::kESDS )
381 index = AliQA::kESD ;
383 TDirectory * refDir = NULL ;
384 TObjArray * refOCDBDir = NULL ;
386 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
387 if ( refDir || refOCDBDir) // references found
388 qac->SetRefandData(refDir, refOCDBDir) ;
390 TString className(obj->ClassName()) ;
391 if (className.Contains(TObjArray::Class()->GetName())) {
392 qac->Run(index, static_cast<TObjArray *>(obj)) ;
393 } else if (className.Contains(TNtupleD::Class()->GetName())) {
394 qac->Run(index, static_cast<TNtupleD *>(obj)) ;
396 AliError(Form("%s class not implemented", className.Data())) ;