]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisRLContainer.cxx
new configuration, accesst to DAQ FES (Alberto)
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisRLContainer.cxx
CommitLineData
d3106602 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// Author: Andrei Gheata, 31/05/2006
18
19//==============================================================================
20// AliAnalysysRLContainer -
21//==============================================================================
22
23#include "AliAnalysisRLContainer.h"
24#include "TTree.h"
25#include "TFile.h"
26
27#include "AliLog.h"
28#include "AliRunLoader.h"
29#include "AliESD.h"
30#include "AliHeader.h"
31#include "AliStack.h"
32#include "AliAnalysisDataContainer.h"
33#include "AliAnalysisDataSlot.h"
34#include "AliAnalysisTask.h"
35
36ClassImp(AliAnalysisRLContainer)
37
38//______________________________________________________________________________
39AliAnalysisRLContainer::AliAnalysisRLContainer()
40{
41// Dummy ctor.
42 fRunLoader = 0;
43 fESD = 0;
44 fKineFile = 0;
45 fKinematicsLoaded = kFALSE;
46 fHeaderLoaded = kFALSE;
47}
48
49//______________________________________________________________________________
50AliAnalysisRLContainer::AliAnalysisRLContainer(const char *name)
51 :AliAnalysisDataContainer(name, TTree::Class())
52{
53// Normal constructor.
54 fRunLoader = 0;
55 fESD = 0;
56 fKineFile = 0;
57 fKinematicsLoaded = kFALSE;
58 fHeaderLoaded = kFALSE;
59}
60
61//______________________________________________________________________________
62AliAnalysisRLContainer::~AliAnalysisRLContainer()
63{
64// Destructor. Deletes data ! (What happens if data is a container ???)
65}
66
67//______________________________________________________________________________
68Bool_t AliAnalysisRLContainer::SetData(TObject *data, Option_t */*option*/)
69{
70// Data must be a tree here.
71 fData = data;
72 TTree *tree = (TTree *)data;
73 // Set branch address
74 tree->SetBranchAddress("ESD", &fESD);
75 fDataReady = kTRUE;
76 return kTRUE;
77}
78
79//______________________________________________________________________________
80void AliAnalysisRLContainer::GetEntry(Long64_t ientry)
81{
82// If data is ready and derives from TTree or from TBranch, this will get the
83// requested entry in memory if not already loaded.
84 if (!fDataReady) return;
85 TTree *tree = (TTree*)fData;
86 tree->GetTree()->GetEntry(ientry);
87 if (fRunLoader) fRunLoader->GetEvent(ientry);
88}
89
90//______________________________________________________________________________
91void AliAnalysisRLContainer::NotifyChange(ENotifyMessage type)
92{
93// Notify container that file has changed.
94 AliAnalysisDataContainer::NotifyChange(type);
95 if (!type==kFileChange) return;
96 DeleteKinematicsFile();
97 DeleteRunLoader();
98}
99
100//______________________________________________________________________________
101void AliAnalysisRLContainer::DeleteRunLoader()
102{
103// Deletes the runloader.
104 if (fRunLoader) {
105 fRunLoader->Delete();
106 fRunLoader = 0;
107 }
108 fKinematicsLoaded = kFALSE;
109 fHeaderLoaded = kFALSE;
110}
111
112//______________________________________________________________________________
113void AliAnalysisRLContainer::DeleteKinematicsFile()
114{
115// Closes the kinematics file and deletes the pointer.
116 if (fKineFile) {
117 fKineFile->Close();
118 delete fKineFile;
119 fKineFile = 0;
120 }
121}
122
123//______________________________________________________________________________
124AliRunLoader* AliAnalysisRLContainer::GetRunLoader()
125{
126// Returns AliRun instance corresponding to current ESD active in fTree
127// Loads galice.root, the file is identified by replacing "AliESDs" to
128// "galice" in the file path of the ESD file. This is a hack, to be changed!
129
130 if (!fDataReady) return 0;
131 TTree *tree = (TTree*)fData;
132 if (!fRunLoader) {
133 if (!tree->GetCurrentFile()) return 0;
134 TString fileName(tree->GetCurrentFile()->GetName());
135 fileName.ReplaceAll("AliESDs", "galice");
136 fRunLoader = AliRunLoader::Open(fileName);
137 if (!fRunLoader) return 0;
138 if (fRunLoader->LoadgAlice() != 0) {
139 delete fRunLoader;
140 fRunLoader = 0;
141 return 0;
142 }
143 fRunLoader->GetEvent(tree->GetTree()->GetReadEntry());
144 }
145 return fRunLoader;
146}
147
148//______________________________________________________________________________
149AliHeader* AliAnalysisRLContainer::GetHeader()
150{
151// Returns header retrieved from RunLoader
152 AliRunLoader* runLoader = GetRunLoader();
153 if (!runLoader) return 0;
154 if (!fHeaderLoaded)
155 if (runLoader->LoadHeader() != 0) return 0;
156 fHeaderLoaded = kTRUE;
157 return runLoader->GetHeader();
158}
159
160//______________________________________________________________________________
161TTree* AliAnalysisRLContainer::GetKinematics()
162{
163// Returns kinematics tree corresponding to current ESD active in fTree
164// Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
165// "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
166
167 if (!fDataReady) return 0;
168 TTree *tree = (TTree*)fData;
169 if (!fKineFile) {
170 if (!tree->GetCurrentFile()) return 0;
171 TString fileName(tree->GetCurrentFile()->GetName());
172 fileName.ReplaceAll("AliESDs", "Kinematics");
173
174 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
175
176 fKineFile = TFile::Open(fileName);
177 if (!fKineFile) return 0;
178 }
179 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", tree->GetTree()->GetReadEntry())));
180}
181
182//______________________________________________________________________________
183AliStack* AliAnalysisRLContainer::GetStack()
184{
185// Returns stack retrieved from RunLoader
186
187 AliRunLoader* runLoader = GetRunLoader();
188 if (!runLoader) return 0;
189 if (!fKinematicsLoaded)
190 if (runLoader->LoadKinematics() != 0) return 0;
191 fKinematicsLoaded = kTRUE;
192 return runLoader->Stack();
193}