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"
27 #include "AliEventInfo.h"
29 #include "AliModule.h"
31 #include "AliQAChecker.h"
32 #include "AliQACheckerBase.h"
35 #include <TObjArray.h>
36 #include <TObjString.h>
37 #include <TPluginManager.h>
39 #include <TStopwatch.h>
44 ClassImp(AliQAChecker)
45 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
47 //_____________________________________________________________________________
48 AliQAChecker::AliQAChecker(const char* name, const char* title) :
52 fEventInfoOwner(kFALSE),
56 // ctor: initialise checkers and open the data file
57 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
58 fCheckers[det] = NULL ;
61 //_____________________________________________________________________________
62 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
64 fDataFile(qac.fDataFile),
65 fEventInfo(qac.fEventInfo),
66 fEventInfoOwner(kFALSE),
67 fRefFile(qac.fRefFile),
68 fFoundDetectors(qac.fFoundDetectors)
72 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
73 fCheckers[det] = NULL ;
76 //_____________________________________________________________________________
77 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
79 // assignment operator
81 this->~AliQAChecker();
82 new(this) AliQAChecker(qac);
86 //_____________________________________________________________________________
87 AliQAChecker::~AliQAChecker()
96 //_____________________________________________________________________________
97 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
99 // Gets the Quality Assurance checker for the detector specified by its name
102 return fCheckers[det];
104 TString detName(AliQA::GetDetName(det)) ;
106 AliDebug(1, Form("Retrieving QA checker for %s", detName.Data())) ;
107 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
108 TString qacName = "Ali" + detName + "QAChecker" ;
110 AliQACheckerBase * qac = NULL ;
111 // first check if a plugin is defined for the quality assurance checker
112 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
113 // if not, add a plugin for it
114 if (!pluginHandler) {
115 //AliInfo(Form("defining plugin for %s", qacName.Data()));
116 TString libs = gSystem->GetLibraries();
118 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
119 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
121 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
123 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
125 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
126 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
129 fCheckers[det] = qac ;
135 //_____________________________________________________________________________
136 void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray *& dirOCDB)
138 // Opens and returns the file with the reference data
142 TString refStorage(AliQA::GetQARefStorage()) ;
143 //refStorage += AliQA::GetQARefFileName() ;
144 if (refStorage.Contains(AliQA::GetLabLocalFile())) {
145 refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ;
147 if ( fRefFile->IsOpen() )
149 fRefFile = TFile::Open(refStorage.Data()) ;
151 AliError(Form("Cannot find reference file %s", refStorage.Data())) ;
154 dirFile = fRefFile->GetDirectory(det) ;
156 AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ;
158 dirFile = dirFile->GetDirectory(task) ;
160 AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ;
162 } else if (refStorage.Contains(AliQA::GetLabLocalOCDB()) || refStorage.Contains(AliQA::GetLabAliEnOCDB())) {
163 AliCDBManager* man = AliCDBManager::Instance() ;
164 if ( strcmp(AliQA::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (RUNTYPE)
165 // Get it from EventInfo
166 if (!fEventInfo) // not yet set, get the info from GRP
167 LoadEventInfoFromGRP() ;
169 AliQA::SetQARefDataDirName(fEventInfo->GetRunType()) ;
171 if ( ! man->GetLock() ) {
172 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
173 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
175 char * detOCDBDir = Form("%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ;
176 AliInfo(Form("Reference QA data are taken from %s", detOCDBDir)) ;
177 AliCDBEntry * entry = man->Get(detOCDBDir, man->GetRun()) ;
179 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
181 dirOCDB = dynamic_cast<TObjArray *>(listDetQAD->FindObject(task)) ;
186 //_____________________________________________________________________________
187 AliQAChecker * AliQAChecker::Instance()
189 // returns unique instance of the checker
191 fgQAChecker = new AliQAChecker() ;
195 //_____________________________________________________________________________
196 void AliQAChecker::LoadEventInfoFromGRP()
198 AliCDBManager* man = AliCDBManager::Instance() ;
199 AliCDBEntry* entry = man->Get(AliQA::GetGRPPath().Data());
202 data = dynamic_cast<TMap*>(entry->GetObject());
204 AliFatal("No GRP entry found in OCDB!");
206 TObjString *lhcState=
207 dynamic_cast<TObjString*>(data->GetValue("fLHCState"));
209 AliWarning(Form("%s entry: missing value for the LHC state ! Using UNKNOWN", AliQA::GetGRPPath().Data()));
211 TObjString *beamType=
212 dynamic_cast<TObjString*>(data->GetValue("fAliceBeamType"));
214 AliWarning(Form("%s entry: missing value for the LHC state ! Using UNKNOWN", AliQA::GetGRPPath().Data()));
217 dynamic_cast<TObjString*>(data->GetValue("fRunType"));
219 AliWarning(Form("%s entry: missing value for the run type ! Using UNKNOWN", AliQA::GetGRPPath().Data())); }
220 TObjString *activeDetectors=
221 dynamic_cast<TObjString*>(data->GetValue("fDetectorMask"));
222 if (!activeDetectors) {
223 AliWarning(Form("%s entry: missing value for the detector mask ! Using ALL", AliQA::GetGRPPath().Data()));
225 fEventInfo = new AliEventInfo(lhcState ? lhcState->GetString().Data() : "UNKNOWN",
226 beamType ? beamType->GetString().Data() : "UNKNOWN",
227 runType ? runType->GetString().Data() : "UNKNOWN",
228 activeDetectors ? activeDetectors->GetString().Data() : "ALL");
229 fEventInfoOwner = kTRUE ;
232 //_____________________________________________________________________________
233 Bool_t AliQAChecker::Run(const char * fileName)
235 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
236 // starting from data in file
240 TStopwatch stopwatch;
243 //search for all detectors QA directories
244 TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ;
245 TIter nextd(detKeyList) ;
247 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
248 AliDebug(1, Form("Found %s", detKey->GetName())) ;
249 //Check which detector
251 TString detNameQA(detKey->GetName()) ;
253 for ( det = 0; det < AliQA::kNDET ; det++) {
254 detName = AliQA::GetDetName(det) ;
255 if (detNameQA.Contains(detName)) {
256 fFoundDetectors+=detName ;
257 fFoundDetectors+="." ;
261 TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
262 TList * taskKeyList = detDir->GetListOfKeys() ;
263 TIter nextt(taskKeyList) ;
265 // now search for the tasks dir
266 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
267 TString taskName( taskKey->GetName() ) ;
268 AliInfo(Form("Found %s", taskName.Data())) ;
269 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
271 AliQACheckerBase * qac = GetDetQAChecker(det) ;
273 AliInfo(Form("QA checker found for %s", detName.Data())) ;
275 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
276 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
277 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
278 index = AliQA::kSIM ;
279 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
280 index = AliQA::kSIM ;
281 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
282 index = AliQA::kSIM ;
283 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
284 index = AliQA::kREC ;
285 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
286 index = AliQA::kREC ;
287 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
288 index = AliQA::kREC ;
289 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
290 index = AliQA::kESD ;
291 qac->Init(AliQA::DETECTORINDEX_t(det)) ;
293 TDirectory * refDir = NULL ;
294 TObjArray * refOCDBDir = NULL ;
295 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
296 if ( refDir || refOCDBDir) {
297 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
302 AliInfo("QA performed for following detectors:") ;
303 for ( Int_t det = 0; det < AliQA::kNDET; det++) {
304 if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
305 printf("%s, ",AliQA::GetDetName(det)) ;
306 fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ;
316 //_____________________________________________________________________________
317 Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObjArray * list)
319 // run the Quality Assurance Checker for detector det, for task task starting from data in list
321 AliQACheckerBase * qac = GetDetQAChecker(det) ;
323 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
325 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
327 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
328 if ( task == AliQA::kRAWS )
329 index = AliQA::kRAW ;
330 else if ( task == AliQA::kHITS )
331 index = AliQA::kSIM ;
332 else if ( task == AliQA::kSDIGITS )
333 index = AliQA::kSIM ;
334 else if ( task == AliQA::kDIGITS )
335 index = AliQA::kSIM ;
336 else if ( task == AliQA::kRECPOINTS )
337 index = AliQA::kREC ;
338 else if ( task == AliQA::kTRACKSEGMENTS )
339 index = AliQA::kREC ;
340 else if ( task == AliQA::kRECPARTICLES )
341 index = AliQA::kREC ;
342 else if ( task == AliQA::kESDS )
343 index = AliQA::kESD ;
345 TDirectory * refDir = NULL ;
346 TObjArray * refOCDBDir = NULL ;
348 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
349 if ( refDir || refOCDBDir) // references found
350 qac->SetRefandData(refDir, refOCDBDir) ;
351 qac->Run(index, list) ;