1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for running the Quality Assurance Checker
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliCDBEntry.h"
25 #include "AliQAManager.h"
26 #include "AliCDBStorage.h"
27 #include "AliRunInfo.h"
29 #include "AliModule.h"
31 #include "AliQAChecker.h"
32 #include "AliQACheckerBase.h"
33 #include "AliCorrQAChecker.h"
34 #include "AliGlobalQAChecker.h"
35 #include "AliGRPObject.h"
38 #include <TObjArray.h>
39 #include <TObjString.h>
40 #include <TPluginManager.h>
42 #include <TStopwatch.h>
48 ClassImp(AliQAChecker)
49 AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
51 //_____________________________________________________________________________
52 AliQAChecker::AliQAChecker(const char* name, const char* title) :
56 fRunInfoOwner(kFALSE),
59 fEventSpecie(AliRecoParam::kDefault),
62 // ctor: initialise checkers and open the data file
63 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
64 fCheckers[det] = NULL ;
67 //_____________________________________________________________________________
68 AliQAChecker::AliQAChecker(const AliQAChecker& qac) :
70 fDataFile(qac.fDataFile),
71 fRunInfo(qac.fRunInfo),
72 fRunInfoOwner(kFALSE),
73 fRefFile(qac.fRefFile),
74 fFoundDetectors(qac.fFoundDetectors),
75 fEventSpecie(qac.fEventSpecie),
80 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
81 fCheckers[det] = NULL ;
84 //_____________________________________________________________________________
85 AliQAChecker& AliQAChecker::operator = (const AliQAChecker& qac)
87 // assignment operator
89 this->~AliQAChecker();
90 new(this) AliQAChecker(qac);
94 //_____________________________________________________________________________
95 AliQAChecker::~AliQAChecker()
100 for (Int_t det=0; det<AliQAv1::kNDET; det++)
101 delete fCheckers[det] ;
105 //_____________________________________________________________________________
106 AliQACheckerBase * AliQAChecker::GetDetQAChecker(Int_t det)
108 // Gets the Quality Assurance checker for the detector specified by its name
111 return fCheckers[det];
113 AliQACheckerBase * qac = NULL ;
115 TString detName(AliQAv1::GetDetName(det)) ;
117 if (det == AliQAv1::kGLOBAL) {
118 qac = new AliGlobalQAChecker() ;
119 } else if (det == AliQAv1::kCORR) {
120 qac = new AliCorrQAChecker() ;
122 AliDebugClass(AliQAv1::GetQADebugLevel(), Form("Retrieving QA checker for %s", detName.Data())) ;
123 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
124 TString qacName = "Ali" + detName + "QAChecker" ;
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) {
130 //AliDebug(AliQAv1::GetQADebugLevel(), Form("defining plugin for %s", qacName.Data()));
131 TString libs = gSystem->GetLibraries();
133 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0))
134 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
136 pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
138 pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
140 if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
141 qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
146 fCheckers[det] = qac ;
151 //_____________________________________________________________________________
152 AliQAChecker * AliQAChecker::Instance()
154 // returns unique instance of the checker
156 fgQAChecker = new AliQAChecker() ;
160 //_____________________________________________________________________________
161 void AliQAChecker::LoadRunInfoFromGRP()
163 AliCDBManager* man = AliCDBManager::Instance() ;
164 AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
165 AliGRPObject* grpObject = 0x0;
168 TMap* m = static_cast<TMap*>(entry->GetObject()); // old GRP entry
171 AliDebug(AliQAv1::GetQADebugLevel(), "It is a map");
173 grpObject = new AliGRPObject();
174 grpObject->ReadValuesFromMap(m);
178 AliDebug(AliQAv1::GetQADebugLevel(), "It is a new GRP object");
179 grpObject = static_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
183 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
187 AliFatal("No GRP entry found in OCDB!");
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";
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";
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");
208 TString runType = grpObject->GetRunType();
209 if (runType==AliGRPObject::GetInvalidString()) {
210 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
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;
220 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
222 fRunInfoOwner = kTRUE ;
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 ;
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 ;
243 else if (strcmp(beamType,"-") == 0) {
244 // No beams, we assume cosmic data
245 fEventSpecie = AliRecoParam::kCosmic ;
247 else if (strcmp(beamType,"UNKNOWN") == 0) {
248 // No LHC beam information is available, we use the default event specie
249 fEventSpecie = AliRecoParam::kDefault ;
254 //_____________________________________________________________________________
255 Bool_t AliQAChecker::Run(const char * fileName, AliDetectorRecoParam * recoParam)
257 // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, DigitsR, RecPoints, TrackSegments, RecParticles and ESDs
258 // starting from data in file
259 TStopwatch stopwatch;
262 //search for all detectors QA directories
263 TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ;
264 TIter nextd(detKeyList) ;
266 while ( (detKey = static_cast<TKey *>(nextd()) ) ) {
267 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", detKey->GetName())) ;
268 //Check which detector
270 TString detNameQA(detKey->GetName()) ;
272 for ( det = 0; det < AliQAv1::kNDET ; det++) {
273 detName = AliQAv1::GetDetName(det) ;
274 if (detNameQA.Contains(detName)) {
275 fFoundDetectors+=detName ;
276 fFoundDetectors+="." ;
280 TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
281 TList * taskKeyList = detDir->GetListOfKeys() ;
282 TIter nextt(taskKeyList) ;
284 // now search for the tasks dir
285 while ( (taskKey = static_cast<TKey *>(nextt()) ) ) {
286 TString taskName( taskKey->GetName() ) ;
287 AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", taskName.Data())) ;
288 TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
290 AliQACheckerBase * qac = GetDetQAChecker(det) ;
292 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", detName.Data())) ;
294 AliFatal(Form("QA checker not found for %s", detName.Data())) ;
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 ;
302 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRAWS) )
303 index = AliQAv1::kRAW ;
304 if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITSR) )
305 index = AliQAv1::kREC ;
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)) ;
315 qac->Run(index, recoParam) ;
319 for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
320 if (fFoundDetectors.Contains(AliQAv1::GetDetName(det))) {
321 detList += AliQAv1::GetDetName(det) ;
323 fFoundDetectors.ReplaceAll(AliQAv1::GetDetName(det), "") ;
324 AliQAv1::Instance()->Show(AliQAv1::GetDetIndex(AliQAv1::GetDetName(det))) ;
327 AliInfo(Form("QA performed for following detectors: %s", detList.Data())) ;
331 //_____________________________________________________________________________
332 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TObjArray ** list, AliDetectorRecoParam * recoParam)
334 // run the Quality Assurance Checker for detector det, for task task starting from data in list
336 if (det >= AliQAv1::kNDET) {
337 AliError(Form("det = %i is larger than AliQAv1::kNDET ... should never happen", det));
340 AliQACheckerBase * qac = GetDetQAChecker(det) ;
342 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
344 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
346 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
347 if ( task == AliQAv1::kRAWS )
348 index = AliQAv1::kRAW ;
349 else if ( task == AliQAv1::kHITS )
350 index = AliQAv1::kSIM ;
351 else if ( task == AliQAv1::kSDIGITS )
352 index = AliQAv1::kSIM ;
353 else if ( task == AliQAv1::kDIGITS )
354 index = AliQAv1::kSIM ;
355 else if ( task == AliQAv1::kDIGITSR )
356 index = AliQAv1::kREC ;
357 else if ( task == AliQAv1::kRECPOINTS )
358 index = AliQAv1::kREC ;
359 else if ( task == AliQAv1::kTRACKSEGMENTS )
360 index = AliQAv1::kREC ;
361 else if ( task == AliQAv1::kRECPARTICLES )
362 index = AliQAv1::kREC ;
363 else if ( task == AliQAv1::kESDS )
364 index = AliQAv1::kESD ;
367 qac->Run(index, list, recoParam) ;
370 qac->MakeImage(list, task, AliQAv1::Mode(task)) ;
375 //_____________________________________________________________________________
376 Bool_t AliQAChecker::Run(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, TNtupleD ** list, AliDetectorRecoParam * recoParam)
378 // run the Quality Assurance Checker for detector det, for task task starting from data in list
380 AliQACheckerBase * qac = GetDetQAChecker(det) ;
382 AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", AliQAv1::GetDetName(det).Data())) ;
384 AliError(Form("QA checker not found for %s", AliQAv1::GetDetName(det).Data())) ;
386 AliQAv1::ALITASK_t index = AliQAv1::kNULLTASK ;
387 if ( task == AliQAv1::kRAWS )
388 index = AliQAv1::kRAW ;
389 else if ( task == AliQAv1::kHITS )
390 index = AliQAv1::kSIM ;
391 else if ( task == AliQAv1::kSDIGITS )
392 index = AliQAv1::kSIM ;
393 else if ( task == AliQAv1::kDIGITS )
394 index = AliQAv1::kSIM ;
395 else if ( task == AliQAv1::kDIGITSR )
396 index = AliQAv1::kREC ;
397 else if ( task == AliQAv1::kRECPOINTS )
398 index = AliQAv1::kREC ;
399 else if ( task == AliQAv1::kTRACKSEGMENTS )
400 index = AliQAv1::kREC ;
401 else if ( task == AliQAv1::kRECPARTICLES )
402 index = AliQAv1::kREC ;
403 else if ( task == AliQAv1::kESDS )
404 index = AliQAv1::kESD ;
407 qac->Run(index, list, recoParam) ;