1 // **************************************************************************
2 // This file is property of and copyright by the ALICE HLT Project *
3 // ALICE Experiment at CERN, All rights reserved. *
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. *
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. *
17 //***************************************************************************
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"
29 #ifdef HLTCA_STANDALONE
33 AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::Instance()
35 // reference to static object
36 static AliHLTTPCCAStandaloneFramework gAliHLTTPCCAStandaloneFramework;
37 return gAliHLTTPCCAStandaloneFramework;
40 AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework()
41 : fMerger(), fOutputControl(), fTracker(), fStatNEvents( 0 ), fDebugLevel(0)
45 for ( int i = 0; i < 20; i++ ) {
49 for ( int i = 0;i < fgkNSlices;i++) fSliceOutput[i] = NULL;
50 fTracker.SetOutputControl(&fOutputControl);
53 AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework( const AliHLTTPCCAStandaloneFramework& )
54 : fMerger(), fOutputControl(), fTracker(), fStatNEvents( 0 ), fDebugLevel(0)
59 const AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::operator=( const AliHLTTPCCAStandaloneFramework& ) const
65 AliHLTTPCCAStandaloneFramework::~AliHLTTPCCAStandaloneFramework()
67 for (int i = 0;i < fgkNSlices;i++) if (fSliceOutput[i]) free(fSliceOutput[i]);
72 void AliHLTTPCCAStandaloneFramework::StartDataReading( int guessForNumberOfClusters )
74 //prepare for reading of the event
76 int sliceGuess = 2 * guessForNumberOfClusters / fgkNSlices;
78 for ( int i = 0; i < fgkNSlices; i++ ) {
79 fClusterData[i].StartReading( i, sliceGuess );
83 void AliHLTTPCCAStandaloneFramework::FinishDataReading()
85 // finish reading of the event
87 /*static int event_number = 0;
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);
95 printf("Error opening event dump file\n");
101 printf("Error writing event dump file\n");
106 sprintf(filename, "events/settings.%d.dump", event_number);
107 outfile.open(filename);
108 WriteSettings(outfile);
113 /*std::ifstream infile(filename, std::ifstream::binary);
117 for ( int i = 0; i < fgkNSlices; i++ ) {
118 fClusterData[i].FinishReading();
124 void AliHLTTPCCAStandaloneFramework::ProcessEvent(int forceSingleSlice)
126 // perform the event reconstruction
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);
139 fOutputControl.fObsoleteOutput = 0;
142 if (forceSingleSlice != -1)
144 if (fTracker.ProcessSlices(forceSingleSlice, 1, &fClusterData[forceSingleSlice], &fSliceOutput[forceSingleSlice])) return;
148 for (int iSlice = 0;iSlice < fgkNSlices;iSlice += fTracker.MaxSliceCount())
150 if (fTracker.ProcessSlices(iSlice, fTracker.MaxSliceCount(), &fClusterData[iSlice], &fSliceOutput[iSlice])) return;
154 #ifdef HLTCA_STANDALONE
155 StandaloneQueryTime(&endTime);
156 StandaloneQueryTime(&checkTime);
163 fMerger.SetSliceParam( fTracker.Param(0) );
165 for ( int i = 0; i < fgkNSlices; i++ ) {
166 //printf("slice %d clusters %d tracks %d\n", i, fClusterData[i].NumberOfClusters(), fSliceOutput[i]->NTracks());
167 fMerger.SetSliceData( i, fSliceOutput[i] );
170 fMerger.Reconstruct();
175 fLastTime[0] = timer0.CpuTime();
176 fLastTime[1] = timer1.CpuTime();
177 fLastTime[2] = timer2.CpuTime();
179 #ifdef HLTCA_STANDALONE
180 printf("Tracking Time: %lld us\nTime uncertainty: %lld ns\n", (endTime - startTime) * 1000000 / tmpFreq, (checkTime - endTime) * 1000000000 / tmpFreq);
182 if (fDebugLevel >= 1)
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"};
186 for (int i = 0;i < 10;i++)
188 if (i == 6) continue;
189 cpuTimers[i] = gpuTimers[i] = 0;
190 for ( int iSlice = 0; iSlice < fgkNSlices;iSlice++)
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;
198 if (forceSingleSlice == -1)
200 cpuTimers[i] /= fgkNSlices;
201 gpuTimers[i] /= fgkNSlices;
203 cpuTimers[i] *= 1000000;
204 gpuTimers[i] *= 1000000;
205 cpuTimers[i] /= tmpFreq;
206 gpuTimers[i] /= tmpFreq;
207 cpuTimers[i] /= omp_get_max_threads();
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]);
216 printf("Execution Time: Task: %20s CPU: %15lld\n", "Merger", (long long int) (timer2.CpuTime() * 1000000));
220 for ( int i = 0; i < 3; i++ ) fStatTime[i] += fLastTime[i];
226 void AliHLTTPCCAStandaloneFramework::WriteSettings( std::ostream &out ) const
228 //* write settings to the file
229 out << NSlices() << std::endl;
230 for ( int iSlice = 0; iSlice < NSlices(); iSlice++ ) {
231 fTracker.Param(iSlice).WriteSettings( out );
235 void AliHLTTPCCAStandaloneFramework::ReadSettings( std::istream &in )
237 //* Read settings from the file
240 for ( int iSlice = 0; iSlice < nSlices; iSlice++ ) {
241 AliHLTTPCCAParam param;
242 param.ReadSettings ( in );
243 fTracker.InitializeSliceParam(iSlice, param);
247 void AliHLTTPCCAStandaloneFramework::WriteEvent( std::ostream &out ) const
249 // write event to the file
250 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
251 fClusterData[iSlice].WriteEvent( out );
255 void AliHLTTPCCAStandaloneFramework::ReadEvent( std::istream &in )
257 //* Read event from file
258 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
259 fClusterData[iSlice].ReadEvent( in );
263 void AliHLTTPCCAStandaloneFramework::WriteTracks( std::ostream &out ) const
265 //* Write tracks to file
267 for ( int i = 0; i < 20; i++ ) out << fLastTime[i] << std::endl;
268 //fMerger.Output()->Write( out );
271 void AliHLTTPCCAStandaloneFramework::ReadTracks( std::istream &in )
273 //* Read tracks from file
275 for ( int i = 0; i < 20; i++ ) {
277 fStatTime[i] += fLastTime[i];
279 //fMerger.Output()->Read( in );