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 //If not building GPU Code then build dummy functions to link against
31 AliHLTTPCCAGPUTracker::AliHLTTPCCAGPUTracker() : gpuTracker(), DebugLevel(0) {}
32 AliHLTTPCCAGPUTracker::~AliHLTTPCCAGPUTracker() {}
33 int AliHLTTPCCAGPUTracker::InitGPU() {return(0);}
34 //template <class T> inline T* AliHLTTPCCAGPUTracker::alignPointer(T* ptr, int alignment) {return(NULL);}
35 //bool AliHLTTPCCAGPUTracker::CUDA_FAILED_MSG(cudaError_t error) {return(true);}
36 //int AliHLTTPCCAGPUTracker::CUDASync() {return(1);}
37 void AliHLTTPCCAGPUTracker::SetDebugLevel(int dwLevel, std::ostream *NewOutFile) {};
38 int AliHLTTPCCAGPUTracker::Reconstruct(AliHLTTPCCATracker* tracker) {return(1);}
39 int AliHLTTPCCAGPUTracker::ExitGPU() {return(0);}
42 AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::Instance()
44 // reference to static object
45 static AliHLTTPCCAStandaloneFramework gAliHLTTPCCAStandaloneFramework;
46 return gAliHLTTPCCAStandaloneFramework;
49 AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework()
50 : fMerger(), fStatNEvents( 0 ), fUseGPUTracker(false), fGPUDebugLevel(0)
54 for ( int i = 0; i < 20; i++ ) {
60 AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework( const AliHLTTPCCAStandaloneFramework& )
61 : fMerger(), fStatNEvents( 0 )
66 const AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::operator=( const AliHLTTPCCAStandaloneFramework& ) const
72 AliHLTTPCCAStandaloneFramework::~AliHLTTPCCAStandaloneFramework()
78 void AliHLTTPCCAStandaloneFramework::StartDataReading( int guessForNumberOfClusters )
80 //prepare for reading of the event
82 int sliceGuess = 2 * guessForNumberOfClusters / fgkNSlices;
84 for ( int i = 0; i < fgkNSlices; i++ ) {
85 fClusterData[i].StartReading( i, sliceGuess );
89 void AliHLTTPCCAStandaloneFramework::FinishDataReading()
91 // finish reading of the event
93 /*static int event_number = 0;
96 sprintf(filename, "events/event.%d.dump", event_number);
97 printf("Dumping event into file %s\n", filename);
98 std::ofstream outfile(filename, std::ofstream::binary);
101 printf("Error opening event dump file\n");
107 printf("Error writing event dump file\n");
112 sprintf(filename, "events/settings.%d.dump", event_number);
113 outfile.open(filename);
114 WriteSettings(outfile);
119 std::ifstream infile(filename, std::ifstream::binary);
123 for ( int i = 0; i < fgkNSlices; i++ ) {
124 fClusterData[i].FinishReading();
130 void AliHLTTPCCAStandaloneFramework::ProcessEvent()
132 // perform the event reconstruction
139 if (!fUseGPUTracker || fGPUDebugLevel >= 3)
141 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
142 fSliceTrackers[iSlice].ReadEvent( &( fClusterData[iSlice] ) );
143 fSliceTrackers[iSlice].Reconstruct();
145 if (fGPUDebugLevel >= 2) printf("\n");
150 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
151 fSliceTrackers[iSlice].ReadEvent( &( fClusterData[iSlice] ) );
152 if (fGPUTracker.Reconstruct(&fSliceTrackers[iSlice]))
154 printf("Error during GPU Reconstruction!!!\n");
158 if (fGPUDebugLevel >= 2) printf("\n");
165 fMerger.SetSliceParam( fSliceTrackers[0].Param() );
167 for ( int i = 0; i < fgkNSlices; i++ ) {
168 fMerger.SetSliceData( i, fSliceTrackers[i].Output() );
171 fMerger.Reconstruct();
176 fLastTime[0] = timer0.CpuTime();
177 fLastTime[1] = timer1.CpuTime();
178 fLastTime[2] = timer2.CpuTime();
180 for ( int i = 0; i < 3; i++ ) fStatTime[i] += fLastTime[i];
186 void AliHLTTPCCAStandaloneFramework::WriteSettings( std::ostream &out ) const
188 //* write settings to the file
189 out << NSlices() << std::endl;
190 for ( int iSlice = 0; iSlice < NSlices(); iSlice++ ) {
191 fSliceTrackers[iSlice].Param().WriteSettings( out );
195 void AliHLTTPCCAStandaloneFramework::ReadSettings( std::istream &in )
197 //* Read settings from the file
200 for ( int iSlice = 0; iSlice < nSlices; iSlice++ ) {
201 AliHLTTPCCAParam param;
202 param.ReadSettings ( in );
203 fSliceTrackers[iSlice].Initialize( param );
207 void AliHLTTPCCAStandaloneFramework::WriteEvent( std::ostream &out ) const
209 // write event to the file
210 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
211 fClusterData[iSlice].WriteEvent( out );
215 void AliHLTTPCCAStandaloneFramework::ReadEvent( std::istream &in )
217 //* Read event from file
218 for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
219 fClusterData[iSlice].ReadEvent( in );
223 void AliHLTTPCCAStandaloneFramework::WriteTracks( std::ostream &out ) const
225 //* Write tracks to file
227 for ( int i = 0; i < 20; i++ ) out << fLastTime[i] << std::endl;
228 //fMerger.Output()->Write( out );
231 void AliHLTTPCCAStandaloneFramework::ReadTracks( std::istream &in )
233 //* Read tracks from file
235 for ( int i = 0; i < 20; i++ ) {
237 fStatTime[i] += fLastTime[i];
239 //fMerger.Output()->Read( in );
242 int AliHLTTPCCAStandaloneFramework::InitGPU()
244 if (fUseGPUTracker) return(1);
245 int retVal = fGPUTracker.InitGPU();
246 fUseGPUTracker = retVal == 0;
250 int AliHLTTPCCAStandaloneFramework::ExitGPU()
252 if (!fUseGPUTracker) return(1);
253 return(fGPUTracker.ExitGPU());
256 void AliHLTTPCCAStandaloneFramework::SetGPUDebugLevel(int Level, std::ostream *OutFile, std::ostream *GPUOutFile)
258 fGPUTracker.SetDebugLevel(Level, GPUOutFile);
259 fGPUDebugLevel = Level;
260 for (int i = 0;i < fgkNSlices;i++)
262 fSliceTrackers[i].SetGPUDebugLevel(Level, OutFile);