]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliJetEventParticles.cxx
Fixing memory leaks
[u/mrichter/AliRoot.git] / JETAN / AliJetEventParticles.cxx
1 // $Id$
2
3 //__________________________________________________________
4 ///////////////////////////////////////////////////////////////////
5 //
6 // class AliJetEventParticles
7 //
8 // loizides@ikf.uni-frankfurt.de
9 //
10 ///////////////////////////////////////////////////////////////////
11
12 #include <Riostream.h>
13 #include <TClonesArray.h>
14 #include "AliJetParticle.h"
15 #include "AliJetEventParticles.h"
16
17 ClassImp(AliJetEventParticles)
18
19 /**************************************************************************/ 
20  
21 AliJetEventParticles::AliJetEventParticles(Int_t size) :
22   fNParticles(0),
23   fParticles(new TClonesArray("AliJetParticle",size)),
24   fVertexX(0.),
25   fVertexY(0.),
26   fVertexZ(0.)
27 {
28   //default constructor   
29 }
30
31 /**************************************************************************/ 
32  
33 AliJetEventParticles::AliJetEventParticles(const AliJetEventParticles& source) :
34   TObject(source), 
35   fNParticles(source.fNParticles),
36   fParticles(new TClonesArray("AliJetEventParticles",source.fNParticles)),
37   fVertexX(0.),
38   fVertexY(0.),
39   fVertexZ(0.)
40 {
41   //copy constructor
42   for(Int_t i =0; i<fNParticles; i++)
43     {
44       const AliJetParticle *kjp=(const AliJetParticle *)source.fParticles->At(i);
45       fParticles->AddAt(new AliJetParticle(*(kjp)),i);
46     }
47 }
48
49 /**************************************************************************/ 
50
51 AliJetEventParticles::~AliJetEventParticles()
52 {
53   //destructor   
54   Reset();
55   delete fParticles;
56 }
57
58
59 /**************************************************************************/ 
60
61 void  AliJetEventParticles::Reset(Int_t size)
62 {
63   //deletes all particles from the event
64
65   if(fParticles) fParticles->Clear();
66   if(size>=0) fParticles->Expand(size);
67   fNParticles = 0;
68
69
70 /**************************************************************************/ 
71
72 void AliJetEventParticles::AddParticle(AliJetParticle* part)
73 {
74   //Adds new particle to the event
75   fParticles->AddAt(part,fNParticles++);
76 }
77
78 /**************************************************************************/ 
79
80 void AliJetEventParticles::AddParticle(const AliJetParticle* part)
81 {
82   //Adds new particle to the event
83   new((*fParticles)[fNParticles++]) AliJetParticle(*part);
84 }
85
86 /**************************************************************************/ 
87
88 void AliJetEventParticles::AddParticle(const TParticle* part,Int_t idx, Int_t l)
89 {
90   //Adds new particle to the event
91   new((*fParticles)[fNParticles++]) AliJetParticle(part,idx,l);
92 }
93
94 /**************************************************************************/ 
95
96 void AliJetEventParticles::AddParticle(Float_t px, Float_t py, Float_t pz, 
97                               Float_t etot, Int_t idx, Int_t l)
98 {
99   //Adds new particle to the event
100   new((*fParticles)[fNParticles++]) AliJetParticle(px,py,pz,etot,idx,l); 
101 }
102
103 /**************************************************************************/ 
104
105 void AliJetEventParticles::AddParticle(Float_t px, Float_t py, Float_t pz, Float_t etot, Int_t idx, Int_t l,
106                               Float_t pt, Float_t phi, Float_t eta)
107 {
108   //Adds new particle to the event
109   new((*fParticles)[fNParticles++]) AliJetParticle(px,py,pz,etot,idx,l,pt,phi,eta); 
110 }
111
112
113 /**************************************************************************/ 
114
115 const AliJetParticle* AliJetEventParticles::GetParticleSafely(Int_t n)
116 {
117   //returns nth particle with range check
118   if( (n<0) || (fNParticles<=n) ) return 0;
119   return (const AliJetParticle*)fParticles->At(n);
120 }
121
122 /**************************************************************************/ 
123
124 void AliJetEventParticles::Print(Option_t* /*t*/) const
125 {
126   cout << "--- AliJetEventParticles ---" << endl;
127   if(fHeader.Length()) cout << fHeader.Data() << endl;
128   cout << "no of particles: " << fNParticles << endl;
129 }