]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCAStandaloneFramework.cxx
1edf5d0521feccc8788ccf1dc68f0d2c62e87af8
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCAStandaloneFramework.cxx
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
29 //If not building GPU Code then build dummy functions to link against
30 #ifndef BUILD_GPU
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);}
40 #endif
41
42 AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::Instance()
43 {
44   // reference to static object
45   static AliHLTTPCCAStandaloneFramework gAliHLTTPCCAStandaloneFramework;
46   return gAliHLTTPCCAStandaloneFramework;
47 }
48
49 AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework()
50     : fMerger(), fStatNEvents( 0 ), fUseGPUTracker(false), fGPUDebugLevel(0)
51 {
52   //* constructor
53
54   for ( int i = 0; i < 20; i++ ) {
55     fLastTime[i] = 0;
56     fStatTime[i] = 0;
57   }
58 }
59
60 AliHLTTPCCAStandaloneFramework::AliHLTTPCCAStandaloneFramework( const AliHLTTPCCAStandaloneFramework& )
61     : fMerger(), fStatNEvents( 0 )
62 {
63   //* dummy
64 }
65
66 const AliHLTTPCCAStandaloneFramework &AliHLTTPCCAStandaloneFramework::operator=( const AliHLTTPCCAStandaloneFramework& ) const
67 {
68   //* dummy
69   return *this;
70 }
71
72 AliHLTTPCCAStandaloneFramework::~AliHLTTPCCAStandaloneFramework()
73 {
74   //* destructor
75 }
76
77
78 void AliHLTTPCCAStandaloneFramework::StartDataReading( int guessForNumberOfClusters )
79 {
80   //prepare for reading of the event
81
82   int sliceGuess = 2 * guessForNumberOfClusters / fgkNSlices;
83
84   for ( int i = 0; i < fgkNSlices; i++ ) {
85     fClusterData[i].StartReading( i, sliceGuess );
86   }
87 }
88
89 void AliHLTTPCCAStandaloneFramework::FinishDataReading()
90 {
91   // finish reading of the event
92
93   /*static int event_number = 0;
94   char filename[256];
95
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);
99   if (outfile.fail())
100   {
101     printf("Error opening event dump file\n");
102     exit(1);
103   }
104   WriteEvent(outfile);
105   if (outfile.fail())
106   {
107     printf("Error writing event dump file\n");
108     exit(1);
109   }
110   outfile.close();
111
112   sprintf(filename, "events/settings.%d.dump", event_number);
113   outfile.open(filename);
114   WriteSettings(outfile);
115   outfile.close();
116
117   event_number++;
118   
119   std::ifstream infile(filename, std::ifstream::binary);
120   ReadEvent(infile);
121   infile.close();*/
122
123   for ( int i = 0; i < fgkNSlices; i++ ) {
124     fClusterData[i].FinishReading();
125   }
126 }
127
128
129 //int
130 void AliHLTTPCCAStandaloneFramework::ProcessEvent()
131 {
132   // perform the event reconstruction
133
134   fStatNEvents++;
135
136   TStopwatch timer0;
137   TStopwatch timer1;
138
139   if (!fUseGPUTracker || fGPUDebugLevel >= 3)
140   {
141         for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
142           fSliceTrackers[iSlice].ReadEvent( &( fClusterData[iSlice] ) );
143       fSliceTrackers[iSlice].Reconstruct();
144         }
145         if (fGPUDebugLevel >= 2) printf("\n");
146   }
147
148   if (fUseGPUTracker)
149   {
150           for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
151             fSliceTrackers[iSlice].ReadEvent( &( fClusterData[iSlice] ) );
152                 if (fGPUTracker.Reconstruct(&fSliceTrackers[iSlice]))
153                 {
154                         printf("Error during GPU Reconstruction!!!\n");
155                         //return(1);
156                 }
157           }
158           if (fGPUDebugLevel >= 2) printf("\n");
159   }
160
161   timer1.Stop();
162   TStopwatch timer2;
163
164   fMerger.Clear();
165   fMerger.SetSliceParam( fSliceTrackers[0].Param() );
166
167   for ( int i = 0; i < fgkNSlices; i++ ) {
168     fMerger.SetSliceData( i, fSliceTrackers[i].Output() );
169   }
170
171   fMerger.Reconstruct();
172
173   timer2.Stop();
174   timer0.Stop();
175
176   fLastTime[0] = timer0.CpuTime();
177   fLastTime[1] = timer1.CpuTime();
178   fLastTime[2] = timer2.CpuTime();
179
180   for ( int i = 0; i < 3; i++ ) fStatTime[i] += fLastTime[i];
181
182   //return(0);
183 }
184
185
186 void AliHLTTPCCAStandaloneFramework::WriteSettings( std::ostream &out ) const
187 {
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 );
192   }
193 }
194
195 void AliHLTTPCCAStandaloneFramework::ReadSettings( std::istream &in )
196 {
197   //* Read settings from the file
198   int nSlices = 0;
199   in >> nSlices;
200   for ( int iSlice = 0; iSlice < nSlices; iSlice++ ) {
201     AliHLTTPCCAParam param;
202     param.ReadSettings ( in );
203     fSliceTrackers[iSlice].Initialize( param );
204   }
205 }
206
207 void AliHLTTPCCAStandaloneFramework::WriteEvent( std::ostream &out ) const
208 {
209   // write event to the file
210   for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
211     fClusterData[iSlice].WriteEvent( out );
212   }
213 }
214
215 void AliHLTTPCCAStandaloneFramework::ReadEvent( std::istream &in )
216 {
217   //* Read event from file
218   for ( int iSlice = 0; iSlice < fgkNSlices; iSlice++ ) {
219     fClusterData[iSlice].ReadEvent( in );
220   }
221 }
222
223 void AliHLTTPCCAStandaloneFramework::WriteTracks( std::ostream &out ) const
224 {
225   //* Write tracks to file
226
227   for ( int i = 0; i < 20; i++ ) out << fLastTime[i] << std::endl;
228   //fMerger.Output()->Write( out );
229 }
230
231 void AliHLTTPCCAStandaloneFramework::ReadTracks( std::istream &in )
232 {
233   //* Read tracks  from file
234
235   for ( int i = 0; i < 20; i++ ) {
236     in >> fLastTime[i];
237     fStatTime[i] += fLastTime[i];
238   }
239   //fMerger.Output()->Read( in );
240 }
241
242 int AliHLTTPCCAStandaloneFramework::InitGPU()
243 {
244         if (fUseGPUTracker) return(1);
245         int retVal = fGPUTracker.InitGPU();
246         fUseGPUTracker = retVal == 0;
247         return(retVal);
248 }
249
250 int AliHLTTPCCAStandaloneFramework::ExitGPU()
251 {
252         if (!fUseGPUTracker) return(1);
253         return(fGPUTracker.ExitGPU());
254 }
255
256 void AliHLTTPCCAStandaloneFramework::SetGPUDebugLevel(int Level, std::ostream *OutFile, std::ostream *GPUOutFile)
257 {
258         fGPUTracker.SetDebugLevel(Level, GPUOutFile);
259         fGPUDebugLevel = Level;
260         for (int i = 0;i < fgkNSlices;i++)
261         {
262                 fSliceTrackers[i].SetGPUDebugLevel(Level, OutFile);
263         }
264 }