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