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