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 **************************************************************************/
20 #include <TParticle.h>
21 #include <TObjString.h>
22 #include <TObjArray.h>
24 #include "AliGenReaderTreeK.h"
25 #include "AliHeader.h"
27 #include "AliRunLoader.h"
29 ClassImp(AliGenReaderTreeK);
31 const TString AliGenReaderTreeK::fgkEventFolderName("GenReaderTreeK");
33 AliGenReaderTreeK::AliGenReaderTreeK():
41 fOnlyPrimaries(kFALSE),
45 // Default constructor
48 AliGenReaderTreeK::AliGenReaderTreeK(const AliGenReaderTreeK &reader):
55 fOnlyPrimaries(kFALSE),
63 AliGenReaderTreeK::~AliGenReaderTreeK()
66 delete fInRunLoader;//it cleans all the loaded data
70 void AliGenReaderTreeK::Init()
73 // Connect base file and file to read from
75 TTree *ali = gAlice->TreeE();
77 fBaseFile = ali->GetCurrentFile();
79 printf("\n Warning: Basefile cannot be found !\n");
81 //if (!fFile) fFile = new TFile(fFileName);
82 if (fInRunLoader == 0x0)
84 fInRunLoader = AliRunLoader::Open((GetDirName(fCurrentDir++)+"/")+fFileName,fgkEventFolderName);
85 fInRunLoader->LoadHeader();
86 fInRunLoader->LoadKinematics("READ");
90 Int_t AliGenReaderTreeK::NextEvent()
92 // Read the next event
93 // cd to file with old kine tree
94 if (!fBaseFile) Init();
97 if (fNcurrent >= fInRunLoader->GetNumberOfEvents())
99 if (fCurrentDir >= fDirs->GetEntries())
101 Warning("NextEvent","No more events");
105 fInRunLoader = AliRunLoader::Open((GetDirName(fCurrentDir++)+"/")+fFileName,fgkEventFolderName);
106 fInRunLoader->LoadHeader();
107 fInRunLoader->LoadKinematics("READ");
110 fInRunLoader->GetEvent(fNcurrent);
111 fStack = fInRunLoader->Stack();
113 // cd back to base file
118 fNp = fStack->GetNtrack();
119 printf("\n Next event contains %d particles", fNp);
124 TParticle* AliGenReaderTreeK::NextParticle()
126 //Return next particle
127 TParticle* part = GetParticle(fNparticle++);
128 if (part == 0x0) return 0x0;
129 //if only primaries are to be read, and this particle is not primary enter loop
130 if (fOnlyPrimaries && ( part->GetFirstMother() > -1) )
132 { //look for a primary
133 part = GetParticle(fNparticle++);
134 if (part == 0x0) return 0x0;
135 if (part->GetFirstMother() == -1) return part;
141 void AliGenReaderTreeK::RewindEvent()
143 // Go back to the first particle of the event
148 AliGenReaderTreeK& AliGenReaderTreeK::operator=(const AliGenReaderTreeK& rhs)
150 // Assignment operator
156 TString& AliGenReaderTreeK::GetDirName(Int_t entry)
158 TString* retval;//return value
161 retval = new TString(".");
165 if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string
166 { //note that entry==0 is accepted even if array is empty (size=0)
167 Error("GetDirName","Name out of bounds");
168 retval = new TString();
172 if (fDirs->GetEntries() == 0)
174 retval = new TString(".");
178 TObjString *dir = dynamic_cast<TObjString*>(fDirs->At(entry));
181 Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
182 retval = new TString();
185 if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
186 return dir->String();
189 void AliGenReaderTreeK::AddDir(const char* dirname)
191 //adds a directory to the list of directories where data are looked for
194 fDirs = new TObjArray();
195 fDirs->SetOwner(kTRUE);
197 TObjString *odir= new TObjString(dirname);