]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQAChecker.cxx
A new method DrawPMDModule is added
[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
4edbc5bc 24#include "AliCDBEntry.h"
25#include "AliCDBManager.h"
96d67a8d 26#include "AliCDBStorage.h"
421ab0fb 27#include "AliLog.h"
28#include "AliModule.h"
2e42b4d4 29#include "AliQA.h"
30#include "AliQAChecker.h"
31#include "AliQACheckerBase.h"
421ab0fb 32
a5fa6165 33#include <TKey.h>
421ab0fb 34#include <TObjArray.h>
a5fa6165 35#include <TPluginManager.h>
36#include <TROOT.h>
421ab0fb 37#include <TStopwatch.h>
38#include <TString.h>
a5fa6165 39#include <TSystem.h>
a4976ef3 40#include <TList.h>
421ab0fb 41
2e42b4d4 42ClassImp(AliQAChecker)
43 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
421ab0fb 44
45//_____________________________________________________________________________
2e42b4d4 46AliQAChecker::AliQAChecker(const char* name, const char* title) :
421ab0fb 47 TNamed(name, title),
a5fa6165 48 fDataFile(0x0),
4edbc5bc 49 fRefFile(0x0),
a5fa6165 50 fFoundDetectors(".")
421ab0fb 51{
a5fa6165 52 // ctor: initialise checkers and open the data file
2e42b4d4 53 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
a5fa6165 54 fCheckers[det] = NULL ;
421ab0fb 55}
56
57//_____________________________________________________________________________
2e42b4d4 58AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
421ab0fb 59 TNamed(qac),
a5fa6165 60 fDataFile(qac.fDataFile),
4edbc5bc 61 fRefFile(qac.fRefFile),
a5fa6165 62 fFoundDetectors(qac.fFoundDetectors)
421ab0fb 63{
a5fa6165 64 // copy constructor
65
2e42b4d4 66 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
a5fa6165 67 fCheckers[det] = NULL ;
421ab0fb 68}
69
70//_____________________________________________________________________________
2e42b4d4 71AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
421ab0fb 72{
73// assignment operator
74
2e42b4d4 75 this->~AliQAChecker();
76 new(this) AliQAChecker(qac);
421ab0fb 77 return *this;
78}
79
80//_____________________________________________________________________________
2e42b4d4 81AliQAChecker::~AliQAChecker()
421ab0fb 82{
83// clean up
a4976ef3 84 delete [] fCheckers ;
8bea2de0 85 AliQA::Close() ;
421ab0fb 86}
87
88//_____________________________________________________________________________
2e42b4d4 89 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
421ab0fb 90{
a5fa6165 91 // Gets the Quality Assurance checker for the detector specified by its name
92
93 if (fCheckers[det])
94 return fCheckers[det];
95
2e42b4d4 96 TString detName(AliQA::GetDetName(det)) ;
a5fa6165 97
54a7f3ac 98 AliDebug(1, Form("Retrieving QA checker for %s", detName.Data())) ;
a5fa6165 99 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
2e42b4d4 100 TString qacName = "Ali" + detName + "QAChecker" ;
a5fa6165 101
2e42b4d4 102 AliQACheckerBase * qac = NULL ;
a5fa6165 103 // first check if a plugin is defined for the quality assurance checker
2e42b4d4 104 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
a5fa6165 105 // if not, add a plugin for it
106 if (!pluginHandler) {
107 //AliInfo(Form("defining plugin for %s", qacName.Data()));
108 TString libs = gSystem->GetLibraries();
109
110 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
2e42b4d4 111 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
a5fa6165 112 else
2e42b4d4 113 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
a5fa6165 114
2e42b4d4 115 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
a5fa6165 116
117 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
2e42b4d4 118 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
a5fa6165 119
120 if (qac)
121 fCheckers[det] = qac ;
421ab0fb 122 }
a5fa6165 123
124 return qac ;
125}
126
127
128//_____________________________________________________________________________
f73f556a 129void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray *& dirOCDB)
a5fa6165 130{
131 // Opens and returns the file with the reference data
4edbc5bc 132
133 dirFile = NULL ;
134 dirOCDB = NULL ;
135 TString refStorage(AliQA::GetQARefStorage()) ;
96d67a8d 136 //refStorage += AliQA::GetQARefFileName() ;
4edbc5bc 137 if (refStorage.Contains(AliQA::GetLabLocalFile())) {
138 refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ;
139 if ( fRefFile )
140 if ( fRefFile->IsOpen() )
141 fRefFile->Close() ;
142 fRefFile = TFile::Open(refStorage.Data()) ;
143 if (!fRefFile) {
144 AliError(Form("Cannot find reference file %s", refStorage.Data())) ;
145 dirFile = NULL ;
146 }
147 dirFile = fRefFile->GetDirectory(det) ;
148 if (!dirFile) {
149 AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ;
150 } else {
151 dirFile = dirFile->GetDirectory(task) ;
152 if (!dirFile)
153 AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ;
154 }
155 } else if (refStorage.Contains(AliQA::GetLabLocalOCDB()) || refStorage.Contains(AliQA::GetLabAliEnOCDB())) {
156 AliCDBManager* man = AliCDBManager::Instance() ;
65c771ca 157 if ( ! man->GetLock() ) {
d3b3019c 158 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
159 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
bb6fc63e 160 }
4edbc5bc 161 char detOCDBDir[20] ;
96d67a8d 162 sprintf(detOCDBDir, "%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ;
163 AliCDBEntry * entry = man->Get(detOCDBDir, man->GetRun()) ;
f73f556a 164 if (entry) {
165 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
166 if ( listDetQAD )
167 dirOCDB = dynamic_cast<TObjArray *>(listDetQAD->FindObject(task)) ;
168 }
4edbc5bc 169 }
421ab0fb 170}
171
a4976ef3 172//_____________________________________________________________________________
2e42b4d4 173AliQAChecker * AliQAChecker::Instance()
a4976ef3 174{
175 // returns unique instance of the checker
176 if ( ! fgQAChecker )
2e42b4d4 177 fgQAChecker = new AliQAChecker() ;
a4976ef3 178 return fgQAChecker ;
179}
180
421ab0fb 181//_____________________________________________________________________________
808b7099 182Bool_t AliQAChecker::Run(const char * fileName)
421ab0fb 183{
a5fa6165 184 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
a4976ef3 185 // starting from data in file
421ab0fb 186
187 Bool_t rv = kFALSE ;
a5fa6165 188
421ab0fb 189 TStopwatch stopwatch;
190 stopwatch.Start();
191
a5fa6165 192 //search for all detectors QA directories
8bea2de0 193 TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ;
a5fa6165 194 TIter nextd(detKeyList) ;
195 TKey * detKey ;
196 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
54a7f3ac 197 AliDebug(1, Form("Found %s", detKey->GetName())) ;
a5fa6165 198 //Check which detector
199 TString detName ;
200 TString detNameQA(detKey->GetName()) ;
201 Int_t det ;
2e42b4d4 202 for ( det = 0; det < AliQA::kNDET ; det++) {
203 detName = AliQA::GetDetName(det) ;
a5fa6165 204 if (detNameQA.Contains(detName)) {
205 fFoundDetectors+=detName ;
206 fFoundDetectors+="." ;
207 break ;
208 }
209 }
8bea2de0 210 TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
a5fa6165 211 TList * taskKeyList = detDir->GetListOfKeys() ;
212 TIter nextt(taskKeyList) ;
213 TKey * taskKey ;
214 // now search for the tasks dir
215 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
216 TString taskName( taskKey->GetName() ) ;
217 AliInfo(Form("Found %s", taskName.Data())) ;
218 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
219 taskDir->cd() ;
2e42b4d4 220 AliQACheckerBase * qac = GetDetQAChecker(det) ;
a5fa6165 221 if (qac)
a4976ef3 222 AliInfo(Form("QA checker found for %s", detName.Data())) ;
a5fa6165 223 if (!qac)
a4976ef3 224 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
96d67a8d 225 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
2e42b4d4 226 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
227 index = AliQA::kSIM ;
228 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
229 index = AliQA::kSIM ;
230 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
231 index = AliQA::kSIM ;
232 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
233 index = AliQA::kREC ;
234 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
235 index = AliQA::kREC ;
236 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
237 index = AliQA::kREC ;
238 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
239 index = AliQA::kESD ;
96d67a8d 240 qac->Init(AliQA::DETECTORINDEX_t(det)) ;
10a28129 241
f73f556a 242 TDirectory * refDir = NULL ;
243 TObjArray * refOCDBDir = NULL ;
4edbc5bc 244 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
245 if ( refDir || refOCDBDir) {
246 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
247 qac->Run(index) ;
ac2bb64a 248 }
4edbc5bc 249 }
250 }
a5fa6165 251 AliInfo("QA performed for following detectors:") ;
2e42b4d4 252 for ( Int_t det = 0; det < AliQA::kNDET; det++) {
253 if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
254 printf("%s, ",AliQA::GetDetName(det)) ;
255 fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ;
a5fa6165 256 }
421ab0fb 257 }
a5fa6165 258 printf("\n") ;
259 rv = kTRUE ;
421ab0fb 260
a5fa6165 261 return rv ;
262
421ab0fb 263}
264
a4976ef3 265//_____________________________________________________________________________
96d67a8d 266Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObjArray * list)
a4976ef3 267{
d6372ce8 268 // run the Quality Assurance Checker for detector det, for task task starting from data in list
a4976ef3 269
d6372ce8 270 AliQACheckerBase * qac = GetDetQAChecker(det) ;
271 if (qac)
272 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
273 if (!qac)
274 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
a4976ef3 275
d6372ce8 276 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
277 if ( task == AliQA::kRAWS )
2e42b4d4 278 index = AliQA::kRAW ;
d6372ce8 279 else if ( task == AliQA::kHITS )
2e42b4d4 280 index = AliQA::kSIM ;
d6372ce8 281 else if ( task == AliQA::kSDIGITS )
2e42b4d4 282 index = AliQA::kSIM ;
d6372ce8 283 else if ( task == AliQA::kDIGITS )
2e42b4d4 284 index = AliQA::kSIM ;
d6372ce8 285 else if ( task == AliQA::kRECPOINTS )
2e42b4d4 286 index = AliQA::kREC ;
d6372ce8 287 else if ( task == AliQA::kTRACKSEGMENTS )
2e42b4d4 288 index = AliQA::kREC ;
d6372ce8 289 else if ( task == AliQA::kRECPARTICLES )
2e42b4d4 290 index = AliQA::kREC ;
d6372ce8 291 else if ( task == AliQA::kESDS )
2e42b4d4 292 index = AliQA::kESD ;
4edbc5bc 293
d6372ce8 294 TDirectory * refDir = NULL ;
295 TObjArray * refOCDBDir = NULL ;
296 qac->Init(det) ;
4edbc5bc 297 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
d6372ce8 298 if ( refDir || refOCDBDir) // references found
4edbc5bc 299 qac->SetRefandData(refDir, refOCDBDir) ;
d6372ce8 300 qac->Run(index, list) ;
301 return kTRUE ;
a4976ef3 302}
303
421ab0fb 304
305