fix mem leak and compiler warning
[u/mrichter/AliRoot.git] / ANALYSIS / AliAODRun.h
1 #ifndef ALIAODRUN_H
2 #define ALIAODRUN_H
3 //____________________
4 ///////////////////////////////////////////////////////
5 //                                                   //
6 // AliAODRun                                         //
7 //                                                   //
8 // Class storing and managing set events             //
9 // designed for fast acces                           //
10 //                                                   //
11 // Piotr.Skowronski@cern.ch                          //
12 // http://aliweb.cern.ch/people/skowron/analyzer    //
13 //                                                   //
14 ///////////////////////////////////////////////////////
15
16
17 #include "AliAOD.h"
18 #include <TObjArray.h>
19
20 class AliVAODParticle;
21 class TParticle;
22
23 class AliAODRun: public TObject
24  {
25   public:
26     AliAODRun();
27     virtual ~AliAODRun();
28
29     void            AddParticle(Int_t event, AliVAODParticle* part); //inerface to AliAOD::AddParticle(AliVAODParticle*) 
30     void            AddParticle(Int_t event, TParticle* part, Int_t idx);//inerface to AliAOD::AddParticle(TParticle*) 
31     
32     //inerface to AliAOD::AddParticle(Int_t.Double_t,Double_t,Double_t,Double_t,Double_t,Double_t,Double_t,Double_t,Double_t)
33     void            AddParticle(Int_t event, Int_t pdg, Int_t idx,
34                                 Double_t px, Double_t py, Double_t pz, Double_t etot,
35                                 Double_t vx, Double_t vy, Double_t vz, Double_t time); 
36     
37     void            SetEvent(Int_t number, AliAOD* event);
38     AliVAODParticle* GetParticle(Int_t event, Int_t n); //returns nth particle from event
39     AliAOD*    GetEvent(Int_t event) const; //returns AliAOD number "event"
40     
41     Int_t           GetNumberOfEvents() const; //returns number of events
42     Int_t               GetNumberOfParticlesInEvent(Int_t event) const; //returns number of particles in event number "event"
43     void            Reset();//clears all events in the array (deletes)
44   protected:
45     TObjArray* fEvents;//!Array containig AliAODs
46   private:
47
48     AliAODRun(const AliAODRun&); // Not implemented    
49     AliAODRun& operator=(const AliAODRun&); // Not implemented    
50
51     ClassDef(AliAODRun,1)
52  };
53  
54  
55 /**************************************************************************/
56
57 inline
58 AliAOD* AliAODRun::GetEvent(Int_t event) const
59 {
60 //returns pointer to AliAOD number "event"
61   //check if array is enough big - protect from error massage from array "Out Of Bounds"
62   if (event>=fEvents->GetSize()) return 0x0;//WARNING, that line relies 
63                                             //on index of first object in TObjArray is 0
64                     //== LowerBound = 0
65   return (AliAOD*)fEvents->At(event);
66 }
67 /**************************************************************************/
68 inline
69 AliVAODParticle* AliAODRun::GetParticle(Int_t event, Int_t n) 
70 {
71  //returns nth particle from event number event
72   AliAOD* e = GetEvent(event);
73   return (e)?e->GetParticle(n):0x0;
74 }
75
76 /**************************************************************************/
77
78 inline
79 Int_t AliAODRun::GetNumberOfEvents() const
80  {
81 //returns number of events in collection
82
83    return fEvents->GetEntriesFast(); //there may be empty slots but we do not care
84                                      //Analysis checks it if return is not NULL
85  }
86 /**************************************************************************/
87
88 inline
89 Int_t AliAODRun::GetNumberOfParticlesInEvent(Int_t event) const
90 {
91 //returns number of Particles in event 
92   AliAOD* e = GetEvent(event);
93   return (e)?e->GetNumberOfParticles():0x0;
94 }
95  
96 #endif