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