Using common HLT track data format for TRD tracks (Theodor)
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDUtils.cxx
CommitLineData
dc2e6604 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16///////////////////////////////////////////////////////////////////////////////
17// //
18// HLT TRD Utillities Class //
19// //
20///////////////////////////////////////////////////////////////////////////////
21
22#include "AliHLTTRDUtils.h"
23#include <TClonesArray.h>
24#include "AliHLTTRDTrack.h"
25#include "AliHLTTRDCluster.h"
18ada816 26#include "AliHLTExternalTrackParam.h"
27#include "AliESDEvent.h"
28#include "AliESDtrack.h"
29#include "AliPID.h"
30
31ClassImp(AliHLTTRDUtils)
dc2e6604 32
33AliHLTUInt32_t AliHLTTRDUtils::AddClustersToOutput(TClonesArray* inClusterArray, AliHLTUInt8_t* outBlockPtr)
34{
35 AliTRDcluster* cluster = 0;
36 AliHLTUInt32_t addedSize = 0;
37 // == OUTdatatype pointer
38 AliHLTTRDCluster * outPtr = (AliHLTTRDCluster*)outBlockPtr;
39
40 if (inClusterArray){
41 Int_t nbEntries = inClusterArray->GetEntries();
42 for (Int_t iCluster = 0; iCluster<nbEntries; iCluster++){
43 //cout << "Geting cluster #" << iCluster << endl;
44 UInt_t blockSize=0;
45
46 cluster = dynamic_cast<AliTRDcluster*>(inClusterArray->At(iCluster));
47
48 AliHLTTRDCluster *hltCluster = new (outPtr) AliHLTTRDCluster(cluster);
49 //cout << Form("cluster added at 0x%x (%i)\n",outPtr,outPtr);
50
51 blockSize = sizeof(*hltCluster);
52
53 addedSize += blockSize;
54 outBlockPtr += blockSize;
55 outPtr = (AliHLTTRDCluster*)outBlockPtr;
56 }
57 }
58 return addedSize;
59
60}
61
62AliHLTUInt32_t AliHLTTRDUtils::AddTracksToOutput(TClonesArray* inTrackArray, AliHLTUInt8_t* output)
63{
18ada816 64 //cout << "\nWriting tracks to the Memory\n ============= \n";
dc2e6604 65 AliTRDtrackV1* track = 0;
66 AliHLTUInt32_t addedSize = 0;
67 AliHLTUInt8_t *iterPtr = output;
68 AliHLTTRDTrack * outPtr = (AliHLTTRDTrack*)iterPtr;
69
70 if (inTrackArray){
71 Int_t nbTracks = inTrackArray->GetEntries();
72 for (Int_t iTrack = 0; iTrack<nbTracks; iTrack++){
73 AliHLTUInt32_t trackSize=0;
74
75 track = dynamic_cast<AliTRDtrackV1*>(inTrackArray->At(iTrack));
76 //track->Print();
77
78 AliHLTTRDTrack *hltTrack = new (outPtr) AliHLTTRDTrack(track);
79 trackSize = hltTrack->GetSize();
80 addedSize += trackSize;
e3e5ac39 81 //HLTDebug("addedSize %i, trackSize %i", addedSize, trackSize);
dc2e6604 82
83 iterPtr += trackSize;
84 outPtr = (AliHLTTRDTrack*)iterPtr;
85 }
86 }
87 return addedSize;
88
89}
90
91/**
92 * Read cluster to the TClonesArray from the memory
93 */
94//============================================================================
95AliHLTUInt32_t AliHLTTRDUtils::ReadClusters(TClonesArray *outArray, void* inputPtr, AliHLTUInt32_t size)
96{
97 //HLTDebug("\nReading clusters from the Memory\n ============= \n");
98 AliHLTTRDCluster * curCluster;
99 UInt_t clusterSize = sizeof(AliHLTTRDCluster), curSize = 0;
100 Int_t i=0;
101
102 curCluster = (AliHLTTRDCluster*) inputPtr;
103 while (curSize + clusterSize <= size)
104 {
e3e5ac39 105 //HLTDebug(" fX = %f; fY = %f; fZ = %f", curCluster->fX, curCluster->fY, curCluster->fZ);
dc2e6604 106
107 AliTRDcluster* curTRDCluster = new((*outArray)[i]) AliTRDcluster();
108 curCluster->ExportTRDCluster(curTRDCluster);
e3e5ac39 109 //HLTDebug(" fX = %f; fY = %f; fZ = %f", curTRDCluster->GetX(), curTRDCluster->GetY(), curTRDCluster->GetZ());
dc2e6604 110 curSize += clusterSize;
111 i++;
112 curCluster++;
113 //cout << " current readed size is " << curSize << "/" << size << endl;
114 }
115
116 return i;
117}
118
119AliHLTUInt32_t AliHLTTRDUtils::ReadTracks(TClonesArray *outArray, void* inputPtr, AliHLTUInt32_t size)
120{
121 AliHLTUInt8_t* iterPtr = (AliHLTUInt8_t* )inputPtr;
122
123 //cout << "\nReading tracks from the Memory\n ============= \n";
e3e5ac39 124 //HLTDebug ("\nReading tracks from the Memory\n ============= \n");
dc2e6604 125 AliHLTTRDTrack * hltTrack;
126 AliHLTUInt32_t trackSize = 0, curSize = 0;
127 Int_t counter=0;
128
129 while (curSize < size)
130 {
131 hltTrack = (AliHLTTRDTrack*) iterPtr;
e3e5ac39 132 //HLTDebug("curSize %i, size %i",curSize, size);
dc2e6604 133
134 trackSize = hltTrack->GetSize();
e3e5ac39 135 //HLTDebug("GetSize() %i", trackSize);
dc2e6604 136
137 hltTrack->ReadTrackletsFromMemory(iterPtr + sizeof(AliHLTTRDTrack));
138
139 AliTRDtrackV1* curTRDTrack = new((*outArray)[counter]) AliTRDtrackV1();
140 hltTrack->ExportTRDTrack(curTRDTrack);
141
142 curSize += trackSize;
143 iterPtr += trackSize;
144 counter++;
145 }
146
147 //CheckTrackArray(outArray);
148
149 return counter;
150}
151
18ada816 152AliHLTUInt32_t AliHLTTRDUtils::AddESDToOutput(const AliESDEvent* const esd, AliHLTUInt8_t* const outBlockPtr)
153{
154 AliESDtrack* esdTrack = 0;
155 AliHLTUInt8_t* iterPtr = outBlockPtr;
156
157 AliHLTTracksData* trksData = new(iterPtr) AliHLTTracksData;
158 iterPtr += sizeof(AliHLTTracksData);
159 trksData->fCount=0;
160
161 if(esd){
162 Double_t pid[5];
163 for(Int_t i=0; i<esd->GetNumberOfTracks(); i++){
164 esdTrack=esd->GetTrack(i);
165 if(!esdTrack)continue;
166 AliHLTExternalTrackParam* trk = new(iterPtr) AliHLTExternalTrackParam;
167 iterPtr += sizeof(AliHLTExternalTrackParam);
168 trk->fAlpha = esdTrack->GetAlpha();
169 trk->fX = esdTrack->GetX();
170 trk->fY = esdTrack->GetY();
171 trk->fZ = esdTrack->GetZ();
172 trk->fSinPsi = esdTrack->GetSnp();
173 trk->fTgl = esdTrack->GetTgl();
174 trk->fq1Pt = esdTrack->GetSigned1Pt();
175 trk->fC[0] = esdTrack->GetSigmaY2();
176 trk->fC[1] = esdTrack->GetSigmaZY();
177 trk->fC[2] = esdTrack->GetSigmaZ2();
178 trk->fC[3] = esdTrack->GetSigmaSnpY();
179 trk->fC[4] = esdTrack->GetSigmaSnpZ();
180 trk->fC[5] = esdTrack->GetSigmaSnp2();
181 trk->fC[6] = esdTrack->GetSigmaTglY();
182 trk->fC[7] = esdTrack->GetSigmaTglZ();
183 trk->fC[8] = esdTrack->GetSigmaTglSnp();
184 trk->fC[9] = esdTrack->GetSigmaTgl2();
185 trk->fC[10] = esdTrack->GetSigma1PtY();
186 trk->fC[11] = esdTrack->GetSigma1PtZ();
187 trk->fC[12] = esdTrack->GetSigma1PtSnp();
188 trk->fC[13] = esdTrack->GetSigma1PtTgl();
189 trk->fC[14] = esdTrack->GetSigma1Pt2();
190 esdTrack->GetTRDpid(pid);
191 //trk->fTRDpid = pid[AliPID::kElectron]; ...
192 trk->fNPoints = 0;
193 trksData->fCount++;
194 }
195 }
196 return iterPtr - outBlockPtr;
197}