AliRoot Core  3dc7879 (3dc7879)
AliQAChecker.cxx
Go to the documentation of this file.
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 
19 // //
20 // class for running the Quality Assurance Checker
21 // //
23 
24 #include "AliCDBEntry.h"
25 #include "AliQAManager.h"
26 #include "AliCDBStorage.h"
27 #include "AliRunInfo.h"
28 #include "AliLog.h"
29 #include "AliModule.h"
30 #include "AliQAv1.h"
31 #include "AliQAChecker.h"
32 #include "AliQACheckerBase.h"
33 #include "AliCorrQAChecker.h"
34 #include "AliGlobalQAChecker.h"
35 #include "AliGRPObject.h"
36 
37 #include <TKey.h>
38 #include <TObjArray.h>
39 #include <TObjString.h>
40 #include <TPluginManager.h>
41 #include <TROOT.h>
42 #include <TStopwatch.h>
43 #include <TString.h>
44 #include <TSystem.h>
45 #include <TList.h>
46 #include <TNtupleD.h>
47 
48 ClassImp(AliQAChecker)
49  AliQAChecker * AliQAChecker::fgQAChecker = 0x0 ;
50 
51 //_____________________________________________________________________________
52 AliQAChecker::AliQAChecker(const char* name, const char* title) :
53  TNamed(name, title),
54  fDataFile(0x0),
55  fRunInfo(0x0),
56  fRunInfoOwner(kFALSE),
57  fRefFile(0x0),
58  fFoundDetectors("."),
59  fEventSpecie(AliRecoParam::kDefault),
60  fRun(0)
61 {
62  // ctor: initialise checkers and open the data file
63  for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
64  fCheckers[det] = NULL ;
65 }
66 
67 //_____________________________________________________________________________
69  TNamed(qac),
70  fDataFile(qac.fDataFile),
71  fRunInfo(qac.fRunInfo),
72  fRunInfoOwner(kFALSE),
73  fRefFile(qac.fRefFile),
74  fFoundDetectors(qac.fFoundDetectors),
75  fEventSpecie(qac.fEventSpecie),
76  fRun(qac.fRun)
77 {
78  // copy constructor
79 
80  for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
81  fCheckers[det] = NULL ;
82 }
83 
84 //_____________________________________________________________________________
86 {
87 // assignment operator
88 
89  this->~AliQAChecker();
90  new(this) AliQAChecker(qac);
91  return *this;
92 }
93 
94 //_____________________________________________________________________________
96 {
97 // clean up
98  if (fRunInfo)
99  delete fRunInfo ;
100  for (Int_t det=0; det<AliQAv1::kNDET; det++)
101  delete fCheckers[det] ;
102  AliQAv1::Close() ;
103 }
104 
105 //_____________________________________________________________________________
107 {
108  // Gets the Quality Assurance checker for the detector specified by its name
109 
110  if (det<0 || det>=AliQAv1::kNDET) return NULL;
111 
112  if (fCheckers[det])
113  return fCheckers[det];
114 
115  AliQACheckerBase * qac = NULL ;
116 
117  TString detName(AliQAv1::GetDetName(det)) ;
118 
119  if (det == AliQAv1::kGLOBAL) {
120  qac = new AliGlobalQAChecker() ;
121  } else if (det == AliQAv1::kCORR) {
122  qac = new AliCorrQAChecker() ;
123  } else {
124  AliDebugClass(AliQAv1::GetQADebugLevel(), Form("Retrieving QA checker for %s", detName.Data())) ;
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) {
132  //AliDebug(AliQAv1::GetQADebugLevel(), Form("defining plugin for %s", qacName.Data()));
133  TString libs = gSystem->GetLibraries();
134 
135  if (libs.Contains("lib" + detName + "base") || (gSystem->Load("lib" + detName + "base") >= 0))
136  pluginManager->AddHandler("AliQAChecker", detName, qacName, detName + "qac", qacName + "()");
137  else
138  pluginManager->AddHandler("AliQAChecker", detName, qacName, detName, qacName + "()");
139 
140  pluginHandler = pluginManager->FindHandler("AliQAChecker", detName);
141 
142  if (pluginHandler && (pluginHandler->LoadPlugin() == 0))
143  qac = (AliQACheckerBase *) pluginHandler->ExecPlugin(0);
144 
145  }
146  }
147  if (qac)
148  fCheckers[det] = qac ;
149 
150  return qac ;
151 }
152 
153 //_____________________________________________________________________________
155 {
156  // returns unique instance of the checker
157  if ( ! fgQAChecker )
158  fgQAChecker = new AliQAChecker() ;
159  return fgQAChecker ;
160 }
161 
162 //_____________________________________________________________________________
164 {
166  AliCDBEntry* entry = man->Get(AliQAv1::GetGRPPath().Data());
167  AliGRPObject* grpObject = 0x0;
168  if (entry) {
169 
170  TMap* m = static_cast<TMap*>(entry->GetObject()); // old GRP entry
171 
172  if (m) {
173  AliDebug(AliQAv1::GetQADebugLevel(), "It is a map");
174  //m->Print();
175  grpObject = new AliGRPObject();
176  grpObject->ReadValuesFromMap(m);
177  }
178 
179  else {
180  AliDebug(AliQAv1::GetQADebugLevel(), "It is a new GRP object");
181  grpObject = static_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
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!");
190  }
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";
202  }
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;
208  }
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";
214  }
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;
220  }
221 
222  fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
223 
224  fRunInfoOwner = kTRUE ;
225 
226  // set the event specie
228  if (strcmp(runType,"PHYSICS")) {
229  // Not a physics run, the event specie is set to 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
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
244  }
245  else if (strcmp(beamType,"-") == 0) {
246  // No beams, we assume cosmic data
248  }
249  else if (strcmp(beamType,"UNKNOWN") == 0) {
250  // No LHC beam information is available, we use the default event specie
252  }
253  }
254 }
255 
256 //_____________________________________________________________________________
257 Bool_t AliQAChecker::Run(const char * fileName, AliDetectorRecoParam * recoParam)
258 {
259  // run the Quality Assurance Checker for all tasks Hits, SDigits, Digits, DigitsR, RecPoints, TrackSegments, RecParticles and ESDs
260  // starting from data in file
261  TStopwatch stopwatch;
262  stopwatch.Start();
263 
264  //search for all detectors QA directories
265  TList * detKeyList = AliQAv1::GetQADataFile(fileName)->GetListOfKeys() ;
266  TIter nextd(detKeyList) ;
267  TKey * detKey ;
268  while ( (detKey = static_cast<TKey *>(nextd()) ) ) {
269  AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", detKey->GetName())) ;
270  //Check which detector
271  TString detName ;
272  TString detNameQA(detKey->GetName()) ;
273  Int_t det ;
274  for ( det = 0; det < AliQAv1::kNDET ; det++) {
275  detName = AliQAv1::GetDetName(det) ;
276  if (detNameQA.Contains(detName)) {
277  fFoundDetectors+=detName ;
278  fFoundDetectors+="." ;
279  break ;
280  }
281  }
282  TDirectory * detDir = AliQAv1::GetQADataFile(fileName)->GetDirectory(detKey->GetName()) ;
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() ) ;
289  AliDebug(AliQAv1::GetQADebugLevel(), Form("Found %s", taskName.Data())) ;
290  TDirectory * taskDir = detDir->GetDirectory(taskName.Data()) ;
291  taskDir->cd() ;
292  AliQACheckerBase * qac = GetDetQAChecker(det) ;
293  if (qac)
294  AliDebug(AliQAv1::GetQADebugLevel(), Form("QA checker found for %s", detName.Data())) ;
295  if (!qac)
296  AliFatal(Form("QA checker not found for %s", detName.Data())) ;
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 ;
304  if ( taskName == AliQAv1::GetTaskName(AliQAv1::kRAWS) )
305  index = AliQAv1::kRAW ;
306  if ( taskName == AliQAv1::GetTaskName(AliQAv1::kDIGITSR) )
307  index = AliQAv1::kREC ;
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)) ;
317  qac->Run(index, recoParam) ;
318  }
319  }
320  TString detList ;
321  for ( Int_t det = 0; det < AliQAv1::kNDET; det++) {
322  if (fFoundDetectors.Contains(AliQAv1::GetDetName(det))) {
323  detList += AliQAv1::GetDetName(det) ;
324  detList += " " ;
325  fFoundDetectors.ReplaceAll(AliQAv1::GetDetName(det), "") ;
327  }
328  }
329  AliInfo(Form("QA performed for following detectors: %s", detList.Data())) ;
330  return kTRUE ;
331 }
332 
333 //_____________________________________________________________________________
335 {
336  // run the Quality Assurance Checker for detector det, for task task starting from data in list
337 
338  if (det >= AliQAv1::kNDET) {
339  AliError(Form("det = %i is larger than AliQAv1::kNDET ... should never happen", det));
340  return kFALSE ;
341  }
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 
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 
370  qac->Init(det) ;
371  qac->Run(index, list, recoParam) ;
372 
373  // make the image
374  qac->MakeImage(list, task, AliQAv1::Mode(task)) ;
375 
376  return kTRUE ;
377 }
378 
379 //_____________________________________________________________________________
381 {
382  // run the Quality Assurance Checker for detector det, for task task starting from data in list
383 
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  }
391 
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 ;
411 
412  qac->Init(det) ;
413  qac->Run(index, list, recoParam) ;
414 
415  return kTRUE ;
416 }
TString GetRunType() const
Definition: AliGRPObject.h:62
AliQAChecker(const char *name="AliQAChecker", const char *title="Quality Assurance checker for Raws, Hits, Digits and ESDs")
AliRecoParam::EventSpecie_t fEventSpecie
list of detectors checkers
Definition: AliQAChecker.h:56
void LoadRunInfoFromGRP()
UInt_t GetDetectorMask() const
Definition: AliGRPObject.h:60
Bool_t Run(const char *fileName=NULL, AliDetectorRecoParam *recoParam=NULL)
#define TObjArray
ALITASK_t
Definition: AliQAv1.h:26
TROOT * gROOT
static TString GetInvalidString()
Definition: AliGRPObject.h:147
Bool_t fRunInfoOwner
Event info object.
Definition: AliQAChecker.h:52
TString fileName(const char *dir, int runNumber, const char *da, int i, const char *type)
virtual ~AliQAChecker()
AliCDBEntry * Get(const AliCDBId &query, Bool_t forceCaching=kFALSE)
TString GetBeamType() const
Definition: AliGRPObject.h:58
TObject * GetObject()
Definition: AliCDBEntry.h:56
#define AliDebugClass(logLevel, message)
Definition: AliLog.h:313
static void Close()
Definition: AliQAv1.cxx:207
static DETECTORINDEX_t GetDetIndex(const char *name)
Definition: AliQAv1.cxx:348
virtual void Init(const AliQAv1::DETECTORINDEX_t det)
static Int_t GetInvalidInt()
Definition: AliGRPObject.h:148
AliRunInfo * fRunInfo
Data file to check.
Definition: AliQAChecker.h:51
void Show(DETECTORINDEX_t det=kNULLDET) const
Definition: AliQAv1.cxx:824
#define AliInfo(message)
Definition: AliLog.h:484
virtual void MakeImage(TObjArray **list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
void Run(AliQAv1::ALITASK_t tsk, const AliDetectorRecoParam *recoParam=NULL)
AliQACheckerBase * fCheckers[AliQAv1::kNDET]
detectors for which the Quality assurance could be done
Definition: AliQAChecker.h:55
static TFile * GetQADataFile(const char *name, Int_t run)
Definition: AliQAv1.cxx:374
TString fFoundDetectors
Reference Data file.
Definition: AliQAChecker.h:54
void ReadValuesFromMap(const TMap *map)
static const TString GetDetName(DETECTORINDEX_t det)
Definition: AliQAv1.h:62
Definition: AliCDBEntry.h:18
#define AliFatal(message)
Definition: AliLog.h:640
void UnloadFromCache(const char *path)
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
static MODE_t Mode(TASKINDEX_t task)
Definition: AliQAv1.cxx:401
static const TString GetGRPPath()
Definition: AliQAv1.h:64
DETECTORINDEX_t
Definition: AliQAv1.h:23
TASKINDEX_t
Definition: AliQAv1.h:30
static Float_t GetInvalidFloat()
Definition: AliGRPObject.h:146
AliQACheckerBase * GetDetQAChecker(Int_t det)
void SetOwner(Bool_t owner)
Definition: AliCDBEntry.h:64
#define AliError(message)
Definition: AliLog.h:591
TString GetLHCState() const
Definition: AliGRPObject.h:63
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
static Int_t GetQADebugLevel()
Definition: AliQAv1.h:72
static AliQAChecker * Instance()
AliQAChecker & operator=(const AliQAChecker &qac)
static TString GetTaskName(UInt_t tsk)
Definition: AliQAv1.h:90
Float_t GetBeamEnergy() const
static AliQAChecker * fgQAChecker
Definition: AliQAChecker.h:49
static AliQAv1 * Instance()
Definition: AliQAv1.cxx:585