3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Author: The ALICE Off-line Project. *
7 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 * >> Flat structure representing an ESD <<
21 * To be used in the online and offline calibration schema.
23 * Class provides interface methods for
24 * - Filling from AliESDEvent, but also from HLT (to be added)
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.
31 * Primary Authors : Sergey Gorbunov, Jochen Thaeder, Chiara Zampolli
33 * ************************************************************************
37 * AliESDEvent* esd = ....;
38 * Bool_t useESDFriends = kTRUE;
40 * // -- Book memory for AliFlatESDEvent
41 * Byte_t *mem = new Byte_t[AliFlatESDEvent::EstimateSize(esd, useESDFriends)];
42 * AliFlatESDEvent *flatEsd = reinterpret_cast<AliFlatESDEvent*>(mem);
44 * // -- Fill AliFlatESDEvent
45 * flatEsd->Fill(esd, useESDFriends);
48 **************************************************************************/
50 #include "AliESDEvent.h"
51 #include "AliESDtrack.h"
52 #include "AliESDfriend.h"
55 #include "AliFlatESDEvent.h"
56 #include "AliFlatESDTrack.h"
57 #include "AliFlatTPCCluster.h"
58 #include "AliFlatExternalTrackParam.h"
59 #include "Riostream.h"
60 #include "AliFlatESDVertex.h"
62 // _______________________________________________________________________________________________________
63 AliFlatESDEvent::AliFlatESDEvent() :
64 // Default constructor
65 fPrimaryVertexMask(0),
75 // _______________________________________________________________________________________________________
76 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd) :
78 fPrimaryVertexMask(0),
89 // _______________________________________________________________________________________________________
90 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd, Bool_t useESDFriends) :
92 fPrimaryVertexMask(0),
100 Fill(esd, useESDFriends);
103 // _______________________________________________________________________________________________________
104 AliFlatESDEvent::~AliFlatESDEvent()
109 // _______________________________________________________________________________________________________
110 ULong64_t AliFlatESDEvent::EstimateSize(AliESDEvent *esd, Bool_t useESDFriends, Bool_t fillV0s)
112 // Estimate upper limit of the object size
113 // -> Added objects have to be added here as well
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);
122 void AliFlatESDEvent::FillPrimaryVertices( const AliESDVertex *vertexSPD,
123 const AliESDVertex *vertexTracks )
125 // fill primary vertices
127 fPrimaryVertexMask = 0;
131 FillPrimaryVertex(vertexSPD, flag);
134 FillPrimaryVertex(vertexTracks, flag);
136 fTracksPointer = fSize;
140 void AliFlatESDEvent::FillPrimaryVertex(const AliESDVertex *v, Byte_t flag)
143 // Fill primary vertex parameters
147 AliFlatESDVertex *vtx = reinterpret_cast<AliFlatESDVertex*> (fContent + fSize);
149 fPrimaryVertexMask |= flag;
150 fSize += sizeof(AliFlatESDVertex);
154 Int_t AliFlatESDEvent::FillNextTrack( const AliESDtrack* esdTrack, AliESDfriendTrack* friendTrack)
158 AliFlatESDTrack *flatTrack = reinterpret_cast<AliFlatESDTrack*>(fContent+fSize);
159 //new (flatTrack) AliFlatESDTrack;
160 flatTrack->Fill(esdTrack, friendTrack);
161 fSize += flatTrack->GetSize();
166 void AliFlatESDEvent::Reset()
171 fPrimaryVertexMask = 0;
176 // _______________________________________________________________________________________________________
177 Int_t AliFlatESDEvent::Fill(const AliESDEvent *esd, const Bool_t useESDFriends, const Bool_t fillV0s )
179 // Fill flat ESD event from normal ALiESDEvent
180 // - Fill tracks + friends (if requested)
181 // -> Added objects have to be added here as well
185 FillPrimaryVertices( esd->GetPrimaryVertexSPD(), esd->GetPrimaryVertexTracks() );
187 // -- Get ESD friends
188 // -------------------------------------------------------
189 Bool_t connectESDFriends = useESDFriends;
190 AliESDfriend* esdFriend = NULL;
192 if (connectESDFriends) {
193 esdFriend = dynamic_cast<AliESDfriend*>(esd->FindListObject("AliESDfriend"));
195 connectESDFriends = kFALSE;
196 Printf("WARNING: friends not available, cluster information will not be included");
199 Printf("INFO: friends are available, cluster information will be included");
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;
209 if (connectESDFriends){
210 friendTrack = esdFriend->GetTrack(idxTrack);
212 FillNextTrack( esdTrack, friendTrack);
221 for( int i=0; i < esd->GetNumberOfV0s(); i++){
222 AliESDv0 *esdV0 = esd->GetV0( i );
223 AliFlatESDV0 *v0 = GetNextV0Pointer();
225 v0->fNegTrackID = esdV0->GetNindex();
226 v0->fPosTrackID = esdV0->GetNindex();
234 UInt_t AliFlatESDEvent::CountBits(Byte_t field, UInt_t mask) {
235 // Count bits in field
242 for (count = 0; reg; count++)