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"
26 #include "AliQualAss.h"
27 #include "AliQualAssChecker.h"
28 #include "AliQualAssCheckerBase.h"
31 #include <TObjArray.h>
32 #include <TPluginManager.h>
34 #include <TStopwatch.h>
38 ClassImp(AliQualAssChecker)
39 TFile * AliQualAssChecker::fgQAResultFile = 0x0 ;
40 TString AliQualAssChecker::fgQAResultDirName = "local://RUN/";
41 TString AliQualAssChecker::fgQAResultFileName = "QA.root" ;
43 //_____________________________________________________________________________
44 AliQualAssChecker::AliQualAssChecker(const char* name, const char* title) :
47 fRefDirName("/QA/Ref/"),
51 // ctor: initialise checkers and open the data file
52 for (Int_t det = 0 ; det < AliQualAss::kNDET ; det++)
53 fCheckers[det] = NULL ;
58 //_____________________________________________________________________________
59 AliQualAssChecker::AliQualAssChecker(const AliQualAssChecker& qac) :
61 fDataFile(qac.fDataFile),
62 fRefDirName(qac.fRefDirName),
63 fRefName(qac.fRefName),
64 fFoundDetectors(qac.fFoundDetectors)
68 for (Int_t det = 0 ; det < AliQualAss::kNDET ; det++)
69 fCheckers[det] = NULL ;
72 //_____________________________________________________________________________
73 AliQualAssChecker& AliQualAssChecker::operator = (const AliQualAssChecker& qac)
75 // assignment operator
77 this->~AliQualAssChecker();
78 new(this) AliQualAssChecker(qac);
82 //_____________________________________________________________________________
83 AliQualAssChecker::~AliQualAssChecker()
88 //_____________________________________________________________________________
89 TFile * AliQualAssChecker:: GetDataFile()
91 // Open if necessary the Data file and return its pointer
94 fDataFile = TFile::Open(AliQualAss::GetDataName()) ;
96 AliFatal(Form("QA Data File %s does not exist", AliQualAss::GetDataName() )) ;
100 //_____________________________________________________________________________
101 TFile * AliQualAssChecker:: GetQAResultFile()
103 // Check if file to store QA exists, if not create it
105 if (fgQAResultFile) {
106 if (fgQAResultFile->IsOpen()){
107 fgQAResultFile->Close() ;
108 fgQAResultFile = 0x0 ;
111 if ( fgQAResultFileName.Contains("local://"))
112 fgQAResultFileName.ReplaceAll("local:/", "") ;
115 if ( !gSystem->AccessPathName(fgQAResultFileName) )
119 fgQAResultFile = TFile::Open(fgQAResultFileName, opt) ;
121 return fgQAResultFile ;
124 //_____________________________________________________________________________
125 AliQualAssCheckerBase * AliQualAssChecker::GetDetQualAssChecker(Int_t det)
127 // Gets the Quality Assurance checker for the detector specified by its name
130 return fCheckers[det];
132 TString detName(AliQualAss::GetDetName(det)) ;
134 AliInfo(Form("Retrieving QA checker for %s", detName.Data())) ;
135 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
136 TString qacName = "Ali" + detName + "QualAssChecker" ;
138 AliQualAssCheckerBase * qac = NULL ;
139 // first check if a plugin is defined for the quality assurance checker
140 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQualAssChecker", detName.Data());
141 // if not, add a plugin for it
142 if (!pluginHandler) {
143 //AliInfo(Form("defining plugin for %s", qacName.Data()));
144 TString libs = gSystem->GetLibraries();
146 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
147 pluginManager->AddHandler("AliQualAssChecker", detName, qacName, detName + "qac", qacName + "()");
149 pluginManager->AddHandler("AliQualAssChecker", detName, qacName, detName, qacName + "()");
151 pluginHandler = pluginManager->FindHandler("AliQualAssChecker", detName);
153 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
154 qac = (AliQualAssCheckerBase *) pluginHandler->ExecPlugin(0);
157 fCheckers[det] = qac ;
164 //_____________________________________________________________________________
165 TDirectory * AliQualAssChecker::GetRefSubDir(const char * det, const char * task)
167 // Opens and returns the file with the reference data
168 TFile * f = TFile::Open(fRefDirName, "READ") ;
170 AliFatal(Form("Cannot find reference file %s", fRefDirName.Data())) ;
171 TDirectory * rv = NULL ;
172 rv = f->GetDirectory(det) ;
174 AliWarning(Form("Directory %s not found in %d", det, fRefDirName.Data())) ;
176 rv = rv->GetDirectory(task) ;
178 AliWarning(Form("Directory %s/%s not found in %s", det, task, fRefDirName.Data())) ;
183 //_____________________________________________________________________________
184 Bool_t AliQualAssChecker::Run()
186 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
190 TStopwatch stopwatch;
193 //search for all detectors QA directories
194 TList * detKeyList = GetDataFile()->GetListOfKeys() ;
195 TIter nextd(detKeyList) ;
197 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
198 AliInfo(Form("Found %s", detKey->GetName())) ;
199 //Check which detector
201 TString detNameQA(detKey->GetName()) ;
203 for ( det = 0; det < AliQualAss::kNDET ; det++) {
204 detName = AliQualAss::GetDetName(det) ;
205 if (detNameQA.Contains(detName)) {
206 fFoundDetectors+=detName ;
207 fFoundDetectors+="." ;
211 TDirectory * detDir = GetDataFile()->GetDirectory(detKey->GetName()) ;
212 TList * taskKeyList = detDir->GetListOfKeys() ;
213 TIter nextt(taskKeyList) ;
215 // now search for the tasks dir
216 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
217 TString taskName( taskKey->GetName() ) ;
218 AliInfo(Form("Found %s", taskName.Data())) ;
219 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
221 AliQualAssCheckerBase * qac = GetDetQualAssChecker(det) ;
223 AliInfo(Form("QA checker found for %s", detName.Data())) ;
225 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
226 AliQualAss::ALITASK index = AliQualAss::kNULLTASK ;
227 if ( taskName == AliQualAss::GetTaskName(AliQualAss::kHITS) )
228 index = AliQualAss::kSIM ;
229 if ( taskName == AliQualAss::GetTaskName(AliQualAss::kSDIGITS) )
230 index = AliQualAss::kSIM ;
231 if ( taskName == AliQualAss::GetTaskName(AliQualAss::kDIGITS) )
232 index = AliQualAss::kSIM ;
233 if ( taskName == AliQualAss::GetTaskName(AliQualAss::kRECPOINTS) )
234 index = AliQualAss::kREC ;
235 if ( taskName == AliQualAss::GetTaskName(AliQualAss::kTRACKSEGMENTS) )
236 index = AliQualAss::kREC ;
237 if ( taskName == AliQualAss::GetTaskName(AliQualAss::kRECPARTICLES) )
238 index = AliQualAss::kREC ;
239 if ( taskName == AliQualAss::GetTaskName(AliQualAss::kESDS) )
240 index = AliQualAss::kESD ;
241 qac->Init(AliQualAss::DETECTORINDEX(det)) ;
242 qac->SetRefandData(GetRefSubDir(detNameQA.Data(), taskName.Data()), taskDir) ;
246 AliInfo("QA performed for following detectors:") ;
247 for ( Int_t det = 0; det < AliQualAss::kNDET; det++) {
248 if (fFoundDetectors.Contains(AliQualAss::GetDetName(det))) {
249 printf("%s, ",AliQualAss::GetDetName(det)) ;
250 fFoundDetectors.ReplaceAll(AliQualAss::GetDetName(det), "") ;
260 //_____________________________________________________________________________
261 void AliQualAssChecker::SetQAResultDirName(const char * name)
263 // Set the root directory where to store the QA status object
265 fgQAResultDirName.Prepend(name) ;
266 AliInfo(Form("QA results are in %s", fgQAResultDirName.Data())) ;
267 if ( fgQAResultDirName.Contains("local://"))
268 fgQAResultDirName.ReplaceAll("local:/", "") ;
269 fgQAResultFileName.Prepend(fgQAResultDirName) ;
272 //_____________________________________________________________________________
273 void AliQualAssChecker::SetRefDirName(const char * name)
275 // Set the root directory of reference data
277 fRefDirName.Prepend(name) ;
278 fRefDirName.Append(fRefName) ;
279 AliInfo(Form("Reference data are taken from %s", fRefDirName.Data())) ;
280 if ( fRefDirName.Contains("local://"))
281 fRefDirName.ReplaceAll("local:/", "") ;