Does the exercise itself.
30 {
32
33 if ( argc != 2 )
34 {
35 std::cerr << "usage: " << argv[0] << " <test-file>" << std::endl;
36 std::exit( 1 );
37 }
38
39
40 double cpu_time_used = 0;
41 uint32_t elements_read = 0;
42 uint32_t robs_read = 0;
43 RealTimeClock my_clock;
44
45
46 std::fstream in( argv[1], std::ios::in | std::ios::binary );
47 if ( !in )
48 {
49 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl;
50 std::exit( 1 );
51 }
52 size_t offset = 0;
53
54#ifdef PAGED_MEMORY
55 std::cout <<
"Working with paged storage with page size = " <<
PAGE_SIZE <<
" bytes."
56 << std::endl;
57#else
58 std::cout << "Working with contiguous storage." << std::endl;
59#endif
60
61 while ( in && in.good() && !in.eof() )
62 {
63
65 in.read( (
char*)
data, 8 );
66 if ( !in.good() || in.eof() ) break;
68 {
69
70 std::cout <<
"Word at offset " <<
HEX( offset ) <<
" is not "
72 std::exit( 1 );
73 }
74
75#ifdef PAGED_MEMORY
76
77 in.seekg( offset );
78
79 size_t to_read =
data[1] << 2;
80 size_t page_counter = 0;
81
83 while ( to_read > 0 )
84 {
86 in.read( (char*)paged_event[page_counter], readnow );
87 to_read -= readnow;
88 ++page_counter;
89
90 }
91
93 for ( size_t i = 0; i < page_counter; ++i )
94 {
95 myvec[i].iov_base = paged_event[i];
97 }
98
99 myvec[page_counter - 1].iov_len =
data[1] << 2 - ( page_counter - 1 ) *
PAGE_SIZE;
101#else
102 in.seekg( offset );
104 in.read( (
char*)event,
data[1] << 2 );
105#endif
106
107 offset +=
data[1] << 2;
108
109 try
110 {
111#ifdef PAGED_MEMORY
113 mem.begin() );
115#else
117 typedef const uint32_t* pointer_t;
118#endif
119
120 std::vector<pointer_t> robs;
121
122 pointer_t sdp[64];
123 uint32_t nsd = fe.children( sdp, 64 );
124 for ( size_t i = 0; i < nsd; ++i )
125 {
127
128 pointer_t rosp[256];
129 uint32_t nros = sd.children( rosp, 256 );
130 for ( size_t j = 0; j < nros; ++j )
131 {
133
134 pointer_t robp[2048];
135 uint32_t nrob = ros.children( robp, 2048 );
136 robs.insert( robs.end(), robp, &robp[nrob] );
137 }
138 }
139
140 uint32_t global_counter = 0;
141 Time start = my_clock.time();
142 for ( std::vector<pointer_t>::const_iterator it = robs.begin(); it != robs.end(); ++it )
143 {
145 pointer_t my;
146 rob.rod_data( my );
147 size_t ndata = rob.rod_ndata();
148 for ( size_t m = 0; m < ndata; ++m )
149 {
150 global_counter += my[m];
151 ++elements_read;
152 }
153 ++robs_read;
154 }
155 Time end = my_clock.time();
156 Time diff = end - start;
157 cpu_time_used += diff.as_milliseconds();
158 }
159
161 {
162 std::cerr << std::endl <<
"Uncaught eformat exception: " << ex.
what() << std::endl;
163 }
164
166 {
167 std::cerr << std::endl <<
"Uncaught ERS exception: " << ex.
what() << std::endl;
168 }
169
170 catch ( std::exception& ex )
171 {
172 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
173 }
174
175 catch ( ... )
176 { std::cerr << std::endl << "Uncaught unknown exception" << std::endl; }
177 }
178
179 std::cout << " Statistics for ROB data access:" << std::endl;
180 std::cout << " -------------------------------" << std::endl;
181 std::cout << " - Total reading time: " << cpu_time_used << " millisecs" << std::endl;
182 std::cout << " - Reading time per ROB (" << robs_read
183 << "): " << 1e3 * cpu_time_used / robs_read << " microsecs" << std::endl;
184 std::cout << " - Reading time per data word in a ROB (" << elements_read
185 << "): " << 1e6 * cpu_time_used / elements_read << " nanosecs" << std::endl;
186
187 std::exit( 0 );
188}
const char * what() const
Human description message.