]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliEmcalContainer.cxx
Transition to new base class (Salvatore/Marta).
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalContainer.cxx
1 //
2 // Emcal Container Base class
3 //
4 // Author: M. Verweij
5
6
7 #include <TClonesArray.h>
8
9 #include "AliEmcalJet.h"
10 #include "AliVEvent.h"
11 #include "AliLog.h"
12 #include "AliNamedArrayI.h"
13
14 #include "AliEmcalContainer.h"
15
16 ClassImp(AliEmcalContainer)
17
18 //________________________________________________________________________
19 AliEmcalContainer::AliEmcalContainer():
20   TNamed("AliEmcalContainer","AliEmcalContainer"),
21   fClArrayName(),
22   fClassName(),
23   fIsParticleLevel(kFALSE),
24   fClArray(0),
25   fCurrentID(0),
26   fLabelMap(0)
27 {
28   // Default constructor.
29
30   fVertex[0] = 0;
31   fVertex[1] = 0;
32   fVertex[2] = 0;
33 }
34
35 //________________________________________________________________________
36 AliEmcalContainer::AliEmcalContainer(const char *name):
37   TNamed(name,name),
38   fClArrayName(),
39   fClassName(),
40   fIsParticleLevel(kFALSE),
41   fClArray(0),
42   fCurrentID(0),
43   fLabelMap(0)
44 {
45   // Standard constructor.
46
47   fVertex[0] = 0;
48   fVertex[1] = 0;
49   fVertex[2] = 0;
50 }
51
52 //________________________________________________________________________
53 void AliEmcalContainer::SetArray(AliVEvent *event) 
54 {
55   // Get array from event.
56
57   const AliVVertex *vertex = event->GetPrimaryVertex();
58   if (vertex) vertex->GetXYZ(fVertex);
59
60   if (!fClArrayName.IsNull() && !fClArray) {
61     fClArray = dynamic_cast<TClonesArray*>(event->FindListObject(fClArrayName));
62     if (!fClArray) {
63       AliError(Form("%s: Could not retrieve array with name %s!", GetName(), fClArrayName.Data())); 
64       return;
65     }
66   } else {
67     return;
68   }
69
70   if (!fClassName.IsNull()) {
71     TString objname(fClArray->GetClass()->GetName());
72     TClass cls(objname);
73     if (!cls.InheritsFrom(fClassName)) {
74       AliError(Form("%s: Objects of type %s in %s are not inherited from %s!", 
75                     GetName(), cls.GetName(), fClArrayName.Data(), fClassName.Data())); 
76       fClArray = 0;
77     }
78   }
79
80   fLabelMap = dynamic_cast<AliNamedArrayI*>(event->FindListObject(fClArrayName + "_Map"));
81 }
82
83 //________________________________________________________________________
84 Int_t AliEmcalContainer::GetIndexFromLabel(Int_t lab) const
85
86   if (fLabelMap) {
87     if (lab < fLabelMap->GetSize()) {
88       return fLabelMap->At(lab); 
89     }
90     else {
91       AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - Label not found in the map, returning -1...",fClArrayName.Data()));
92       return -1;
93     }
94   }
95   else {
96     AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - No index-label map found, returning label...",fClArrayName.Data()));
97     return lab; 
98   }
99 }