]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliFlatESDEvent.cxx
Merge branch 'flatdev' of https://git.cern.ch/reps/AliRoot into flatdev
[u/mrichter/AliRoot.git] / HLT / global / AliFlatESDEvent.cxx
1 /* $Id$ */
2
3 /**************************************************************************
4  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  *                                                                        *
6  * Author: The ALICE Off-line Project.                                    *
7  * Contributors are mentioned in the code where appropriate.              *
8  *                                                                        *
9  * Permission to use, copy, modify and distribute this software and its   *
10  * documentation strictly for non-commercial purposes is hereby granted   *
11  * without fee, provided that the above copyright notice appears in all   *
12  * copies and that both the copyright notice and this permission notice   *
13  * appear in the supporting documentation. The authors make no claims     *
14  * about the suitability of this software for any purpose. It is          *
15  * provided "as is" without express or implied warranty.                  *
16  **************************************************************************/
17
18 /**
19  * >> Flat structure representing an ESD <<
20  *
21  * To be used in the online and offline calibration schema.
22  *
23  * Class provides interface methods for 
24  *   - Filling from AliESDEvent, but also from HLT (to be added)
25  *   - Getter methods
26  *
27  * In the online case, the structure can be directly written into a shared 
28  * memory, in the offline case, the size has to be estimated first.
29  *
30  * 
31  * Primary Authors : Sergey Gorbunov, Jochen Thaeder, Chiara Zampolli
32  *
33  * ************************************************************************
34  * Offline usage:
35  *
36  *  ...
37  *  AliESDEvent* esd = ....;
38  *  Bool_t useESDFriends = kTRUE;
39  *
40  *  // -- Book memory for AliFlatESDEvent
41  *  Byte_t *mem = new Byte_t[AliFlatESDEvent::EstimateSize(esd, useESDFriends)];
42  *  AliFlatESDEvent *flatEsd = reinterpret_cast<AliFlatESDEvent*>(mem);
43  *
44  *  // -- Fill AliFlatESDEvent
45  *  flatEsd->Fill(esd, useESDFriends);  
46  *  ...
47  *
48  **************************************************************************/
49
50 #include "AliESDEvent.h"
51 #include "AliESDtrack.h"
52 #include "AliESDfriend.h"
53 #include "AliESDv0.h"
54
55 #include "AliFlatESDEvent.h"
56 #include "AliFlatESDTrack.h"
57 #include "AliFlatTPCCluster.h"
58 #include "AliFlatExternalTrackParam.h"
59 #include "Riostream.h"
60 #include "AliFlatESDVertex.h"
61
62 // _______________________________________________________________________________________________________
63 AliFlatESDEvent::AliFlatESDEvent() :
64   // Default constructor
65   fPrimaryVertexMask(0),
66   fNTracks(0),
67   fTracksPointer(0),
68   fNV0s(0),
69   fV0Pointer(0),
70   fSize(0),
71   fContent() 
72 {
73 }
74
75 /*
76 AliFlatESDEvent::AliFlatESDEvent(const AliFlatESDEvent& ev) :
77   // Default constructor
78   fPrimaryVertexMask(ev.fPrimaryVertexMask),
79   fNTracks(ev.fNTracks),
80   fTracksPointer(ev.fTracksPointer),
81   fNV0s(ev.fNV0s),
82   fV0Pointer(ev.fV0Pointer),
83   fSize(ev.fSize),
84   fContent() 
85 {
86 }
87 */
88 // _______________________________________________________________________________________________________
89 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd) :
90   // Constructor
91   fPrimaryVertexMask(0),
92   fNTracks(0),
93   fTracksPointer(0),
94   fNV0s(0),
95   fV0Pointer(0),
96   fSize(0),
97   fContent() 
98
99   Fill(esd);
100 }
101
102 // _______________________________________________________________________________________________________
103 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd, Bool_t useESDFriends) :
104   // Constructor
105   fPrimaryVertexMask(0),
106   fNTracks(0),
107   fTracksPointer(0),
108   fNV0s(0),
109   fV0Pointer(0),
110   fSize(0),
111   fContent() 
112
113   Fill(esd, useESDFriends);
114 }
115
116 // _______________________________________________________________________________________________________
117 AliFlatESDEvent::~AliFlatESDEvent() 
118 {
119   // Destructor
120 }
121
122 // _______________________________________________________________________________________________________
123   ULong64_t AliFlatESDEvent::EstimateSize(AliESDEvent *esd, Bool_t useESDFriends, Bool_t fillV0s) 
124 {
125   // Estimate upper limit of the object size
126   // -> Added objects have to be added here as well
127   
128   ULong64_t size = sizeof(AliFlatESDEvent);
129   size += 2 * sizeof( AliFlatESDVertex );
130   size += esd->GetNumberOfTracks() * AliFlatESDTrack::EstimateSize(useESDFriends);
131   if( fillV0s ) size += esd->GetNumberOfV0s()*sizeof(AliFlatESDV0);
132   return size;
133 }
134
135 void AliFlatESDEvent::FillPrimaryVertices( const AliESDVertex *vertexSPD,
136                                             const AliESDVertex *vertexTracks )
137 {
138   // fill primary vertices
139   
140   fPrimaryVertexMask = 0;
141   fSize = 0;
142
143   Byte_t flag = 0x1;
144   FillPrimaryVertex(vertexSPD, flag);
145
146   flag = 0x2;
147   FillPrimaryVertex(vertexTracks, flag);
148
149   fTracksPointer = fSize;
150   fV0Pointer = fSize;
151 }
152
153 void AliFlatESDEvent::FillPrimaryVertex(const AliESDVertex *v, Byte_t flag) 
154 {
155   
156   // Fill primary vertex parameters
157
158   if (!v) return;
159
160   AliFlatESDVertex *vtx = reinterpret_cast<AliFlatESDVertex*> (fContent + fSize);
161   new(vtx) AliFlatESDVertex;
162   vtx->Set( *v );    
163   fPrimaryVertexMask |= flag;
164   fSize += sizeof(AliFlatESDVertex);
165 }
166
167
168 Int_t AliFlatESDEvent::FillNextTrack( const AliESDtrack* esdTrack, AliESDfriendTrack* friendTrack)
169 {
170   // fill next track
171
172   AliFlatESDTrack * flatTrack = reinterpret_cast<AliFlatESDTrack*>(fContent+fSize);
173   new(flatTrack) AliFlatESDTrack;
174   flatTrack->Fill(esdTrack, friendTrack);
175   fSize += flatTrack->GetSize();
176   ++fNTracks;
177   return 0;
178 }
179
180 void AliFlatESDEvent::Reset()
181 {
182   fSize = 0;
183   fNTracks=0;
184   fNV0s = 0;  
185   fPrimaryVertexMask = 0;
186   fTracksPointer = 0;  
187   fV0Pointer = 0; 
188 }
189
190 // _______________________________________________________________________________________________________
191 Int_t AliFlatESDEvent::Fill(const AliESDEvent *esd, const Bool_t useESDFriends, const Bool_t fillV0s )
192 {
193   // Fill flat ESD event from normal ALiESDEvent
194   // - Fill tracks + friends (if requested)
195   // -> Added objects have to be added here as well
196
197   Reset();
198   
199   FillPrimaryVertices( esd->GetPrimaryVertexSPD(), esd->GetPrimaryVertexTracks() );
200
201   // -- Get ESD friends
202   // -------------------------------------------------------
203   Bool_t connectESDFriends = useESDFriends;
204   AliESDfriend* esdFriend  = NULL;
205
206    if (connectESDFriends) {
207     esdFriend = dynamic_cast<AliESDfriend*>(esd->FindListObject("AliESDfriend"));  
208     if (!esdFriend) {
209       connectESDFriends = kFALSE;
210       Printf("WARNING: friends not available, cluster information will not be included");
211     }
212     else 
213       Printf("INFO: friends are available, cluster information will be included");
214   }
215
216   // -- Track loop, fill AliFlatESDTrack sub structure
217   // -------------------------------------------------------
218   for (Int_t idxTrack = 0; idxTrack < esd->GetNumberOfTracks(); ++idxTrack) {
219     AliESDtrack       *esdTrack    = esd->GetTrack(idxTrack);
220     AliESDfriendTrack *friendTrack = NULL;
221
222     if (esdTrack) {
223       if (connectESDFriends){
224         friendTrack = esdFriend->GetTrack(idxTrack);
225       }
226       FillNextTrack( esdTrack, friendTrack);
227     }
228   }
229
230   // Fill V0s
231   
232   fV0Pointer = fSize;
233   fNV0s = 0;
234   if( fillV0s ){
235     for( int i=0; i < esd->GetNumberOfV0s(); i++){
236       AliESDv0 *esdV0 = esd->GetV0( i );
237       AliFlatESDV0 *v0 = GetNextV0Pointer();
238       if( !v0 ) continue;
239       v0->fNegTrackID = esdV0->GetNindex();
240       v0->fPosTrackID = esdV0->GetNindex();
241       StoreLastV0();      
242     }
243   }
244
245   return 0;
246 }
247
248 UInt_t AliFlatESDEvent::CountBits(Byte_t field, UInt_t mask) const {
249   // Count bits in field
250   UInt_t count = 0; 
251   UInt_t reg = 0x0; 
252   
253   reg |= field;   
254   reg &= mask;
255   
256   for (count = 0; reg; count++)
257     reg &= reg - 1; 
258
259   return count;
260 }