Adaption to new fluka common blocks (E. Futo)
[u/mrichter/AliRoot.git] / EVGEN / AliGenReaderTreeK.cxx
CommitLineData
8020fb14 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/*
17$Log$
b9d0a01d 18Revision 1.4.4.1 2002/06/10 14:57:41 hristov
19Merged with v3-08-02
20
21Revision 1.5 2002/04/26 10:37:23 morsch
22Method RewindEvent() added. (N. Carrer)
23
d1d1da57 24Revision 1.4 2002/03/22 08:25:33 morsch
25TreeE connected correctly.
26
314a87b5 27Revision 1.3 2001/12/12 11:21:37 morsch
28Dummy copy constructor added.
29
43342f51 30Revision 1.2 2001/11/12 14:31:00 morsch
31Memory leaks fixed. (M. Bondila)
32
ae872676 33Revision 1.1 2001/11/09 09:11:24 morsch
34Realisation of AliGenReader that reads the kine tree (TreeK).
35
8020fb14 36*/
37#include <TFile.h>
38#include <TTree.h>
39#include <TParticle.h>
40
41#include "AliGenReaderTreeK.h"
42#include "AliStack.h"
43#include "AliHeader.h"
44#include "AliRun.h"
45
46ClassImp(AliGenReaderTreeK);
47
48
49AliGenReaderTreeK::AliGenReaderTreeK():AliGenReader()
50{
51// Default constructor
52 fFileName = NULL;
53 fStack = 0;
54 fHeader = 0;
55 fNcurrent = 0;
56 fNparticle = 0;
57 fFile = 0;
58 fBaseFile = 0;
ae872676 59 fTreeE = 0;
60}
61
43342f51 62AliGenReaderTreeK::AliGenReaderTreeK(const AliGenReaderTreeK &reader)
63{
64 ;
65}
66
67
ae872676 68AliGenReaderTreeK::~AliGenReaderTreeK()
69{
70// Destructor
71 delete fTreeE;
8020fb14 72}
73
74void AliGenReaderTreeK::Init()
75{
76// Initialization
77// Connect base file and file to read from
78
79 TTree *ali = gAlice->TreeE();
80 if (ali) {
81 fBaseFile = ali->GetCurrentFile();
82 } else {
83 printf("\n Warning: Basefile cannot be found !\n");
84 }
314a87b5 85 if (!fFile) fFile = new TFile(fFileName);
8020fb14 86}
87
88Int_t AliGenReaderTreeK::NextEvent()
89{
314a87b5 90// Read the next event
8020fb14 91// cd to file with old kine tree
92 if (!fBaseFile) Init();
8020fb14 93 fFile->cd();
314a87b5 94// Connect header tree
95 if (!fTreeE) fTreeE = (TTree*)gDirectory->Get("TE");
8020fb14 96 if (fHeader) delete fHeader;
97 fHeader = 0;
ae872676 98 fTreeE->SetBranchAddress("Header", &fHeader);
8020fb14 99// Get next event
ae872676 100 fTreeE->GetEntry(fNcurrent);
314a87b5 101// Connect Stack
102 if (fStack) delete fStack;
8020fb14 103 fStack = fHeader->Stack();
104 fStack->GetEvent(fNcurrent);
8020fb14 105// cd back to base file
106 fBaseFile->cd();
107//
108 fNcurrent++;
109 fNparticle = 0;
110 Int_t ntrack = fStack->GetNtrack();
111 printf("\n Next event contains %d particles", ntrack);
314a87b5 112//
8020fb14 113 return ntrack;
114}
115
116TParticle* AliGenReaderTreeK::NextParticle()
117{
118// Return next particle
119 TParticle* part = fStack->Particle(fNparticle);
120 fNparticle++;
121 return part;
122}
123
d1d1da57 124void AliGenReaderTreeK::RewindEvent()
125{
126 // Go back to the first particle of the event
127 fNparticle = 0;
128}
8020fb14 129
130
ae872676 131AliGenReaderTreeK& AliGenReaderTreeK::operator=(const AliGenReaderTreeK& rhs)
132{
133// Assignment operator
134 return *this;
135}
8020fb14 136
137
138