BOSS 8.0.0
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: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 header information access. The test tries
11 * to read some words of ROBHeaders, starting from full events.
12 */
13
14#include "clocks/Clock.h"
15#include "clocks/Time.h"
16#include "eformat/eformat.h"
17#include <fstream>
18#include <iostream>
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 using namespace eformat;
31
32 if ( argc != 2 )
33 {
34 std::cerr << "usage: " << argv[0] << " <test-file>" << std::endl;
35 std::exit( 1 );
36 }
37
38 // time accounting
39 double cpu_time_used = 0;
40 double validation_cpu_time = 0;
41 uint32_t info_read = 0;
42 uint32_t dummy = 0;
43 uint32_t robs_read = 0;
44 uint32_t ros_counter = 0;
45 uint32_t event_counter = 0;
46 RealTimeClock my_clock;
47
48 // open normally a file
49 std::fstream in( argv[1], std::ios::in | std::ios::binary );
50 if ( !in )
51 {
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 = " << PAGE_SIZE << std::endl;
59#else
60 std::cout << "Working with contiguous storage." << std::endl;
61#endif
62
63 while ( in && in.good() && !in.eof() )
64 {
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 {
71 // stop!
72 std::cout << "Word at offset " << HEX( offset ) << " is not "
73 << HEX( eformat::FULL_EVENT ) << std::endl;
74 std::exit( 1 );
75 }
76
77#ifdef PAGED_MEMORY
78 // data[1] is the fragment size, in words. Take it and read the fragment
79 in.seekg( offset );
80 // read the event into my pages
81 size_t to_read = data[1] << 2;
82 size_t page_counter = 0;
83 // std::cout << "Loading page";
84 uint32_t paged_event[BUFFER_SIZE / PAGE_SIZE][PAGE_SIZE / sizeof( uint32_t )];
85 while ( to_read > 0 )
86 {
87 size_t readnow = ( PAGE_SIZE > to_read ) ? to_read : PAGE_SIZE;
88 in.read( (char*)paged_event[page_counter], readnow );
89 to_read -= readnow;
90 ++page_counter;
91 // std::cout << " " << page_counter;
92 }
93 // std::cout << ": ";
94 struct iovec myvec[BUFFER_SIZE / PAGE_SIZE];
95 for ( size_t i = 0; i < page_counter; ++i )
96 {
97 myvec[i].iov_base = paged_event[i];
98 myvec[i].iov_len = PAGE_SIZE;
99 }
100 // correct last page
101 myvec[page_counter - 1].iov_len = data[1] << 2 - ( page_counter - 1 ) * PAGE_SIZE;
102 eformat::PagedMemory<BUFFER_SIZE / PAGE_SIZE> mem( myvec, page_counter );
103#else
104 in.seekg( offset );
105 uint32_t event[BUFFER_SIZE / 4];
106 in.read( (char*)event, data[1] << 2 );
107#endif
108
109 offset += data[1] << 2;
110
111 try
112 {
113#ifdef PAGED_MEMORY
115 mem.begin() );
116 typedef eformat::PagedMemory<BUFFER_SIZE / PAGE_SIZE>::const_iterator pointer_t;
117#else
119 typedef const uint32_t* pointer_t;
120#endif
121
122 fe.check_tree();
123 ++event_counter;
124
125 Time start = my_clock.time();
126
127 // max SD's is well bellow 64
128 pointer_t sdp[64];
129 uint32_t nsd = fe.children( sdp, 64 );
130 for ( size_t i = 0; i < nsd; ++i )
131 {
133 // max ROS's in system is well bellow 256
134 pointer_t rosp[256];
135 uint32_t nros = sd.children( rosp, 256 );
136 for ( size_t j = 0; j < nros; ++j )
137 {
138 ROSFragment<pointer_t> ros( rosp[j] );
139 ++ros_counter;
140 // max number of ROB's is well bellow 2048
141 pointer_t robp[2048];
142 uint32_t nrob = ros.children( robp, 2048 );
143 for ( size_t k = 0; k < nrob; ++k )
144 {
145 ROBFragment<pointer_t> rob( robp[k] );
146 dummy += rob.rod_lvl1_id(); // access
147 ++info_read;
148 ++robs_read;
149 }
150 }
151 }
152
153 Time end = my_clock.time();
154 Time diff = end - start;
155 cpu_time_used += diff.as_nanoseconds();
156 start = my_clock.time();
157 end = my_clock.time();
158 diff = end - start;
159 validation_cpu_time += diff.as_microseconds();
160
161 // if check is ok, print the lvl1 identifier
162 // std::cout << fe.lvl1_id() << "..";
163 }
164
165 catch ( eformat::Issue& ex )
166 {
167 std::cerr << std::endl << "Uncaught eformat exception: " << ex.what() << std::endl;
168 }
169
170 catch ( ers::Issue& ex )
171 {
172 std::cerr << std::endl << "Uncaught ERS exception: " << ex.what() << std::endl;
173 }
174
175 catch ( std::exception& ex )
176 {
177 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
178 }
179
180 catch ( ... )
181 { std::cerr << std::endl << "Uncaught unknown exception" << std::endl; }
182
183 } /// event loop
184
185 std::cout << " Statistics for ROB Header access:" << std::endl;
186 std::cout << " ---------------------------------" << std::endl;
187 std::cout << " - Total reading time: " << cpu_time_used / 1e6 << " milisecs" << std::endl;
188 std::cout << " - Reading time per Event (" << event_counter
189 << "): " << cpu_time_used / ( event_counter * 1e3 ) << " usecs" << std::endl;
190 std::cout << " - Reading time per ROS (" << ros_counter
191 << "): " << cpu_time_used / ( ros_counter * 1e3 ) << " usecs" << std::endl;
192 std::cout << " - Reading time per ROB (" << robs_read
193 << "): " << cpu_time_used / ( robs_read ) << " nanosecs" << std::endl;
194 std::cout << " - Reading time per info (" << info_read
195 << "): " << cpu_time_used / ( info_read ) << " nanosecs" << std::endl;
196 std::cout << " - Validation per event (after header access): "
197 << validation_cpu_time / ( event_counter ) << " microseconds" << std::endl;
198
199 std::exit( 0 );
200}
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