]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskRL.cxx
Updating macro to check the various methods of the AliMUONMCDataInterface
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskRL.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 //-----------------------------------------------------------------
19 //           AliAnalysisTaskRL class
20 //     Task that gives access to the run loader
21 //   Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
22 //-----------------------------------------------------------------
23
24 #include "AliAnalysisTaskRL.h"
25 #include "AliRunLoader.h"
26 #include "AliStack.h"
27 #include "AliHeader.h"
28
29
30 #include <TTree.h>
31 #include <TChain.h>
32 #include <TFile.h>
33
34 ClassImp(AliAnalysisTaskRL)
35
36 //___________________________________________________________________________
37 AliAnalysisTaskRL::AliAnalysisTaskRL() :
38   AliAnalysisTask(),
39   fTree(0), fRunLoader(0),
40   fKinematicsLoaded(kFALSE), fHeaderLoaded(kFALSE) {
41   //
42   // Constructor. Initialization of pointers
43   //
44 }
45
46 //___________________________________________________________________________
47 AliAnalysisTaskRL::AliAnalysisTaskRL(const char *name, const char *title) :
48   AliAnalysisTask(name,title),
49   fTree(0), fRunLoader(0),
50   fKinematicsLoaded(kFALSE), fHeaderLoaded(kFALSE) {
51   // Constructor.
52 }
53
54 //___________________________________________________________________________
55 AliAnalysisTaskRL::~AliAnalysisTaskRL() {
56   //
57   // Destructor
58   //
59   DeleteRunLoader();
60 }
61
62 //___________________________________________________________________________
63 Bool_t AliAnalysisTaskRL::GetEntry(Long64_t ientry) {
64   //returns the entry of the run loader
65   if(fRunLoader) {
66     if(fRunLoader->GetEvent((Int_t)ientry) != 0)
67       return kFALSE;
68   }
69   return kTRUE;
70 }
71
72 //___________________________________________________________________________
73 Bool_t AliAnalysisTaskRL::Notify() {
74 // The file has changed or there is a new tree. Delete the run loader.
75    DeleteRunLoader();
76    return kTRUE;
77 }   
78
79 //___________________________________________________________________________
80 AliRunLoader *AliAnalysisTaskRL::GetRunLoader() {
81   // Returns AliRun instance corresponding to current ESD active in fTree
82   // Loads galice.root, the file is identified by replacing "AliESDs" to
83   // "galice" in the file path of the ESD file. 
84
85   fTree = (TTree *)AliAnalysisTask::GetInputData(0);
86       
87   if (!fRunLoader) {
88     if (!fTree->GetCurrentFile())
89       return 0;
90     
91     TString fileName(fTree->GetCurrentFile()->GetName());
92     printf("Current file %s \n", fileName.Data());
93     
94     fileName.ReplaceAll("AliESDs", "galice");
95     
96     // temporary workaround for PROOF bug #18505
97     fileName.ReplaceAll("#galice.root#galice.root", "#galice.root");
98     
99     fRunLoader = AliRunLoader::Open(fileName);
100     if (!fRunLoader)
101       return 0;
102     fRunLoader->GetEvent((Int_t)(fTree->GetTree()->GetReadEntry()));
103   }
104   
105   return fRunLoader;
106 }
107
108 //___________________________________________________________________________
109 void AliAnalysisTaskRL::DeleteRunLoader() {
110   //
111   // deletes the runloader
112   //
113   if (fRunLoader) {
114     fRunLoader->Delete();
115     fRunLoader = 0;
116   }
117   
118   fKinematicsLoaded = kFALSE;
119   fHeaderLoaded = kFALSE;
120 }
121
122 //___________________________________________________________________________
123 AliHeader* AliAnalysisTaskRL::GetHeader() {
124   // Returns header retrieved from RunLoader
125   
126   AliRunLoader* runLoader = GetRunLoader();
127   if (!runLoader)
128     return 0;
129   
130   if (fHeaderLoaded == kFALSE)
131     if (runLoader->LoadHeader() != 0)
132       return 0;
133   
134   fHeaderLoaded = kTRUE;
135   
136   return runLoader->GetHeader();
137 }
138
139 //___________________________________________________________________________
140 AliStack* AliAnalysisTaskRL::GetStack() {
141   // Returns stack retrieved from RunLoader
142   
143   AliRunLoader* runLoader = GetRunLoader();
144   if (!runLoader)
145     return 0;
146   
147   if (fKinematicsLoaded == kFALSE)
148     if (runLoader->LoadKinematics() != 0)
149       return 0;
150   
151   fKinematicsLoaded = kTRUE;
152   
153   return runLoader->Stack();
154 }