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),
76 AliFlatESDEvent::AliFlatESDEvent(const AliFlatESDEvent& ev) :
77 // Default constructor
78 fPrimaryVertexMask(ev.fPrimaryVertexMask),
79 fNTracks(ev.fNTracks),
80 fTracksPointer(ev.fTracksPointer),
82 fV0Pointer(ev.fV0Pointer),
88 // _______________________________________________________________________________________________________
89 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd) :
91 fPrimaryVertexMask(0),
102 // _______________________________________________________________________________________________________
103 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd, Bool_t useESDFriends) :
105 fPrimaryVertexMask(0),
113 Fill(esd, useESDFriends);
116 // _______________________________________________________________________________________________________
117 AliFlatESDEvent::~AliFlatESDEvent()
122 // _______________________________________________________________________________________________________
123 ULong64_t AliFlatESDEvent::EstimateSize(AliESDEvent *esd, Bool_t useESDFriends, Bool_t fillV0s)
125 // Estimate upper limit of the object size
126 // -> Added objects have to be added here as well
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);
135 void AliFlatESDEvent::FillPrimaryVertices( const AliESDVertex *vertexSPD,
136 const AliESDVertex *vertexTracks )
138 // fill primary vertices
140 fPrimaryVertexMask = 0;
144 FillPrimaryVertex(vertexSPD, flag);
147 FillPrimaryVertex(vertexTracks, flag);
149 fTracksPointer = fSize;
153 void AliFlatESDEvent::FillPrimaryVertex(const AliESDVertex *v, Byte_t flag)
156 // Fill primary vertex parameters
160 AliFlatESDVertex *vtx = reinterpret_cast<AliFlatESDVertex*> (fContent + fSize);
161 new(vtx) AliFlatESDVertex;
163 fPrimaryVertexMask |= flag;
164 fSize += sizeof(AliFlatESDVertex);
168 Int_t AliFlatESDEvent::FillNextTrack( const AliESDtrack* esdTrack, AliESDfriendTrack* friendTrack)
172 AliFlatESDTrack * flatTrack = reinterpret_cast<AliFlatESDTrack*>(fContent+fSize);
173 new(flatTrack) AliFlatESDTrack;
174 flatTrack->Fill(esdTrack, friendTrack);
175 fSize += flatTrack->GetSize();
180 void AliFlatESDEvent::Reset()
185 fPrimaryVertexMask = 0;
190 // _______________________________________________________________________________________________________
191 Int_t AliFlatESDEvent::Fill(const AliESDEvent *esd, const Bool_t useESDFriends, const Bool_t fillV0s )
193 // Fill flat ESD event from normal ALiESDEvent
194 // - Fill tracks + friends (if requested)
195 // -> Added objects have to be added here as well
199 FillPrimaryVertices( esd->GetPrimaryVertexSPD(), esd->GetPrimaryVertexTracks() );
201 // -- Get ESD friends
202 // -------------------------------------------------------
203 Bool_t connectESDFriends = useESDFriends;
204 AliESDfriend* esdFriend = NULL;
206 if (connectESDFriends) {
207 esdFriend = dynamic_cast<AliESDfriend*>(esd->FindListObject("AliESDfriend"));
209 connectESDFriends = kFALSE;
210 Printf("WARNING: friends not available, cluster information will not be included");
213 Printf("INFO: friends are available, cluster information will be included");
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;
223 if (connectESDFriends){
224 friendTrack = esdFriend->GetTrack(idxTrack);
226 FillNextTrack( esdTrack, friendTrack);
235 for( int i=0; i < esd->GetNumberOfV0s(); i++){
236 AliESDv0 *esdV0 = esd->GetV0( i );
237 AliFlatESDV0 *v0 = GetNextV0Pointer();
239 v0->fNegTrackID = esdV0->GetNindex();
240 v0->fPosTrackID = esdV0->GetNindex();
248 UInt_t AliFlatESDEvent::CountBits(Byte_t field, UInt_t mask) const {
249 // Count bits in field
256 for (count = 0; reg; count++)