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