BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
validate.cxx File Reference
#include "eformat/eformat.h"
#include "clocks/Clock.h"
#include "clocks/Time.h"
#include <iostream>
#include <fstream>

Go to the source code of this file.

Functions

template<class TPointer >
uint32_t components (const eformat::FullEventFragment< TPointer > &f)
 
int main (int argc, char **argv)
 

Variables

const size_t PAGE_SIZE = 8192
 
const size_t BUFFER_SIZE = 4194304
 

Detailed Description

Author
Andre DOS ANJOS
Author
zhangy
Revision
1.1.1.1
Date
2009/06/19 07:35:41

Describes a test that benchmarks validation of full events.

Definition in file validate.cxx.

Function Documentation

◆ components()

template<class TPointer >
uint32_t components ( const eformat::FullEventFragment< TPointer > &  f)

Calculates the number of components in an event

Definition at line 29 of file validate.cxx.

30{
31 using namespace eformat;
32 uint32_t retval = 0;
33
34 //max SD's is well bellow 64
35 TPointer sdp[64];
36 uint32_t nsd = f.children(sdp, 64);
37 retval += nsd;
38 for (size_t i=0; i<nsd; ++i) {
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 ROSFragment<TPointer> ros(rosp[j]);
46 retval += ros.nchildren();
47 }
48 }
49
50 return retval;
51}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Does the exercise itself.

Definition at line 56 of file validate.cxx.

57{
58 using namespace eformat;
59
60 if ( argc != 2 ) {
61 std::cerr << "usage: " << argv[0] << " <test-file>"
62 << 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 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl;
77 std::exit(1);
78 }
79 size_t offset = 0;
80
81#ifdef PAGED_MEMORY
82 std::cout << "Working with paged storage with page size = "
83 << PAGE_SIZE << " bytes." << std::endl;
84#else
85 std::cout << "Working with contiguous storage." << std::endl;
86#endif
87
88 while (in && in.good() && ! in.eof()) {
89 //soft check, so we don't mistake too often
90 uint32_t data[2];
91 in.read((char*)data, 8);
92 if (!in.good() || in.eof()) break; // end-of-file
93 if (data[0] != eformat::FULL_EVENT) {
94 //stop!
95 std::cout << "Word at offset " << HEX(offset) << " is not "
96 << HEX(eformat::FULL_EVENT) << std::endl;
97 std::exit(1);
98 }
99
100#ifdef PAGED_MEMORY
101 //data[1] is the fragment size, in words. Take it and read the fragment
102 in.seekg(offset);
103 //read the event into my pages
104 size_t to_read = data[1]<<2;
105 size_t page_counter = 0;
106 //std::cout << "Loading page";
107 uint32_t paged_event[BUFFER_SIZE/PAGE_SIZE][PAGE_SIZE/sizeof(uint32_t)];
108 while (to_read > 0) {
109 size_t readnow = (PAGE_SIZE>to_read)?to_read:PAGE_SIZE;
110 in.read((char*)paged_event[page_counter], readnow);
111 to_read -= readnow;
112 ++page_counter;
113 //std::cout << " " << page_counter;
114 }
115 //std::cout << ": ";
116 struct iovec myvec[BUFFER_SIZE/PAGE_SIZE];
117 for (size_t i=0; i<page_counter; ++i) {
118 myvec[i].iov_base = paged_event[i];
119 myvec[i].iov_len = PAGE_SIZE;
120 }
121 //correct last page
122 myvec[page_counter-1].iov_len = data[1]<<2 - (page_counter-1)*PAGE_SIZE;
123 eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE> mem(myvec, page_counter);
124#else
125 in.seekg(offset);
126 uint32_t event[BUFFER_SIZE/4];
127 in.read((char*)event, data[1]<<2);
128#endif
129
130 offset += data[1]<<2;
131
132 try {
133#ifdef PAGED_MEMORY
135 const_iterator> fe(mem.begin());
136#else
138#endif
139
140 event_size += 4*fe.fragment_size_word();
141
142 Time start = my_clock.time();
143 fe.check_tree();
144 Time end = my_clock.time();
145 Time diff = end - start;
146
147 //calculate the number of event components:
148 uint32_t comps = components(fe);
149 components_instantiated += comps;
150
151 //std::cout << " > Timing : " << diff.as_milliseconds()
152 // << " ms" << std::endl;
153 //std::cout << " > Timing/component: " << diff.as_milliseconds()*1e3/comps
154 // << " us" << std::endl;
155 cpu_time_used += diff.as_milliseconds();
156 ++events_read;
157
158 //if check is ok, print the lvl1 identifier
159 //std::cout << fe.lvl1_id() << "..";
160 }
161
162 catch (eformat::Issue& ex) {
163 std::cerr << std::endl
164 << "Uncaught eformat exception: " << ex.what() << std::endl;
165 }
166
167 catch (ers::Issue& ex) {
168 std::cerr << std::endl
169 << "Uncaught ERS exception: " << ex.what() << std::endl;
170 }
171
172 catch (std::exception& ex) {
173 std::cerr << std::endl
174 << "Uncaught std exception: " << ex.what() << std::endl;
175 }
176
177 catch (...) {
178 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
179 }
180
181 }
182
183 std::cout << std::endl;
184 std::cout << " Statistics for Event Validation:" << std::endl;
185 std::cout << " --------------------------------" << std::endl;
186 std::cout << " - Total reading time: " << cpu_time_used << " millisecs"
187 << std::endl;
188 std::cout << " - Validation time per event ("
189 << events_read << "): " << cpu_time_used/events_read
190 << " millisecs" << std::endl;
191 std::cout << " - Average event size: "
192 << event_size/(1024.0*1024*events_read) << " megabytes" << std::endl;
193 std::cout << " - Validation time per component ("
194 << components_instantiated << "): "
195 << 1e3*cpu_time_used/components_instantiated
196 << " microsecs" << std::endl;
197 std::exit(0);
198}
Root Issue class.
const char * what() const
Human description message.
@ FULL_EVENT
Definition: HeaderMarker.h:30
#define HEX(m)
Definition: util.h:107
const size_t PAGE_SIZE
Definition: validate.cxx:22
const size_t BUFFER_SIZE
Definition: validate.cxx:23
uint32_t components(const eformat::FullEventFragment< TPointer > &f)
Definition: validate.cxx:29

Variable Documentation

◆ BUFFER_SIZE

const size_t BUFFER_SIZE = 4194304

Definition at line 23 of file validate.cxx.

Referenced by main().

◆ PAGE_SIZE

const size_t PAGE_SIZE = 8192

Page size used as reference

Definition at line 22 of file validate.cxx.

Referenced by main().