BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
validate.cxx
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file validate.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 validation of full events.
11 */
12
13#include "clocks/Clock.h"
14#include "clocks/Time.h"
15#include "eformat/eformat.h"
16#include <fstream>
17#include <iostream>
18
19/**
20 * Page size used as reference
21 */
22const size_t PAGE_SIZE = 8192; // 8 kilobytes pages
23const size_t BUFFER_SIZE = 4194304; // 4 Megabytes
24
25/**
26 * Calculates the number of components in an event
27 */
28template <class TPointer>
30 using namespace eformat;
31 uint32_t retval = 0;
32
33 // max SD's is well bellow 64
34 TPointer sdp[64];
35 uint32_t nsd = f.children( sdp, 64 );
36 retval += nsd;
37 for ( size_t i = 0; i < nsd; ++i )
38 {
40 // max ROS's in system is well bellow 256
41 TPointer rosp[256];
42 uint32_t nros = sd.children( rosp, 256 );
43 retval += nros;
44 for ( size_t j = 0; j < nros; ++j )
45 {
46 ROSFragment<TPointer> ros( rosp[j] );
47 retval += ros.nchildren();
48 }
49 }
50
51 return retval;
52}
53
54/**
55 * Does the exercise itself.
56 */
57int main( int argc, char** argv ) {
58 using namespace eformat;
59
60 if ( argc != 2 )
61 {
62 std::cerr << "usage: " << argv[0] << " <test-file>" << std::endl;
63 std::exit( 1 );
64 }
65
66 // time accounting
67 double cpu_time_used = 0;
68 uint32_t events_read = 0;
69 uint32_t components_instantiated = 0;
70 RealTimeClock my_clock;
71 uint32_t event_size = 0;
72
73 // open normally a file
74 std::fstream in( argv[1], std::ios::in | std::ios::binary );
75 if ( !in )
76 {
77 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl;
78 std::exit( 1 );
79 }
80 size_t offset = 0;
81
82#ifdef PAGED_MEMORY
83 std::cout << "Working with paged storage with page size = " << PAGE_SIZE << " bytes."
84 << std::endl;
85#else
86 std::cout << "Working with contiguous storage." << std::endl;
87#endif
88
89 while ( in && in.good() && !in.eof() )
90 {
91 // soft check, so we don't mistake too often
92 uint32_t data[2];
93 in.read( (char*)data, 8 );
94 if ( !in.good() || in.eof() ) break; // end-of-file
95 if ( data[0] != eformat::FULL_EVENT )
96 {
97 // stop!
98 std::cout << "Word at offset " << HEX( offset ) << " is not "
99 << HEX( eformat::FULL_EVENT ) << std::endl;
100 std::exit( 1 );
101 }
102
103#ifdef PAGED_MEMORY
104 // data[1] is the fragment size, in words. Take it and read the fragment
105 in.seekg( offset );
106 // read the event into my pages
107 size_t to_read = data[1] << 2;
108 size_t page_counter = 0;
109 // std::cout << "Loading page";
110 uint32_t paged_event[BUFFER_SIZE / PAGE_SIZE][PAGE_SIZE / sizeof( uint32_t )];
111 while ( to_read > 0 )
112 {
113 size_t readnow = ( PAGE_SIZE > to_read ) ? to_read : PAGE_SIZE;
114 in.read( (char*)paged_event[page_counter], readnow );
115 to_read -= readnow;
116 ++page_counter;
117 // std::cout << " " << page_counter;
118 }
119 // std::cout << ": ";
120 struct iovec myvec[BUFFER_SIZE / PAGE_SIZE];
121 for ( size_t i = 0; i < page_counter; ++i )
122 {
123 myvec[i].iov_base = paged_event[i];
124 myvec[i].iov_len = PAGE_SIZE;
125 }
126 // correct last page
127 myvec[page_counter - 1].iov_len = data[1] << 2 - ( page_counter - 1 ) * PAGE_SIZE;
128 eformat::PagedMemory<BUFFER_SIZE / PAGE_SIZE> mem( myvec, page_counter );
129#else
130 in.seekg( offset );
131 uint32_t event[BUFFER_SIZE / 4];
132 in.read( (char*)event, data[1] << 2 );
133#endif
134
135 offset += data[1] << 2;
136
137 try
138 {
139#ifdef PAGED_MEMORY
141 mem.begin() );
142#else
144#endif
145
146 event_size += 4 * fe.fragment_size_word();
147
148 Time start = my_clock.time();
149 fe.check_tree();
150 Time end = my_clock.time();
151 Time diff = end - start;
152
153 // calculate the number of event components:
154 uint32_t comps = components( fe );
155 components_instantiated += comps;
156
157 // std::cout << " > Timing : " << diff.as_milliseconds()
158 // << " ms" << std::endl;
159 // std::cout << " > Timing/component: " << diff.as_milliseconds()*1e3/comps
160 // << " us" << std::endl;
161 cpu_time_used += diff.as_milliseconds();
162 ++events_read;
163
164 // if check is ok, print the lvl1 identifier
165 // std::cout << fe.lvl1_id() << "..";
166 }
167
168 catch ( eformat::Issue& ex )
169 {
170 std::cerr << std::endl << "Uncaught eformat exception: " << ex.what() << std::endl;
171 }
172
173 catch ( ers::Issue& ex )
174 {
175 std::cerr << std::endl << "Uncaught ERS exception: " << ex.what() << std::endl;
176 }
177
178 catch ( std::exception& ex )
179 {
180 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
181 }
182
183 catch ( ... )
184 { std::cerr << std::endl << "Uncaught unknown exception" << std::endl; }
185 }
186
187 std::cout << std::endl;
188 std::cout << " Statistics for Event Validation:" << std::endl;
189 std::cout << " --------------------------------" << std::endl;
190 std::cout << " - Total reading time: " << cpu_time_used << " millisecs" << std::endl;
191 std::cout << " - Validation time per event (" << events_read
192 << "): " << cpu_time_used / events_read << " millisecs" << std::endl;
193 std::cout << " - Average event size: " << event_size / ( 1024.0 * 1024 * events_read )
194 << " megabytes" << std::endl;
195 std::cout << " - Validation time per component (" << components_instantiated
196 << "): " << 1e3 * cpu_time_used / components_instantiated << " microsecs"
197 << std::endl;
198 std::exit( 0 );
199}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
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
uint32_t components(const eformat::FullEventFragment< TPointer > &f)
Definition validate.cxx:29