]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMakerSteer.cxx
Changed the call to the QA data maker in AliSimulation
[u/mrichter/AliRoot.git] / STEER / AliQADataMakerSteer.cxx
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 #include <TFile.h>
19 #include <TPluginManager.h>
20 #include <TROOT.h>
21 #include <TString.h>
22 #include <TSystem.h>
23
24 #include "AliESDEvent.h"
25 #include "AliLog.h"
26 #include "AliModule.h"
27 #include "AliQA.h"
28 #include "AliQADataMaker.h"
29 #include "AliQADataMakerSteer.h" 
30 #include "AliRawReaderRoot.h"
31 #include "AliRun.h"
32 #include "AliRunLoader.h"
33
34 ClassImp(AliQADataMakerSteer) 
35
36 //_____________________________________________________________________________
37 AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) :
38         TNamed(name, title), 
39         fCycleSame(kFALSE),
40         fESD(NULL), 
41         fESDTree(NULL),
42         fFirst(kTRUE),  
43         fGAliceFileName(gAliceFilename), 
44         fRunNumber(0), 
45         fNumberOfEvents(0), 
46         fRawReader(NULL), 
47         fRunLoader(NULL)  
48 {
49         // default ctor
50         for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
51                 fLoader[iDet]      = NULL ;
52                 fQADataMaker[iDet] = NULL ;
53                 fQACycles[iDet]    = 999999 ;   
54         }       
55 }
56
57 //_____________________________________________________________________________
58 AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) : 
59         TNamed(qas), 
60         fCycleSame(kFALSE),
61         fESD(NULL), 
62         fESDTree(NULL), 
63         fFirst(qas.fFirst),  
64         fGAliceFileName(qas.fGAliceFileName), 
65         fRunNumber(qas.fRunNumber), 
66         fNumberOfEvents(qas.fNumberOfEvents), 
67         fRawReader(NULL), 
68         fRunLoader(NULL)  
69 {
70         // cpy ctor
71         for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
72                 fLoader[iDet]      = qas.fLoader[iDet] ;
73                 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
74                 fQACycles[iDet]    = qas.fQACycles[iDet] ;      
75         }
76 }
77
78 //_____________________________________________________________________________
79 AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas) 
80 {
81         // assignment operator
82   this->~AliQADataMakerSteer() ;
83   new(this) AliQADataMakerSteer(qas) ;
84   return *this ;
85 }
86
87 //_____________________________________________________________________________
88 AliQADataMakerSteer::~AliQADataMakerSteer() 
89 {
90         // dtor
91   for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
92     fLoader[iDet] = NULL;
93         if (fQADataMaker[iDet]) {
94                 (fQADataMaker[iDet])->Finish() ; 
95                 delete fQADataMaker[iDet] ;
96                 fQADataMaker[iDet] = NULL ;
97         }
98   }
99
100   fRunLoader = NULL ;
101   delete fRawReader ;
102   fRawReader = NULL ;
103 }
104
105 //_____________________________________________________________________________
106 AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
107 {
108         // get the loader for a detector
109         
110         TString detName = AliQA::GetDetName(iDet) ;
111     fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
112         if (fLoader[iDet]) 
113                 return fLoader[iDet] ;
114         
115         // load the QA data maker object
116         TPluginManager* pluginManager = gROOT->GetPluginManager() ;
117         TString loaderName = "Ali" + detName + "Loader" ;
118
119         AliLoader * loader = NULL ;
120         // first check if a plugin is defined for the quality assurance data maker
121         TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
122         // if not, add a plugin for it
123         if (!pluginHandler) {
124                 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
125                 TString libs = gSystem->GetLibraries() ;
126                 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
127                         pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
128                 } else {
129                         pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
130                 }
131                 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
132         }
133         if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
134                 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
135         }
136         if (loader) 
137                 fLoader[iDet] = loader ;
138         return loader ;
139 }
140
141 //_____________________________________________________________________________
142 AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet)
143 {
144         // get the quality assurance data maker for a detector
145         
146         if (fQADataMaker[iDet]) 
147                 return fQADataMaker[iDet] ;
148         
149         AliQADataMaker * qadm = NULL ;
150         
151         if (fFirst) {
152                 // load the QA data maker object
153                 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
154                 TString detName = AliQA::GetDetName(iDet) ;
155                 TString qadmName = "Ali" + detName + "QADataMaker" ;
156
157                 // first check if a plugin is defined for the quality assurance data maker
158                 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
159                 // if not, add a plugin for it
160                 if (!pluginHandler) {
161                         AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
162                         TString libs = gSystem->GetLibraries() ;
163                         if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
164                                 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
165                         } else {
166                                 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
167                         }
168                         pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
169                 }
170                 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
171                         qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
172                 }
173                 if (qadm) 
174                         fQADataMaker[iDet] = qadm ;
175         }
176         return qadm ;
177 }
178
179 //_____________________________________________________________________________
180 Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const  char * fileName )
181 {
182         // Initialize the event source and QA data makers
183         
184         if (taskIndex == AliQA::kRAWS) {
185                 fRawReader = new AliRawReaderRoot(fileName) ; 
186             if ( ! fRawReader ) 
187                         return kFALSE ; 
188                 fRawReader->NextEvent() ; 
189                 fRunNumber = fRawReader->GetRunNumber() ; 
190                 fRawReader->RewindEvents();
191                 fNumberOfEvents = 999999 ;
192                 
193         } else if (taskIndex == AliQA::kESDS) {
194                 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
195                         TFile * esdFile = TFile::Open("AliESDs.root") ;
196                         fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ; 
197                 fESD     = new AliESDEvent() ;
198             fESD->ReadFromTree(fESDTree) ;
199                         fESDTree->GetEntry(0) ; 
200                         fRunNumber = fESD->GetRunNumber() ; 
201                         fNumberOfEvents = fESDTree->GetEntries() ;
202                 } else {
203                         AliError("AliESDs.root not found") ; 
204                         return kFALSE ; 
205                 }
206                 
207         } else {
208                 if ( !InitRunLoader() ) {
209                         AliError("Problems in getting the Run Loader") ; 
210                         return kFALSE ; 
211                 } else {
212                         fRunNumber      = fRunLoader->GetAliRun()->GetRunNumber() ; 
213                         fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
214                 }
215         }
216                 
217         // Initialize all QA data makers for all detectors
218         for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
219                 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
220                 if (!qadm) {
221                         AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; 
222                 } else {
223                         AliInfo(Form("Data Maker found for %s", qadm->GetName())) ; 
224                         qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ;
225                         qadm->StartOfCycle(taskIndex, fCycleSame) ;
226                 }
227         } 
228         fFirst = kFALSE ;
229         return kTRUE ; 
230 }
231
232 //_____________________________________________________________________________
233 Bool_t AliQADataMakerSteer::InitRunLoader()
234 {
235         // get or create the run loader
236         if (fRunLoader) {
237                 fCycleSame = kTRUE ; 
238                 return kTRUE ;
239         } 
240                 
241         if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
242     // load all base libraries to get the loader classes
243                 TString libs = gSystem->GetLibraries() ;
244                 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
245                         TString detName = AliQA::GetDetName(iDet) ;
246                         if (detName == "HLT") 
247                                 continue;
248                         if (libs.Contains("lib" + detName + "base.so")) 
249                                 continue;
250                         gSystem->Load("lib" + detName + "base.so");
251                 }
252                 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
253                 if (!fRunLoader) {
254                         AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
255                         return kFALSE;
256                 }
257                 fRunLoader->CdGAFile();
258                 if (fRunLoader->LoadgAlice() == 0) {
259                         gAlice = fRunLoader->GetAliRun();
260                 }
261                 if (!gAlice) {
262                         AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
263                         return kFALSE;
264                 }
265
266         } else {               // galice.root does not exist
267                 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
268                 return kFALSE;
269     }
270
271   return kTRUE;
272 }
273
274 //_____________________________________________________________________________
275 Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex) 
276 {
277         // write output to file for all detectors
278         for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
279                 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
280                 if (qadm) {
281                         qadm->EndOfCycle(taskIndex) ; 
282                 }
283         }
284         return kTRUE ; 
285 }
286
287 //_____________________________________________________________________________
288 void AliQADataMakerSteer::Reset()
289 {
290         // Reset the default data members
291         for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
292                 fLoader[iDet] = NULL;
293                 if (fQADataMaker[iDet]) {
294                         (fQADataMaker[iDet])->Reset() ; 
295 //                      delete fQADataMaker[iDet] ;
296 //                      fQADataMaker[iDet] = NULL ;
297                 }
298         }
299
300         delete fRawReader ;
301         fRawReader      = NULL ;
302
303         fCycleSame      = kFALSE ; 
304         fESD            = NULL ; 
305         fESDTree        = NULL ; 
306         fFirst          = kTRUE ;   
307         fNumberOfEvents = 0 ;  
308 }
309
310 //_____________________________________________________________________________
311 Bool_t AliQADataMakerSteer::Run(const AliQA::TASKINDEX taskIndex, const  char * fileName )
312 {
313         // Runs all the QA data Maker for every detector
314         Bool_t rv = kFALSE ;
315         
316         if ( !Init(taskIndex, fileName) ) 
317                 return kFALSE ; 
318                 
319     // Fill QA data in event loop 
320         for (UInt_t iEvent = 0 ; iEvent < fNumberOfEvents ; iEvent++) {
321                 // Get the event
322                 AliInfo(Form("processing event %d", iEvent));
323                 if ( taskIndex == AliQA::kRAWS ) {
324                         if ( !fRawReader->NextEvent() )
325                                 break ;
326                 } else if ( taskIndex == AliQA::kESDS ) {
327                         fESDTree->GetEntry(iEvent) ;
328                 } else {
329                         fRunLoader->GetEvent(iEvent);
330                 }
331                 // loop over detectors
332                 TObjArray* detArray = fRunLoader->GetAliRun()->Detectors() ;
333                 for (UInt_t iDet = 0 ; iDet < fgkNDetectors ; iDet++) {
334                         AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
335                         if (!det || !det->IsActive()) 
336                                 continue;
337                         AliQADataMaker * qadm = GetQADataMaker(iDet) ;
338                         if (!qadm) {
339                                 rv = kFALSE ;
340                         } else {
341                                 if ( qadm->IsCycleDone() ) {
342                                         qadm->EndOfCycle(AliQA::kRAWS) ;
343                                         qadm->StartOfCycle(AliQA::kRAWS) ;
344                                 }
345                                 TTree * data ; 
346                                 switch (taskIndex) {
347                                         case AliQA::kRAWS :
348                                                 qadm->Exec(taskIndex, fRawReader) ; 
349                                         break ; 
350                                         case AliQA::kHITS :
351                                                 GetLoader(iDet)->LoadHits() ; 
352                                                 data = GetLoader(iDet)->TreeH() ; 
353                                                 if ( ! data ) {
354                                                         AliWarning(Form(" Hit Tree not found for  %s", AliQA::GetDetName(iDet))) ; 
355                                                 } else {
356                                                         qadm->Exec(taskIndex, data) ;
357                                                 } 
358                                         break ;
359                                         case AliQA::kSDIGITS :
360                                                 GetLoader(iDet)->LoadSDigits() ; 
361                                                 data = GetLoader(iDet)->TreeS() ; 
362                                                 if ( ! data ) {
363                                                         AliWarning(Form(" SDigit Tree not found for  %s", AliQA::GetDetName(iDet))) ; 
364                                                 } else {
365                                                         qadm->Exec(taskIndex, data) ; 
366                                                 }
367                                         break; 
368                                         case AliQA::kDIGITS :
369                                                 GetLoader(iDet)->LoadDigits() ; 
370                                                 data = GetLoader(iDet)->TreeD() ; 
371                                                 if ( ! data ) {
372                                                         AliWarning(Form(" Digit Tree not found for  %s", AliQA::GetDetName(iDet))) ; 
373                                                 } else {
374                                                         qadm->Exec(taskIndex, data) ;
375                                                 }
376                                         break; 
377                                         case AliQA::kRECPOINTS :
378                                                 GetLoader(iDet)->LoadRecPoints() ; 
379                                                 data = GetLoader(iDet)->TreeR() ; 
380                                                 if (!data) {
381                                                         AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ; 
382                                                 } else {
383                                                         qadm->Exec(taskIndex, data) ; 
384                                                 }
385                                         break; 
386                                         case AliQA::kTRACKSEGMENTS :
387                                         break; 
388                                         case AliQA::kRECPARTICLES :
389                                         break; 
390                                         case AliQA::kESDS :
391                                                 qadm->Exec(taskIndex, fESD) ;
392                                         break; 
393                                 } //task switch
394                                 qadm->Increment() ; 
395                         } //data maker exist
396                 } // detector loop
397         } // event loop 
398         // Save QA data for all detectors
399         rv = Finish(taskIndex) ;
400         return rv ; 
401 }