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