BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
data_read.cxx
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file data_read.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 ROB reading. Each ROB is read once and all
11 * of its ROD fragment data is touched.
12 */
13
14#include "eformat/eformat.h"
15#include "clocks/Clock.h"
16#include "clocks/Time.h"
17#include <iostream>
18#include <fstream>
19#include <vector>
20
21/**
22 * Page size used as reference
23 */
24const size_t PAGE_SIZE = 8192; //8 kilobytes pages
25const size_t BUFFER_SIZE = 4194304; //4 Megabytes
26
27/**
28 * Does the exercise itself.
29 */
30int main (int argc, char** argv)
31{
32 using namespace eformat;
33
34 if ( argc != 2 ) {
35 std::cerr << "usage: " << argv[0] << " <test-file>"
36 << std::endl;
37 std::exit(1);
38 }
39
40 //time accounting
41 double cpu_time_used = 0;
42 uint32_t elements_read = 0;
43 uint32_t robs_read = 0;
44 RealTimeClock my_clock;
45
46 //open normally a file
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 = "
56 << PAGE_SIZE << " bytes." << std::endl;
57#else
58 std::cout << "Working with contiguous storage." << std::endl;
59#endif
60
61 while (in && in.good() && ! in.eof()) {
62 //soft check, so we don't mistake too often
63 uint32_t data[2];
64 in.read((char*)data, 8);
65 if (!in.good() || in.eof()) break; // end-of-file
66 if (data[0] != eformat::FULL_EVENT) {
67 //stop!
68 std::cout << "Word at offset " << HEX(offset) << " is not "
69 << HEX(eformat::FULL_EVENT) << std::endl;
70 std::exit(1);
71 }
72
73#ifdef PAGED_MEMORY
74 //data[1] is the fragment size, in words. Take it and read the fragment
75 in.seekg(offset);
76 //read the event into my pages
77 size_t to_read = data[1]<<2;
78 size_t page_counter = 0;
79 //std::cout << "Loading page";
80 uint32_t paged_event[BUFFER_SIZE/PAGE_SIZE][PAGE_SIZE/sizeof(uint32_t)];
81 while (to_read > 0) {
82 size_t readnow = (PAGE_SIZE>to_read)?to_read:PAGE_SIZE;
83 in.read((char*)paged_event[page_counter], readnow);
84 to_read -= readnow;
85 ++page_counter;
86 //std::cout << " " << page_counter;
87 }
88 //std::cout << ": ";
89 struct iovec myvec[BUFFER_SIZE/PAGE_SIZE];
90 for (size_t i=0; i<page_counter; ++i) {
91 myvec[i].iov_base = paged_event[i];
92 myvec[i].iov_len = PAGE_SIZE;
93 }
94 //correct last page
95 myvec[page_counter-1].iov_len = data[1]<<2 - (page_counter-1)*PAGE_SIZE;
96 eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE> mem(myvec, page_counter);
97#else
98 in.seekg(offset);
99 uint32_t event[BUFFER_SIZE/4];
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());
109 typedef eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE>::const_iterator
110 pointer_t;
111#else
113 typedef const uint32_t* pointer_t;
114#endif
115
116 std::vector<pointer_t> robs;
117 //max SD's is well bellow 64
118 pointer_t sdp[64];
119 uint32_t nsd = fe.children(sdp, 64);
120 for (size_t i=0; i<nsd; ++i) {
122 //max ROS's in system is well bellow 256
123 pointer_t rosp[256];
124 uint32_t nros = sd.children(rosp, 256);
125 for (size_t j=0; j<nros; ++j) {
126 ROSFragment<pointer_t> ros(rosp[j]);
127 //max number of ROB's is well bellow 2048
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) {
138 ROBFragment<pointer_t> rob(*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
153 catch (eformat::Issue& ex) {
154 std::cerr << std::endl
155 << "Uncaught eformat exception: " << ex.what() << std::endl;
156 }
157
158 catch (ers::Issue& ex) {
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}
187
188
TTree * data
virtual uint32_t children(TPointer *p, size_t max) const
Definition: Header.h:293
void rod_data(TPointer &it) const
Definition: ROBFragment.h:257
uint32_t rod_ndata() const
Definition: ROBFragment.h:159
Root Issue class.
const char * what() const
Human description message.
const size_t PAGE_SIZE
Definition: data_read.cxx:24
const size_t BUFFER_SIZE
Definition: data_read.cxx:25
Includes all entities from the Event Format Library (eformat)
@ FULL_EVENT
Definition: HeaderMarker.h:30
int main()
Definition: test_IFile.cxx:11
#define HEX(m)
Definition: util.h:107