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"
61 #include "AliFlatESDVertex.h"
63 #include "AliFlatESDV0.h"
64 #include "AliFlatESDTrigger.h"
66 #include "AliESDEvent.h"
67 #include "AliESDVertex.h"
69 // _______________________________________________________________________________________________________
70 AliFlatESDEvent::AliFlatESDEvent() :
78 fPrimaryVertexMask(0),
85 fPrimaryVertexPointer(0),
89 // Default constructor
94 // _______________________________________________________________________________________________________
95 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd) :
102 fBunchCrossNumber(0),
103 fPrimaryVertexMask(0),
106 fNPrimaryVertices(0),
110 fPrimaryVertexPointer(0),
118 // _______________________________________________________________________________________________________
119 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd, Bool_t useESDFriends) :
121 fPrimaryVertexMask(0),
131 fBunchCrossNumber(0),
135 Fill(esd, useESDFriends);
139 // _______________________________________________________________________________________________________
140 AliFlatESDEvent::~AliFlatESDEvent()
145 void AliFlatESDEvent::Init()
155 fBunchCrossNumber = 0;
156 fPrimaryVertexMask = 0;
158 fNTriggerClasses = 0;
159 fNPrimaryVertices = 0;
163 fPrimaryVertexPointer = 0;
168 // _______________________________________________________________________________________________________
169 ULong64_t AliFlatESDEvent::EstimateSize(AliESDEvent *esd, Bool_t useESDFriends, Bool_t fillV0s)
171 // Estimate upper limit of the object size
172 // -> Added objects have to be added here as well
174 ULong64_t size = sizeof(AliFlatESDEvent);
175 size += 2 * sizeof( AliFlatESDVertex );
176 size += esd->GetNumberOfTracks() * AliFlatESDTrack::EstimateSize(useESDFriends);
177 if( fillV0s ) size += esd->GetNumberOfV0s()*sizeof(AliFlatESDV0);
181 void AliFlatESDEvent::FillPrimaryVertices( const AliESDVertex *vertexSPD,
182 const AliESDVertex *vertexTracks )
184 // fill primary vertices
186 fPrimaryVertexMask = 0;
190 FillPrimaryVertex(vertexSPD, flag);
193 FillPrimaryVertex(vertexTracks, flag);
195 fTracksPointer = fContentSize;
196 fV0Pointer = fContentSize;
199 void AliFlatESDEvent::FillPrimaryVertex(const AliESDVertex *v, Byte_t flag)
202 // Fill primary vertex parameters
206 AliFlatESDVertex *vtx = reinterpret_cast<AliFlatESDVertex*> (fContent + fContentSize);
208 fPrimaryVertexMask |= flag;
209 fContentSize += sizeof(AliFlatESDVertex);
213 Int_t AliFlatESDEvent::FillNextTrack( const AliESDtrack* esdTrack, AliESDfriendTrack* friendTrack)
217 AliFlatESDTrack *flatTrack = reinterpret_cast<AliFlatESDTrack*>(fContent+fContentSize);
218 //new (flatTrack) AliFlatESDTrack;
219 flatTrack->Fill(esdTrack, friendTrack);
220 fContentSize += flatTrack->GetSize();
225 Int_t AliFlatESDEvent::AddTriggerClass( const char *TriggerClassName, Int_t TriggerIndex, ULong64_t MaxSize )
228 AliFlatESDTrigger *flatTrigger = reinterpret_cast<AliFlatESDTrigger*>(fContent+fContentSize);
229 Int_t err = flatTrigger->SetTriggerClass( TriggerClassName, TriggerIndex, MaxSize );
231 fContentSize+= flatTrigger->GetSize();
238 // _______________________________________________________________________________________________________
239 Int_t AliFlatESDEvent::FillFromESD( const size_t allocatedMemorySize, const AliESDEvent *esd, const Bool_t useESDFriends, const Bool_t fillV0s)
241 // Fill flat ESD event from normal ALiESDEvent
242 // - Fill tracks + friends (if requested)
243 // -> Added objects have to be added here as well
246 if( allocatedMemorySize < sizeof(AliFlatESDEvent) ) return -1;
253 size_t freeSpace = allocatedMemorySize - GetSize();
257 SetTriggerMask( esd->GetTriggerMask() );
261 // Fill trigger information
263 size_t triggerSize = 0;
265 AliFlatESDTrigger *trigger = FillTriggersStart();
266 const AliESDRun* esdRun = esd->GetESDRun();
268 for( int index=0; index<AliESDRun::kNTriggerClasses; index++){
269 const char* name = esdRun->GetTriggerClass(index);
270 if( name && name[0]!='\0' ){
271 err = trigger->SetTriggerClass( name, index, freeSpace );
272 if( err!=0 ) return err;
274 freeSpace -= trigger->GetSize();
275 triggerSize += trigger->GetSize();
276 trigger = trigger->GetNextTrigger();
280 FillTriggersEnd( nTriggers, triggerSize );
283 // fill primary vertices
286 err = FillPrimaryVertices( freeSpace, esd->GetPrimaryVertexSPD(), esd->GetPrimaryVertexTracks() );
288 if( err!=0 ) return err;
290 freeSpace = allocatedMemorySize - GetSize();
293 ULong64_t GetTriggerMask() const {return fHeader?fHeader->GetTriggerMask():0;}
294 TString GetFiredTriggerClasses() const {return (fESDRun&&fHeader)?fESDRun->GetFiredTriggerClasses(fHeader->GetTriggerMask()):"";}
295 Bool_t IsTriggerClassFired(const char *name) const {return (fESDRun&&fHeader)?fESDRun->IsTriggerClassFired(fHeader->GetTriggerMask(),name):kFALSE;}
297 const AliHLTCTPData* pCTPData=CTPData();
299 AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
300 for (int index=0; index<gkNCTPTriggerClasses; index++) {
301 if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
302 pESD->SetTriggerClass(pCTPData->Name(index), index);
304 pESD->SetTriggerMask(mask);
308 //allocatedMemorySize - GetSize();
310 FillTriggersEnd(nTriggers, triggerSize );
312 // -- Get ESD friends
313 // -------------------------------------------------------
314 Bool_t connectESDFriends = useESDFriends;
315 AliESDfriend* esdFriend = NULL;
317 if (connectESDFriends) {
318 esdFriend = dynamic_cast<AliESDfriend*>(esd->FindListObject("AliESDfriend"));
320 connectESDFriends = kFALSE;
321 Printf("WARNING: friends not available, cluster information will not be included");
324 Printf("INFO: friends are available, cluster information will be included");
327 // -- Track loop, fill AliFlatESDTrack sub structure
328 // -------------------------------------------------------
329 for (Int_t idxTrack = 0; idxTrack < esd->GetNumberOfTracks(); ++idxTrack) {
330 AliESDtrack *esdTrack = esd->GetTrack(idxTrack);
331 AliESDfriendTrack *friendTrack = NULL;
334 if (connectESDFriends){
335 friendTrack = esdFriend->GetTrack(idxTrack);
337 FillNextTrack( esdTrack, friendTrack);
343 fV0Pointer = fContentSize;
346 for( int i=0; i < esd->GetNumberOfV0s(); i++){
347 AliESDv0 *esdV0 = esd->GetV0( i );
348 AliFlatESDV0 *v0 = GetNextV0Pointer();
350 v0->fNegTrackID = esdV0->GetNindex();
351 v0->fPosTrackID = esdV0->GetNindex();
359 UInt_t AliFlatESDEvent::CountBits(Byte_t field, UInt_t mask) const {
360 // Count bits in field
367 for (count = 0; reg; count++)