X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=EVGEN%2FAliGenReaderTreeK.cxx;h=62614be4b2f845d85cef2d29c906e060fbef4c0e;hb=b46c05d4b362f5f59559f2f67a6cf1cc7dface40;hp=c56763903c262ff13f0f61567d750cc9a0b336d8;hpb=43342f51ac83e2e20d02a2369d222d3efd8129f0;p=u%2Fmrichter%2FAliRoot.git diff --git a/EVGEN/AliGenReaderTreeK.cxx b/EVGEN/AliGenReaderTreeK.cxx index c56763903c2..62614be4b2f 100644 --- a/EVGEN/AliGenReaderTreeK.cxx +++ b/EVGEN/AliGenReaderTreeK.cxx @@ -13,50 +13,66 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -/* -$Log$ -Revision 1.2 2001/11/12 14:31:00 morsch -Memory leaks fixed. (M. Bondila) - -Revision 1.1 2001/11/09 09:11:24 morsch -Realisation of AliGenReader that reads the kine tree (TreeK). - -*/ +/* $Id$ */ +// +// Realisation of AliGenReader to be used with AliGenExtFile +// It reads events from a kinematics TreeK. +// NextEvent() is used to loop over events +// and NextParticle() to loop over particles. +// Author: andreas.morsch@cern.ch +// #include #include #include +#include +#include #include "AliGenReaderTreeK.h" -#include "AliStack.h" #include "AliHeader.h" #include "AliRun.h" - -ClassImp(AliGenReaderTreeK); - - -AliGenReaderTreeK::AliGenReaderTreeK():AliGenReader() +#include "AliStack.h" +#include "AliRunLoader.h" + +ClassImp(AliGenReaderTreeK) + +const TString AliGenReaderTreeK::fgkEventFolderName("GenReaderTreeK"); + +AliGenReaderTreeK::AliGenReaderTreeK(): + AliGenReader(), + fNcurrent(0), + fNparticle(0), + fNp(0), + fInRunLoader(0), + fBaseFile(0), + fStack(0), + fOnlyPrimaries(kFALSE), + fDirs(0x0), + fCurrentDir(0) { // Default constructor - fFileName = NULL; - fStack = 0; - fHeader = 0; - fNcurrent = 0; - fNparticle = 0; - fFile = 0; - fBaseFile = 0; - fTreeE = 0; } -AliGenReaderTreeK::AliGenReaderTreeK(const AliGenReaderTreeK &reader) +AliGenReaderTreeK::AliGenReaderTreeK(const AliGenReaderTreeK &reader): + AliGenReader(reader), + fNcurrent(0), + fNparticle(0), + fNp(0), + fInRunLoader(0), + fBaseFile(0), + fStack(0), + fOnlyPrimaries(kFALSE), + fDirs(0x0), + fCurrentDir(0) { - ; + reader.Copy(*this); } AliGenReaderTreeK::~AliGenReaderTreeK() { // Destructor - delete fTreeE; + delete fInRunLoader;//it cleans all the loaded data + delete fDirs; } void AliGenReaderTreeK::Init() @@ -64,64 +80,145 @@ void AliGenReaderTreeK::Init() // Initialization // Connect base file and file to read from - TTree *ali = gAlice->TreeE(); + TTree *ali = AliRunLoader::Instance()->TreeE(); if (ali) { - fBaseFile = ali->GetCurrentFile(); + fBaseFile = ali->GetCurrentFile(); } else { - printf("\n Warning: Basefile cannot be found !\n"); + printf("\n Warning: Basefile cannot be found !\n"); } - fFile = new TFile(fFileName); + //if (!fFile) fFile = new TFile(fFileName); + if (fInRunLoader == 0x0) + { + fInRunLoader = AliRunLoader::Open((GetDirName(fCurrentDir++)+"/")+fFileName,fgkEventFolderName); + fInRunLoader->LoadHeader(); + fInRunLoader->LoadKinematics("READ"); + } } Int_t AliGenReaderTreeK::NextEvent() { -// Read the next event +// Read the next event // cd to file with old kine tree if (!fBaseFile) Init(); - if (fStack) delete fStack; - fStack = new AliStack(1000); - fFile->cd(); -// Connect treeE - if (fTreeE) { - delete fTreeE; - } else { - fTreeE = (TTree*)gDirectory->Get("TE"); - } - - if (fHeader) delete fHeader; - fHeader = 0; - fTreeE->SetBranchAddress("Header", &fHeader); // Get next event - fTreeE->GetEntry(fNcurrent); - fStack = fHeader->Stack(); - fStack->GetEvent(fNcurrent); + + if (fNcurrent >= fInRunLoader->GetNumberOfEvents()) + { + if (fCurrentDir >= fDirs->GetEntries()) + { + Warning("NextEvent","No more events"); + return 0; + } + delete fInRunLoader; + fInRunLoader = AliRunLoader::Open((GetDirName(fCurrentDir++)+"/")+fFileName,fgkEventFolderName); + fInRunLoader->LoadHeader(); + fInRunLoader->LoadKinematics("READ"); + fNcurrent = 0; + } + fInRunLoader->GetEvent(fNcurrent); + fStack = fInRunLoader->Stack(); // cd back to base file fBaseFile->cd(); // fNcurrent++; fNparticle = 0; - Int_t ntrack = fStack->GetNtrack(); - printf("\n Next event contains %d particles", ntrack); - - return ntrack; + fNp = fStack->GetNtrack(); + printf("\n Next event contains %d particles", fNp); +// + return fNp; } TParticle* AliGenReaderTreeK::NextParticle() { -// Return next particle - TParticle* part = fStack->Particle(fNparticle); - fNparticle++; - return part; +//Return next particle + TParticle* part = GetParticle(fNparticle++); + if (part == 0x0) return 0x0; + //if only primaries are to be read, and this particle is not primary enter loop + if (fOnlyPrimaries && ( part->GetFirstMother() > -1) ) + for (;;) + { //look for a primary + part = GetParticle(fNparticle++); + if (part == 0x0) return 0x0; + if (part->GetFirstMother() == -1) return part; + } + + return part; } +void AliGenReaderTreeK::RewindEvent() +{ + // Go back to the first particle of the event + fNparticle = 0; +} AliGenReaderTreeK& AliGenReaderTreeK::operator=(const AliGenReaderTreeK& rhs) { // Assignment operator + rhs.Copy(*this); return *this; } +void AliGenReaderTreeK::Copy(TObject&) const +{ + // + // Copy + // + Fatal("Copy","Not implemented!\n"); +} + + +TString& AliGenReaderTreeK::GetDirName(Int_t entry) + { +// Get the current directory name + + TString* retval;//return value + if (fDirs == 0x0) + { + retval = new TString("."); + return *retval; + } + + if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string + { //note that entry==0 is accepted even if array is empty (size=0) + Error("GetDirName","Name out of bounds"); + retval = new TString(); + return *retval; + } + + if (fDirs->GetEntries() == 0) + { + retval = new TString("."); + return *retval; + } + + TObjString *dir = dynamic_cast(fDirs->At(entry)); + if(dir == 0x0) + { + Error("GetDirName","Object in TObjArray is not a TObjString or its descendant"); + retval = new TString(); + return *retval; + } + if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data()); + return dir->String(); + } + +void AliGenReaderTreeK::AddDir(const char* dirname) +{ + //adds a directory to the list of directories where data are looked for + if(fDirs == 0x0) + { + fDirs = new TObjArray(); + fDirs->SetOwner(kTRUE); + } + TObjString *odir= new TObjString(dirname); + fDirs->Add(odir); +} +TParticle* AliGenReaderTreeK::GetParticle(Int_t i) + { + if (fStack && iParticle(i); + return 0x0; + }