]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCAStandaloneFramework.cxx
bugfix: wrong result convention was used in r36516
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCAStandaloneFramework.cxx
CommitLineData
6de2bc40 1// **************************************************************************
2// This file is property of and copyright by the ALICE HLT Project *
3// ALICE Experiment at CERN, All rights reserved. *
4// *
5// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
6// Ivan Kisel <kisel@kip.uni-heidelberg.de> *
7// for The ALICE HLT Project. *
8// *
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// *
17//***************************************************************************
18
19
20#include "AliHLTTPCCAStandaloneFramework.h"
21#include "AliHLTTPCCATrackParam.h"
22#include "AliHLTTPCCAMerger.h"
23#include "AliHLTTPCCAMergerOutput.h"
24#include "AliHLTTPCCADataCompressor.h"
25#include "AliHLTTPCCAMath.h"
26#include "AliHLTTPCCAClusterData.h"
27#include "TStopwatch.h"
28
b22af1bf 29#ifdef HLTCA_STANDALONE
30#include <omp.h>
7be9b0d7 31#endif
6de2bc40 32
33AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::Instance()
34{
35 // reference to static object
36 static AliHLTTPCCAStandaloneFramework gAliHLTTPCCAStandaloneFramework;
37 return gAliHLTTPCCAStandaloneFramework;
38}
b8139972 39
6de2bc40 40AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework()
d4594e7d 41 : fMerger(), fOutputControl(), fTracker(), fStatNEvents( 0 ), fDebugLevel(0)
6de2bc40 42{
43 //* constructor
44
b8139972 45 for ( int i = 0; i < 20; i++ ) {
6de2bc40 46 fLastTime[i] = 0;
47 fStatTime[i] = 0;
48 }
98512261 49 for ( int i = 0;i < fgkNSlices;i++) fSliceOutput[i] = NULL;
d4594e7d 50 fTracker.SetOutputControl(&fOutputControl);
6de2bc40 51}
52
53AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework( const AliHLTTPCCAStandaloneFramework& )
d4594e7d 54 : fMerger(), fOutputControl(), fTracker(), fStatNEvents( 0 ), fDebugLevel(0)
6de2bc40 55{
56 //* dummy
57}
58
59const AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::operator=( const AliHLTTPCCAStandaloneFramework& ) const
60{
61 //* dummy
62 return *this;
63}
64
65AliHLTTPCCAStandaloneFramework::~AliHLTTPCCAStandaloneFramework()
66{
98512261 67 for (int i = 0;i < fgkNSlices;i++) if (fSliceOutput[i]) free(fSliceOutput[i]);
b8139972 68 //* destructor
6de2bc40 69}
70
71
72void AliHLTTPCCAStandaloneFramework::StartDataReading( int guessForNumberOfClusters )
73{
74 //prepare for reading of the event
75
b8139972 76 int sliceGuess = 2 * guessForNumberOfClusters / fgkNSlices;
6de2bc40 77
b8139972 78 for ( int i = 0; i < fgkNSlices; i++ ) {
6de2bc40 79 fClusterData[i].StartReading( i, sliceGuess );
80 }
81}
82
83void AliHLTTPCCAStandaloneFramework::FinishDataReading()
84{
85 // finish reading of the event
86
7be9b0d7 87 /*static int event_number = 0;
88 char filename[256];
89
90 sprintf(filename, "events/event.%d.dump", event_number);
91 printf("Dumping event into file %s\n", filename);
92 std::ofstream outfile(filename, std::ofstream::binary);
93 if (outfile.fail())
94 {
95 printf("Error opening event dump file\n");
96 exit(1);
97 }
98 WriteEvent(outfile);
99 if (outfile.fail())
100 {
101 printf("Error writing event dump file\n");
102 exit(1);
103 }
104 outfile.close();
105
106 sprintf(filename, "events/settings.%d.dump", event_number);
107 outfile.open(filename);
108 WriteSettings(outfile);
109 outfile.close();
110
b22af1bf 111 event_number++;*/
7be9b0d7 112
b22af1bf 113 /*std::ifstream infile(filename, std::ifstream::binary);
7be9b0d7 114 ReadEvent(infile);
115 infile.close();*/
116
b8139972 117 for ( int i = 0; i < fgkNSlices; i++ ) {
6de2bc40 118 fClusterData[i].FinishReading();
119 }
120}
121
122
7be9b0d7 123//int
b22af1bf 124void AliHLTTPCCAStandaloneFramework::ProcessEvent(int forceSingleSlice)
6de2bc40 125{
126 // perform the event reconstruction
127
128 fStatNEvents++;
129
130 TStopwatch timer0;
131 TStopwatch timer1;
132
b22af1bf 133#ifdef HLTCA_STANDALONE
134 unsigned long long int startTime, endTime, checkTime;
135 unsigned long long int cpuTimers[16], gpuTimers[16], tmpFreq;
136 StandaloneQueryFreq(&tmpFreq);
137 StandaloneQueryTime(&startTime);
d4594e7d 138
139 fOutputControl.fObsoleteOutput = 0;
b22af1bf 140#endif
141
142 if (forceSingleSlice != -1)
7be9b0d7 143 {
b22af1bf 144 if (fTracker.ProcessSlices(forceSingleSlice, 1, &fClusterData[forceSingleSlice], &fSliceOutput[forceSingleSlice])) return;
7be9b0d7 145 }
b22af1bf 146 else
7be9b0d7 147 {
b22af1bf 148 for (int iSlice = 0;iSlice < fgkNSlices;iSlice += fTracker.MaxSliceCount())
149 {
150 if (fTracker.ProcessSlices(iSlice, fTracker.MaxSliceCount(), &fClusterData[iSlice], &fSliceOutput[iSlice])) return;
151 }
6de2bc40 152 }
153
b22af1bf 154#ifdef HLTCA_STANDALONE
155 StandaloneQueryTime(&endTime);
156 StandaloneQueryTime(&checkTime);
157#endif
158
6de2bc40 159 timer1.Stop();
160 TStopwatch timer2;
161
b8139972 162 fMerger.Clear();
b22af1bf 163 fMerger.SetSliceParam( fTracker.Param(0) );
6de2bc40 164
165 for ( int i = 0; i < fgkNSlices; i++ ) {
d4594e7d 166 //printf("slice %d clusters %d tracks %d\n", i, fClusterData[i].NumberOfClusters(), fSliceOutput[i]->NTracks());
98512261 167 fMerger.SetSliceData( i, fSliceOutput[i] );
6de2bc40 168 }
169
170 fMerger.Reconstruct();
171
172 timer2.Stop();
173 timer0.Stop();
174
175 fLastTime[0] = timer0.CpuTime();
176 fLastTime[1] = timer1.CpuTime();
177 fLastTime[2] = timer2.CpuTime();
178
b22af1bf 179#ifdef HLTCA_STANDALONE
180 printf("Tracking Time: %lld us\nTime uncertainty: %lld ns\n", (endTime - startTime) * 1000000 / tmpFreq, (checkTime - endTime) * 1000000000 / tmpFreq);
181
182 if (fDebugLevel >= 1)
183 {
184 const char* tmpNames[16] = {"Initialisation", "Neighbours Finder", "Neighbours Cleaner", "Starts Hits Finder", "Start Hits Sorter", "Weight Cleaner", "Reserved", "Tracklet Constructor", "Tracklet Selector", "Write Output", "Unused", "Unused", "Unused", "Unused", "Unused", "Unused"};
185
186 for (int i = 0;i < 10;i++)
187 {
188 if (i == 6) continue;
189 cpuTimers[i] = gpuTimers[i] = 0;
190 for ( int iSlice = 0; iSlice < fgkNSlices;iSlice++)
191 {
192 if (forceSingleSlice != -1) iSlice = forceSingleSlice;
193 cpuTimers[i] += *fTracker.PerfTimer(0, iSlice, i + 1) - *fTracker.PerfTimer(0, iSlice, i);
194 if (forceSingleSlice != -1 || (fTracker.MaxSliceCount() && (iSlice % fTracker.MaxSliceCount() == 0 || i <= 5)))
195 gpuTimers[i] += *fTracker.PerfTimer(1, iSlice, i + 1) - *fTracker.PerfTimer(1, iSlice, i);
196 if (forceSingleSlice != -1) break;
197 }
198 if (forceSingleSlice == -1)
199 {
200 cpuTimers[i] /= fgkNSlices;
201 gpuTimers[i] /= fgkNSlices;
202 }
203 cpuTimers[i] *= 1000000;
204 gpuTimers[i] *= 1000000;
205 cpuTimers[i] /= tmpFreq;
206 gpuTimers[i] /= tmpFreq;
207 cpuTimers[i] /= omp_get_max_threads();
208
209 printf("Execution Time: Task: %20s ", tmpNames[i]);
210 printf("CPU: %15lld\t\t", cpuTimers[i]);
211 printf("GPU: %15lld\t\t", gpuTimers[i]);
212 if (fDebugLevel >=6 && gpuTimers[i])
213 printf("Speedup: %4lld%%", cpuTimers[i] * 100 / gpuTimers[i]);
214 printf("\n");
215 }
216 printf("Execution Time: Task: %20s CPU: %15lld\n", "Merger", (long long int) (timer2.CpuTime() * 1000000));
217 }
218#endif
219
b8139972 220 for ( int i = 0; i < 3; i++ ) fStatTime[i] += fLastTime[i];
7be9b0d7 221
222 //return(0);
6de2bc40 223}
224
225
226void AliHLTTPCCAStandaloneFramework::WriteSettings( std::ostream &out ) const
227{
228 //* write settings to the file
229 out << NSlices() << std::endl;
230 for ( int iSlice = 0; iSlice < NSlices(); iSlice++ ) {
b22af1bf 231 fTracker.Param(iSlice).WriteSettings( out );
6de2bc40 232 }
233}
234
235void AliHLTTPCCAStandaloneFramework::ReadSettings( std::istream &in )
236{
237 //* Read settings from the file
238 int nSlices = 0;
239 in >> nSlices;
240 for ( int iSlice = 0; iSlice < nSlices; iSlice++ ) {
241 AliHLTTPCCAParam param;
242 param.ReadSettings ( in );
b22af1bf 243 fTracker.InitializeSliceParam(iSlice, param);
6de2bc40 244 }
245}
246
7be9b0d7 247void AliHLTTPCCAStandaloneFramework::WriteEvent( std::ostream &out ) const
6de2bc40 248{
249 // write event to the file
b8139972 250 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
7be9b0d7 251 fClusterData[iSlice].WriteEvent( out );
6de2bc40 252 }
253}
254
7be9b0d7 255void AliHLTTPCCAStandaloneFramework::ReadEvent( std::istream &in )
6de2bc40 256{
257 //* Read event from file
b8139972 258 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
7be9b0d7 259 fClusterData[iSlice].ReadEvent( in );
6de2bc40 260 }
261}
262
263void AliHLTTPCCAStandaloneFramework::WriteTracks( std::ostream &out ) const
264{
265 //* Write tracks to file
266
b8139972 267 for ( int i = 0; i < 20; i++ ) out << fLastTime[i] << std::endl;
6de2bc40 268 //fMerger.Output()->Write( out );
269}
270
271void AliHLTTPCCAStandaloneFramework::ReadTracks( std::istream &in )
272{
273 //* Read tracks from file
274
b8139972 275 for ( int i = 0; i < 20; i++ ) {
276 in >> fLastTime[i];
277 fStatTime[i] += fLastTime[i];
6de2bc40 278 }
279 //fMerger.Output()->Read( in );
a59a784e 280}