StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CA.C
1 #include <AliHLTTPCCAGBTracker.h>
2 #include <AliHLTTPCCATracker.h>
3 
4 #include <fstream>
5 #include <iostream>
6 #include <iomanip>
7 #include <cstdio>
8 #include <cstring>
9 
10 #ifndef HLTCA_STANDALONE
11 #include <AliHLTTPCCAPerformance.h>
12 #endif
13 
14 #ifdef DRAW3
15 #define MAIN_DRAW
16 #endif //DRAW3
17 #ifdef DRAW2
18  #define MAIN_DRAW
19 #endif //DRAW
20 #ifdef DRAW
21  #define MAIN_DRAW
22 #endif //DRAW
23 
24 static int kEvents;
25 static bool SAVE = false;
26 extern bool SINGLE_THREADED;
27 extern bool DRAW_EVERY_LINK;
28 
29 #ifdef DUMP_LINKS
30 void dumpLinksFile( std::fstream &file, int sliceNumber )
31 {
32  if ( !SAVE ) {
33  return;
34  }
35  char name[255];
36  sprintf( name, "Links/%02i.%02i.dat", kEvents, sliceNumber );
37  file.open( name, std::ios::out );
38 }
39 #endif
40 
41 #ifdef DUMP_TC_OUTPUT
42 void dumpTrackletconstructionFile( std::fstream &file, int sliceNumber )
43 {
44  if ( !SAVE ) {
45  return;
46  }
47  char name[255];
48  sprintf( name, "TrackletConstruction/%02i.%02i.dat", kEvents, sliceNumber );
49  file.open( name, std::ios::out );
50 }
51 #endif // DUMP_TRACKLETCONSTRUCTION
52 
53 static void readSettings( const char *filename, AliHLTTPCCAGBTracker *tracker )
54 {
55  std::fstream geo;
56  geo.open( filename, std::ios::in );
57  if ( !geo.is_open() ) {
58  std::exit( 1 );
59  }
60  CALLGRIND_TOGGLE_COLLECT
61  tracker->ReadSettings(geo);
62  CALLGRIND_TOGGLE_COLLECT
63  geo.close();
64 }
65 
66 static bool readEvent( const char *filename, AliHLTTPCCAGBTracker *tracker )
67 {
68  FILE *file = std::fopen( filename, "rb" );
69  if ( !file ) {
70  return false;
71  }
72  CALLGRIND_TOGGLE_COLLECT
73  tracker->ReadEvent( file );
74  CALLGRIND_TOGGLE_COLLECT
75  fclose( file );
76  return true;
77 }
78 
79 static bool file_exists( const char *filename )
80 {
81  FILE *f = 0;
82  if ( ( f = std::fopen( filename, "r" ) ) != NULL ) {
83  std::fclose( f );
84  return true;
85  }
86  return false;
87 }
88 
89 static void usage(const char *execName)
90 {
91  std::cout << "Usage: " << execName << " [OPTION] [event number]\n"
92  "Reconstruct slice tracks and merge them from cluster data read from the Events directory.\n\n"
93  " -h, --help print this message\n"
94 #ifdef MAIN_DRAW
95  " -links let it draw every vector of links the NeighboursFinder found.\n"
96 #else
97  " -single force tracker to run on only one core. Per default all available cores will be used\n"
98 #endif
99  " -save dump result of the tracker/merger into a file for later analysis\n"
100 #ifndef HLTCA_STANDALONE
101  " -perf do a performance analysis against Monte-Carlo information right after reconstruction\n\n"
102 #endif
103  "You may specify a specific event to reconstruct if there is more than one available in the Events directory"
104  << std::endl;
105 }
106 
107 int main(int argc, char **argv)
108 {
109  bool fullTiming = false;
110 #ifndef HLTCA_STANDALONE
111  AliHLTTPCCAPerformance *perf = 0;
112 #endif
113  int eventNumber = -1;
114  int repetitions = 1;
115  for( int i=1; i < argc; i++ ){
116  if ( !std::strcmp( argv[i], "-h" ) || !std::strcmp( argv[i], "--help" ) || !std::strcmp( argv[i], "-help" ) ) {
117  usage(argv[0]);
118  return 0;
119 #ifdef DRAW
120  } else if ( !std::strcmp( argv[i], "-links" ) ) {
121  DRAW_EVERY_LINK = true;
122 #else
123  } else if ( !std::strcmp( argv[i], "-single" ) ) {
124  SINGLE_THREADED = true;
125 #endif
126  } else if ( !std::strcmp( argv[i], "-save" ) ) {
127  SAVE = true;
128 #ifndef HLTCA_STANDALONE
129  } else if ( !std::strcmp( argv[i], "-perf" ) ) {
130  perf = &AliHLTTPCCAPerformance::Instance();
131 #endif
132  } else if ( !std::strcmp( argv[i], "-time" ) ) {
133  fullTiming = true;
134  } else if ( !std::strcmp( argv[i], "-repeat" ) && ++i < argc ) {
135  repetitions = atoi( argv[i] );
136  } else {
137  eventNumber = atoi( argv[i] );
138  std::cout << "Only process event " << eventNumber << std::endl;
139  }
140  }
141 #ifdef MAIN_DRAW
142  SINGLE_THREADED = true;
143  perf = &AliHLTTPCCAPerformance::Instance();
144 #endif
145 
146 
147  AliHLTTPCCAGBTracker *tracker = 0;
148  const AliHLTTPCCAGBTracker *trackerConst = 0;
149 
150  tracker = new AliHLTTPCCAGBTracker;
151 
152  readSettings( "Events/settings.dat", tracker );
153  trackerConst = tracker;
154 
155  kEvents = 0;
156  if ( eventNumber >= 0 ) {
157  kEvents = eventNumber;
158  }
159  while ( eventNumber == -1 || eventNumber == kEvents ) {
160  char name[255];
161  sprintf( name,"Events/%i.bin", kEvents );
162 
163  std::cout << "Loading Event " << kEvents << "..." << std::endl;
164  if ( !readEvent( name, tracker ) ) {
165  std::cout << "Data for event: " << kEvents << " has NOT been read succesfull" << std::endl;
166  break;
167  }
168  std::cout << "Event " << kEvents << " CPU reconstruction..." << std::endl;
169 
170 #ifndef HLTCA_STANDALONE
171  if ( perf ) {
172  char nameTr[255], nameP[255];
173  sprintf( nameTr, "Events/%i.mc.bin", kEvents );
174  sprintf( nameP, "Events/%i.mcpoints.bin", kEvents );
175  std::cout << "Loading Monte-Carlo Data for Event " << kEvents << "..." << std::endl;
176  if ( !perf->SetNewEvent( tracker, nameTr, nameP ) ) std::cout << "MCdata for event: " << kEvents << " has NOT been read succesfull" << std::endl;
177  }
178 #endif
179 
180  tracker->FindTracks();
181 
182 #ifndef HLTCA_STANDALONE
183  if ( perf) {
184  perf->InitSubPerformances();
185  perf->ExecPerformance();
186  }
187 #endif
188 
189  const bool ifAvarageTime = 1;
190  if (!ifAvarageTime){
191 
192  std::cout << "Reconstruction Time"
193  << " Real = " << std::setw( 10 ) << trackerConst->SliceTrackerTime() * 1.e3 << " ms,"
194  << " CPU = " << std::setw( 10 ) << trackerConst->SliceTrackerCpuTime() * 1.e3 << " ms,"
195  << " parallelization speedup: " << trackerConst->SliceTrackerCpuTime() / trackerConst->SliceTrackerTime()
196  << std::endl;
197  if ( fullTiming ) {
198  std::cout
199  << " | sum slice trackers: " << std::setw( 10 ) << trackerConst->StatTime( 0 ) * 1000. << " ms\n"
200  << " | NeighboursFinder: " << std::setw( 10 ) << trackerConst->StatTime( 1 ) * 1000. << " ms, " << std::setw( 12 ) << trackerConst->StatTime( 5 ) << " cycles\n"
201  << " | StartHitsFinder: " << std::setw( 10 ) << trackerConst->StatTime( 4 ) * 1000. << " ms\n"
202  << " | TrackletConstructor: " << std::setw( 10 ) << trackerConst->StatTime( 2 ) * 1000. << " ms, " << std::setw( 12 ) << trackerConst->StatTime( 7 ) << " cycles\n"
203  << " | TrackletSelector: " << std::setw( 10 ) << trackerConst->StatTime( 3 ) * 1000. << " ms, " << std::setw( 12 ) << trackerConst->StatTime( 8 ) << " cycles\n"
204  << " | WriteOutput: " << std::setw( 10 ) << trackerConst->StatTime( 6 ) * 1000. << " ms\n"
205  << " | merge: " << std::setw( 10 ) << trackerConst->StatTime( 9 ) * 1000. << " ms" << std::endl;
206  }
207 
208  }
209  else{
210  const int NTimers = 10;
211  static int statIEvent = 0;
212  static double statTime[NTimers];
213  static double statTime_SliceTrackerTime = 0;
214  static double statTime_SliceTrackerCpuTime = 0;
215 
216  if (!statIEvent){
217  for (int i = 0; i < NTimers; i++){
218  statTime[i] = 0;
219  }
220  }
221 
222  statIEvent++;
223  for (int i = 0; i < NTimers; i++){
224  statTime[i] += trackerConst->StatTime( i );
225  }
226  statTime_SliceTrackerTime += trackerConst->SliceTrackerTime();
227  statTime_SliceTrackerCpuTime += trackerConst->SliceTrackerCpuTime();
228 
229 
230  std::cout << "Reconstruction Time"
231  << " Real = " << std::setw( 10 ) << 1./statIEvent*statTime_SliceTrackerTime * 1.e3 << " ms,"
232  << " CPU = " << std::setw( 10 ) << 1./statIEvent*statTime_SliceTrackerCpuTime * 1.e3 << " ms,"
233  << " parallelization speedup: " << statTime_SliceTrackerCpuTime / statTime_SliceTrackerTime
234  << std::endl;
235  if ( fullTiming ) {
236  std::cout
237  << " | sum slice trackers: " << std::setw( 10 ) << 1./statIEvent*statTime[ 0 ] * 1000. << " ms\n"
238  << " | NeighboursFinder: " << std::setw( 10 ) << 1./statIEvent*statTime[ 1 ] * 1000. << " ms, " << std::setw( 12 ) << 1./statIEvent*statTime[ 5 ] << " cycles\n"
239  << " | StartHitsFinder: " << std::setw( 10 ) << 1./statIEvent*statTime[ 4 ] * 1000. << " ms\n"
240  << " | TrackletConstructor: " << std::setw( 10 ) << 1./statIEvent*statTime[ 2 ] * 1000. << " ms, " << std::setw( 12 ) << 1./statIEvent*statTime[ 7 ] << " cycles\n"
241  << " | TrackletSelector: " << std::setw( 10 ) << 1./statIEvent*statTime[ 3 ] * 1000. << " ms, " << std::setw( 12 ) << 1./statIEvent*statTime[ 8 ] << " cycles\n"
242  << " | WriteOutput: " << std::setw( 10 ) << 1./statIEvent*statTime[ 6 ] * 1000. << " ms\n"
243  << " | merge: " << std::setw( 10 ) << 1./statIEvent*statTime[ 9 ] * 1000. << " ms" << std::endl;
244  }
245 
246  }
247 
248  sprintf( name, "%i.dat", kEvents );
249  if ( SAVE ) {
250  trackerConst->StoreToFile( name );
251  }
252  kEvents++;
253  }
254  delete tracker;
255  return 0;
256 }