BOSS 8.0.0
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:Andre.dos.Anjos@cern.ch">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 "clocks/Clock.h"
15#include "clocks/Time.h"
16#include "eformat/eformat.h"
17#include <fstream>
18#include <iostream>
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 using namespace eformat;
32
33 if ( argc != 2 )
34 {
35 std::cerr << "usage: " << argv[0] << " <test-file>" << std::endl;
36 std::exit( 1 );
37 }
38
39 // time accounting
40 double cpu_time_used = 0;
41 uint32_t elements_read = 0;
42 uint32_t robs_read = 0;
43 RealTimeClock my_clock;
44
45 // open normally a file
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 // soft check, so we don't mistake too often
64 uint32_t data[2];
65 in.read( (char*)data, 8 );
66 if ( !in.good() || in.eof() ) break; // end-of-file
67 if ( data[0] != eformat::FULL_EVENT )
68 {
69 // stop!
70 std::cout << "Word at offset " << HEX( offset ) << " is not "
71 << HEX( eformat::FULL_EVENT ) << std::endl;
72 std::exit( 1 );
73 }
74
75#ifdef PAGED_MEMORY
76 // data[1] is the fragment size, in words. Take it and read the fragment
77 in.seekg( offset );
78 // read the event into my pages
79 size_t to_read = data[1] << 2;
80 size_t page_counter = 0;
81 // std::cout << "Loading page";
82 uint32_t paged_event[BUFFER_SIZE / PAGE_SIZE][PAGE_SIZE / sizeof( uint32_t )];
83 while ( to_read > 0 )
84 {
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 {
95 myvec[i].iov_base = paged_event[i];
96 myvec[i].iov_len = PAGE_SIZE;
97 }
98 // correct last page
99 myvec[page_counter - 1].iov_len = data[1] << 2 - ( page_counter - 1 ) * PAGE_SIZE;
100 eformat::PagedMemory<BUFFER_SIZE / PAGE_SIZE> mem( myvec, page_counter );
101#else
102 in.seekg( offset );
103 uint32_t event[BUFFER_SIZE / 4];
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() );
114 typedef eformat::PagedMemory<BUFFER_SIZE / PAGE_SIZE>::const_iterator pointer_t;
115#else
117 typedef const uint32_t* pointer_t;
118#endif
119
120 std::vector<pointer_t> robs;
121 // max SD's is well bellow 64
122 pointer_t sdp[64];
123 uint32_t nsd = fe.children( sdp, 64 );
124 for ( size_t i = 0; i < nsd; ++i )
125 {
127 // max ROS's in system is well bellow 256
128 pointer_t rosp[256];
129 uint32_t nros = sd.children( rosp, 256 );
130 for ( size_t j = 0; j < nros; ++j )
131 {
132 ROSFragment<pointer_t> ros( rosp[j] );
133 // max number of ROB's is well bellow 2048
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 {
144 ROBFragment<pointer_t> rob( *it );
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
160 catch ( eformat::Issue& ex )
161 {
162 std::cerr << std::endl << "Uncaught eformat exception: " << ex.what() << std::endl;
163 }
164
165 catch ( ers::Issue& ex )
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}
TTree * data
virtual uint32_t children(TPointer *p, size_t max) const
Root Issue class.
const char * what() const
Human description message.
const size_t PAGE_SIZE
Definition data_read.cxx:24
#define BUFFER_SIZE
int main()
Definition phokhara.cc:42