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 ClassImp(AliFlatESDEvent);
71 // _______________________________________________________________________________________________________
72 AliFlatESDEvent::AliFlatESDEvent() :
80 fPrimaryVertexMask(0),
87 fPrimaryVertexPointer(0),
91 // Default constructor
96 // _______________________________________________________________________________________________________
97 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd) :
104 fBunchCrossNumber(0),
105 fPrimaryVertexMask(0),
108 fNPrimaryVertices(0),
112 fPrimaryVertexPointer(0),
120 // _______________________________________________________________________________________________________
121 AliFlatESDEvent::AliFlatESDEvent(AliESDEvent *esd, Bool_t useESDFriends) :
123 fPrimaryVertexMask(0),
133 fBunchCrossNumber(0),
137 Fill(esd, useESDFriends);
141 // _______________________________________________________________________________________________________
142 AliFlatESDEvent::~AliFlatESDEvent()
147 void AliFlatESDEvent::Init()
157 fBunchCrossNumber = 0;
158 fPrimaryVertexMask = 0;
160 fNTriggerClasses = 0;
161 fNPrimaryVertices = 0;
165 fPrimaryVertexPointer = 0;
170 // _______________________________________________________________________________________________________
171 ULong64_t AliFlatESDEvent::EstimateSize(AliESDEvent *esd, Bool_t useESDFriends, Bool_t fillV0s)
173 // Estimate upper limit of the object size
174 // -> Added objects have to be added here as well
176 ULong64_t size = sizeof(AliFlatESDEvent);
177 size += 2 * sizeof( AliFlatESDVertex );
178 size += esd->GetNumberOfTracks() * AliFlatESDTrack::EstimateSize(useESDFriends);
179 if( fillV0s ) size += esd->GetNumberOfV0s()*sizeof(AliFlatESDV0);
183 void AliFlatESDEvent::FillPrimaryVertices( const AliESDVertex *vertexSPD,
184 const AliESDVertex *vertexTracks )
186 // fill primary vertices
188 fPrimaryVertexMask = 0;
192 FillPrimaryVertex(vertexSPD, flag);
195 FillPrimaryVertex(vertexTracks, flag);
197 fTracksPointer = fContentSize;
198 fV0Pointer = fContentSize;
201 void AliFlatESDEvent::FillPrimaryVertex(const AliESDVertex *v, Byte_t flag)
204 // Fill primary vertex parameters
208 AliFlatESDVertex *vtx = reinterpret_cast<AliFlatESDVertex*> (fContent + fContentSize);
210 fPrimaryVertexMask |= flag;
211 fContentSize += sizeof(AliFlatESDVertex);
215 Int_t AliFlatESDEvent::FillNextTrack( const AliESDtrack* esdTrack, AliESDfriendTrack* friendTrack)
219 AliFlatESDTrack *flatTrack = reinterpret_cast<AliFlatESDTrack*>(fContent+fContentSize);
220 //new (flatTrack) AliFlatESDTrack;
221 flatTrack->Fill(esdTrack, friendTrack);
222 fContentSize += flatTrack->GetSize();
227 Int_t AliFlatESDEvent::AddTriggerClass( const char *TriggerClassName, Int_t TriggerIndex, ULong64_t MaxSize )
230 AliFlatESDTrigger *flatTrigger = reinterpret_cast<AliFlatESDTrigger*>(fContent+fContentSize);
231 Int_t err = flatTrigger->SetTriggerClass( TriggerClassName, TriggerIndex, MaxSize );
233 fContentSize+= flatTrigger->GetSize();
240 // _______________________________________________________________________________________________________
241 Int_t AliFlatESDEvent::FillFromESD( const size_t allocatedMemorySize, const AliESDEvent *esd, const Bool_t useESDFriends, const Bool_t fillV0s)
243 // Fill flat ESD event from normal ALiESDEvent
244 // - Fill tracks + friends (if requested)
245 // -> Added objects have to be added here as well
248 if( allocatedMemorySize < sizeof(AliFlatESDEvent) ) return -1;
255 size_t freeSpace = allocatedMemorySize - GetSize();
259 SetTriggerMask( esd->GetTriggerMask() );
263 // Fill trigger information
265 size_t triggerSize = 0;
267 AliFlatESDTrigger *trigger = FillTriggersStart();
268 const AliESDRun* esdRun = esd->GetESDRun();
270 for( int index=0; index<AliESDRun::kNTriggerClasses; index++){
271 const char* name = esdRun->GetTriggerClass(index);
272 if( name && name[0]!='\0' ){
273 err = trigger->SetTriggerClass( name, index, freeSpace );
274 if( err!=0 ) return err;
276 freeSpace -= trigger->GetSize();
277 triggerSize += trigger->GetSize();
278 trigger = trigger->GetNextTrigger();
282 FillTriggersEnd( nTriggers, triggerSize );
285 // fill primary vertices
288 err = FillPrimaryVertices( freeSpace, esd->GetPrimaryVertexSPD(), esd->GetPrimaryVertexTracks() );
290 if( err!=0 ) return err;
292 freeSpace = allocatedMemorySize - GetSize();
295 ULong64_t GetTriggerMask() const {return fHeader?fHeader->GetTriggerMask():0;}
296 TString GetFiredTriggerClasses() const {return (fESDRun&&fHeader)?fESDRun->GetFiredTriggerClasses(fHeader->GetTriggerMask()):"";}
297 Bool_t IsTriggerClassFired(const char *name) const {return (fESDRun&&fHeader)?fESDRun->IsTriggerClassFired(fHeader->GetTriggerMask(),name):kFALSE;}
299 const AliHLTCTPData* pCTPData=CTPData();
301 AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
302 for (int index=0; index<gkNCTPTriggerClasses; index++) {
303 if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
304 pESD->SetTriggerClass(pCTPData->Name(index), index);
306 pESD->SetTriggerMask(mask);
310 //allocatedMemorySize - GetSize();
312 FillTriggersEnd(nTriggers, triggerSize );
314 // -- Get ESD friends
315 // -------------------------------------------------------
316 Bool_t connectESDFriends = useESDFriends;
317 AliESDfriend* esdFriend = NULL;
319 if (connectESDFriends) {
320 esdFriend = dynamic_cast<AliESDfriend*>(esd->FindListObject("AliESDfriend"));
322 connectESDFriends = kFALSE;
323 Printf("WARNING: friends not available, cluster information will not be included");
326 Printf("INFO: friends are available, cluster information will be included");
329 // -- Track loop, fill AliFlatESDTrack sub structure
330 // -------------------------------------------------------
331 for (Int_t idxTrack = 0; idxTrack < esd->GetNumberOfTracks(); ++idxTrack) {
332 AliESDtrack *esdTrack = esd->GetTrack(idxTrack);
333 AliESDfriendTrack *friendTrack = NULL;
336 if (connectESDFriends){
337 friendTrack = esdFriend->GetTrack(idxTrack);
339 FillNextTrack( esdTrack, friendTrack);
345 fV0Pointer = fContentSize;
348 for( int i=0; i < esd->GetNumberOfV0s(); i++){
349 AliESDv0 *esdV0 = esd->GetV0( i );
350 AliFlatESDV0 *v0 = GetNextV0Pointer();
352 v0->fNegTrackID = esdV0->GetNindex();
353 v0->fPosTrackID = esdV0->GetNindex();
361 UInt_t AliFlatESDEvent::CountBits(Byte_t field, UInt_t mask) const {
362 // Count bits in field
369 for (count = 0; reg; count++)