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