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 -
24 //==============================================================================
26 #include "AliAnalysisRLContainer.h"
31 #include "AliRunLoader.h"
33 #include "AliHeader.h"
35 #include "AliAnalysisDataContainer.h"
36 #include "AliAnalysisDataSlot.h"
37 #include "AliAnalysisTask.h"
39 ClassImp(AliAnalysisRLContainer)
41 //______________________________________________________________________________
42 AliAnalysisRLContainer::AliAnalysisRLContainer()
43 :AliAnalysisDataContainer(),
47 fKinematicsLoaded(kFALSE),
53 //______________________________________________________________________________
54 AliAnalysisRLContainer::AliAnalysisRLContainer(const char *name)
55 :AliAnalysisDataContainer(name, TTree::Class()),
59 fKinematicsLoaded(kFALSE),
62 // Normal constructor.
65 //______________________________________________________________________________
66 AliAnalysisRLContainer::AliAnalysisRLContainer(const AliAnalysisRLContainer &rlc)
67 :AliAnalysisDataContainer(rlc),
68 fRunLoader(rlc.fRunLoader),
70 fKineFile(rlc.fKineFile),
71 fKinematicsLoaded(rlc.fKinematicsLoaded),
72 fHeaderLoaded(rlc.fHeaderLoaded)
77 //______________________________________________________________________________
78 AliAnalysisRLContainer::~AliAnalysisRLContainer()
80 // Destructor. Deletes data ! (What happens if data is a container ???)
83 //______________________________________________________________________________
84 AliAnalysisRLContainer &AliAnalysisRLContainer::operator=(const AliAnalysisRLContainer &rlc)
88 AliAnalysisDataContainer::operator=(rlc);
89 fRunLoader = rlc.fRunLoader;
91 fKineFile = rlc.fKineFile;
92 fKinematicsLoaded = rlc.fKinematicsLoaded;
93 fHeaderLoaded = rlc.fHeaderLoaded;
98 //______________________________________________________________________________
99 Bool_t AliAnalysisRLContainer::SetData(TObject *data, Option_t */*option*/)
101 // Data must be a tree here.
103 TTree *tree = (TTree *)data;
104 // Set branch address
105 tree->SetBranchAddress("ESD", &fESD);
110 //______________________________________________________________________________
111 void AliAnalysisRLContainer::GetEntry(Long64_t ientry)
113 // If data is ready and derives from TTree or from TBranch, this will get the
114 // requested entry in memory if not already loaded.
115 if (!fDataReady) return;
116 TTree *tree = (TTree*)fData;
117 tree->GetTree()->GetEntry(ientry);
118 if (fRunLoader) fRunLoader->GetEvent(ientry);
121 //______________________________________________________________________________
122 void AliAnalysisRLContainer::NotifyChange(ENotifyMessage type)
124 // Notify container that file has changed.
125 AliAnalysisDataContainer::NotifyChange(type);
126 if (!type==kFileChange) return;
127 DeleteKinematicsFile();
131 //______________________________________________________________________________
132 void AliAnalysisRLContainer::DeleteRunLoader()
134 // Deletes the runloader.
136 fRunLoader->Delete();
139 fKinematicsLoaded = kFALSE;
140 fHeaderLoaded = kFALSE;
143 //______________________________________________________________________________
144 void AliAnalysisRLContainer::DeleteKinematicsFile()
146 // Closes the kinematics file and deletes the pointer.
154 //______________________________________________________________________________
155 AliRunLoader* AliAnalysisRLContainer::GetRunLoader()
157 // Returns AliRun instance corresponding to current ESD active in fTree
158 // Loads galice.root, the file is identified by replacing "AliESDs" to
159 // "galice" in the file path of the ESD file. This is a hack, to be changed!
161 if (!fDataReady) return 0;
162 TTree *tree = (TTree*)fData;
164 if (!tree->GetCurrentFile()) return 0;
165 TString fileName(tree->GetCurrentFile()->GetName());
166 fileName.ReplaceAll("AliESDs", "galice");
167 fRunLoader = AliRunLoader::Open(fileName);
168 if (!fRunLoader) return 0;
169 if (fRunLoader->LoadgAlice() != 0) {
174 fRunLoader->GetEvent(tree->GetTree()->GetReadEntry());
179 //______________________________________________________________________________
180 AliHeader* AliAnalysisRLContainer::GetHeader()
182 // Returns header retrieved from RunLoader
183 AliRunLoader* runLoader = GetRunLoader();
184 if (!runLoader) return 0;
186 if (runLoader->LoadHeader() != 0) return 0;
187 fHeaderLoaded = kTRUE;
188 return runLoader->GetHeader();
191 //______________________________________________________________________________
192 TTree* AliAnalysisRLContainer::GetKinematics()
194 // Returns kinematics tree corresponding to current ESD active in fTree
195 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
196 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
198 if (!fDataReady) return 0;
199 TTree *tree = (TTree*)fData;
201 if (!tree->GetCurrentFile()) return 0;
202 TString fileName(tree->GetCurrentFile()->GetName());
203 fileName.ReplaceAll("AliESDs", "Kinematics");
205 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
207 fKineFile = TFile::Open(fileName);
208 if (!fKineFile) return 0;
210 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", tree->GetTree()->GetReadEntry())));
213 //______________________________________________________________________________
214 AliStack* AliAnalysisRLContainer::GetStack()
216 // Returns stack retrieved from RunLoader
218 AliRunLoader* runLoader = GetRunLoader();
219 if (!runLoader) return 0;
220 if (!fKinematicsLoaded)
221 if (runLoader->LoadKinematics() != 0) return 0;
222 fKinematicsLoaded = kTRUE;
223 return runLoader->Stack();