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 "AliGlobalQAChecker.h"
36 #include <TObjArray.h>
37 #include <TObjString.h>
38 #include <TPluginManager.h>
40 #include <TStopwatch.h>
45 ClassImp(AliQAChecker)
46 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
48 //_____________________________________________________________________________
49 AliQAChecker::AliQAChecker(const char* name, const char* title) :
53 fRunInfoOwner(kFALSE),
57 // ctor: initialise checkers and open the data file
58 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
59 fCheckers[det] = NULL ;
62 //_____________________________________________________________________________
63 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
65 fDataFile(qac.fDataFile),
66 fRunInfo(qac.fRunInfo),
67 fRunInfoOwner(kFALSE),
68 fRefFile(qac.fRefFile),
69 fFoundDetectors(qac.fFoundDetectors)
73 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
74 fCheckers[det] = NULL ;
77 //_____________________________________________________________________________
78 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
80 // assignment operator
82 this->~AliQAChecker();
83 new(this) AliQAChecker(qac);
87 //_____________________________________________________________________________
88 AliQAChecker::~AliQAChecker()
97 //_____________________________________________________________________________
98 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
100 // Gets the Quality Assurance checker for the detector specified by its name
103 return fCheckers[det];
105 AliQACheckerBase * qac = NULL ;
107 TString detName(AliQA::GetDetName(det)) ;
109 if (det == AliQA::kGLOBAL) {
110 qac = new AliGlobalQAChecker() ;
112 AliDebug(1, Form("Retrieving QA checker for %s", detName.Data())) ;
113 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
114 TString qacName = "Ali" + detName + "QAChecker" ;
116 // first check if a plugin is defined for the quality assurance checker
117 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
118 // if not, add a plugin for it
119 if (!pluginHandler) {
120 //AliInfo(Form("defining plugin for %s", qacName.Data()));
121 TString libs = gSystem->GetLibraries();
123 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
124 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
126 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
128 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
130 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
131 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
136 fCheckers[det] = qac ;
141 //_____________________________________________________________________________
142 void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray *& dirOCDB)
144 // Opens and returns the file with the reference data
148 TString refStorage(AliQA::GetQARefStorage()) ;
149 //refStorage += AliQA::GetQARefFileName() ;
150 if (refStorage.Contains(AliQA::GetLabLocalFile())) {
151 refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ;
153 if ( fRefFile->IsOpen() )
155 fRefFile = TFile::Open(refStorage.Data()) ;
157 AliError(Form("Cannot find reference file %s", refStorage.Data())) ;
160 dirFile = fRefFile->GetDirectory(det) ;
162 AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ;
164 dirFile = dirFile->GetDirectory(task) ;
166 AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ;
168 } else if (refStorage.Contains(AliQA::GetLabLocalOCDB()) || refStorage.Contains(AliQA::GetLabAliEnOCDB())) {
169 AliCDBManager* man = AliCDBManager::Instance() ;
170 if ( strcmp(AliQA::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (RUNTYPE)
171 // Get it from RunInfo
172 if (!fRunInfo) // not yet set, get the info from GRP
173 LoadRunInfoFromGRP() ;
174 AliQA::SetQARefDataDirName(fRunInfo->GetRunType()) ;
176 if ( ! man->GetLock() ) {
177 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
178 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
180 char * detOCDBDir = Form("%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ;
181 AliInfo(Form("Reference QA data are taken from %s", detOCDBDir)) ;
182 AliCDBEntry * entry = man->Get(detOCDBDir, man->GetRun()) ;
184 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
186 dirOCDB = dynamic_cast<TObjArray *>(listDetQAD->FindObject(task)) ;
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(AliQA::GetGRPPath().Data());
207 data = dynamic_cast<TMap*>(entry->GetObject());
209 AliFatal("No GRP entry found in OCDB!");
211 TObjString *lhcState=
212 dynamic_cast<TObjString*>(data->GetValue("fLHCState"));
214 AliWarning(Form("%s entry: missing value for the LHC state ! Using UNKNOWN", AliQA::GetGRPPath().Data()));
216 TObjString *beamType=
217 dynamic_cast<TObjString*>(data->GetValue("fAliceBeamType"));
219 AliWarning(Form("%s entry: missing value for the LHC state ! Using UNKNOWN", AliQA::GetGRPPath().Data()));
221 TObjString *beamEnergyStr=
222 dynamic_cast<TObjString*>(data->GetValue("fAliceBeamEnergy"));
223 if (!beamEnergyStr) {
224 AliWarning(Form("%s entry: missing value for the beam energy ! Using 0", AliQA::GetGRPPath().Data()));
227 dynamic_cast<TObjString*>(data->GetValue("fRunType"));
229 AliWarning(Form("%s entry: missing value for the run type ! Using UNKNOWN", AliQA::GetGRPPath().Data())); }
230 TObjString *activeDetectors=
231 dynamic_cast<TObjString*>(data->GetValue("fDetectorMask"));
232 if (!activeDetectors) {
233 AliWarning(Form("%s entry: missing value for the detector mask ! Using 1074790399", AliQA::GetGRPPath().Data()));
235 fRunInfo = new AliRunInfo(lhcState ? lhcState->GetString().Data() : "UNKNOWN",
236 beamType ? beamType->GetString().Data() : "UNKNOWN",
237 beamEnergyStr ? beamEnergyStr->GetString().Atof() : 0,
238 runType ? runType->GetString().Data() : "UNKNOWN",
239 activeDetectors ? activeDetectors->GetString().Atoi() : 1074790399);
240 fRunInfoOwner = kTRUE ;
243 //_____________________________________________________________________________
244 Bool_t AliQAChecker::Run(const char * fileName)
246 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
247 // starting from data in file
251 TStopwatch stopwatch;
254 //search for all detectors QA directories
255 TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ;
256 TIter nextd(detKeyList) ;
258 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
259 AliDebug(1, Form("Found %s", detKey->GetName())) ;
260 //Check which detector
262 TString detNameQA(detKey->GetName()) ;
264 for ( det = 0; det < AliQA::kNDET ; det++) {
265 detName = AliQA::GetDetName(det) ;
266 if (detNameQA.Contains(detName)) {
267 fFoundDetectors+=detName ;
268 fFoundDetectors+="." ;
272 TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
273 TList * taskKeyList = detDir->GetListOfKeys() ;
274 TIter nextt(taskKeyList) ;
276 // now search for the tasks dir
277 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
278 TString taskName( taskKey->GetName() ) ;
279 AliInfo(Form("Found %s", taskName.Data())) ;
280 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
282 AliQACheckerBase * qac = GetDetQAChecker(det) ;
284 AliInfo(Form("QA checker found for %s", detName.Data())) ;
286 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
287 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
288 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
289 index = AliQA::kSIM ;
290 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
291 index = AliQA::kSIM ;
292 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
293 index = AliQA::kSIM ;
294 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
295 index = AliQA::kREC ;
296 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
297 index = AliQA::kREC ;
298 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
299 index = AliQA::kREC ;
300 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
301 index = AliQA::kESD ;
302 qac->Init(AliQA::DETECTORINDEX_t(det)) ;
304 TDirectory * refDir = NULL ;
305 TObjArray * refOCDBDir = NULL ;
306 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
307 if ( refDir || refOCDBDir) {
308 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
313 AliInfo("QA performed for following detectors:") ;
314 for ( Int_t det = 0; det < AliQA::kNDET; det++) {
315 if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
316 printf("%s, ",AliQA::GetDetName(det)) ;
317 fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ;
327 //_____________________________________________________________________________
328 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObjArray * list)
330 // run the Quality Assurance Checker for detector det, for task task starting from data in list
332 AliQACheckerBase * qac = GetDetQAChecker(det) ;
334 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
336 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
338 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
339 if ( task == AliQA::kRAWS )
340 index = AliQA::kRAW ;
341 else if ( task == AliQA::kHITS )
342 index = AliQA::kSIM ;
343 else if ( task == AliQA::kSDIGITS )
344 index = AliQA::kSIM ;
345 else if ( task == AliQA::kDIGITS )
346 index = AliQA::kSIM ;
347 else if ( task == AliQA::kRECPOINTS )
348 index = AliQA::kREC ;
349 else if ( task == AliQA::kTRACKSEGMENTS )
350 index = AliQA::kREC ;
351 else if ( task == AliQA::kRECPARTICLES )
352 index = AliQA::kREC ;
353 else if ( task == AliQA::kESDS )
354 index = AliQA::kESD ;
356 TDirectory * refDir = NULL ;
357 TObjArray * refOCDBDir = NULL ;
359 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
360 if ( refDir || refOCDBDir) // references found
361 qac->SetRefandData(refDir, refOCDBDir) ;
362 qac->Run(index, list) ;