]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQAChecker.cxx
Macro to perform QA
[u/mrichter/AliRoot.git] / STEER / AliQAChecker.cxx
CommitLineData
421ab0fb 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id: */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class for running the Quality Assurance Checker
21// //
22///////////////////////////////////////////////////////////////////////////////
23
24#include "AliLog.h"
25#include "AliModule.h"
2e42b4d4 26#include "AliQA.h"
27#include "AliQAChecker.h"
28#include "AliQACheckerBase.h"
421ab0fb 29
a5fa6165 30#include <TKey.h>
421ab0fb 31#include <TObjArray.h>
a5fa6165 32#include <TPluginManager.h>
33#include <TROOT.h>
421ab0fb 34#include <TStopwatch.h>
35#include <TString.h>
a5fa6165 36#include <TSystem.h>
a4976ef3 37#include <TList.h>
421ab0fb 38
2e42b4d4 39ClassImp(AliQAChecker)
40 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
41 TFile * AliQAChecker::fgQAResultFile = 0x0 ;
4ecde5fc 42// TString AliQAChecker::fgQAResultDirName = "local://RUN/";
43// TString AliQAChecker::fgQAResultFileName = "QA.root" ;
421ab0fb 44
45//_____________________________________________________________________________
2e42b4d4 46AliQAChecker::AliQAChecker(const char* name, const char* title) :
421ab0fb 47 TNamed(name, title),
a5fa6165 48 fDataFile(0x0),
4ecde5fc 49// fRefDirName("./Ref/"),
50// fRefName("QA.root"),
a5fa6165 51 fFoundDetectors(".")
421ab0fb 52{
a5fa6165 53 // ctor: initialise checkers and open the data file
2e42b4d4 54 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
a5fa6165 55 fCheckers[det] = NULL ;
56
4ecde5fc 57// fRefDirName.Append(fRefName) ;
421ab0fb 58}
59
60//_____________________________________________________________________________
2e42b4d4 61AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
421ab0fb 62 TNamed(qac),
a5fa6165 63 fDataFile(qac.fDataFile),
4ecde5fc 64// fRefDirName(qac.fRefDirName),
65// fRefName(qac.fRefName),
a5fa6165 66 fFoundDetectors(qac.fFoundDetectors)
421ab0fb 67{
a5fa6165 68 // copy constructor
69
2e42b4d4 70 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
a5fa6165 71 fCheckers[det] = NULL ;
421ab0fb 72}
73
74//_____________________________________________________________________________
2e42b4d4 75AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
421ab0fb 76{
77// assignment operator
78
2e42b4d4 79 this->~AliQAChecker();
80 new(this) AliQAChecker(qac);
421ab0fb 81 return *this;
82}
83
84//_____________________________________________________________________________
2e42b4d4 85AliQAChecker::~AliQAChecker()
421ab0fb 86{
87// clean up
a4976ef3 88 delete [] fCheckers ;
9a223722 89 fgQAResultFile->Close() ;
421ab0fb 90}
91
92//_____________________________________________________________________________
808b7099 93TFile * AliQAChecker:: GetDataFile(const char * fileName)
a5fa6165 94{
95 // Open if necessary the Data file and return its pointer
96
97 if (!fDataFile)
808b7099 98 if (!fileName)
99 fileName = AliQA::GetDataName() ;
100 if (!gSystem->AccessPathName(fileName)) {
101 fDataFile = TFile::Open(fileName) ;
102 } else {
103 AliFatal(Form("File %s not found", fileName)) ;
104 }
a5fa6165 105 return fDataFile ;
106}
107
108//_____________________________________________________________________________
2e42b4d4 109TFile * AliQAChecker:: GetQAResultFile()
421ab0fb 110{
111 // Check if file to store QA exists, if not create it
112
a5fa6165 113 if (fgQAResultFile) {
114 if (fgQAResultFile->IsOpen()){
115 fgQAResultFile->Close() ;
116 fgQAResultFile = 0x0 ;
421ab0fb 117 }
118 }
4ecde5fc 119// if ( fgQAResultFileName.Contains("local://"))
120// fgQAResultFileName.ReplaceAll("local:/", "") ;
121//
122// TString opt("") ;
123// if ( !gSystem->AccessPathName(fgQAResultFileName) )
124// opt = "UPDATE" ;
125// else
126// opt = "NEW" ;
127// fgQAResultFile = TFile::Open(fgQAResultFileName, opt) ;
128//
129 fgQAResultFile = AliQA::GetQAResultFile() ;
a5fa6165 130 return fgQAResultFile ;
421ab0fb 131}
132
133//_____________________________________________________________________________
2e42b4d4 134 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
421ab0fb 135{
a5fa6165 136 // Gets the Quality Assurance checker for the detector specified by its name
137
138 if (fCheckers[det])
139 return fCheckers[det];
140
2e42b4d4 141 TString detName(AliQA::GetDetName(det)) ;
a5fa6165 142
143 AliInfo(Form("Retrieving QA checker for %s", detName.Data())) ;
144 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
2e42b4d4 145 TString qacName = "Ali" + detName + "QAChecker" ;
a5fa6165 146
2e42b4d4 147 AliQACheckerBase * qac = NULL ;
a5fa6165 148 // first check if a plugin is defined for the quality assurance checker
2e42b4d4 149 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
a5fa6165 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();
154
155 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
2e42b4d4 156 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
a5fa6165 157 else
2e42b4d4 158 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
a5fa6165 159
2e42b4d4 160 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
a5fa6165 161
162 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
2e42b4d4 163 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
a5fa6165 164
165 if (qac)
166 fCheckers[det] = qac ;
421ab0fb 167 }
a5fa6165 168
169 return qac ;
170}
171
172
173//_____________________________________________________________________________
2e42b4d4 174TDirectory * AliQAChecker::GetRefSubDir(const char * det, const char * task)
a5fa6165 175{
176 // Opens and returns the file with the reference data
4ecde5fc 177 TFile * f = AliQA::GetQARefFile() ; //TFile::Open(fRefDirName, "READ") ;
a5fa6165 178 TDirectory * rv = NULL ;
10a28129 179 if (!f) {
4ecde5fc 180 AliError(Form("Cannot find reference file %s", (AliQA::GetQARefFileName()))) ;
10a28129 181 return rv ;
182 }
a5fa6165 183 rv = f->GetDirectory(det) ;
184 if (!rv) {
4ecde5fc 185 AliWarning(Form("Directory %s not found in %d", det, (AliQA::GetQARefFileName()))) ;
a5fa6165 186 } else {
187 rv = rv->GetDirectory(task) ;
188 if (!rv)
4ecde5fc 189 AliWarning(Form("Directory %s/%s not found in %s", det, task, (AliQA::GetQARefFileName()))) ;
a5fa6165 190 }
191 return rv ;
421ab0fb 192}
193
a4976ef3 194//_____________________________________________________________________________
2e42b4d4 195AliQAChecker * AliQAChecker::Instance()
a4976ef3 196{
197 // returns unique instance of the checker
198 if ( ! fgQAChecker )
2e42b4d4 199 fgQAChecker = new AliQAChecker() ;
a4976ef3 200 return fgQAChecker ;
201}
202
421ab0fb 203//_____________________________________________________________________________
808b7099 204Bool_t AliQAChecker::Run(const char * fileName)
421ab0fb 205{
a5fa6165 206 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
a4976ef3 207 // starting from data in file
421ab0fb 208
209 Bool_t rv = kFALSE ;
a5fa6165 210
421ab0fb 211 TStopwatch stopwatch;
212 stopwatch.Start();
213
a5fa6165 214 //search for all detectors QA directories
808b7099 215 TList * detKeyList = GetDataFile(fileName)->GetListOfKeys() ;
a5fa6165 216 TIter nextd(detKeyList) ;
217 TKey * detKey ;
218 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
219 AliInfo(Form("Found %s", detKey->GetName())) ;
220 //Check which detector
221 TString detName ;
222 TString detNameQA(detKey->GetName()) ;
223 Int_t det ;
2e42b4d4 224 for ( det = 0; det < AliQA::kNDET ; det++) {
225 detName = AliQA::GetDetName(det) ;
a5fa6165 226 if (detNameQA.Contains(detName)) {
227 fFoundDetectors+=detName ;
228 fFoundDetectors+="." ;
229 break ;
230 }
231 }
808b7099 232 TDirectory * detDir = GetDataFile(fileName)->GetDirectory(detKey->GetName()) ;
a5fa6165 233 TList * taskKeyList = detDir->GetListOfKeys() ;
234 TIter nextt(taskKeyList) ;
235 TKey * taskKey ;
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()) ;
241 taskDir->cd() ;
2e42b4d4 242 AliQACheckerBase * qac = GetDetQAChecker(det) ;
a5fa6165 243 if (qac)
a4976ef3 244 AliInfo(Form("QA checker found for %s", detName.Data())) ;
a5fa6165 245 if (!qac)
a4976ef3 246 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
2e42b4d4 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)) ;
10a28129 263
ac2bb64a 264 TDirectory * refDir = GetRefSubDir(detNameQA.Data(), taskName.Data()) ;
265 if ( refDir ) {
266 qac->SetRefandData(refDir, taskDir) ;
267 qac->Run(index) ;
268 }
421ab0fb 269 }
a5fa6165 270 }
271 AliInfo("QA performed for following detectors:") ;
2e42b4d4 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), "") ;
a5fa6165 276 }
421ab0fb 277 }
a5fa6165 278 printf("\n") ;
279 rv = kTRUE ;
421ab0fb 280
a5fa6165 281 return rv ;
282
421ab0fb 283}
284
a4976ef3 285//_____________________________________________________________________________
2e42b4d4 286Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX det, AliQA::TASKINDEX task, TList * list)
a4976ef3 287{
288 // run the Quality Assurance Checker for detector det, for task task starting from data in list
289
2e42b4d4 290 AliQACheckerBase * qac = GetDetQAChecker(det) ;
a4976ef3 291 if (qac)
2e42b4d4 292 AliInfo(Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
a4976ef3 293 if (!qac)
2e42b4d4 294 AliFatal(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
a4976ef3 295
2e42b4d4 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 ;
a4976ef3 313
10a28129 314 TDirectory * refDir = GetRefSubDir(AliQA::GetDetName(det).Data(), AliQA::GetTaskName(task).Data()) ;
315 if ( refDir ) {
316 qac->Init(det) ;
317 qac->SetRefandData(refDir) ;
318 qac->Run(index, list) ;
319 }
a4976ef3 320 return kTRUE ;
321
322}
323
421ab0fb 324//_____________________________________________________________________________
4ecde5fc 325//void AliQAChecker::SetQAResultDirName(const char * name)
326//{
327// // Set the root directory where to store the QA status object
328//
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) ;
334//}
421ab0fb 335
336//_____________________________________________________________________________
4ecde5fc 337//void AliQAChecker::SetRefDirName(const char * name)
338//{
339// // Set the root directory of reference data
340//
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:/", "") ;
346//}
347//
421ab0fb 348
349
350
351