1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // Author: Andrei Gheata, 31/05/2006
19 //==============================================================================
20 // AliAnalysysRLContainer -
21 //==============================================================================
23 #include "AliAnalysisRLContainer.h"
28 #include "AliRunLoader.h"
30 #include "AliHeader.h"
32 #include "AliAnalysisDataContainer.h"
33 #include "AliAnalysisDataSlot.h"
34 #include "AliAnalysisTask.h"
36 ClassImp(AliAnalysisRLContainer)
38 //______________________________________________________________________________
39 AliAnalysisRLContainer::AliAnalysisRLContainer()
40 :AliAnalysisDataContainer(),
44 fKinematicsLoaded(kFALSE),
50 //______________________________________________________________________________
51 AliAnalysisRLContainer::AliAnalysisRLContainer(const char *name)
52 :AliAnalysisDataContainer(name, TTree::Class()),
56 fKinematicsLoaded(kFALSE),
59 // Normal constructor.
62 //______________________________________________________________________________
63 AliAnalysisRLContainer::AliAnalysisRLContainer(const AliAnalysisRLContainer &rlc)
64 :AliAnalysisDataContainer(rlc),
65 fRunLoader(rlc.fRunLoader),
67 fKineFile(rlc.fKineFile),
68 fKinematicsLoaded(rlc.fKinematicsLoaded),
69 fHeaderLoaded(rlc.fHeaderLoaded)
74 //______________________________________________________________________________
75 AliAnalysisRLContainer::~AliAnalysisRLContainer()
77 // Destructor. Deletes data ! (What happens if data is a container ???)
80 //______________________________________________________________________________
81 AliAnalysisRLContainer &AliAnalysisRLContainer::operator=(const AliAnalysisRLContainer &rlc)
85 AliAnalysisDataContainer::operator=(rlc);
86 fRunLoader = rlc.fRunLoader;
88 fKineFile = rlc.fKineFile;
89 fKinematicsLoaded = rlc.fKinematicsLoaded;
90 fHeaderLoaded = rlc.fHeaderLoaded;
95 //______________________________________________________________________________
96 Bool_t AliAnalysisRLContainer::SetData(TObject *data, Option_t */*option*/)
98 // Data must be a tree here.
100 TTree *tree = (TTree *)data;
101 // Set branch address
102 tree->SetBranchAddress("ESD", &fESD);
107 //______________________________________________________________________________
108 void AliAnalysisRLContainer::GetEntry(Long64_t ientry)
110 // If data is ready and derives from TTree or from TBranch, this will get the
111 // requested entry in memory if not already loaded.
112 if (!fDataReady) return;
113 TTree *tree = (TTree*)fData;
114 tree->GetTree()->GetEntry(ientry);
115 if (fRunLoader) fRunLoader->GetEvent(ientry);
118 //______________________________________________________________________________
119 void AliAnalysisRLContainer::NotifyChange(ENotifyMessage type)
121 // Notify container that file has changed.
122 AliAnalysisDataContainer::NotifyChange(type);
123 if (!type==kFileChange) return;
124 DeleteKinematicsFile();
128 //______________________________________________________________________________
129 void AliAnalysisRLContainer::DeleteRunLoader()
131 // Deletes the runloader.
133 fRunLoader->Delete();
136 fKinematicsLoaded = kFALSE;
137 fHeaderLoaded = kFALSE;
140 //______________________________________________________________________________
141 void AliAnalysisRLContainer::DeleteKinematicsFile()
143 // Closes the kinematics file and deletes the pointer.
151 //______________________________________________________________________________
152 AliRunLoader* AliAnalysisRLContainer::GetRunLoader()
154 // Returns AliRun instance corresponding to current ESD active in fTree
155 // Loads galice.root, the file is identified by replacing "AliESDs" to
156 // "galice" in the file path of the ESD file. This is a hack, to be changed!
158 if (!fDataReady) return 0;
159 TTree *tree = (TTree*)fData;
161 if (!tree->GetCurrentFile()) return 0;
162 TString fileName(tree->GetCurrentFile()->GetName());
163 fileName.ReplaceAll("AliESDs", "galice");
164 fRunLoader = AliRunLoader::Open(fileName);
165 if (!fRunLoader) return 0;
166 if (fRunLoader->LoadgAlice() != 0) {
171 fRunLoader->GetEvent(tree->GetTree()->GetReadEntry());
176 //______________________________________________________________________________
177 AliHeader* AliAnalysisRLContainer::GetHeader()
179 // Returns header retrieved from RunLoader
180 AliRunLoader* runLoader = GetRunLoader();
181 if (!runLoader) return 0;
183 if (runLoader->LoadHeader() != 0) return 0;
184 fHeaderLoaded = kTRUE;
185 return runLoader->GetHeader();
188 //______________________________________________________________________________
189 TTree* AliAnalysisRLContainer::GetKinematics()
191 // Returns kinematics tree corresponding to current ESD active in fTree
192 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
193 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
195 if (!fDataReady) return 0;
196 TTree *tree = (TTree*)fData;
198 if (!tree->GetCurrentFile()) return 0;
199 TString fileName(tree->GetCurrentFile()->GetName());
200 fileName.ReplaceAll("AliESDs", "Kinematics");
202 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
204 fKineFile = TFile::Open(fileName);
205 if (!fKineFile) return 0;
207 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", tree->GetTree()->GetReadEntry())));
210 //______________________________________________________________________________
211 AliStack* AliAnalysisRLContainer::GetStack()
213 // Returns stack retrieved from RunLoader
215 AliRunLoader* runLoader = GetRunLoader();
216 if (!runLoader) return 0;
217 if (!fKinematicsLoaded)
218 if (runLoader->LoadKinematics() != 0) return 0;
219 fKinematicsLoaded = kTRUE;
220 return runLoader->Stack();