]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisTaskRL.cxx
Runloader is updated when moving to next file (quick fix).
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskRL.cxx
CommitLineData
8d169fb2 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>
6b61a3ef 31#include <TChain.h>
8d169fb2 32#include <TFile.h>
33
34ClassImp(AliAnalysisTaskRL)
35
36//___________________________________________________________________________
37AliAnalysisTaskRL::AliAnalysisTaskRL() :
38 AliAnalysisTask(),
39 fTree(0), fRunLoader(0),
6b61a3ef 40 fKinematicsLoaded(kFALSE), fHeaderLoaded(kFALSE), fTreeNumber(-1) {
8d169fb2 41 //
42 // Constructor. Initialization of pointers
43 //
44}
45
46//___________________________________________________________________________
47AliAnalysisTaskRL::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//___________________________________________________________________________
55AliAnalysisTaskRL::~AliAnalysisTaskRL() {
56 //
57 // Destructor
58 //
59 DeleteRunLoader();
60}
61
62//___________________________________________________________________________
63Bool_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//___________________________________________________________________________
73AliRunLoader *AliAnalysisTaskRL::GetRunLoader() {
74 // Returns AliRun instance corresponding to current ESD active in fTree
75 // Loads galice.root, the file is identified by replacing "AliESDs" to
76 // "galice" in the file path of the ESD file.
77
78 fTree = (TTree *)AliAnalysisTask::GetInputData(0);
6b61a3ef 79 Int_t iTree = ((TChain *)AliAnalysisTask::GetInputData(0))->GetTreeNumber();
80 if (iTree != fTreeNumber) {
81 DeleteRunLoader();
82 fTreeNumber = iTree;
83 }
84
85
8d169fb2 86 if (!fRunLoader) {
87 if (!fTree->GetCurrentFile())
88 return 0;
89
90 TString fileName(fTree->GetCurrentFile()->GetName());
6b61a3ef 91 printf("Current file %s \n", fileName.Data());
92
8d169fb2 93 fileName.ReplaceAll("AliESDs", "galice");
94
95 // temporary workaround for PROOF bug #18505
96 fileName.ReplaceAll("#galice.root#galice.root", "#galice.root");
97
98 fRunLoader = AliRunLoader::Open(fileName);
99 if (!fRunLoader)
100 return 0;
101 fRunLoader->GetEvent((Int_t)(fTree->GetTree()->GetReadEntry()));
102 }
103
104 return fRunLoader;
105}
106
107//___________________________________________________________________________
108void AliAnalysisTaskRL::DeleteRunLoader() {
109 //
110 // deletes the runloader
111 //
112 if (fRunLoader) {
113 fRunLoader->Delete();
114 fRunLoader = 0;
115 }
116
117 fKinematicsLoaded = kFALSE;
118 fHeaderLoaded = kFALSE;
119}
120
121//___________________________________________________________________________
122AliHeader* AliAnalysisTaskRL::GetHeader() {
123 // Returns header retrieved from RunLoader
124
125 AliRunLoader* runLoader = GetRunLoader();
126 if (!runLoader)
127 return 0;
128
129 if (fHeaderLoaded == kFALSE)
130 if (runLoader->LoadHeader() != 0)
131 return 0;
132
133 fHeaderLoaded = kTRUE;
134
135 return runLoader->GetHeader();
136}
137
138//___________________________________________________________________________
139AliStack* AliAnalysisTaskRL::GetStack() {
140 // Returns stack retrieved from RunLoader
141
142 AliRunLoader* runLoader = GetRunLoader();
143 if (!runLoader)
144 return 0;
145
146 if (fKinematicsLoaded == kFALSE)
147 if (runLoader->LoadKinematics() != 0)
148 return 0;
149
150 fKinematicsLoaded = kTRUE;
151
152 return runLoader->Stack();
153}