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 ///////////////////////////////////////////////////////////////////////////////
25 #include "AliModule.h"
27 #include "AliQAChecker.h"
28 #include "AliQACheckerBase.h"
31 #include <TObjArray.h>
32 #include <TPluginManager.h>
34 #include <TStopwatch.h>
39 ClassImp(AliQAChecker)
40 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
41 TFile * AliQAChecker::fgQAResultFile = 0x0 ;
42 // TString AliQAChecker::fgQAResultDirName = "local://RUN/";
43 // TString AliQAChecker::fgQAResultFileName = "QA.root" ;
45 //_____________________________________________________________________________
46 AliQAChecker::AliQAChecker(const char* name, const char* title) :
49 // fRefDirName("./Ref/"),
50 // fRefName("QA.root"),
53 // ctor: initialise checkers and open the data file
54 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
55 fCheckers[det] = NULL ;
57 // fRefDirName.Append(fRefName) ;
60 //_____________________________________________________________________________
61 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
63 fDataFile(qac.fDataFile),
64 // fRefDirName(qac.fRefDirName),
65 // fRefName(qac.fRefName),
66 fFoundDetectors(qac.fFoundDetectors)
70 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
71 fCheckers[det] = NULL ;
74 //_____________________________________________________________________________
75 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
77 // assignment operator
79 this->~AliQAChecker();
80 new(this) AliQAChecker(qac);
84 //_____________________________________________________________________________
85 AliQAChecker::~AliQAChecker()
89 fgQAResultFile->Close() ;
92 //_____________________________________________________________________________
93 TFile * AliQAChecker:: GetDataFile(const char * fileName)
95 // Open if necessary the Data file and return its pointer
99 fileName = AliQA::GetDataName() ;
100 if (!gSystem->AccessPathName(fileName)) {
101 fDataFile = TFile::Open(fileName) ;
103 AliFatal(Form("File %s not found", fileName)) ;
108 //_____________________________________________________________________________
109 TFile * AliQAChecker:: GetQAResultFile()
111 // Check if file to store QA exists, if not create it
113 if (fgQAResultFile) {
114 if (fgQAResultFile->IsOpen()){
115 fgQAResultFile->Close() ;
116 fgQAResultFile = 0x0 ;
119 // if ( fgQAResultFileName.Contains("local://"))
120 // fgQAResultFileName.ReplaceAll("local:/", "") ;
123 // if ( !gSystem->AccessPathName(fgQAResultFileName) )
127 // fgQAResultFile = TFile::Open(fgQAResultFileName, opt) ;
129 fgQAResultFile = AliQA::GetQAResultFile() ;
130 return fgQAResultFile ;
133 //_____________________________________________________________________________
134 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
136 // Gets the Quality Assurance checker for the detector specified by its name
139 return fCheckers[det];
141 TString detName(AliQA::GetDetName(det)) ;
143 AliInfo(Form("Retrieving QA checker for %s", detName.Data())) ;
144 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
145 TString qacName = "Ali" + detName + "QAChecker" ;
147 AliQACheckerBase * qac = NULL ;
148 // first check if a plugin is defined for the quality assurance checker
149 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
150 // if not, add a plugin for it
151 if (!pluginHandler) {
152 //AliInfo(Form("defining plugin for %s", qacName.Data()));
153 TString libs = gSystem->GetLibraries();
155 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
156 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
158 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
160 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
162 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
163 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
166 fCheckers[det] = qac ;
173 //_____________________________________________________________________________
174 TDirectory * AliQAChecker::GetRefSubDir(const char * det, const char * task)
176 // Opens and returns the file with the reference data
177 TFile * f = AliQA::GetQARefFile() ; //TFile::Open(fRefDirName, "READ") ;
178 TDirectory * rv = NULL ;
180 AliError(Form("Cannot find reference file %s", (AliQA::GetQARefFileName()))) ;
183 rv = f->GetDirectory(det) ;
185 AliWarning(Form("Directory %s not found in %d", det, (AliQA::GetQARefFileName()))) ;
187 rv = rv->GetDirectory(task) ;
189 AliWarning(Form("Directory %s/%s not found in %s", det, task, (AliQA::GetQARefFileName()))) ;
194 //_____________________________________________________________________________
195 AliQAChecker * AliQAChecker::Instance()
197 // returns unique instance of the checker
199 fgQAChecker = new AliQAChecker() ;
203 //_____________________________________________________________________________
204 Bool_t AliQAChecker::Run(const char * fileName)
206 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
207 // starting from data in file
211 TStopwatch stopwatch;
214 //search for all detectors QA directories
215 TList * detKeyList = GetDataFile(fileName)->GetListOfKeys() ;
216 TIter nextd(detKeyList) ;
218 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
219 AliInfo(Form("Found %s", detKey->GetName())) ;
220 //Check which detector
222 TString detNameQA(detKey->GetName()) ;
224 for ( det = 0; det < AliQA::kNDET ; det++) {
225 detName = AliQA::GetDetName(det) ;
226 if (detNameQA.Contains(detName)) {
227 fFoundDetectors+=detName ;
228 fFoundDetectors+="." ;
232 TDirectory * detDir = GetDataFile(fileName)->GetDirectory(detKey->GetName()) ;
233 TList * taskKeyList = detDir->GetListOfKeys() ;
234 TIter nextt(taskKeyList) ;
236 // now search for the tasks dir
237 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
238 TString taskName( taskKey->GetName() ) ;
239 AliInfo(Form("Found %s", taskName.Data())) ;
240 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
242 AliQACheckerBase * qac = GetDetQAChecker(det) ;
244 AliInfo(Form("QA checker found for %s", detName.Data())) ;
246 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
247 AliQA::ALITASK index = AliQA::kNULLTASK ;
248 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
249 index = AliQA::kSIM ;
250 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
251 index = AliQA::kSIM ;
252 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
253 index = AliQA::kSIM ;
254 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
255 index = AliQA::kREC ;
256 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
257 index = AliQA::kREC ;
258 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
259 index = AliQA::kREC ;
260 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
261 index = AliQA::kESD ;
262 qac->Init(AliQA::DETECTORINDEX(det)) ;
264 TDirectory * refDir = GetRefSubDir(detNameQA.Data(), taskName.Data()) ;
266 qac->SetRefandData(refDir, taskDir) ;
271 AliInfo("QA performed for following detectors:") ;
272 for ( Int_t det = 0; det < AliQA::kNDET; det++) {
273 if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
274 printf("%s, ",AliQA::GetDetName(det)) ;
275 fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ;
285 //_____________________________________________________________________________
286 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX det, AliQA::TASKINDEX task, TList * list)
288 // run the Quality Assurance Checker for detector det, for task task starting from data in list
290 AliQACheckerBase * qac = GetDetQAChecker(det) ;
292 AliInfo(Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
294 AliFatal(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
296 AliQA::ALITASK index = AliQA::kNULLTASK ;
297 if ( task == AliQA::kRAWS )
298 index = AliQA::kRAW ;
299 else if ( task == AliQA::kHITS )
300 index = AliQA::kSIM ;
301 else if ( task == AliQA::kSDIGITS )
302 index = AliQA::kSIM ;
303 else if ( task == AliQA::kDIGITS )
304 index = AliQA::kSIM ;
305 else if ( task == AliQA::kRECPOINTS )
306 index = AliQA::kREC ;
307 else if ( task == AliQA::kTRACKSEGMENTS )
308 index = AliQA::kREC ;
309 else if ( task == AliQA::kRECPARTICLES )
310 index = AliQA::kREC ;
311 else if ( task == AliQA::kESDS )
312 index = AliQA::kESD ;
314 TDirectory * refDir = GetRefSubDir(AliQA::GetDetName(det).Data(), AliQA::GetTaskName(task).Data()) ;
317 qac->SetRefandData(refDir) ;
318 qac->Run(index, list) ;
324 //_____________________________________________________________________________
325 //void AliQAChecker::SetQAResultDirName(const char * name)
327 // // Set the root directory where to store the QA status object
329 // fgQAResultDirName.Prepend(name) ;
330 // AliInfo(Form("QA results are in %s", fgQAResultDirName.Data())) ;
331 // if ( fgQAResultDirName.Contains("local://"))
332 // fgQAResultDirName.ReplaceAll("local:/", "") ;
333 // fgQAResultFileName.Prepend(fgQAResultDirName) ;
336 //_____________________________________________________________________________
337 //void AliQAChecker::SetRefDirName(const char * name)
339 // // Set the root directory of reference data
341 // fRefDirName.Prepend(name) ;
342 // fRefDirName.Append(fRefName) ;
343 // AliInfo(Form("Reference data are taken from %s", fRefDirName.Data())) ;
344 // if ( fRefDirName.Contains("local://"))
345 // fRefDirName.ReplaceAll("local:/", "") ;