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 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliCDBEntry.h"
25 #include "AliCDBManager.h"
26 #include "AliCDBStorage.h"
28 #include "AliModule.h"
30 #include "AliQAChecker.h"
31 #include "AliQACheckerBase.h"
34 #include <TObjArray.h>
35 #include <TPluginManager.h>
37 #include <TStopwatch.h>
42 ClassImp(AliQAChecker)
43 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
45 //_____________________________________________________________________________
46 AliQAChecker::AliQAChecker(const char* name, const char* title) :
52 // ctor: initialise checkers and open the data file
53 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
54 fCheckers[det] = NULL ;
57 //_____________________________________________________________________________
58 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
60 fDataFile(qac.fDataFile),
61 fRefFile(qac.fRefFile),
62 fFoundDetectors(qac.fFoundDetectors)
66 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
67 fCheckers[det] = NULL ;
70 //_____________________________________________________________________________
71 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
73 // assignment operator
75 this->~AliQAChecker();
76 new(this) AliQAChecker(qac);
80 //_____________________________________________________________________________
81 AliQAChecker::~AliQAChecker()
88 //_____________________________________________________________________________
89 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
91 // Gets the Quality Assurance checker for the detector specified by its name
94 return fCheckers[det];
96 TString detName(AliQA::GetDetName(det)) ;
98 AliDebug(1, Form("Retrieving QA checker for %s", detName.Data())) ;
99 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
100 TString qacName = "Ali" + detName + "QAChecker" ;
102 AliQACheckerBase * qac = NULL ;
103 // first check if a plugin is defined for the quality assurance checker
104 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
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();
110 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
111 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
113 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
115 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
117 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
118 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
121 fCheckers[det] = qac ;
128 //_____________________________________________________________________________
129 void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray *& dirOCDB)
131 // Opens and returns the file with the reference data
135 TString refStorage(AliQA::GetQARefStorage()) ;
136 //refStorage += AliQA::GetQARefFileName() ;
137 if (refStorage.Contains(AliQA::GetLabLocalFile())) {
138 refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ;
140 if ( fRefFile->IsOpen() )
142 fRefFile = TFile::Open(refStorage.Data()) ;
144 AliError(Form("Cannot find reference file %s", refStorage.Data())) ;
147 dirFile = fRefFile->GetDirectory(det) ;
149 AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ;
151 dirFile = dirFile->GetDirectory(task) ;
153 AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ;
155 } else if (refStorage.Contains(AliQA::GetLabLocalOCDB()) || refStorage.Contains(AliQA::GetLabAliEnOCDB())) {
156 AliCDBManager* man = AliCDBManager::Instance() ;
157 if ( ! man->GetLock() ) {
158 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
159 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
161 char detOCDBDir[20] ;
162 sprintf(detOCDBDir, "%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ;
163 AliCDBEntry * entry = man->Get(detOCDBDir, man->GetRun()) ;
165 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
167 dirOCDB = dynamic_cast<TObjArray *>(listDetQAD->FindObject(task)) ;
172 //_____________________________________________________________________________
173 AliQAChecker * AliQAChecker::Instance()
175 // returns unique instance of the checker
177 fgQAChecker = new AliQAChecker() ;
181 //_____________________________________________________________________________
182 Bool_t AliQAChecker::Run(const char * fileName)
184 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
185 // starting from data in file
189 TStopwatch stopwatch;
192 //search for all detectors QA directories
193 TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ;
194 TIter nextd(detKeyList) ;
196 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
197 AliDebug(1, Form("Found %s", detKey->GetName())) ;
198 //Check which detector
200 TString detNameQA(detKey->GetName()) ;
202 for ( det = 0; det < AliQA::kNDET ; det++) {
203 detName = AliQA::GetDetName(det) ;
204 if (detNameQA.Contains(detName)) {
205 fFoundDetectors+=detName ;
206 fFoundDetectors+="." ;
210 TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
211 TList * taskKeyList = detDir->GetListOfKeys() ;
212 TIter nextt(taskKeyList) ;
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()) ;
220 AliQACheckerBase * qac = GetDetQAChecker(det) ;
222 AliInfo(Form("QA checker found for %s", detName.Data())) ;
224 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
225 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
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 ;
240 qac->Init(AliQA::DETECTORINDEX_t(det)) ;
242 TDirectory * refDir = NULL ;
243 TObjArray * refOCDBDir = NULL ;
244 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
245 if ( refDir || refOCDBDir) {
246 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
251 AliInfo("QA performed for following detectors:") ;
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), "") ;
265 //_____________________________________________________________________________
266 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObjArray * list)
268 // run the Quality Assurance Checker for detector det, for task task starting from data in list
270 AliQACheckerBase * qac = GetDetQAChecker(det) ;
272 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
274 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
276 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
277 if ( task == AliQA::kRAWS )
278 index = AliQA::kRAW ;
279 else if ( task == AliQA::kHITS )
280 index = AliQA::kSIM ;
281 else if ( task == AliQA::kSDIGITS )
282 index = AliQA::kSIM ;
283 else if ( task == AliQA::kDIGITS )
284 index = AliQA::kSIM ;
285 else if ( task == AliQA::kRECPOINTS )
286 index = AliQA::kREC ;
287 else if ( task == AliQA::kTRACKSEGMENTS )
288 index = AliQA::kREC ;
289 else if ( task == AliQA::kRECPARTICLES )
290 index = AliQA::kREC ;
291 else if ( task == AliQA::kESDS )
292 index = AliQA::kESD ;
294 TDirectory * refDir = NULL ;
295 TObjArray * refOCDBDir = NULL ;
297 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
298 if ( refDir || refOCDBDir) // references found
299 qac->SetRefandData(refDir, refOCDBDir) ;
300 qac->Run(index, list) ;