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"
37 #include <TObjArray.h>
38 #include <TObjString.h>
39 #include <TPluginManager.h>
41 #include <TStopwatch.h>
47 ClassImp(AliQAChecker)
48 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
50 //_____________________________________________________________________________
51 AliQAChecker::AliQAChecker(const char* name, const char* title) :
55 fRunInfoOwner(kFALSE),
59 // ctor: initialise checkers and open the data file
60 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
61 fCheckers[det] = NULL ;
64 //_____________________________________________________________________________
65 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
67 fDataFile(qac.fDataFile),
68 fRunInfo(qac.fRunInfo),
69 fRunInfoOwner(kFALSE),
70 fRefFile(qac.fRefFile),
71 fFoundDetectors(qac.fFoundDetectors)
75 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
76 fCheckers[det] = NULL ;
79 //_____________________________________________________________________________
80 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
82 // assignment operator
84 this->~AliQAChecker();
85 new(this) AliQAChecker(qac);
89 //_____________________________________________________________________________
90 AliQAChecker::~AliQAChecker()
99 //_____________________________________________________________________________
100 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
102 // Gets the Quality Assurance checker for the detector specified by its name
105 return fCheckers[det];
107 AliQACheckerBase * qac = NULL ;
109 TString detName(AliQA::GetDetName(det)) ;
111 if (det == AliQA::kGLOBAL) {
112 qac = new AliGlobalQAChecker() ;
113 } else if (det == AliQA::kCORR) {
114 qac = new AliCorrQAChecker() ;
116 AliDebug(1, Form("Retrieving QA checker for %s", detName.Data())) ;
117 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
118 TString qacName = "Ali" + detName + "QAChecker" ;
120 // first check if a plugin is defined for the quality assurance checker
121 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
122 // if not, add a plugin for it
123 if (!pluginHandler) {
124 //AliInfo(Form("defining plugin for %s", qacName.Data()));
125 TString libs = gSystem->GetLibraries();
127 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
128 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
130 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
132 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
134 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
135 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
140 fCheckers[det] = qac ;
145 //_____________________________________________________________________________
146 void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray *& dirOCDB)
148 // Opens and returns the file with the reference data
152 TString refStorage(AliQA::GetQARefStorage()) ;
153 //refStorage += AliQA::GetQARefFileName() ;
154 if (refStorage.Contains(AliQA::GetLabLocalFile())) {
155 refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ;
157 if ( fRefFile->IsOpen() )
159 fRefFile = TFile::Open(refStorage.Data()) ;
161 AliError(Form("Cannot find reference file %s", refStorage.Data())) ;
164 dirFile = fRefFile->GetDirectory(det) ;
166 AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ;
168 dirFile = dirFile->GetDirectory(task) ;
170 AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ;
172 } else if (refStorage.Contains(AliQA::GetLabLocalOCDB()) || refStorage.Contains(AliQA::GetLabAliEnOCDB())) {
173 AliCDBManager* man = AliCDBManager::Instance() ;
174 if ( strcmp(AliQA::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (RUNTYPE)
175 // Get it from RunInfo
176 if (!fRunInfo) // not yet set, get the info from GRP
177 LoadRunInfoFromGRP() ;
178 AliQA::SetQARefDataDirName(fRunInfo->GetRunType()) ;
180 if ( ! man->GetLock() ) {
181 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
182 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
184 char * detOCDBDir = Form("%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ;
185 AliInfo(Form("Reference QA data are taken from %s", detOCDBDir)) ;
186 AliCDBEntry * entry = man->Get(detOCDBDir, man->GetRun()) ;
188 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
190 dirOCDB = dynamic_cast<TObjArray *>(listDetQAD->FindObject(task)) ;
195 //_____________________________________________________________________________
196 AliQAChecker * AliQAChecker::Instance()
198 // returns unique instance of the checker
200 fgQAChecker = new AliQAChecker() ;
204 //_____________________________________________________________________________
205 void AliQAChecker::LoadRunInfoFromGRP()
207 AliCDBManager* man = AliCDBManager::Instance() ;
208 AliCDBEntry* entry = man->Get(AliQA::GetGRPPath().Data());
211 data = dynamic_cast<TMap*>(entry->GetObject());
213 AliFatal("No GRP entry found in OCDB!");
215 TObjString *lhcState=
216 dynamic_cast<TObjString*>(data->GetValue("fLHCState"));
218 AliWarning(Form("%s entry: missing value for the LHC state ! Using UNKNOWN", AliQA::GetGRPPath().Data()));
220 TObjString *beamType=
221 dynamic_cast<TObjString*>(data->GetValue("fAliceBeamType"));
223 AliWarning(Form("%s entry: missing value for the LHC state ! Using UNKNOWN", AliQA::GetGRPPath().Data()));
225 TObjString *beamEnergyStr=
226 dynamic_cast<TObjString*>(data->GetValue("fAliceBeamEnergy"));
227 if (!beamEnergyStr) {
228 AliWarning(Form("%s entry: missing value for the beam energy ! Using 0", AliQA::GetGRPPath().Data()));
231 dynamic_cast<TObjString*>(data->GetValue("fRunType"));
233 AliWarning(Form("%s entry: missing value for the run type ! Using UNKNOWN", AliQA::GetGRPPath().Data())); }
234 TObjString *activeDetectors=
235 dynamic_cast<TObjString*>(data->GetValue("fDetectorMask"));
236 if (!activeDetectors) {
237 AliWarning(Form("%s entry: missing value for the detector mask ! Using 1074790399", AliQA::GetGRPPath().Data()));
239 fRunInfo = new AliRunInfo(lhcState ? lhcState->GetString().Data() : "UNKNOWN",
240 beamType ? beamType->GetString().Data() : "UNKNOWN",
241 beamEnergyStr ? beamEnergyStr->GetString().Atof() : 0,
242 runType ? runType->GetString().Data() : "UNKNOWN",
243 activeDetectors ? activeDetectors->GetString().Atoi() : 1074790399);
244 fRunInfoOwner = kTRUE ;
247 //_____________________________________________________________________________
248 Bool_t AliQAChecker::Run(const char * fileName)
250 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
251 // starting from data in file
255 TStopwatch stopwatch;
258 //search for all detectors QA directories
259 TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ;
260 TIter nextd(detKeyList) ;
262 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
263 AliDebug(1, Form("Found %s", detKey->GetName())) ;
264 //Check which detector
266 TString detNameQA(detKey->GetName()) ;
268 for ( det = 0; det < AliQA::kNDET ; det++) {
269 detName = AliQA::GetDetName(det) ;
270 if (detNameQA.Contains(detName)) {
271 fFoundDetectors+=detName ;
272 fFoundDetectors+="." ;
276 TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
277 TList * taskKeyList = detDir->GetListOfKeys() ;
278 TIter nextt(taskKeyList) ;
280 // now search for the tasks dir
281 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
282 TString taskName( taskKey->GetName() ) ;
283 AliInfo(Form("Found %s", taskName.Data())) ;
284 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
286 AliQACheckerBase * qac = GetDetQAChecker(det) ;
288 AliInfo(Form("QA checker found for %s", detName.Data())) ;
290 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
291 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
292 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
293 index = AliQA::kSIM ;
294 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
295 index = AliQA::kSIM ;
296 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
297 index = AliQA::kSIM ;
298 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
299 index = AliQA::kREC ;
300 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
301 index = AliQA::kREC ;
302 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
303 index = AliQA::kREC ;
304 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
305 index = AliQA::kESD ;
306 qac->Init(AliQA::DETECTORINDEX_t(det)) ;
308 TDirectory * refDir = NULL ;
309 TObjArray * refOCDBDir = NULL ;
310 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
311 if ( refDir || refOCDBDir) {
312 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
317 AliInfo("QA performed for following detectors:") ;
318 for ( Int_t det = 0; det < AliQA::kNDET; det++) {
319 if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
320 printf("%s, ",AliQA::GetDetName(det)) ;
321 fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ;
331 //_____________________________________________________________________________
332 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObject * obj)
334 // run the Quality Assurance Checker for detector det, for task task starting from data in list
336 AliQACheckerBase * qac = GetDetQAChecker(det) ;
338 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
340 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
342 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
343 if ( task == AliQA::kRAWS )
344 index = AliQA::kRAW ;
345 else if ( task == AliQA::kHITS )
346 index = AliQA::kSIM ;
347 else if ( task == AliQA::kSDIGITS )
348 index = AliQA::kSIM ;
349 else if ( task == AliQA::kDIGITS )
350 index = AliQA::kSIM ;
351 else if ( task == AliQA::kRECPOINTS )
352 index = AliQA::kREC ;
353 else if ( task == AliQA::kTRACKSEGMENTS )
354 index = AliQA::kREC ;
355 else if ( task == AliQA::kRECPARTICLES )
356 index = AliQA::kREC ;
357 else if ( task == AliQA::kESDS )
358 index = AliQA::kESD ;
360 TDirectory * refDir = NULL ;
361 TObjArray * refOCDBDir = NULL ;
363 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
364 if ( refDir || refOCDBDir) // references found
365 qac->SetRefandData(refDir, refOCDBDir) ;
367 TString className(obj->ClassName()) ;
368 if (className.Contains(TObjArray::Class()->GetName())) {
369 qac->Run(index, static_cast<TObjArray *>(obj)) ;
370 } else if (className.Contains(TNtupleD::Class()->GetName())) {
371 qac->Run(index, static_cast<TNtupleD *>(obj)) ;
373 AliError(Form("%s class not implemented", className.Data())) ;