]>
Commit | Line | Data |
---|---|---|
93ce7d1b | 1 | // $Id$ |
dc2e6604 | 2 | /************************************************************************** |
3 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
4 | * * | |
5 | * Author: The ALICE Off-line Project. * | |
6 | * Contributors are mentioned in the code where appropriate. * | |
7 | * * | |
8 | * Permission to use, copy, modify and distribute this software and its * | |
9 | * documentation strictly for non-commercial purposes is hereby granted * | |
10 | * without fee, provided that the above copyright notice appears in all * | |
11 | * copies and that both the copyright notice and this permission notice * | |
12 | * appear in the supporting documentation. The authors make no claims * | |
13 | * about the suitability of this software for any purpose. It is * | |
14 | * provided "as is" without express or implied warranty. * | |
15 | **************************************************************************/ | |
16 | ||
196a8c4f | 17 | // @file AliHLTTRDUtils.cxx |
18 | // @author Theodor Rascanu | |
19 | // @date | |
20 | // @brief Utilities needed the HLT::TRD code. | |
21 | // | |
22 | ||
dc2e6604 | 23 | /////////////////////////////////////////////////////////////////////////////// |
24 | // // | |
196a8c4f | 25 | // HLT TRD Utilities Class // |
dc2e6604 | 26 | // // |
27 | /////////////////////////////////////////////////////////////////////////////// | |
28 | ||
29 | #include "AliHLTTRDUtils.h" | |
30 | #include <TClonesArray.h> | |
31 | #include "AliHLTTRDTrack.h" | |
4a6879bb | 32 | #include "AliHLTTRDTracklet.h" |
dc2e6604 | 33 | #include "AliHLTTRDCluster.h" |
18ada816 | 34 | #include "AliHLTExternalTrackParam.h" |
196a8c4f | 35 | #include "AliTRDtransform.h" |
18ada816 | 36 | #include "AliESDEvent.h" |
37 | #include "AliESDtrack.h" | |
38 | #include "AliPID.h" | |
39 | ||
40 | ClassImp(AliHLTTRDUtils) | |
dc2e6604 | 41 | |
196a8c4f | 42 | AliHLTUInt32_t AliHLTTRDUtils::AddClustersToOutput(const TClonesArray *const inClusterArray, AliHLTUInt8_t *const outBlockPtr, Int_t nTimeBins) |
dc2e6604 | 43 | { |
44 | AliTRDcluster* cluster = 0; | |
45 | AliHLTUInt32_t addedSize = 0; | |
196a8c4f | 46 | Int_t lastDet = -1; |
47 | ||
dc2e6604 | 48 | if (inClusterArray){ |
196a8c4f | 49 | AliHLTTRDClustersArray* clsArr = NULL; |
50 | Int_t nbEntries = inClusterArray->GetEntries(); | |
dc2e6604 | 51 | for (Int_t iCluster = 0; iCluster<nbEntries; iCluster++){ |
93ce7d1b | 52 | cluster = (AliTRDcluster*)(inClusterArray->At(iCluster)); |
196a8c4f | 53 | if(lastDet!=cluster->GetDetector()){ |
54 | lastDet=cluster->GetDetector(); | |
55 | clsArr = new(outBlockPtr+addedSize) AliHLTTRDClustersArray(lastDet); | |
56 | addedSize += sizeof(AliHLTTRDClustersArray); | |
57 | } | |
58 | ||
59 | new (&clsArr->fCluster[clsArr->fCount]) AliHLTTRDClustersArray::cluster_type(cluster); | |
60 | clsArr->fCount++; | |
61 | addedSize += sizeof(AliHLTTRDClustersArray::cluster_type); | |
dc2e6604 | 62 | } |
63 | } | |
93ce7d1b | 64 | |
196a8c4f | 65 | Int_t *TBptr = (Int_t*)(outBlockPtr+addedSize); |
93ce7d1b | 66 | *TBptr = nTimeBins; |
67 | ||
68 | addedSize += sizeof(*TBptr); | |
93ce7d1b | 69 | |
dc2e6604 | 70 | return addedSize; |
71 | ||
72 | } | |
73 | ||
196a8c4f | 74 | AliHLTUInt32_t AliHLTTRDUtils::AddTracksToOutput(const TClonesArray *const inTrackArray, AliHLTUInt8_t *const output, Int_t nTimeBins) |
dc2e6604 | 75 | { |
93ce7d1b | 76 | |
77 | Int_t *TBptr = (Int_t*)output; | |
78 | *TBptr = nTimeBins; | |
79 | ||
dc2e6604 | 80 | AliTRDtrackV1* track = 0; |
93ce7d1b | 81 | AliHLTUInt32_t addedSize = sizeof(*TBptr); |
93ce7d1b | 82 | |
dc2e6604 | 83 | if (inTrackArray){ |
84 | Int_t nbTracks = inTrackArray->GetEntries(); | |
85 | for (Int_t iTrack = 0; iTrack<nbTracks; iTrack++){ | |
86 | AliHLTUInt32_t trackSize=0; | |
87 | ||
93ce7d1b | 88 | track = (AliTRDtrackV1*)(inTrackArray->At(iTrack)); |
dc2e6604 | 89 | |
196a8c4f | 90 | AliHLTTRDTrack *hltTrack = new (output+addedSize) AliHLTTRDTrack(track); |
dc2e6604 | 91 | trackSize = hltTrack->GetSize(); |
92 | addedSize += trackSize; | |
dc2e6604 | 93 | } |
94 | } | |
95 | return addedSize; | |
96 | ||
97 | } | |
98 | ||
196a8c4f | 99 | AliHLTUInt32_t AliHLTTRDUtils::AddTracksToOutputAlt(const TClonesArray *const inTrackArray, AliHLTUInt8_t *const block, Int_t nTimeBins) |
100 | { | |
101 | AliHLTUInt32_t addedSize = 0; | |
102 | ||
103 | AliHLTUInt64_t *TBptr = (AliHLTUInt64_t*)block; | |
104 | *TBptr = nTimeBins; | |
105 | ||
106 | addedSize += sizeof(AliHLTUInt64_t); | |
107 | ||
108 | if(!inTrackArray) return addedSize; | |
109 | ||
110 | Int_t nbTracks = inTrackArray->GetEntriesFast(); | |
111 | for (Int_t i = 0; i<nbTracks; i++){ | |
112 | AliTRDtrackV1* inTrack = (AliTRDtrackV1*)(inTrackArray->At(i)); | |
113 | if(inTrack)addedSize+=AliHLTTRDTrack::SaveAt(block+addedSize, inTrack); | |
114 | } | |
115 | ||
116 | return addedSize; | |
117 | ||
118 | } | |
119 | ||
dc2e6604 | 120 | /** |
121 | * Read cluster to the TClonesArray from the memory | |
122 | */ | |
123 | //============================================================================ | |
196a8c4f | 124 | AliHLTUInt32_t AliHLTTRDUtils::ReadClusters(TClonesArray *const outArray, const void *const inputPtr, AliHLTUInt32_t size, Int_t* nTimeBins) |
dc2e6604 | 125 | { |
196a8c4f | 126 | const AliHLTUInt8_t* inPtr = (AliHLTUInt8_t*)inputPtr; |
127 | UInt_t curSize = 0; | |
128 | Int_t counter = outArray->GetEntriesFast(); | |
93ce7d1b | 129 | |
130 | if(nTimeBins){ | |
196a8c4f | 131 | *nTimeBins=*(Int_t*)(inPtr+size-sizeof(*nTimeBins)); |
93ce7d1b | 132 | } |
133 | size-=sizeof(*nTimeBins); | |
21aabbaa | 134 | #ifndef HAVE_NOT_ALITRD_CLUSTERIZER_r42837 |
196a8c4f | 135 | AliTRDtransform trans; |
136 | #endif | |
4a6879bb | 137 | while (curSize < size) |
dc2e6604 | 138 | { |
196a8c4f | 139 | AliHLTTRDClustersArray* clsArr = (AliHLTTRDClustersArray*)(inPtr+curSize); |
140 | curSize+=sizeof(AliHLTTRDClustersArray); | |
21aabbaa | 141 | #ifndef HAVE_NOT_ALITRD_CLUSTERIZER_r42837 |
196a8c4f | 142 | trans.SetDetector(clsArr->fDetector); |
143 | #endif | |
144 | for(Int_t iCluster = 0; iCluster<clsArr->fCount; iCluster++){ | |
145 | AliTRDcluster* curTRDCluster = new((*outArray)[counter]) AliTRDcluster(); | |
146 | clsArr->fCluster[iCluster].ExportTRDCluster(curTRDCluster); | |
147 | curTRDCluster->SetDetector(clsArr->fDetector); | |
21aabbaa | 148 | #ifndef HAVE_NOT_ALITRD_CLUSTERIZER_r42837 |
196a8c4f | 149 | trans.Transform(curTRDCluster); |
150 | #endif | |
151 | curSize += sizeof(AliHLTTRDClustersArray::cluster_type); | |
152 | counter++; | |
153 | } | |
dc2e6604 | 154 | } |
155 | ||
4a6879bb | 156 | return counter; |
dc2e6604 | 157 | } |
158 | ||
196a8c4f | 159 | AliHLTUInt32_t AliHLTTRDUtils::ReadTracks(TClonesArray *const outArray, const void *const inputPtr, AliHLTUInt32_t size, Int_t* nTimeBins) |
dc2e6604 | 160 | { |
93ce7d1b | 161 | if(nTimeBins){ |
162 | *nTimeBins=*(Int_t*)inputPtr; | |
163 | //HLTDebug("Reading number of time bins from input block: %d", *nTimeBins); | |
164 | } | |
165 | ||
166 | AliHLTUInt8_t* iterPtr = ((AliHLTUInt8_t*)inputPtr)+sizeof(*nTimeBins); | |
dc2e6604 | 167 | |
168 | //cout << "\nReading tracks from the Memory\n ============= \n"; | |
e3e5ac39 | 169 | //HLTDebug ("\nReading tracks from the Memory\n ============= \n"); |
dc2e6604 | 170 | AliHLTTRDTrack * hltTrack; |
93ce7d1b | 171 | AliHLTUInt32_t trackSize = 0, curSize = sizeof(*nTimeBins); |
4a6879bb | 172 | Int_t counter=outArray->GetEntriesFast(); |
dc2e6604 | 173 | |
174 | while (curSize < size) | |
175 | { | |
176 | hltTrack = (AliHLTTRDTrack*) iterPtr; | |
e3e5ac39 | 177 | //HLTDebug("curSize %i, size %i",curSize, size); |
dc2e6604 | 178 | |
179 | trackSize = hltTrack->GetSize(); | |
e3e5ac39 | 180 | //HLTDebug("GetSize() %i", trackSize); |
dc2e6604 | 181 | |
93ce7d1b | 182 | // hltTrack->ReadTrackletsFromMemory(iterPtr + sizeof(AliHLTTRDTrack)); |
dc2e6604 | 183 | |
184 | AliTRDtrackV1* curTRDTrack = new((*outArray)[counter]) AliTRDtrackV1(); | |
185 | hltTrack->ExportTRDTrack(curTRDTrack); | |
186 | ||
187 | curSize += trackSize; | |
188 | iterPtr += trackSize; | |
189 | counter++; | |
190 | } | |
191 | ||
192 | //CheckTrackArray(outArray); | |
193 | ||
194 | return counter; | |
195 | } | |
196 | ||
196a8c4f | 197 | AliHLTUInt32_t AliHLTTRDUtils::ReadTracksAlt(TClonesArray *const outArray, const void *const inputPtr, AliHLTUInt32_t size, Int_t* nTimeBins) |
198 | { | |
199 | const AliHLTUInt8_t *const block = ((AliHLTUInt8_t*)inputPtr); | |
200 | AliHLTUInt32_t readSize = 0; | |
201 | ||
202 | if(nTimeBins){ | |
203 | *nTimeBins=*(AliHLTUInt64_t*)block; | |
204 | //HLTDebug("Reading number of time bins from input block: %d", *nTimeBins); | |
205 | } | |
206 | ||
207 | readSize += sizeof(AliHLTUInt64_t); | |
208 | ||
209 | if(!outArray) return readSize; | |
210 | ||
211 | Int_t counter=outArray->GetEntriesFast(); | |
212 | while(readSize<size){ | |
213 | AliTRDtrackV1 *const outTrack = new((*outArray)[counter]) AliTRDtrackV1; | |
214 | readSize+=AliHLTTRDTrack::LoadFrom(outTrack, block+readSize); | |
215 | counter++; | |
216 | } | |
217 | ||
218 | return counter; | |
219 | ||
220 | } | |
221 | ||
18ada816 | 222 | AliHLTUInt32_t AliHLTTRDUtils::AddESDToOutput(const AliESDEvent* const esd, AliHLTUInt8_t* const outBlockPtr) |
223 | { | |
224 | AliESDtrack* esdTrack = 0; | |
225 | AliHLTUInt8_t* iterPtr = outBlockPtr; | |
226 | ||
227 | AliHLTTracksData* trksData = new(iterPtr) AliHLTTracksData; | |
228 | iterPtr += sizeof(AliHLTTracksData); | |
229 | trksData->fCount=0; | |
230 | ||
231 | if(esd){ | |
232 | Double_t pid[5]; | |
233 | for(Int_t i=0; i<esd->GetNumberOfTracks(); i++){ | |
234 | esdTrack=esd->GetTrack(i); | |
235 | if(!esdTrack)continue; | |
236 | AliHLTExternalTrackParam* trk = new(iterPtr) AliHLTExternalTrackParam; | |
237 | iterPtr += sizeof(AliHLTExternalTrackParam); | |
238 | trk->fAlpha = esdTrack->GetAlpha(); | |
239 | trk->fX = esdTrack->GetX(); | |
240 | trk->fY = esdTrack->GetY(); | |
241 | trk->fZ = esdTrack->GetZ(); | |
242 | trk->fSinPsi = esdTrack->GetSnp(); | |
243 | trk->fTgl = esdTrack->GetTgl(); | |
244 | trk->fq1Pt = esdTrack->GetSigned1Pt(); | |
245 | trk->fC[0] = esdTrack->GetSigmaY2(); | |
246 | trk->fC[1] = esdTrack->GetSigmaZY(); | |
247 | trk->fC[2] = esdTrack->GetSigmaZ2(); | |
248 | trk->fC[3] = esdTrack->GetSigmaSnpY(); | |
249 | trk->fC[4] = esdTrack->GetSigmaSnpZ(); | |
250 | trk->fC[5] = esdTrack->GetSigmaSnp2(); | |
251 | trk->fC[6] = esdTrack->GetSigmaTglY(); | |
252 | trk->fC[7] = esdTrack->GetSigmaTglZ(); | |
253 | trk->fC[8] = esdTrack->GetSigmaTglSnp(); | |
254 | trk->fC[9] = esdTrack->GetSigmaTgl2(); | |
255 | trk->fC[10] = esdTrack->GetSigma1PtY(); | |
256 | trk->fC[11] = esdTrack->GetSigma1PtZ(); | |
257 | trk->fC[12] = esdTrack->GetSigma1PtSnp(); | |
258 | trk->fC[13] = esdTrack->GetSigma1PtTgl(); | |
259 | trk->fC[14] = esdTrack->GetSigma1Pt2(); | |
260 | esdTrack->GetTRDpid(pid); | |
261 | //trk->fTRDpid = pid[AliPID::kElectron]; ... | |
262 | trk->fNPoints = 0; | |
263 | trksData->fCount++; | |
264 | } | |
265 | } | |
266 | return iterPtr - outBlockPtr; | |
267 | } | |
4a6879bb | 268 | |
269 | void AliHLTTRDUtils::EmulateHLTClusters(TClonesArray* clusterArray) | |
270 | { | |
196a8c4f | 271 | AliHLTUInt32_t estimatedSize = (clusterArray->GetEntriesFast()+1)*sizeof(AliHLTTRDClustersArray::cluster_type); |
4a6879bb | 272 | AliHLTUInt8_t* pBlock = (AliHLTUInt8_t*)malloc(estimatedSize); |
273 | AliHLTUInt32_t size = AddClustersToOutput(clusterArray, pBlock); | |
274 | clusterArray->Delete(); | |
275 | ReadClusters(clusterArray, pBlock, size); | |
276 | free(pBlock); | |
277 | } | |
278 | ||
279 | void AliHLTTRDUtils::EmulateHLTTracks(TClonesArray* trackArray) | |
280 | { | |
196a8c4f | 281 | AliHLTUInt32_t estimatedSize = (trackArray->GetEntriesFast()+1)*(sizeof(AliHLTTRDTrack)+6*(sizeof(AliHLTTRDTracklet)+30*sizeof(AliHLTTRDClustersArray::cluster_type))); |
4a6879bb | 282 | AliHLTUInt8_t* pBlock = (AliHLTUInt8_t*)malloc(estimatedSize); |
283 | AliHLTUInt32_t size = AddTracksToOutput(trackArray, pBlock); | |
284 | trackArray->Delete(); | |
285 | ReadTracks(trackArray, pBlock, size); | |
286 | free(pBlock); | |
287 | } | |
db801b10 | 288 | |
289 | AliHLTUInt32_t AliHLTTRDUtils::GetSM(AliHLTUInt32_t spec) | |
290 | { | |
2d7cea9e | 291 | spec = (spec&-spec); // use only least significant bit |
292 | spec -= 1; // as spec is now power of 2, this creates ones.. | |
293 | int count = 0; // .. which are counted | |
db801b10 | 294 | while (spec) { |
295 | count++; | |
296 | spec &= spec - 1; | |
297 | } | |
298 | return count; | |
299 | } |