BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
header_access.cxx
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file header_access.cxx
5 * @author <a href="mailto:[email protected]">Andre DOS ANJOS</a>
6 * $Author: zhangy $
7 * $Revision: 1.1.1.1 $
8 * $Date: 2009/06/19 07:35:41 $
9 *
10 * Describes a test that benchmarks header information access. The test tries
11 * to read some words of ROBHeaders, starting from full events.
12 */
13
14#include "eformat/eformat.h"
15#include "clocks/Clock.h"
16#include "clocks/Time.h"
17#include <iostream>
18#include <fstream>
19
20/**
21 * Page size used as reference
22 */
23const size_t PAGE_SIZE = 8192; //8 kilobytes pages
24const size_t BUFFER_SIZE = 4194304; //4 Megabytes
25
26/**
27 * Does the exercise itself.
28 */
29int main (int argc, char** argv)
30{
31 using namespace eformat;
32
33 if ( argc != 2 ) {
34 std::cerr << "usage: " << argv[0] << " <test-file>"
35 << std::endl;
36 std::exit(1);
37 }
38
39 //time accounting
40 double cpu_time_used = 0;
41 double validation_cpu_time = 0;
42 uint32_t info_read = 0;
43 uint32_t dummy = 0;
44 uint32_t robs_read = 0;
45 uint32_t ros_counter = 0;
46 uint32_t event_counter = 0;
47 RealTimeClock my_clock;
48
49 //open normally a file
50 std::fstream in(argv[1], std::ios::in|std::ios::binary);
51 if (!in) {
52 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl;
53 std::exit(1);
54 }
55 size_t offset = 0;
56
57#ifdef PAGED_MEMORY
58 std::cout << "Working with paged storage with page size = "
59 << PAGE_SIZE << std::endl;
60#else
61 std::cout << "Working with contiguous storage." << std::endl;
62#endif
63
64 while (in && in.good() && ! in.eof()) {
65 //soft check, so we don't mistake too often
66 uint32_t data[2];
67 in.read((char*)data, 8);
68 if (!in.good() || in.eof()) break; // end-of-file
69 if (data[0] != eformat::FULL_EVENT) {
70 //stop!
71 std::cout << "Word at offset " << HEX(offset) << " is not "
72 << HEX(eformat::FULL_EVENT) << std::endl;
73 std::exit(1);
74 }
75
76#ifdef PAGED_MEMORY
77 //data[1] is the fragment size, in words. Take it and read the fragment
78 in.seekg(offset);
79 //read the event into my pages
80 size_t to_read = data[1]<<2;
81 size_t page_counter = 0;
82 //std::cout << "Loading page";
83 uint32_t paged_event[BUFFER_SIZE/PAGE_SIZE][PAGE_SIZE/sizeof(uint32_t)];
84 while (to_read > 0) {
85 size_t readnow = (PAGE_SIZE>to_read)?to_read:PAGE_SIZE;
86 in.read((char*)paged_event[page_counter], readnow);
87 to_read -= readnow;
88 ++page_counter;
89 //std::cout << " " << page_counter;
90 }
91 //std::cout << ": ";
92 struct iovec myvec[BUFFER_SIZE/PAGE_SIZE];
93 for (size_t i=0; i<page_counter; ++i) {
94 myvec[i].iov_base = paged_event[i];
95 myvec[i].iov_len = PAGE_SIZE;
96 }
97 //correct last page
98 myvec[page_counter-1].iov_len = data[1]<<2 - (page_counter-1)*PAGE_SIZE;
99 eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE> mem(myvec, page_counter);
100#else
101 in.seekg(offset);
102 uint32_t event[BUFFER_SIZE/4];
103 in.read((char*)event, data[1]<<2);
104#endif
105
106 offset += data[1]<<2;
107
108 try {
109#ifdef PAGED_MEMORY
111 const_iterator> fe(mem.begin());
112 typedef eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE>::const_iterator
113 pointer_t;
114#else
116 typedef const uint32_t* pointer_t;
117#endif
118
119 fe.check_tree();
120 ++event_counter;
121
122 Time start = my_clock.time();
123
124 //max SD's is well bellow 64
125 pointer_t sdp[64];
126 uint32_t nsd = fe.children(sdp, 64);
127 for (size_t i=0; i<nsd; ++i) {
129 //max ROS's in system is well bellow 256
130 pointer_t rosp[256];
131 uint32_t nros = sd.children(rosp, 256);
132 for (size_t j=0; j<nros; ++j) {
133 ROSFragment<pointer_t> ros(rosp[j]);
134 ++ros_counter;
135 //max number of ROB's is well bellow 2048
136 pointer_t robp[2048];
137 uint32_t nrob = ros.children(robp, 2048);
138 for (size_t k=0; k<nrob; ++k) {
139 ROBFragment<pointer_t> rob(robp[k]);
140 dummy += rob.rod_lvl1_id(); //access
141 ++info_read;
142 ++robs_read;
143 }
144 }
145 }
146
147 Time end = my_clock.time();
148 Time diff = end - start;
149 cpu_time_used += diff.as_nanoseconds();
150 start = my_clock.time();
151 end = my_clock.time();
152 diff = end - start;
153 validation_cpu_time += diff.as_microseconds();
154
155 //if check is ok, print the lvl1 identifier
156 //std::cout << fe.lvl1_id() << "..";
157 }
158
159 catch (eformat::Issue& ex) {
160 std::cerr << std::endl
161 << "Uncaught eformat exception: " << ex.what() << std::endl;
162 }
163
164 catch (ers::Issue& ex) {
165 std::cerr << std::endl
166 << "Uncaught ERS exception: " << ex.what() << std::endl;
167 }
168
169 catch (std::exception& ex) {
170 std::cerr << std::endl
171 << "Uncaught std exception: " << ex.what() << std::endl;
172 }
173
174 catch (...) {
175 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
176 }
177
178 } ///event loop
179
180 std::cout << " Statistics for ROB Header access:" << std::endl;
181 std::cout << " ---------------------------------" << std::endl;
182 std::cout << " - Total reading time: " << cpu_time_used/1e6 << " milisecs"
183 << std::endl;
184 std::cout << " - Reading time per Event ("
185 << event_counter << "): " << cpu_time_used/(event_counter*1e3)
186 << " usecs" << std::endl;
187 std::cout << " - Reading time per ROS ("
188 << ros_counter << "): " << cpu_time_used/(ros_counter*1e3)
189 << " usecs" << std::endl;
190 std::cout << " - Reading time per ROB ("
191 << robs_read << "): " << cpu_time_used/(robs_read)
192 << " nanosecs" << std::endl;
193 std::cout << " - Reading time per info ("
194 << info_read << "): " << cpu_time_used/(info_read)
195 << " nanosecs" << std::endl;
196 std::cout << " - Validation per event (after header access): "
197 << validation_cpu_time/(event_counter)
198 << " microseconds" << std::endl;
199
200 std::exit(0);
201}
202
203
TTree * data
virtual uint32_t children(TPointer *p, size_t max) const
const char * what() const
Human description message.
const size_t PAGE_SIZE
const size_t BUFFER_SIZE
int main()
Definition: test_IFile.cxx:11