Corrected protection.
[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"
b03591ab 25#include "AliQAManager.h"
96d67a8d 26#include "AliCDBStorage.h"
1aaf4118 27#include "AliRunInfo.h"
421ab0fb 28#include "AliLog.h"
29#include "AliModule.h"
4e25ac79 30#include "AliQAv1.h"
2e42b4d4 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),
57acd2d2 58 fFoundDetectors("."),
634696f5 59 fEventSpecie(AliRecoParam::kDefault),
60 fRun(0)
421ab0fb 61{
a5fa6165 62 // ctor: initialise checkers and open the data file
4e25ac79 63 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
a5fa6165 64 fCheckers[det] = NULL ;
421ab0fb 65}
66
67//_____________________________________________________________________________
2e42b4d4 68AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
421ab0fb 69 TNamed(qac),
a5fa6165 70 fDataFile(qac.fDataFile),
7e88424f 71 fRunInfo(qac.fRunInfo),
72 fRunInfoOwner(kFALSE),
4edbc5bc 73 fRefFile(qac.fRefFile),
57acd2d2 74 fFoundDetectors(qac.fFoundDetectors),
634696f5 75 fEventSpecie(qac.fEventSpecie),
76 fRun(qac.fRun)
421ab0fb 77{
a5fa6165 78 // copy constructor
79
4e25ac79 80 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
a5fa6165 81 fCheckers[det] = NULL ;
421ab0fb 82}
83
84//_____________________________________________________________________________
2e42b4d4 85AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
421ab0fb 86{
87// assignment operator
88
2e42b4d4 89 this->~AliQAChecker();
90 new(this) AliQAChecker(qac);
421ab0fb 91 return *this;
92}
93
94//_____________________________________________________________________________
2e42b4d4 95AliQAChecker::~AliQAChecker()
421ab0fb 96{
97// clean up
7e88424f 98 if (fRunInfo)
99 delete fRunInfo ;
63424920 100 for (Int_t det=0; det<AliQAv1::kNDET; det++)
101 delete fCheckers[det] ;
4e25ac79 102 AliQAv1::Close() ;
421ab0fb 103}
104
105//_____________________________________________________________________________
2e42b4d4 106 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
421ab0fb 107{
7ce961eb 108 // Gets the Quality Assurance checker for the detector specified by its name
109
110 if (fCheckers[det])
a5fa6165 111 return fCheckers[det];
112
401b84d6 113 AliQACheckerBase * qac = NULL ;
a5fa6165 114
4e25ac79 115 TString detName(AliQAv1::GetDetName(det)) ;
401b84d6 116
4e25ac79 117 if (det == AliQAv1::kGLOBAL) {
401b84d6 118 qac = new AliGlobalQAChecker() ;
4e25ac79 119 } else if (det == AliQAv1::kCORR) {
a2b64fbd 120 qac = new AliCorrQAChecker() ;
401b84d6 121 } else {
634696f5 122 AliDebugClass(AliQAv1::GetQADebugLevel(), Form("Retrieving QA checker for %s", detName.Data())) ;
401b84d6 123 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
124 TString qacName = "Ali" + detName + "QAChecker" ;
125
126 // first check if a plugin is defined for the quality assurance checker
127 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQAChecker", detName.Data());
128 // if not, add a plugin for it
129 if (!pluginHandler) {
5379c4a3 130 //AliDebug(AliQAv1::GetQADebugLevel(), Form("defining plugin for %s", qacName.Data()));
401b84d6 131 TString libs = gSystem->GetLibraries();
7ce961eb 132
401b84d6 133 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
134 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
135 else
136 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
a5fa6165 137
401b84d6 138 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
a5fa6165 139
401b84d6 140 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
141 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
a5fa6165 142
401b84d6 143 }
7ce961eb 144 }
401b84d6 145 if (qac)
146 fCheckers[det] = qac ;
147
148 return qac ;
a5fa6165 149}
421ab0fb 150
151//_____________________________________________________________________________
2e42b4d4 152AliQAChecker * AliQAChecker::Instance()
a4976ef3 153{
154 // returns unique instance of the checker
155 if ( ! fgQAChecker )
2e42b4d4 156 fgQAChecker = new AliQAChecker() ;
a4976ef3 157 return fgQAChecker ;
158}
159
160//_____________________________________________________________________________
7e88424f 161void AliQAChecker::LoadRunInfoFromGRP()
cbae8032 162{
163 AliCDBManager* man = AliCDBManager::Instance() ;
4e25ac79 164 AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
44e45fac 165 AliGRPObject* grpObject = 0x0;
166 if (entry) {
167
eca4fa66 168 TMap* m = static_cast<TMap*>(entry->GetObject()); // old GRP entry
44e45fac 169
170 if (m) {
5379c4a3 171 AliDebug(AliQAv1::GetQADebugLevel(), "It is a map");
44e45fac 172 //m->Print();
173 grpObject = new AliGRPObject();
174 grpObject->ReadValuesFromMap(m);
175 }
176
177 else {
5379c4a3 178 AliDebug(AliQAv1::GetQADebugLevel(), "It is a new GRP object");
eca4fa66 179 grpObject = static_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
44e45fac 180 }
181
182 entry->SetOwner(0);
183 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
184 }
185
186 if (!grpObject) {
187 AliFatal("No GRP entry found in OCDB!");
cbae8032 188 }
44e45fac 189
190 TString lhcState = grpObject->GetLHCState();
191 if (lhcState==AliGRPObject::GetInvalidString()) {
192 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
193 lhcState = "UNKNOWN";
194 }
195
196 TString beamType = grpObject->GetBeamType();
197 if (beamType==AliGRPObject::GetInvalidString()) {
198 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
199 beamType = "UNKNOWN";
cbae8032 200 }
44e45fac 201
202 Float_t beamEnergy = grpObject->GetBeamEnergy();
203 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
204 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
205 beamEnergy = 0;
cbae8032 206 }
44e45fac 207
208 TString runType = grpObject->GetRunType();
209 if (runType==AliGRPObject::GetInvalidString()) {
210 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
211 runType = "UNKNOWN";
7e88424f 212 }
44e45fac 213
214 Int_t activeDetectors = grpObject->GetDetectorMask();
215 if (activeDetectors==AliGRPObject::GetInvalidInt()) {
216 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
217 activeDetectors = 1074790399;
cbae8032 218 }
44e45fac 219
220 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
221
7e88424f 222 fRunInfoOwner = kTRUE ;
57acd2d2 223
224 // set the event specie
225 fEventSpecie = AliRecoParam::kDefault ;
226 if (strcmp(runType,"PHYSICS")) {
227 // Not a physics run, the event specie is set to kCalib
228 fEventSpecie = AliRecoParam::kCalib ;
229 return;
230 }
231 if (strcmp(lhcState,"STABLE_BEAMS") == 0) {
232 // Heavy ion run (any beam tha is not pp, the event specie is set to kHighMult
233 fEventSpecie = AliRecoParam::kHighMult ;
234 if ((strcmp(beamType,"p-p") == 0) ||
235 (strcmp(beamType,"p-") == 0) ||
236 (strcmp(beamType,"-p") == 0) ||
237 (strcmp(beamType,"P-P") == 0) ||
238 (strcmp(beamType,"P-") == 0) ||
239 (strcmp(beamType,"-P") == 0)) {
240 // Proton run, the event specie is set to kLowMult
241 fEventSpecie = AliRecoParam::kLowMult ;
242 }
243 else if (strcmp(beamType,"-") == 0) {
244 // No beams, we assume cosmic data
245 fEventSpecie = AliRecoParam::kCosmic ;
246 }
247 else if (strcmp(beamType,"UNKNOWN") == 0) {
248 // No LHC beam information is available, we use the default event specie
249 fEventSpecie = AliRecoParam::kDefault ;
250 }
251 }
cbae8032 252}
253
254//_____________________________________________________________________________
9c980fe5 255Bool_t AliQAChecker::Run(const char * fileName, AliDetectorRecoParam * recoParam)
421ab0fb 256{
44ed7a66 257 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, DigitsR, RecPoints, TrackSegments, RecParticles and ESDs
57acd2d2 258 // starting from data in file
421ab0fb 259 TStopwatch stopwatch;
260 stopwatch.Start();
c39ee44c 261
a5fa6165 262 //search for all detectors QA directories
4e25ac79 263 TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ;
a5fa6165 264 TIter nextd(detKeyList) ;
265 TKey * detKey ;
eca4fa66 266 while ( (detKey = static_cast<TKey *>(nextd()) ) ) {
5379c4a3 267 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", detKey->GetName())) ;
a5fa6165 268 //Check which detector
269 TString detName ;
270 TString detNameQA(detKey->GetName()) ;
271 Int_t det ;
4e25ac79 272 for ( det = 0; det < AliQAv1::kNDET ; det++) {
273 detName = AliQAv1::GetDetName(det) ;
a5fa6165 274 if (detNameQA.Contains(detName)) {
57acd2d2 275 fFoundDetectors+=detName ;
276 fFoundDetectors+="." ;
277 break ;
a5fa6165 278 }
279 }
4e25ac79 280 TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
a5fa6165 281 TList * taskKeyList = detDir->GetListOfKeys() ;
282 TIter nextt(taskKeyList) ;
283 TKey * taskKey ;
284 // now search for the tasks dir
285 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
286 TString taskName( taskKey->GetName() ) ;
5379c4a3 287 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", taskName.Data())) ;
a5fa6165 288 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
289 taskDir->cd() ;
2e42b4d4 290 AliQACheckerBase * qac = GetDetQAChecker(det) ;
a5fa6165 291 if (qac)
5379c4a3 292 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", detName.Data())) ;
a5fa6165 293 if (!qac)
57acd2d2 294 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
4e25ac79 295 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
296 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kHITS) )
297 index = AliQAv1::kSIM ;
298 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kSDIGITS) )
299 index = AliQAv1::kSIM ;
300 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITS) )
301 index = AliQAv1::kSIM ;
d62b07c8 302 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRAWS) )
303 index = AliQAv1::kRAW ;
44ed7a66 304 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITSR) )
305 index = AliQAv1::kREC ;
4e25ac79 306 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPOINTS) )
307 index = AliQAv1::kREC ;
308 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kTRACKSEGMENTS) )
309 index = AliQAv1::kREC ;
310 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRECPARTICLES) )
311 index = AliQAv1::kREC ;
312 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kESDS) )
313 index = AliQAv1::kESD ;
314 qac->Init(AliQAv1::DETECTORINDEX_t(det)) ;
9c980fe5 315 qac->Run(index, recoParam) ;
57acd2d2 316 }
4edbc5bc 317 }
c39ee44c 318 TString detList ;
4e25ac79 319 for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
2a022cb2 320 if (fFoundDetectors.Contains(AliQAv1::GetDetName(det))) {
321 detList += AliQAv1::GetDetName(det) ;
c39ee44c 322 detList += " " ;
2a022cb2 323 fFoundDetectors.ReplaceAll(AliQAv1::GetDetName(det), "") ;
324 AliQAv1::Instance()->Show(AliQAv1::GetDetIndex(AliQAv1::GetDetName(det))) ;
a5fa6165 325 }
421ab0fb 326 }
c39ee44c 327 AliInfo(Form("QA performed for following detectors: %s", detList.Data())) ;
57acd2d2 328 return kTRUE ;
421ab0fb 329}
330
331//_____________________________________________________________________________
9c980fe5 332Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TObjArray ** list, AliDetectorRecoParam * recoParam)
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)
5379c4a3 338 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
d6372ce8 339 if (!qac)
4e25ac79 340 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
a4976ef3 341
4e25ac79 342 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
343 if ( task == AliQAv1::kRAWS )
344 index = AliQAv1::kRAW ;
345 else if ( task == AliQAv1::kHITS )
346 index = AliQAv1::kSIM ;
347 else if ( task == AliQAv1::kSDIGITS )
348 index = AliQAv1::kSIM ;
349 else if ( task == AliQAv1::kDIGITS )
350 index = AliQAv1::kSIM ;
44ed7a66 351 else if ( task == AliQAv1::kDIGITSR )
352 index = AliQAv1::kREC ;
4e25ac79 353 else if ( task == AliQAv1::kRECPOINTS )
354 index = AliQAv1::kREC ;
355 else if ( task == AliQAv1::kTRACKSEGMENTS )
356 index = AliQAv1::kREC ;
357 else if ( task == AliQAv1::kRECPARTICLES )
358 index = AliQAv1::kREC ;
359 else if ( task == AliQAv1::kESDS )
360 index = AliQAv1::kESD ;
4edbc5bc 361
57acd2d2 362 qac->Init(det) ;
9c980fe5 363 qac->Run(index, list, recoParam) ;
634696f5 364
365 // make the image
366 qac->MakeImage(list, task, AliQAv1::Mode(task)) ;
367
d6372ce8 368 return kTRUE ;
31316597 369}
57acd2d2 370
371//_____________________________________________________________________________
9c980fe5 372Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TNtupleD ** list, AliDetectorRecoParam * recoParam)
57acd2d2 373{
374 // run the Quality Assurance Checker for detector det, for task task starting from data in list
375
376 AliQACheckerBase * qac = GetDetQAChecker(det) ;
377 if (qac)
5379c4a3 378 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
57acd2d2 379 if (!qac)
4e25ac79 380 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
57acd2d2 381
4e25ac79 382 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
383 if ( task == AliQAv1::kRAWS )
384 index = AliQAv1::kRAW ;
385 else if ( task == AliQAv1::kHITS )
386 index = AliQAv1::kSIM ;
387 else if ( task == AliQAv1::kSDIGITS )
388 index = AliQAv1::kSIM ;
389 else if ( task == AliQAv1::kDIGITS )
390 index = AliQAv1::kSIM ;
44ed7a66 391 else if ( task == AliQAv1::kDIGITSR )
392 index = AliQAv1::kREC ;
4e25ac79 393 else if ( task == AliQAv1::kRECPOINTS )
394 index = AliQAv1::kREC ;
395 else if ( task == AliQAv1::kTRACKSEGMENTS )
396 index = AliQAv1::kREC ;
397 else if ( task == AliQAv1::kRECPARTICLES )
398 index = AliQAv1::kREC ;
399 else if ( task == AliQAv1::kESDS )
400 index = AliQAv1::kESD ;
57acd2d2 401
57acd2d2 402 qac->Init(det) ;
9c980fe5 403 qac->Run(index, list, recoParam) ;
634696f5 404
57acd2d2 405 return kTRUE ;
406}