]>
Commit | Line | Data |
---|---|---|
251a2c81 | 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" | |
27595dcc | 53 | #include "AliESDv0.h" |
251a2c81 | 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), | |
27595dcc | 68 | fNV0s(0), |
69 | fV0Pointer(0), | |
251a2c81 | 70 | fSize(0), |
71 | fContent() | |
72 | { | |
73 | } | |
74 | ||
8fcd8556 | 75 | // _______________________________________________________________________________________________________ |
f009a562 | 76 | AliFlatESDEvent::AliFlatESDEvent(AliFlatESDSpecialConstructorFlag f) |
8fcd8556 | 77 | { |
78 | //special constructor, used to restore the vtable pointer | |
79 | //uses the special dummy constructors of contained objects | |
f009a562 | 80 | |
81 | if(f == AliFlatESDReinitialize){ | |
82 | AliFlatESDVertex* vertexSPD = const_cast<AliFlatESDVertex*>(GetPrimaryVertexSPD()); | |
83 | if (vertexSPD ) { new (vertexSPD) AliFlatESDVertex(f); } | |
84 | AliFlatESDVertex* vertexTracks = const_cast<AliFlatESDVertex*>(GetPrimaryVertexTracks()); | |
85 | if (vertexTracks ) { new (vertexTracks) AliFlatESDVertex(f); } | |
86 | AliFlatESDTrack* track = GetTracks(); | |
87 | for (Int_t i=0; i<GetNumberOfTracks(); i++) | |
88 | { | |
89 | new (track++) AliFlatESDTrack(f); | |
90 | } | |
91 | AliFlatESDV0* v0 = GetV0s(); | |
92 | for (Int_t i=0; i<GetNumberOfV0s(); i++) | |
93 | { | |
94 | new (v0++) AliFlatESDV0(f); | |
95 | } | |
96 | } | |
97 | else{ | |
98 | AliFlatESDEvent(); | |
99 | } | |
8fcd8556 | 100 | } |
101 | ||
488e1434 | 102 | /* |
103 | AliFlatESDEvent::AliFlatESDEvent(const AliFlatESDEvent& ev) : | |
104 | // Default constructor | |
105 | fPrimaryVertexMask(ev.fPrimaryVertexMask), | |
106 | fNTracks(ev.fNTracks), | |
107 | fTracksPointer(ev.fTracksPointer), | |
108 | fNV0s(ev.fNV0s), | |
109 | fV0Pointer(ev.fV0Pointer), | |
110 | fSize(ev.fSize), | |
111 | fContent() | |
112 | { | |
113 | } | |
114 | */ | |
251a2c81 | 115 | // _______________________________________________________________________________________________________ |
116 | AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd) : | |
117 | // Constructor | |
118 | fPrimaryVertexMask(0), | |
119 | fNTracks(0), | |
120 | fTracksPointer(0), | |
27595dcc | 121 | fNV0s(0), |
122 | fV0Pointer(0), | |
251a2c81 | 123 | fSize(0), |
124 | fContent() | |
125 | { | |
126 | Fill(esd); | |
127 | } | |
128 | ||
129 | // _______________________________________________________________________________________________________ | |
130 | AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd, Bool_t useESDFriends) : | |
131 | // Constructor | |
132 | fPrimaryVertexMask(0), | |
133 | fNTracks(0), | |
134 | fTracksPointer(0), | |
27595dcc | 135 | fNV0s(0), |
136 | fV0Pointer(0), | |
251a2c81 | 137 | fSize(0), |
138 | fContent() | |
139 | { | |
140 | Fill(esd, useESDFriends); | |
141 | } | |
142 | ||
143 | // _______________________________________________________________________________________________________ | |
144 | AliFlatESDEvent::~AliFlatESDEvent() | |
145 | { | |
146 | // Destructor | |
147 | } | |
148 | ||
149 | // _______________________________________________________________________________________________________ | |
150 | ULong64_t AliFlatESDEvent::EstimateSize(AliESDEvent *esd, Bool_t useESDFriends, Bool_t fillV0s) | |
151 | { | |
152 | // Estimate upper limit of the object size | |
153 | // -> Added objects have to be added here as well | |
154 | ||
155 | ULong64_t size = sizeof(AliFlatESDEvent); | |
156 | size += 2 * sizeof( AliFlatESDVertex ); | |
157 | size += esd->GetNumberOfTracks() * AliFlatESDTrack::EstimateSize(useESDFriends); | |
158 | if( fillV0s ) size += esd->GetNumberOfV0s()*sizeof(AliFlatESDV0); | |
159 | return size; | |
160 | } | |
161 | ||
162 | void AliFlatESDEvent::FillPrimaryVertices( const AliESDVertex *vertexSPD, | |
163 | const AliESDVertex *vertexTracks ) | |
164 | { | |
165 | // fill primary vertices | |
166 | ||
167 | fPrimaryVertexMask = 0; | |
168 | fSize = 0; | |
169 | ||
170 | Byte_t flag = 0x1; | |
171 | FillPrimaryVertex(vertexSPD, flag); | |
172 | ||
173 | flag = 0x2; | |
174 | FillPrimaryVertex(vertexTracks, flag); | |
175 | ||
176 | fTracksPointer = fSize; | |
177 | fV0Pointer = fSize; | |
178 | } | |
179 | ||
180 | void AliFlatESDEvent::FillPrimaryVertex(const AliESDVertex *v, Byte_t flag) | |
181 | { | |
182 | ||
183 | // Fill primary vertex parameters | |
184 | ||
185 | if (!v) return; | |
186 | ||
187 | AliFlatESDVertex *vtx = reinterpret_cast<AliFlatESDVertex*> (fContent + fSize); | |
488e1434 | 188 | new(vtx) AliFlatESDVertex; |
251a2c81 | 189 | vtx->Set( *v ); |
190 | fPrimaryVertexMask |= flag; | |
191 | fSize += sizeof(AliFlatESDVertex); | |
192 | } | |
193 | ||
194 | ||
195 | Int_t AliFlatESDEvent::FillNextTrack( const AliESDtrack* esdTrack, AliESDfriendTrack* friendTrack) | |
196 | { | |
197 | // fill next track | |
198 | ||
488e1434 | 199 | AliFlatESDTrack * flatTrack = reinterpret_cast<AliFlatESDTrack*>(fContent+fSize); |
200 | new(flatTrack) AliFlatESDTrack; | |
251a2c81 | 201 | flatTrack->Fill(esdTrack, friendTrack); |
202 | fSize += flatTrack->GetSize(); | |
203 | ++fNTracks; | |
204 | return 0; | |
205 | } | |
206 | ||
207 | void AliFlatESDEvent::Reset() | |
208 | { | |
209 | fSize = 0; | |
210 | fNTracks=0; | |
211 | fNV0s = 0; | |
212 | fPrimaryVertexMask = 0; | |
213 | fTracksPointer = 0; | |
214 | fV0Pointer = 0; | |
215 | } | |
216 | ||
217 | // _______________________________________________________________________________________________________ | |
218 | Int_t AliFlatESDEvent::Fill(const AliESDEvent *esd, const Bool_t useESDFriends, const Bool_t fillV0s ) | |
219 | { | |
220 | // Fill flat ESD event from normal ALiESDEvent | |
221 | // - Fill tracks + friends (if requested) | |
222 | // -> Added objects have to be added here as well | |
223 | ||
224 | Reset(); | |
225 | ||
226 | FillPrimaryVertices( esd->GetPrimaryVertexSPD(), esd->GetPrimaryVertexTracks() ); | |
227 | ||
228 | // -- Get ESD friends | |
229 | // ------------------------------------------------------- | |
230 | Bool_t connectESDFriends = useESDFriends; | |
231 | AliESDfriend* esdFriend = NULL; | |
232 | ||
233 | if (connectESDFriends) { | |
234 | esdFriend = dynamic_cast<AliESDfriend*>(esd->FindListObject("AliESDfriend")); | |
235 | if (!esdFriend) { | |
236 | connectESDFriends = kFALSE; | |
237 | Printf("WARNING: friends not available, cluster information will not be included"); | |
238 | } | |
239 | else | |
240 | Printf("INFO: friends are available, cluster information will be included"); | |
241 | } | |
242 | ||
243 | // -- Track loop, fill AliFlatESDTrack sub structure | |
244 | // ------------------------------------------------------- | |
245 | for (Int_t idxTrack = 0; idxTrack < esd->GetNumberOfTracks(); ++idxTrack) { | |
246 | AliESDtrack *esdTrack = esd->GetTrack(idxTrack); | |
247 | AliESDfriendTrack *friendTrack = NULL; | |
248 | ||
249 | if (esdTrack) { | |
250 | if (connectESDFriends){ | |
251 | friendTrack = esdFriend->GetTrack(idxTrack); | |
252 | } | |
253 | FillNextTrack( esdTrack, friendTrack); | |
254 | } | |
255 | } | |
256 | ||
257 | // Fill V0s | |
258 | ||
259 | fV0Pointer = fSize; | |
260 | fNV0s = 0; | |
261 | if( fillV0s ){ | |
262 | for( int i=0; i < esd->GetNumberOfV0s(); i++){ | |
263 | AliESDv0 *esdV0 = esd->GetV0( i ); | |
264 | AliFlatESDV0 *v0 = GetNextV0Pointer(); | |
265 | if( !v0 ) continue; | |
266 | v0->fNegTrackID = esdV0->GetNindex(); | |
267 | v0->fPosTrackID = esdV0->GetNindex(); | |
268 | StoreLastV0(); | |
269 | } | |
270 | } | |
271 | ||
272 | return 0; | |
273 | } | |
274 | ||
50ff8c36 | 275 | UInt_t AliFlatESDEvent::CountBits(Byte_t field, UInt_t mask) const { |
251a2c81 | 276 | // Count bits in field |
277 | UInt_t count = 0; | |
278 | UInt_t reg = 0x0; | |
279 | ||
280 | reg |= field; | |
281 | reg &= mask; | |
282 | ||
283 | for (count = 0; reg; count++) | |
284 | reg &= reg - 1; | |
285 | ||
286 | return count; | |
287 | } |