]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDUtils.cxx
removing unnecessary include file
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDUtils.cxx
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 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 // HLT TRD Utillities Class                                                  //
20 //                                                                           //
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "AliHLTTRDUtils.h"
24 #include <TClonesArray.h>
25 #include "AliHLTTRDTrack.h"
26 #include "AliHLTTRDTracklet.h"
27 #include "AliHLTTRDCluster.h"
28 #include "AliHLTExternalTrackParam.h"
29 #include "AliESDEvent.h"
30 #include "AliESDtrack.h"
31 #include "AliPID.h"
32
33 ClassImp(AliHLTTRDUtils)
34
35 AliHLTUInt32_t AliHLTTRDUtils::AddClustersToOutput(TClonesArray* inClusterArray, AliHLTUInt8_t* outBlockPtr, Int_t nTimeBins)
36 {
37   AliTRDcluster* cluster = 0;
38   AliHLTUInt32_t addedSize = 0;
39   //  == OUTdatatype pointer
40   AliHLTTRDCluster* outPtr = (AliHLTTRDCluster*)outBlockPtr;
41   
42   if (inClusterArray){
43     Int_t nbEntries  = inClusterArray->GetEntries();
44     for (Int_t iCluster = 0; iCluster<nbEntries; iCluster++){
45       //cout << "Geting cluster #" << iCluster << endl;
46       
47       cluster = (AliTRDcluster*)(inClusterArray->At(iCluster));
48
49       AliHLTTRDCluster *hltCluster = new (outPtr) AliHLTTRDCluster(cluster);
50       //cout << Form("cluster added at 0x%x (%i)\n",outPtr,outPtr);
51
52       addedSize += sizeof(*hltCluster);
53       outBlockPtr += sizeof(*hltCluster);
54       outPtr = (AliHLTTRDCluster*)outBlockPtr;
55     }
56   }
57
58   Int_t *TBptr = (Int_t*)outPtr;
59   *TBptr = nTimeBins;
60   
61   addedSize += sizeof(*TBptr);
62   outBlockPtr += sizeof(*TBptr);
63
64   return addedSize;
65   
66 }
67
68 AliHLTUInt32_t AliHLTTRDUtils::AddTracksToOutput(TClonesArray* inTrackArray, AliHLTUInt8_t* output, Int_t nTimeBins)
69 {
70   //cout << "\nWriting tracks to the Memory\n ============= \n";
71
72   Int_t *TBptr = (Int_t*)output;
73   *TBptr = nTimeBins;
74
75   AliTRDtrackV1* track = 0;
76   AliHLTUInt32_t addedSize = sizeof(*TBptr);
77   AliHLTUInt8_t* iterPtr = output+addedSize;
78   AliHLTTRDTrack* outPtr = (AliHLTTRDTrack*)iterPtr;
79
80   if (inTrackArray){
81     Int_t nbTracks  = inTrackArray->GetEntries();
82     for (Int_t iTrack = 0; iTrack<nbTracks; iTrack++){
83       AliHLTUInt32_t trackSize=0;
84       
85       track = (AliTRDtrackV1*)(inTrackArray->At(iTrack));
86       //track->Print();
87       
88       AliHLTTRDTrack *hltTrack = new (outPtr) AliHLTTRDTrack(track);
89       trackSize = hltTrack->GetSize();
90       addedSize += trackSize;
91       //HLTDebug("addedSize %i, trackSize %i", addedSize, trackSize);
92       
93       iterPtr += trackSize;
94       outPtr = (AliHLTTRDTrack*)iterPtr;
95     }
96   }
97   return addedSize;
98   
99 }
100
101 /**
102  * Read cluster to the TClonesArray from the memory 
103  */
104 //============================================================================
105 AliHLTUInt32_t AliHLTTRDUtils::ReadClusters(TClonesArray *outArray, void* inputPtr, AliHLTUInt32_t size, Int_t* nTimeBins)
106 {
107   //HLTDebug("\nReading clusters from the Memory\n ============= \n");
108   AliHLTTRDCluster * curCluster;
109   UInt_t clusterSize = sizeof(AliHLTTRDCluster), curSize = 0;
110   Int_t counter=outArray->GetEntriesFast();
111
112   if(nTimeBins){
113     *nTimeBins=*(Int_t*)(((AliHLTUInt8_t*)inputPtr)+size-sizeof(Int_t));
114     //HLTDebug("Reading number of time bins from input block: %d", *nTimeBins);
115   }
116   size-=sizeof(*nTimeBins);
117
118   curCluster = (AliHLTTRDCluster*) inputPtr;
119   while (curSize < size)
120     {
121       //HLTDebug(" fX = %f; fY = %f; fZ = %f", curCluster->fX, curCluster->fY, curCluster->fZ);
122
123       AliTRDcluster* curTRDCluster = new((*outArray)[counter]) AliTRDcluster();
124       curCluster->ExportTRDCluster(curTRDCluster);
125       //HLTDebug(" fX = %f; fY = %f; fZ = %f", curTRDCluster->GetX(), curTRDCluster->GetY(), curTRDCluster->GetZ());
126       curSize += clusterSize; 
127       counter++;
128       curCluster++;
129       //cout << " current readed size is " << curSize << "/" << size << endl;
130     }
131   
132   return counter;
133 }
134
135 AliHLTUInt32_t AliHLTTRDUtils::ReadTracks(TClonesArray *outArray, void* inputPtr, AliHLTUInt32_t size, Int_t* nTimeBins)
136 {
137   if(nTimeBins){
138     *nTimeBins=*(Int_t*)inputPtr;
139     //HLTDebug("Reading number of time bins from input block: %d", *nTimeBins);
140   }
141
142   AliHLTUInt8_t* iterPtr = ((AliHLTUInt8_t*)inputPtr)+sizeof(*nTimeBins);
143   
144   //cout << "\nReading tracks from the Memory\n ============= \n";
145   //HLTDebug ("\nReading tracks from the Memory\n ============= \n");
146   AliHLTTRDTrack * hltTrack;
147   AliHLTUInt32_t trackSize = 0, curSize = sizeof(*nTimeBins);
148   Int_t counter=outArray->GetEntriesFast();
149   
150   while (curSize < size)
151     {
152       hltTrack = (AliHLTTRDTrack*) iterPtr;
153       //HLTDebug("curSize %i, size %i",curSize, size);
154       
155       trackSize = hltTrack->GetSize();
156       //HLTDebug("GetSize() %i", trackSize);
157
158       // hltTrack->ReadTrackletsFromMemory(iterPtr + sizeof(AliHLTTRDTrack));
159
160       AliTRDtrackV1* curTRDTrack = new((*outArray)[counter]) AliTRDtrackV1();
161       hltTrack->ExportTRDTrack(curTRDTrack);
162       
163       curSize += trackSize; 
164       iterPtr += trackSize;
165       counter++;
166     }
167
168   //CheckTrackArray(outArray);
169   
170   return counter;
171 }
172
173 AliHLTUInt32_t AliHLTTRDUtils::AddESDToOutput(const AliESDEvent* const esd, AliHLTUInt8_t* const outBlockPtr)
174 {
175   AliESDtrack* esdTrack = 0;
176   AliHLTUInt8_t* iterPtr = outBlockPtr;
177
178   AliHLTTracksData* trksData = new(iterPtr) AliHLTTracksData;
179   iterPtr += sizeof(AliHLTTracksData);
180   trksData->fCount=0;
181   
182   if(esd){
183     Double_t pid[5];
184     for(Int_t i=0; i<esd->GetNumberOfTracks(); i++){
185       esdTrack=esd->GetTrack(i);
186       if(!esdTrack)continue;
187       AliHLTExternalTrackParam* trk = new(iterPtr) AliHLTExternalTrackParam;
188       iterPtr += sizeof(AliHLTExternalTrackParam);
189       trk->fAlpha = esdTrack->GetAlpha();
190       trk->fX = esdTrack->GetX();
191       trk->fY = esdTrack->GetY();
192       trk->fZ = esdTrack->GetZ();
193       trk->fSinPsi = esdTrack->GetSnp();
194       trk->fTgl = esdTrack->GetTgl();
195       trk->fq1Pt = esdTrack->GetSigned1Pt();
196       trk->fC[0] = esdTrack->GetSigmaY2();
197       trk->fC[1] = esdTrack->GetSigmaZY();
198       trk->fC[2] = esdTrack->GetSigmaZ2();
199       trk->fC[3] = esdTrack->GetSigmaSnpY();
200       trk->fC[4] = esdTrack->GetSigmaSnpZ();
201       trk->fC[5] = esdTrack->GetSigmaSnp2();
202       trk->fC[6] = esdTrack->GetSigmaTglY();
203       trk->fC[7] = esdTrack->GetSigmaTglZ();
204       trk->fC[8] = esdTrack->GetSigmaTglSnp();
205       trk->fC[9] = esdTrack->GetSigmaTgl2();
206       trk->fC[10] = esdTrack->GetSigma1PtY();
207       trk->fC[11] = esdTrack->GetSigma1PtZ();
208       trk->fC[12] = esdTrack->GetSigma1PtSnp();
209       trk->fC[13] = esdTrack->GetSigma1PtTgl();
210       trk->fC[14] = esdTrack->GetSigma1Pt2();
211       esdTrack->GetTRDpid(pid);
212       //trk->fTRDpid = pid[AliPID::kElectron]; ...
213       trk->fNPoints = 0;
214       trksData->fCount++;
215     }
216   }
217   return iterPtr - outBlockPtr;
218 }
219
220 void AliHLTTRDUtils::EmulateHLTClusters(TClonesArray* clusterArray)
221 {
222   AliHLTUInt32_t estimatedSize = (clusterArray->GetEntriesFast()+1)*sizeof(AliHLTTRDCluster);
223   AliHLTUInt8_t* pBlock = (AliHLTUInt8_t*)malloc(estimatedSize);
224   AliHLTUInt32_t size = AddClustersToOutput(clusterArray, pBlock);
225   clusterArray->Delete();
226   ReadClusters(clusterArray, pBlock, size);
227   free(pBlock);
228 }
229
230 void AliHLTTRDUtils::EmulateHLTTracks(TClonesArray* trackArray)
231 {
232   AliHLTUInt32_t estimatedSize = (trackArray->GetEntriesFast()+1)*(sizeof(AliHLTTRDTrack)+6*(sizeof(AliHLTTRDTracklet)+30*sizeof(AliHLTTRDCluster)));
233   AliHLTUInt8_t* pBlock = (AliHLTUInt8_t*)malloc(estimatedSize);
234   AliHLTUInt32_t size = AddTracksToOutput(trackArray, pBlock);
235   trackArray->Delete();
236   ReadTracks(trackArray, pBlock, size);
237   free(pBlock);
238 }
239
240 AliHLTUInt32_t AliHLTTRDUtils::GetSM(AliHLTUInt32_t spec)
241 {
242   spec = (spec&-spec); // use only least significant bit
243   spec -= 1;           // as spec is now power of 2, this creates ones..
244   int count = 0;       // .. which are counted
245   while (spec) {
246     count++;
247     spec &= spec - 1;
248   }
249   return count;
250 }