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