added friends to compare component
[u/mrichter/AliRoot.git] / HLT / global / AliFlatESDEvent.cxx
CommitLineData
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"
6a33e0e9 60
251a2c81 61#include "AliFlatESDVertex.h"
62
6a33e0e9 63#include "AliFlatESDV0.h"
64#include "AliFlatESDTrigger.h"
65
66#include "AliESDEvent.h"
67#include "AliESDVertex.h"
68
251a2c81 69// _______________________________________________________________________________________________________
c2ea967e 70AliFlatESDEvent::AliFlatESDEvent()
71 :
6a33e0e9 72 fContentSize(0),
73 fMagneticField(0),
74 fPeriodNumber(0),
75 fRunNumber(0),
76 fOrbitNumber(0),
77 fTimeStamp(0),
888585e5 78 fEventSpecie(0),
6a33e0e9 79 fBunchCrossNumber(0),
251a2c81 80 fPrimaryVertexMask(0),
6a33e0e9 81 fTriggerMask(0),
888585e5 82 fTriggerMaskNext50(0),
6a33e0e9 83 fNTriggerClasses(0),
84 fNPrimaryVertices(0),
251a2c81 85 fNTracks(0),
27595dcc 86 fNV0s(0),
6a33e0e9 87 fTriggerPointer(0),
888585e5 88 fPrimaryVertexTracksPointer(0),
89 fPrimaryVertexSPDPointer(0),
90 fTrackTablePointer(0),
6a33e0e9 91 fTracksPointer(0),
c6f15692 92 fV0Pointer(0),
93 fFriendEvent(NULL)
251a2c81 94{
6a33e0e9 95 // Default constructor
96 fContent[0]=0;
251a2c81 97}
98
bbddf50f 99#pragma GCC diagnostic ignored "-Weffc++"
98ccbd37 100AliFlatESDEvent::AliFlatESDEvent( AliVConstructorReinitialisationFlag /*f*/ )
bbddf50f 101 :
102 fFriendEvent(NULL)
c2ea967e 103{
104 // Constructor for reinitialisation of vtable
c2ea967e 105
106 // Reinitialise trigger information
107 {
108 AliFlatESDTrigger * trigger = reinterpret_cast< AliFlatESDTrigger*>( fContent + fTriggerPointer );
109 for( UInt_t i=0; i<fNTriggerClasses; i++ ){
110 trigger->Reinitialize();
111 trigger = trigger->GetNextTriggerNonConst();
112 }
113 }
114
115 // Reinitialise primary vertices
116
117 if( fPrimaryVertexMask & 0x1 ){
118 AliFlatESDVertex *vtxSPD = reinterpret_cast<AliFlatESDVertex*>(fContent + fPrimaryVertexSPDPointer);
119 vtxSPD->Reinitialize();
120 }
121 if( fPrimaryVertexMask & 0x2 ){
122 AliFlatESDVertex *vtxTracks = reinterpret_cast<AliFlatESDVertex*>(fContent + fPrimaryVertexTracksPointer);
123 vtxTracks->Reinitialize();
124 }
125
126 // Reinitialise tracks
127 {
128 AliFlatESDTrack *track = reinterpret_cast<AliFlatESDTrack*>( fContent + fTracksPointer );
129 for( UInt_t i=0; i<fNTracks; i++ ){
130 track->Reinitialize();
131 track = track->GetNextTrackNonConst();
132 }
133 }
134
135 // Reinitialise V0s
136 {
137 AliFlatESDV0 *v0 = reinterpret_cast<AliFlatESDV0*>( fContent + fV0Pointer );
138 for( UInt_t i=0; i < fNV0s; i++){
139 v0->Reinitialize();
140 v0 = v0->GetNextV0NonConst();
141 }
142 }
143}
bbddf50f 144#pragma GCC diagnostic warning "-Weffc++"
c2ea967e 145
146
888585e5 147TString AliFlatESDEvent::GetFiredTriggerClasses() const
251a2c81 148{
888585e5 149 // Fired trigger classes
150 TString trclasses;
151 const AliFlatESDTrigger *tr = GetTriggerClasses();
152 ULong64_t mask = GetTriggerMask() | GetTriggerMaskNext50();
153 for(Int_t i = 0; i < GetNumberOfTriggerClasses(); i++) {
154 int index = tr->GetTriggerIndex();
155 if( mask & (1ull<<index) ){
156 trclasses += " ";
157 trclasses += tr->GetTriggerClassName();
158 trclasses += " ";
159 }
160 }
161 tr = tr->GetNextTrigger();
162 return trclasses;
251a2c81 163}
164
251a2c81 165
888585e5 166void AliFlatESDEvent::Reset()
6a33e0e9 167{
168 // Init
169
170 fContentSize = 0;
171 fMagneticField = 0;
172 fPeriodNumber = 0;
173 fRunNumber = 0;
174 fOrbitNumber = 0;
175 fTimeStamp = 0;
176 fBunchCrossNumber = 0;
177 fPrimaryVertexMask = 0;
178 fTriggerMask = 0;
888585e5 179 fTriggerMaskNext50 = 0;
6a33e0e9 180 fNTriggerClasses = 0;
181 fNPrimaryVertices = 0;
182 fNTracks = 0;
183 fNV0s = 0;
184 fTriggerPointer = 0;
888585e5 185 fPrimaryVertexTracksPointer = 0;
186 fPrimaryVertexSPDPointer = 0;
187 fTrackTablePointer = 0;
6a33e0e9 188 fTracksPointer = 0;
189 fV0Pointer = 0;
190}
191
251a2c81 192// _______________________________________________________________________________________________________
888585e5 193 ULong64_t AliFlatESDEvent::EstimateSize(AliESDEvent *esd, Bool_t fillV0s)
251a2c81 194{
195 // Estimate upper limit of the object size
196 // -> Added objects have to be added here as well
197
198 ULong64_t size = sizeof(AliFlatESDEvent);
199 size += 2 * sizeof( AliFlatESDVertex );
a88a189e 200 size += esd->GetNumberOfTracks() * AliFlatESDTrack::EstimateSize();
5ec8009a 201 size += AliESDRun::kNTriggerClasses * sizeof(AliFlatESDTrigger) ;
251a2c81 202 if( fillV0s ) size += esd->GetNumberOfV0s()*sizeof(AliFlatESDV0);
203 return size;
204}
205
888585e5 206Int_t AliFlatESDEvent::SetPrimaryVertexTracks( const AliESDVertex *vtx, size_t allocatedVtxMemory )
251a2c81 207{
888585e5 208 // fill primary vertex tracks
209 if( !vtx ) return 0;
fff4e215 210 if(!vtx->GetStatus()) return 0;
888585e5 211 if( allocatedVtxMemory < sizeof(AliFlatESDVertex) ) return -1;
212 fPrimaryVertexMask |= 0x1;
213 fPrimaryVertexTracksPointer = fContentSize;
214 AliFlatESDVertex *flatVtx = reinterpret_cast<AliFlatESDVertex*> (fContent + fContentSize);
0d577a2c 215 flatVtx->SetFromESDVertex( *vtx );
888585e5 216 fContentSize += flatVtx->GetSize();
217 return 0;
251a2c81 218}
219
888585e5 220Int_t AliFlatESDEvent::SetPrimaryVertexSPD( const AliESDVertex *vtx, size_t allocatedVtxMemory )
251a2c81 221{
888585e5 222 // fill primary vertex SPD
223 if( !vtx ) return 0;
fff4e215 224 if(!vtx->GetStatus()) return 0;
888585e5 225 if( allocatedVtxMemory < sizeof(AliFlatESDVertex) ) return -1;
226 fPrimaryVertexMask |= 0x2;
227 fPrimaryVertexSPDPointer = fContentSize;
228 AliFlatESDVertex *flatVtx = reinterpret_cast<AliFlatESDVertex*> (fContent + fContentSize);
0d577a2c 229 flatVtx->SetFromESDVertex( *vtx );
888585e5 230 fContentSize += flatVtx->GetSize();
251a2c81 231 return 0;
232}
233
251a2c81 234
235// _______________________________________________________________________________________________________
888585e5 236Int_t AliFlatESDEvent::SetFromESD( const size_t allocatedMemorySize, const AliESDEvent *esd, const Bool_t fillV0s)
251a2c81 237{
238 // Fill flat ESD event from normal ALiESDEvent
888585e5 239 // - Fill tracks + v0s
251a2c81 240 // -> Added objects have to be added here as well
6a33e0e9 241
6a33e0e9 242 if( allocatedMemorySize < sizeof(AliFlatESDEvent) ) return -1;
251a2c81 243
888585e5 244 Reset();
251a2c81 245
6a33e0e9 246 if( !esd ) return 0;
247
248 Int_t err = 0;
249 size_t freeSpace = allocatedMemorySize - GetSize();
250
251 // fill run info
252 {
888585e5 253 SetMagneticField( esd->GetMagneticField() );
254 SetPeriodNumber( esd->GetPeriodNumber() );
255 SetRunNumber( esd->GetRunNumber() );
256 SetOrbitNumber( esd->GetOrbitNumber() );
257 SetBunchCrossNumber( esd->GetBunchCrossNumber() );
258 SetTimeStamp( esd->GetTimeStamp() );
259 SetEventSpecie( esd->GetEventSpecie() );
6a33e0e9 260 SetTriggerMask( esd->GetTriggerMask() );
888585e5 261 SetTriggerMaskNext50( esd->GetTriggerMaskNext50() );
6a33e0e9 262 }
888585e5 263
6a33e0e9 264 // Fill trigger information
265 {
266 size_t triggerSize = 0;
267 int nTriggers = 0;
888585e5 268 AliFlatESDTrigger *trigger = SetTriggersStart();
6a33e0e9 269 const AliESDRun* esdRun = esd->GetESDRun();
270 if( esdRun ){
271 for( int index=0; index<AliESDRun::kNTriggerClasses; index++){
272 const char* name = esdRun->GetTriggerClass(index);
273 if( name && name[0]!='\0' ){
274 err = trigger->SetTriggerClass( name, index, freeSpace );
275 if( err!=0 ) return err;
276 nTriggers++;
277 freeSpace -= trigger->GetSize();
278 triggerSize += trigger->GetSize();
888585e5 279 trigger = trigger->GetNextTriggerNonConst();
6a33e0e9 280 }
281 }
282 }
888585e5 283 SetTriggersEnd( nTriggers, triggerSize );
6a33e0e9 284 }
285
286 // fill primary vertices
287
888585e5 288 err = SetPrimaryVertexTracks( esd->GetPrimaryVertexTracks(), freeSpace );
6a33e0e9 289 if( err!=0 ) return err;
6a33e0e9 290 freeSpace = allocatedMemorySize - GetSize();
291
888585e5 292 err = SetPrimaryVertexSPD( esd->GetPrimaryVertexSPD(), freeSpace );
293 if( err!=0 ) return err;
294 freeSpace = allocatedMemorySize - GetSize();
251a2c81 295
888585e5 296 // fill tracks
297 {
298 size_t trackSize = 0;
299 int nTracks = 0;
300 Long64_t *table = NULL;
301 AliFlatESDTrack *flatTrack = NULL;
302 err = SetTracksStart( flatTrack, table, esd->GetNumberOfTracks(), freeSpace );
303 if( err!=0 ) return err;
304 freeSpace = allocatedMemorySize - GetSize();
305
306 for (Int_t idxTrack = 0; idxTrack < esd->GetNumberOfTracks(); ++idxTrack) {
307 AliESDtrack *esdTrack = esd->GetTrack(idxTrack);
308 table[idxTrack] = -1;
309 if (esdTrack) {
310 table[idxTrack] = trackSize;
311 if( freeSpace<flatTrack->EstimateSize() ) return -1;
312 new (flatTrack) AliFlatESDTrack;
0d577a2c 313 flatTrack->SetFromESDTrack( esdTrack );
888585e5 314 trackSize += flatTrack->GetSize();
315 freeSpace -= flatTrack->GetSize();
316 nTracks++;
c2ea967e 317 flatTrack = flatTrack->GetNextTrackNonConst();
888585e5 318 }
319 }
320 SetTracksEnd( nTracks, trackSize );
251a2c81 321 }
322
888585e5 323 // fill V0s
251a2c81 324
251a2c81 325 if( fillV0s ){
888585e5 326 size_t v0size = 0;
327 int nV0s = 0;
328 AliFlatESDV0 *flatV0 = SetV0sStart();
251a2c81 329 for( int i=0; i < esd->GetNumberOfV0s(); i++){
330 AliESDv0 *esdV0 = esd->GetV0( i );
888585e5 331 if( !esdV0 || freeSpace < flatV0->GetSize() ) return -1;
332 new (flatV0) AliFlatESDV0;
333 flatV0->SetNegTrackID( esdV0->GetNindex());
334 flatV0->SetPosTrackID( esdV0->GetPindex());
335 nV0s++;
336 v0size += flatV0->GetSize();
337 freeSpace -= flatV0->GetSize();
c2ea967e 338 flatV0 = flatV0->GetNextV0NonConst();
251a2c81 339 }
888585e5 340 SetV0sEnd( nV0s, v0size );
251a2c81 341 }
888585e5 342
251a2c81 343 return 0;
344}
345
c8a50489 346AliVParticle* AliFlatESDEvent::GetTrack(Int_t i) const
347{
348 return const_cast<AliFlatESDTrack*>(GetFlatTrack(i));
349}
15da855d 350
351AliVEvent::EDataLayoutType AliFlatESDEvent::GetDataLayoutType() const
352{
353 return AliVEvent::kFlat;
354}
355