Does the exercise itself.
57 {
59
60 if ( argc != 2 )
61 {
62 std::cerr << "usage: " << argv[0] << " <test-file>" << std::endl;
63 std::exit( 1 );
64 }
65
66
67 double cpu_time_used = 0;
68 uint32_t events_read = 0;
69 uint32_t components_instantiated = 0;
70 RealTimeClock my_clock;
71 uint32_t event_size = 0;
72
73
74 std::fstream in( argv[1], std::ios::in | std::ios::binary );
75 if ( !in )
76 {
77 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl;
78 std::exit( 1 );
79 }
80 size_t offset = 0;
81
82#ifdef PAGED_MEMORY
83 std::cout <<
"Working with paged storage with page size = " <<
PAGE_SIZE <<
" bytes."
84 << std::endl;
85#else
86 std::cout << "Working with contiguous storage." << std::endl;
87#endif
88
89 while ( in && in.good() && !in.eof() )
90 {
91
93 in.read( (
char*)
data, 8 );
94 if ( !in.good() || in.eof() ) break;
96 {
97
98 std::cout <<
"Word at offset " <<
HEX( offset ) <<
" is not "
100 std::exit( 1 );
101 }
102
103#ifdef PAGED_MEMORY
104
105 in.seekg( offset );
106
107 size_t to_read =
data[1] << 2;
108 size_t page_counter = 0;
109
111 while ( to_read > 0 )
112 {
114 in.read( (char*)paged_event[page_counter], readnow );
115 to_read -= readnow;
116 ++page_counter;
117
118 }
119
121 for ( size_t i = 0; i < page_counter; ++i )
122 {
123 myvec[i].iov_base = paged_event[i];
125 }
126
127 myvec[page_counter - 1].iov_len =
data[1] << 2 - ( page_counter - 1 ) *
PAGE_SIZE;
129#else
130 in.seekg( offset );
132 in.read( (
char*)event,
data[1] << 2 );
133#endif
134
135 offset +=
data[1] << 2;
136
137 try
138 {
139#ifdef PAGED_MEMORY
141 mem.begin() );
142#else
144#endif
145
146 event_size += 4 * fe.fragment_size_word();
147
148 Time start = my_clock.time();
149 fe.check_tree();
150 Time end = my_clock.time();
151 Time diff = end - start;
152
153
155 components_instantiated += comps;
156
157
158
159
160
161 cpu_time_used += diff.as_milliseconds();
162 ++events_read;
163
164
165
166 }
167
169 {
170 std::cerr << std::endl <<
"Uncaught eformat exception: " << ex.
what() << std::endl;
171 }
172
174 {
175 std::cerr << std::endl <<
"Uncaught ERS exception: " << ex.
what() << std::endl;
176 }
177
178 catch ( std::exception& ex )
179 {
180 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
181 }
182
183 catch ( ... )
184 { std::cerr << std::endl << "Uncaught unknown exception" << std::endl; }
185 }
186
187 std::cout << std::endl;
188 std::cout << " Statistics for Event Validation:" << std::endl;
189 std::cout << " --------------------------------" << std::endl;
190 std::cout << " - Total reading time: " << cpu_time_used << " millisecs" << std::endl;
191 std::cout << " - Validation time per event (" << events_read
192 << "): " << cpu_time_used / events_read << " millisecs" << std::endl;
193 std::cout << " - Average event size: " << event_size / ( 1024.0 * 1024 * events_read )
194 << " megabytes" << std::endl;
195 std::cout << " - Validation time per component (" << components_instantiated
196 << "): " << 1e3 * cpu_time_used / components_instantiated << " microsecs"
197 << std::endl;
198 std::exit( 0 );
199}
const char * what() const
Human description message.
uint32_t components(const eformat::FullEventFragment< TPointer > &f)