]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQAChecker.cxx
datamember added in AliGeomManager with number of alignable volumes per subdetector...
[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"
1aaf4118 27#include "AliRunInfo.h"
421ab0fb 28#include "AliLog.h"
29#include "AliModule.h"
2e42b4d4 30#include "AliQA.h"
31#include "AliQAChecker.h"
32#include "AliQACheckerBase.h"
a2b64fbd 33#include "AliCorrQAChecker.h"
401b84d6 34#include "AliGlobalQAChecker.h"
44e45fac 35#include "AliGRPObject.h"
421ab0fb 36
a5fa6165 37#include <TKey.h>
421ab0fb 38#include <TObjArray.h>
cbae8032 39#include <TObjString.h>
a5fa6165 40#include <TPluginManager.h>
41#include <TROOT.h>
421ab0fb 42#include <TStopwatch.h>
43#include <TString.h>
a5fa6165 44#include <TSystem.h>
a4976ef3 45#include <TList.h>
a2b64fbd 46#include <TNtupleD.h>
421ab0fb 47
2e42b4d4 48ClassImp(AliQAChecker)
49 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
421ab0fb 50
51//_____________________________________________________________________________
2e42b4d4 52AliQAChecker::AliQAChecker(const char* name, const char* title) :
421ab0fb 53 TNamed(name, title),
a5fa6165 54 fDataFile(0x0),
7e88424f 55 fRunInfo(0x0),
56 fRunInfoOwner(kFALSE),
4edbc5bc 57 fRefFile(0x0),
a5fa6165 58 fFoundDetectors(".")
421ab0fb 59{
a5fa6165 60 // ctor: initialise checkers and open the data file
2e42b4d4 61 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
a5fa6165 62 fCheckers[det] = NULL ;
421ab0fb 63}
64
65//_____________________________________________________________________________
2e42b4d4 66AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
421ab0fb 67 TNamed(qac),
a5fa6165 68 fDataFile(qac.fDataFile),
7e88424f 69 fRunInfo(qac.fRunInfo),
70 fRunInfoOwner(kFALSE),
4edbc5bc 71 fRefFile(qac.fRefFile),
a5fa6165 72 fFoundDetectors(qac.fFoundDetectors)
421ab0fb 73{
a5fa6165 74 // copy constructor
75
2e42b4d4 76 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
a5fa6165 77 fCheckers[det] = NULL ;
421ab0fb 78}
79
80//_____________________________________________________________________________
2e42b4d4 81AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
421ab0fb 82{
83// assignment operator
84
2e42b4d4 85 this->~AliQAChecker();
86 new(this) AliQAChecker(qac);
421ab0fb 87 return *this;
88}
89
90//_____________________________________________________________________________
2e42b4d4 91AliQAChecker::~AliQAChecker()
421ab0fb 92{
93// clean up
7e88424f 94 if (fRunInfo)
95 delete fRunInfo ;
a4976ef3 96 delete [] fCheckers ;
8bea2de0 97 AliQA::Close() ;
421ab0fb 98}
99
100//_____________________________________________________________________________
2e42b4d4 101 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
421ab0fb 102{
7ce961eb 103 // Gets the Quality Assurance checker for the detector specified by its name
104
105 if (fCheckers[det])
a5fa6165 106 return fCheckers[det];
107
401b84d6 108 AliQACheckerBase * qac = NULL ;
a5fa6165 109
401b84d6 110 TString detName(AliQA::GetDetName(det)) ;
111
112 if (det == AliQA::kGLOBAL) {
113 qac = new AliGlobalQAChecker() ;
a2b64fbd 114 } else if (det == AliQA::kCORR) {
115 qac = new AliCorrQAChecker() ;
401b84d6 116 } else {
117 AliDebug(1, Form("Retrieving QA checker for %s", detName.Data())) ;
118 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
119 TString qacName = "Ali" + detName + "QAChecker" ;
120
121 // first check if a plugin is defined for the quality assurance checker
122 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
123 // if not, add a plugin for it
124 if (!pluginHandler) {
125 //AliInfo(Form("defining plugin for %s", qacName.Data()));
126 TString libs = gSystem->GetLibraries();
7ce961eb 127
401b84d6 128 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
129 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
130 else
131 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
a5fa6165 132
401b84d6 133 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
a5fa6165 134
401b84d6 135 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
136 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
a5fa6165 137
401b84d6 138 }
7ce961eb 139 }
401b84d6 140 if (qac)
141 fCheckers[det] = qac ;
142
143 return qac ;
a5fa6165 144}
cbae8032 145
a5fa6165 146//_____________________________________________________________________________
f73f556a 147void AliQAChecker::GetRefSubDir(const char * det, const char * task, TDirectory *& dirFile, TObjArray *& dirOCDB)
a5fa6165 148{
149 // Opens and returns the file with the reference data
4edbc5bc 150
cbae8032 151 dirFile = NULL ;
152 dirOCDB = NULL ;
153 TString refStorage(AliQA::GetQARefStorage()) ;
154 //refStorage += AliQA::GetQARefFileName() ;
155 if (refStorage.Contains(AliQA::GetLabLocalFile())) {
156 refStorage.ReplaceAll(AliQA::GetLabLocalFile(), "") ;
157 if ( fRefFile )
158 if ( fRefFile->IsOpen() )
7ce961eb 159 fRefFile->Close() ;
cbae8032 160 fRefFile = TFile::Open(refStorage.Data()) ;
161 if (!fRefFile) {
162 AliError(Form("Cannot find reference file %s", refStorage.Data())) ;
163 dirFile = NULL ;
164 }
165 dirFile = fRefFile->GetDirectory(det) ;
166 if (!dirFile) {
167 AliWarning(Form("Directory %s not found in %d", det, refStorage.Data())) ;
168 } else {
7ce961eb 169 dirFile = dirFile->GetDirectory(task) ;
cbae8032 170 if (!dirFile)
7ce961eb 171 AliWarning(Form("Directory %s/%s not found in %s", det, task, refStorage.Data())) ;
cbae8032 172 }
173 } else if (refStorage.Contains(AliQA::GetLabLocalOCDB()) || refStorage.Contains(AliQA::GetLabAliEnOCDB())) {
174 AliCDBManager* man = AliCDBManager::Instance() ;
175 if ( strcmp(AliQA::GetRefDataDirName(), "") == 0 ) { // the name of the last level of the directory is not set (RUNTYPE)
7e88424f 176 // Get it from RunInfo
177 if (!fRunInfo) // not yet set, get the info from GRP
178 LoadRunInfoFromGRP() ;
179 AliQA::SetQARefDataDirName(fRunInfo->GetRunType()) ;
cbae8032 180 }
181 if ( ! man->GetLock() ) {
182 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
183 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
184 }
185 char * detOCDBDir = Form("%s/%s/%s", det, AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ;
186 AliInfo(Form("Reference QA data are taken from %s", detOCDBDir)) ;
187 AliCDBEntry * entry = man->Get(detOCDBDir, man->GetRun()) ;
188 if (entry) {
189 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
190 if ( listDetQAD )
7ce961eb 191 dirOCDB = dynamic_cast<TObjArray *>(listDetQAD->FindObject(task)) ;
cbae8032 192 }
193 }
421ab0fb 194}
195
a4976ef3 196//_____________________________________________________________________________
2e42b4d4 197AliQAChecker * AliQAChecker::Instance()
a4976ef3 198{
199 // returns unique instance of the checker
200 if ( ! fgQAChecker )
2e42b4d4 201 fgQAChecker = new AliQAChecker() ;
a4976ef3 202 return fgQAChecker ;
203}
204
cbae8032 205//_____________________________________________________________________________
7e88424f 206void AliQAChecker::LoadRunInfoFromGRP()
cbae8032 207{
208 AliCDBManager* man = AliCDBManager::Instance() ;
209 AliCDBEntry* entry = man->Get(AliQA::GetGRPPath().Data());
44e45fac 210 AliGRPObject* grpObject = 0x0;
211 if (entry) {
212
213 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
214
215 if (m) {
216 AliInfo("It is a map");
217 //m->Print();
218 grpObject = new AliGRPObject();
219 grpObject->ReadValuesFromMap(m);
220 }
221
222 else {
223 AliInfo("It is a new GRP object");
224 grpObject = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
225 }
226
227 entry->SetOwner(0);
228 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
229 }
230
231 if (!grpObject) {
232 AliFatal("No GRP entry found in OCDB!");
cbae8032 233 }
44e45fac 234
235 TString lhcState = grpObject->GetLHCState();
236 if (lhcState==AliGRPObject::GetInvalidString()) {
237 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
238 lhcState = "UNKNOWN";
239 }
240
241 TString beamType = grpObject->GetBeamType();
242 if (beamType==AliGRPObject::GetInvalidString()) {
243 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
244 beamType = "UNKNOWN";
cbae8032 245 }
44e45fac 246
247 Float_t beamEnergy = grpObject->GetBeamEnergy();
248 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
249 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
250 beamEnergy = 0;
cbae8032 251 }
44e45fac 252
253 TString runType = grpObject->GetRunType();
254 if (runType==AliGRPObject::GetInvalidString()) {
255 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
256 runType = "UNKNOWN";
7e88424f 257 }
44e45fac 258
259 Int_t activeDetectors = grpObject->GetDetectorMask();
260 if (activeDetectors==AliGRPObject::GetInvalidInt()) {
261 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
262 activeDetectors = 1074790399;
cbae8032 263 }
44e45fac 264
265 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
266
7e88424f 267 fRunInfoOwner = kTRUE ;
cbae8032 268}
269
421ab0fb 270//_____________________________________________________________________________
808b7099 271Bool_t AliQAChecker::Run(const char * fileName)
421ab0fb 272{
a5fa6165 273 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, recpoints, tracksegments, recparticles and ESDs
a4976ef3 274 // starting from data in file
421ab0fb 275
276 Bool_t rv = kFALSE ;
a5fa6165 277
421ab0fb 278 TStopwatch stopwatch;
279 stopwatch.Start();
280
a5fa6165 281 //search for all detectors QA directories
8bea2de0 282 TList * detKeyList = AliQA::GetQADataFile(fileName)->GetListOfKeys() ;
a5fa6165 283 TIter nextd(detKeyList) ;
284 TKey * detKey ;
285 while ( (detKey = dynamic_cast<TKey *>(nextd()) ) ) {
54a7f3ac 286 AliDebug(1, Form("Found %s", detKey->GetName())) ;
a5fa6165 287 //Check which detector
288 TString detName ;
289 TString detNameQA(detKey->GetName()) ;
290 Int_t det ;
2e42b4d4 291 for ( det = 0; det < AliQA::kNDET ; det++) {
292 detName = AliQA::GetDetName(det) ;
a5fa6165 293 if (detNameQA.Contains(detName)) {
294 fFoundDetectors+=detName ;
295 fFoundDetectors+="." ;
296 break ;
297 }
298 }
8bea2de0 299 TDirectory * detDir = AliQA::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
a5fa6165 300 TList * taskKeyList = detDir->GetListOfKeys() ;
301 TIter nextt(taskKeyList) ;
302 TKey * taskKey ;
303 // now search for the tasks dir
304 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
305 TString taskName( taskKey->GetName() ) ;
306 AliInfo(Form("Found %s", taskName.Data())) ;
307 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
308 taskDir->cd() ;
2e42b4d4 309 AliQACheckerBase * qac = GetDetQAChecker(det) ;
a5fa6165 310 if (qac)
a4976ef3 311 AliInfo(Form("QA checker found for %s", detName.Data())) ;
a5fa6165 312 if (!qac)
a4976ef3 313 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
96d67a8d 314 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
2e42b4d4 315 if ( taskName == AliQA::GetTaskName(AliQA::kHITS) )
316 index = AliQA::kSIM ;
317 if ( taskName == AliQA::GetTaskName(AliQA::kSDIGITS) )
318 index = AliQA::kSIM ;
319 if ( taskName == AliQA::GetTaskName(AliQA::kDIGITS) )
320 index = AliQA::kSIM ;
321 if ( taskName == AliQA::GetTaskName(AliQA::kRECPOINTS) )
322 index = AliQA::kREC ;
323 if ( taskName == AliQA::GetTaskName(AliQA::kTRACKSEGMENTS) )
324 index = AliQA::kREC ;
325 if ( taskName == AliQA::GetTaskName(AliQA::kRECPARTICLES) )
326 index = AliQA::kREC ;
327 if ( taskName == AliQA::GetTaskName(AliQA::kESDS) )
328 index = AliQA::kESD ;
96d67a8d 329 qac->Init(AliQA::DETECTORINDEX_t(det)) ;
10a28129 330
f73f556a 331 TDirectory * refDir = NULL ;
332 TObjArray * refOCDBDir = NULL ;
4edbc5bc 333 GetRefSubDir(detNameQA.Data(), taskName.Data(), refDir, refOCDBDir) ;
334 if ( refDir || refOCDBDir) {
335 qac->SetRefandData(refDir, refOCDBDir, taskDir) ;
336 qac->Run(index) ;
ac2bb64a 337 }
4edbc5bc 338 }
339 }
a5fa6165 340 AliInfo("QA performed for following detectors:") ;
2e42b4d4 341 for ( Int_t det = 0; det < AliQA::kNDET; det++) {
342 if (fFoundDetectors.Contains(AliQA::GetDetName(det))) {
343 printf("%s, ",AliQA::GetDetName(det)) ;
344 fFoundDetectors.ReplaceAll(AliQA::GetDetName(det), "") ;
a5fa6165 345 }
421ab0fb 346 }
a5fa6165 347 printf("\n") ;
348 rv = kTRUE ;
421ab0fb 349
a5fa6165 350 return rv ;
351
421ab0fb 352}
353
a4976ef3 354//_____________________________________________________________________________
a2b64fbd 355Bool_t AliQAChecker::Run(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, TObject * obj)
a4976ef3 356{
d6372ce8 357 // run the Quality Assurance Checker for detector det, for task task starting from data in list
a4976ef3 358
d6372ce8 359 AliQACheckerBase * qac = GetDetQAChecker(det) ;
360 if (qac)
361 AliDebug(1, Form("QA checker found for %s", AliQA::GetDetName(det).Data())) ;
362 if (!qac)
363 AliError(Form("QA checker not found for %s", AliQA::GetDetName(det).Data())) ;
a4976ef3 364
d6372ce8 365 AliQA::ALITASK_t index = AliQA::kNULLTASK ;
366 if ( task == AliQA::kRAWS )
2e42b4d4 367 index = AliQA::kRAW ;
d6372ce8 368 else if ( task == AliQA::kHITS )
2e42b4d4 369 index = AliQA::kSIM ;
d6372ce8 370 else if ( task == AliQA::kSDIGITS )
2e42b4d4 371 index = AliQA::kSIM ;
d6372ce8 372 else if ( task == AliQA::kDIGITS )
2e42b4d4 373 index = AliQA::kSIM ;
d6372ce8 374 else if ( task == AliQA::kRECPOINTS )
2e42b4d4 375 index = AliQA::kREC ;
d6372ce8 376 else if ( task == AliQA::kTRACKSEGMENTS )
2e42b4d4 377 index = AliQA::kREC ;
d6372ce8 378 else if ( task == AliQA::kRECPARTICLES )
2e42b4d4 379 index = AliQA::kREC ;
d6372ce8 380 else if ( task == AliQA::kESDS )
2e42b4d4 381 index = AliQA::kESD ;
4edbc5bc 382
d6372ce8 383 TDirectory * refDir = NULL ;
384 TObjArray * refOCDBDir = NULL ;
385 qac->Init(det) ;
4edbc5bc 386 GetRefSubDir(AliQA::GetDetName(det), AliQA::GetTaskName(task), refDir, refOCDBDir) ;
d6372ce8 387 if ( refDir || refOCDBDir) // references found
4edbc5bc 388 qac->SetRefandData(refDir, refOCDBDir) ;
a2b64fbd 389
390 TString className(obj->ClassName()) ;
391 if (className.Contains(TObjArray::Class()->GetName())) {
392 qac->Run(index, static_cast<TObjArray *>(obj)) ;
393 } else if (className.Contains(TNtupleD::Class()->GetName())) {
394 qac->Run(index, static_cast<TNtupleD *>(obj)) ;
395 } else {
396 AliError(Form("%s class not implemented", className.Data())) ;
397 return kFALSE ;
398 }
d6372ce8 399 return kTRUE ;
31316597 400}