]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQAChecker.cxx
Restored functionality
[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 ;
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),
a4976ef3 49 fRefDirName("./Ref/"),
a5fa6165 50 fRefName("QA.root"),
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
57 GetDataFile() ;
a4976ef3 58 fRefDirName.Append(fRefName) ;
421ab0fb 59}
60
61//_____________________________________________________________________________
2e42b4d4 62AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
421ab0fb 63 TNamed(qac),
a5fa6165 64 fDataFile(qac.fDataFile),
65 fRefDirName(qac.fRefDirName),
66 fRefName(qac.fRefName),
67 fFoundDetectors(qac.fFoundDetectors)
421ab0fb 68{
a5fa6165 69 // copy constructor
70
2e42b4d4 71 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
a5fa6165 72 fCheckers[det] = NULL ;
421ab0fb 73}
74
75//_____________________________________________________________________________
2e42b4d4 76AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
421ab0fb 77{
78// assignment operator
79
2e42b4d4 80 this->~AliQAChecker();
81 new(this) AliQAChecker(qac);
421ab0fb 82 return *this;
83}
84
85//_____________________________________________________________________________
2e42b4d4 86AliQAChecker::~AliQAChecker()
421ab0fb 87{
88// clean up
a4976ef3 89 delete [] fCheckers ;
9a223722 90 fgQAResultFile->Close() ;
421ab0fb 91}
92
93//_____________________________________________________________________________
2e42b4d4 94TFile * AliQAChecker:: GetDataFile()
a5fa6165 95{
96 // Open if necessary the Data file and return its pointer
97
98 if (!fDataFile)
2e42b4d4 99 if (gSystem->AccessPathName(AliQA::GetDataName()))
100 fDataFile = TFile::Open(AliQA::GetDataName()) ;
a5fa6165 101 return fDataFile ;
102}
103
104//_____________________________________________________________________________
2e42b4d4 105TFile * AliQAChecker:: GetQAResultFile()
421ab0fb 106{
107 // Check if file to store QA exists, if not create it
108
a5fa6165 109 if (fgQAResultFile) {
110 if (fgQAResultFile->IsOpen()){
111 fgQAResultFile->Close() ;
112 fgQAResultFile = 0x0 ;
421ab0fb 113 }
114 }
a5fa6165 115 if ( fgQAResultFileName.Contains("local://"))
116 fgQAResultFileName.ReplaceAll("local:/", "") ;
117
421ab0fb 118 TString opt("") ;
a5fa6165 119 if ( !gSystem->AccessPathName(fgQAResultFileName) )
421ab0fb 120 opt = "UPDATE" ;
121 else
122 opt = "NEW" ;
a5fa6165 123 fgQAResultFile = TFile::Open(fgQAResultFileName, opt) ;
124
125 return fgQAResultFile ;
421ab0fb 126}
127
128//_____________________________________________________________________________
2e42b4d4 129 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
421ab0fb 130{
a5fa6165 131 // Gets the Quality Assurance checker for the detector specified by its name
132
133 if (fCheckers[det])
134 return fCheckers[det];
135
2e42b4d4 136 TString detName(AliQA::GetDetName(det)) ;
a5fa6165 137
138 AliInfo(Form("Retrieving QA checker for %s", detName.Data())) ;
139 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
2e42b4d4 140 TString qacName = "Ali" + detName + "QAChecker" ;
a5fa6165 141
2e42b4d4 142 AliQACheckerBase * qac = NULL ;
a5fa6165 143 // first check if a plugin is defined for the quality assurance checker
2e42b4d4 144 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
a5fa6165 145 // if not, add a plugin for it
146 if (!pluginHandler) {
147 //AliInfo(Form("defining plugin for %s", qacName.Data()));
148 TString libs = gSystem->GetLibraries();
149
150 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
2e42b4d4 151 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
a5fa6165 152 else
2e42b4d4 153 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
a5fa6165 154
2e42b4d4 155 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
a5fa6165 156
157 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
2e42b4d4 158 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
a5fa6165 159
160 if (qac)
161 fCheckers[det] = qac ;
421ab0fb 162 }
a5fa6165 163
164 return qac ;
165}
166
167
168//_____________________________________________________________________________
2e42b4d4 169TDirectory * AliQAChecker::GetRefSubDir(const char * det, const char * task)
a5fa6165 170{
171 // Opens and returns the file with the reference data
172 TFile * f = TFile::Open(fRefDirName, "READ") ;
a5fa6165 173 TDirectory * rv = NULL ;
10a28129 174 if (!f) {
175 AliError(Form("Cannot find reference file %s", fRefDirName.Data())) ;
176 return rv ;
177 }
a5fa6165 178 rv = f->GetDirectory(det) ;
179 if (!rv) {
180 AliWarning(Form("Directory %s not found in %d", det, fRefDirName.Data())) ;
181 } else {
182 rv = rv->GetDirectory(task) ;
183 if (!rv)
184 AliWarning(Form("Directory %s/%s not found in %s", det, task, fRefDirName.Data())) ;
185 }
186 return rv ;
421ab0fb 187}
188
a4976ef3 189//_____________________________________________________________________________
2e42b4d4 190AliQAChecker * AliQAChecker::Instance()
a4976ef3 191{
192 // returns unique instance of the checker
193 if ( ! fgQAChecker )
2e42b4d4 194 fgQAChecker = new AliQAChecker() ;
a4976ef3 195 return fgQAChecker ;
196}
197
421ab0fb 198//_____________________________________________________________________________
2e42b4d4 199Bool_t AliQAChecker::Run()
421ab0fb 200{
a5fa6165 201 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
a4976ef3 202 // starting from data in file
421ab0fb 203
204 Bool_t rv = kFALSE ;
a5fa6165 205
421ab0fb 206 TStopwatch stopwatch;
207 stopwatch.Start();
208
a5fa6165 209 //search for all detectors QA directories
210 TList * detKeyList = GetDataFile()->GetListOfKeys() ;
211 TIter nextd(detKeyList) ;
212 TKey * detKey ;
213 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
214 AliInfo(Form("Found %s", detKey->GetName())) ;
215 //Check which detector
216 TString detName ;
217 TString detNameQA(detKey->GetName()) ;
218 Int_t det ;
2e42b4d4 219 for ( det = 0; det < AliQA::kNDET ; det++) {
220 detName = AliQA::GetDetName(det) ;
a5fa6165 221 if (detNameQA.Contains(detName)) {
222 fFoundDetectors+=detName ;
223 fFoundDetectors+="." ;
224 break ;
225 }
226 }
227 TDirectory * detDir = GetDataFile()->GetDirectory(detKey->GetName()) ;
228 TList * taskKeyList = detDir->GetListOfKeys() ;
229 TIter nextt(taskKeyList) ;
230 TKey * taskKey ;
231 // now search for the tasks dir
232 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
233 TString taskName( taskKey->GetName() ) ;
234 AliInfo(Form("Found %s", taskName.Data())) ;
235 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
236 taskDir->cd() ;
2e42b4d4 237 AliQACheckerBase * qac = GetDetQAChecker(det) ;
a5fa6165 238 if (qac)
a4976ef3 239 AliInfo(Form("QA checker found for %s", detName.Data())) ;
a5fa6165 240 if (!qac)
a4976ef3 241 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
2e42b4d4 242 AliQA::ALITASK index = AliQA::kNULLTASK ;
243 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
244 index = AliQA::kSIM ;
245 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
246 index = AliQA::kSIM ;
247 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
248 index = AliQA::kSIM ;
249 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
250 index = AliQA::kREC ;
251 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
252 index = AliQA::kREC ;
253 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
254 index = AliQA::kREC ;
255 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
256 index = AliQA::kESD ;
257 qac->Init(AliQA::DETECTORINDEX(det)) ;
10a28129 258
ac2bb64a 259 TDirectory * refDir = GetRefSubDir(detNameQA.Data(), taskName.Data()) ;
260 if ( refDir ) {
261 qac->SetRefandData(refDir, taskDir) ;
262 qac->Run(index) ;
263 }
421ab0fb 264 }
a5fa6165 265 }
266 AliInfo("QA performed for following detectors:") ;
2e42b4d4 267 for ( Int_t det = 0; det < AliQA::kNDET; det++) {
268 if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
269 printf("%s, ",AliQA::GetDetName(det)) ;
270 fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ;
a5fa6165 271 }
421ab0fb 272 }
a5fa6165 273 printf("\n") ;
274 rv = kTRUE ;
421ab0fb 275
a5fa6165 276 return rv ;
277
421ab0fb 278}
279
a4976ef3 280//_____________________________________________________________________________
2e42b4d4 281Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX det, AliQA::TASKINDEX task, TList * list)
a4976ef3 282{
283 // run the Quality Assurance Checker for detector det, for task task starting from data in list
284
2e42b4d4 285 AliQACheckerBase * qac = GetDetQAChecker(det) ;
a4976ef3 286 if (qac)
2e42b4d4 287 AliInfo(Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
a4976ef3 288 if (!qac)
2e42b4d4 289 AliFatal(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
a4976ef3 290
2e42b4d4 291 AliQA::ALITASK index = AliQA::kNULLTASK ;
292 if ( task == AliQA::kRAWS )
293 index = AliQA::kRAW ;
294 else if ( task == AliQA::kHITS )
295 index = AliQA::kSIM ;
296 else if ( task == AliQA::kSDIGITS )
297 index = AliQA::kSIM ;
298 else if ( task == AliQA::kDIGITS )
299 index = AliQA::kSIM ;
300 else if ( task == AliQA::kRECPOINTS )
301 index = AliQA::kREC ;
302 else if ( task == AliQA::kTRACKSEGMENTS )
303 index = AliQA::kREC ;
304 else if ( task == AliQA::kRECPARTICLES )
305 index = AliQA::kREC ;
306 else if ( task == AliQA::kESDS )
307 index = AliQA::kESD ;
a4976ef3 308
10a28129 309 TDirectory * refDir = GetRefSubDir(AliQA::GetDetName(det).Data(), AliQA::GetTaskName(task).Data()) ;
310 if ( refDir ) {
311 qac->Init(det) ;
312 qac->SetRefandData(refDir) ;
313 qac->Run(index, list) ;
314 }
a4976ef3 315 return kTRUE ;
316
317}
318
421ab0fb 319//_____________________________________________________________________________
2e42b4d4 320void AliQAChecker::SetQAResultDirName(const char * name)
421ab0fb 321{
322 // Set the root directory where to store the QA status object
323
a5fa6165 324 fgQAResultDirName.Prepend(name) ;
325 AliInfo(Form("QA results are in %s", fgQAResultDirName.Data())) ;
326 if ( fgQAResultDirName.Contains("local://"))
327 fgQAResultDirName.ReplaceAll("local:/", "") ;
328 fgQAResultFileName.Prepend(fgQAResultDirName) ;
421ab0fb 329}
330
331//_____________________________________________________________________________
2e42b4d4 332void AliQAChecker::SetRefDirName(const char * name)
421ab0fb 333{
334 // Set the root directory of reference data
335
a5fa6165 336 fRefDirName.Prepend(name) ;
337 fRefDirName.Append(fRefName) ;
338 AliInfo(Form("Reference data are taken from %s", fRefDirName.Data())) ;
339 if ( fRefDirName.Contains("local://"))
340 fRefDirName.ReplaceAll("local:/", "") ;
421ab0fb 341}
342
343
344
345
346