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