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