]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCAStandaloneFramework.cxx
Modifications (M.Nicassio)
[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"
6de2bc40 22#include "AliHLTTPCCADataCompressor.h"
23#include "AliHLTTPCCAMath.h"
24#include "AliHLTTPCCAClusterData.h"
25#include "TStopwatch.h"
26
b22af1bf 27#ifdef HLTCA_STANDALONE
28#include <omp.h>
f0bada7f 29#include "include.h"
30#ifdef R__WIN32
31#include <conio.h>
32#else
33#include <pthread.h>
34#endif
7be9b0d7 35#endif
6de2bc40 36
37AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::Instance()
38{
39 // reference to static object
40 static AliHLTTPCCAStandaloneFramework gAliHLTTPCCAStandaloneFramework;
41 return gAliHLTTPCCAStandaloneFramework;
42}
b8139972 43
6de2bc40 44AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework()
f0bada7f 45 : fMerger(), fOutputControl(), fTracker(), fStatNEvents( 0 ), fDebugLevel(0), fEventDisplay(0), fRunMerger(1)
6de2bc40 46{
47 //* constructor
48
b8139972 49 for ( int i = 0; i < 20; i++ ) {
6de2bc40 50 fLastTime[i] = 0;
51 fStatTime[i] = 0;
52 }
98512261 53 for ( int i = 0;i < fgkNSlices;i++) fSliceOutput[i] = NULL;
d4594e7d 54 fTracker.SetOutputControl(&fOutputControl);
6de2bc40 55}
56
57AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework( const AliHLTTPCCAStandaloneFramework& )
f0bada7f 58 : fMerger(), fOutputControl(), fTracker(), fStatNEvents( 0 ), fDebugLevel(0), fEventDisplay(0), fRunMerger(1)
6de2bc40 59{
60 //* dummy
469e5829 61 for ( int i = 0; i < 20; i++ ) {
62 fLastTime[i] = 0;
63 fStatTime[i] = 0;
64 }
65 for ( int i = 0;i < fgkNSlices;i++) fSliceOutput[i] = NULL;
6de2bc40 66}
67
68const AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::operator=( const AliHLTTPCCAStandaloneFramework& ) const
69{
70 //* dummy
71 return *this;
72}
73
74AliHLTTPCCAStandaloneFramework::~AliHLTTPCCAStandaloneFramework()
75{
f0bada7f 76#ifndef HLTCA_STANDALONE
98512261 77 for (int i = 0;i < fgkNSlices;i++) if (fSliceOutput[i]) free(fSliceOutput[i]);
f0bada7f 78#endif
b8139972 79 //* destructor
6de2bc40 80}
81
82
83void AliHLTTPCCAStandaloneFramework::StartDataReading( int guessForNumberOfClusters )
84{
85 //prepare for reading of the event
86
b8139972 87 int sliceGuess = 2 * guessForNumberOfClusters / fgkNSlices;
6de2bc40 88
b8139972 89 for ( int i = 0; i < fgkNSlices; i++ ) {
6de2bc40 90 fClusterData[i].StartReading( i, sliceGuess );
91 }
92}
93
94void AliHLTTPCCAStandaloneFramework::FinishDataReading()
95{
96 // finish reading of the event
97
7be9b0d7 98 /*static int event_number = 0;
99 char filename[256];
100
101 sprintf(filename, "events/event.%d.dump", event_number);
102 printf("Dumping event into file %s\n", filename);
103 std::ofstream outfile(filename, std::ofstream::binary);
104 if (outfile.fail())
105 {
106 printf("Error opening event dump file\n");
107 exit(1);
108 }
109 WriteEvent(outfile);
110 if (outfile.fail())
111 {
112 printf("Error writing event dump file\n");
113 exit(1);
114 }
115 outfile.close();
116
117 sprintf(filename, "events/settings.%d.dump", event_number);
118 outfile.open(filename);
119 WriteSettings(outfile);
120 outfile.close();
121
b22af1bf 122 event_number++;*/
7be9b0d7 123
b22af1bf 124 /*std::ifstream infile(filename, std::ifstream::binary);
7be9b0d7 125 ReadEvent(infile);
126 infile.close();*/
127
b8139972 128 for ( int i = 0; i < fgkNSlices; i++ ) {
6de2bc40 129 fClusterData[i].FinishReading();
130 }
131}
132
133
f0bada7f 134int AliHLTTPCCAStandaloneFramework::ProcessEvent(int forceSingleSlice)
6de2bc40 135{
136 // perform the event reconstruction
137
138 fStatNEvents++;
139
140 TStopwatch timer0;
141 TStopwatch timer1;
142
b22af1bf 143#ifdef HLTCA_STANDALONE
144 unsigned long long int startTime, endTime, checkTime;
145 unsigned long long int cpuTimers[16], gpuTimers[16], tmpFreq;
146 StandaloneQueryFreq(&tmpFreq);
147 StandaloneQueryTime(&startTime);
d4594e7d 148
f0bada7f 149 if (fEventDisplay)
150 {
151 fTracker.SetKeepData(1);
152 }
b22af1bf 153#endif
154
155 if (forceSingleSlice != -1)
7be9b0d7 156 {
f0bada7f 157 if (fTracker.ProcessSlices(forceSingleSlice, 1, &fClusterData[forceSingleSlice], &fSliceOutput[forceSingleSlice])) return (1);
7be9b0d7 158 }
b22af1bf 159 else
7be9b0d7 160 {
b22af1bf 161 for (int iSlice = 0;iSlice < fgkNSlices;iSlice += fTracker.MaxSliceCount())
162 {
f0bada7f 163 if (fTracker.ProcessSlices(iSlice, CAMath::Min(fTracker.MaxSliceCount(), fgkNSlices - iSlice), &fClusterData[iSlice], &fSliceOutput[iSlice])) return (1);
b22af1bf 164 }
6de2bc40 165 }
166
b22af1bf 167#ifdef HLTCA_STANDALONE
168 StandaloneQueryTime(&endTime);
169 StandaloneQueryTime(&checkTime);
170#endif
171
6de2bc40 172 timer1.Stop();
173 TStopwatch timer2;
174
f0bada7f 175 if (fRunMerger)
176 {
177 fMerger.Clear();
178 fMerger.SetSliceParam( fTracker.Param(0) );
6de2bc40 179
f0bada7f 180 for ( int i = 0; i < fgkNSlices; i++ ) {
181 //printf("slice %d clusters %d tracks %d\n", i, fClusterData[i].NumberOfClusters(), fSliceOutput[i]->NTracks());
182 fMerger.SetSliceData( i, fSliceOutput[i] );
183 }
6de2bc40 184
f0bada7f 185 fMerger.Reconstruct();
186 }
6de2bc40 187
188 timer2.Stop();
189 timer0.Stop();
190
191 fLastTime[0] = timer0.CpuTime();
192 fLastTime[1] = timer1.CpuTime();
193 fLastTime[2] = timer2.CpuTime();
194
b22af1bf 195#ifdef HLTCA_STANDALONE
f0bada7f 196 if (fEventDisplay)
197 {
198 static int displayActive = 0;
199 if (!displayActive)
200 {
201#ifdef R__WIN32
202 semLockDisplay = CreateSemaphore(0, 1, 1, 0);
203 HANDLE hThread;
204 if ((hThread = CreateThread(NULL, NULL, &OpenGLMain, NULL, NULL, NULL)) == NULL)
205#else
206 static pthread_t hThread;
207 if (pthread_create(&hThread, NULL, OpenGLMain, NULL))
208#endif
209 {
210 printf("Coult not Create GL Thread...\nExiting...\n");
211 }
212 displayActive = 1;
213 }
214 else
215 {
216#ifdef R__WIN32
217 ReleaseSemaphore(semLockDisplay, 1, NULL);
218#else
219 pthread_mutex_unlock(&semLockDisplay);
220#endif
221 }
222
223#ifdef R__WIN32
224 while (kbhit()) getch();
225#endif
226 printf("Press key for next event!\n");
227
228 int iKey;
229 do
230 {
231#ifdef R__WIN32
232 Sleep(10);
233 iKey = kbhit() ? getch() : 0;
234#else
235 iKey = getchar();
236#endif
237 if (iKey == 'q') exit(0);
238 } while (iKey != 'n' && buttonPressed == 0);
239 buttonPressed = 0;
240 printf("Loading next event\n");
241
242#ifdef R__WIN32
243 WaitForSingleObject(semLockDisplay, INFINITE);
244#else
245 pthread_mutex_lock(&semLockDisplay);
246#endif
247
248 displayEventNr++;
249 }
250
b22af1bf 251 printf("Tracking Time: %lld us\nTime uncertainty: %lld ns\n", (endTime - startTime) * 1000000 / tmpFreq, (checkTime - endTime) * 1000000000 / tmpFreq);
252
253 if (fDebugLevel >= 1)
254 {
255 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"};
256
257 for (int i = 0;i < 10;i++)
258 {
259 if (i == 6) continue;
260 cpuTimers[i] = gpuTimers[i] = 0;
261 for ( int iSlice = 0; iSlice < fgkNSlices;iSlice++)
262 {
263 if (forceSingleSlice != -1) iSlice = forceSingleSlice;
264 cpuTimers[i] += *fTracker.PerfTimer(0, iSlice, i + 1) - *fTracker.PerfTimer(0, iSlice, i);
265 if (forceSingleSlice != -1 || (fTracker.MaxSliceCount() && (iSlice % fTracker.MaxSliceCount() == 0 || i <= 5)))
266 gpuTimers[i] += *fTracker.PerfTimer(1, iSlice, i + 1) - *fTracker.PerfTimer(1, iSlice, i);
267 if (forceSingleSlice != -1) break;
268 }
269 if (forceSingleSlice == -1)
270 {
271 cpuTimers[i] /= fgkNSlices;
272 gpuTimers[i] /= fgkNSlices;
273 }
274 cpuTimers[i] *= 1000000;
275 gpuTimers[i] *= 1000000;
276 cpuTimers[i] /= tmpFreq;
277 gpuTimers[i] /= tmpFreq;
278 cpuTimers[i] /= omp_get_max_threads();
279
280 printf("Execution Time: Task: %20s ", tmpNames[i]);
281 printf("CPU: %15lld\t\t", cpuTimers[i]);
282 printf("GPU: %15lld\t\t", gpuTimers[i]);
283 if (fDebugLevel >=6 && gpuTimers[i])
284 printf("Speedup: %4lld%%", cpuTimers[i] * 100 / gpuTimers[i]);
285 printf("\n");
286 }
287 printf("Execution Time: Task: %20s CPU: %15lld\n", "Merger", (long long int) (timer2.CpuTime() * 1000000));
288 }
289#endif
290
b8139972 291 for ( int i = 0; i < 3; i++ ) fStatTime[i] += fLastTime[i];
7be9b0d7 292
f0bada7f 293 return(0);
6de2bc40 294}
295
296
297void AliHLTTPCCAStandaloneFramework::WriteSettings( std::ostream &out ) const
298{
299 //* write settings to the file
300 out << NSlices() << std::endl;
301 for ( int iSlice = 0; iSlice < NSlices(); iSlice++ ) {
b22af1bf 302 fTracker.Param(iSlice).WriteSettings( out );
6de2bc40 303 }
304}
305
306void AliHLTTPCCAStandaloneFramework::ReadSettings( std::istream &in )
307{
308 //* Read settings from the file
309 int nSlices = 0;
310 in >> nSlices;
469e5829 311 if( nSlices>0 && nSlices<100 ){
312 for ( int iSlice = 0; iSlice < nSlices; iSlice++ ) {
313 AliHLTTPCCAParam param;
314 param.ReadSettings ( in );
315 fTracker.InitializeSliceParam(iSlice, param);
316 }
6de2bc40 317 }
318}
319
7be9b0d7 320void AliHLTTPCCAStandaloneFramework::WriteEvent( std::ostream &out ) const
6de2bc40 321{
322 // write event to the file
b8139972 323 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
7be9b0d7 324 fClusterData[iSlice].WriteEvent( out );
6de2bc40 325 }
326}
327
7be9b0d7 328void AliHLTTPCCAStandaloneFramework::ReadEvent( std::istream &in )
6de2bc40 329{
330 //* Read event from file
f0bada7f 331 int nClusters = 0;
b8139972 332 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
7be9b0d7 333 fClusterData[iSlice].ReadEvent( in );
f0bada7f 334 nClusters += fClusterData[iSlice].NumberOfClusters();
6de2bc40 335 }
f0bada7f 336#ifdef HLTCA_STANDALONE
337 printf("Read %d Clusters\n", nClusters);
338#endif
6de2bc40 339}
340
341void AliHLTTPCCAStandaloneFramework::WriteTracks( std::ostream &out ) const
342{
343 //* Write tracks to file
344
b8139972 345 for ( int i = 0; i < 20; i++ ) out << fLastTime[i] << std::endl;
6de2bc40 346 //fMerger.Output()->Write( out );
347}
348
349void AliHLTTPCCAStandaloneFramework::ReadTracks( std::istream &in )
350{
351 //* Read tracks from file
352
b8139972 353 for ( int i = 0; i < 20; i++ ) {
354 in >> fLastTime[i];
355 fStatTime[i] += fLastTime[i];
6de2bc40 356 }
357 //fMerger.Output()->Read( in );
a59a784e 358}