00001
00002
00014 #include "eformat/eformat.h"
00015 #include "clocks/Clock.h"
00016 #include "clocks/Time.h"
00017 #include <iostream>
00018 #include <fstream>
00019
00023 const size_t PAGE_SIZE = 8192;
00024 const size_t BUFFER_SIZE = 4194304;
00025
00029 int main (int argc, char** argv)
00030 {
00031 using namespace eformat;
00032
00033 if ( argc != 2 ) {
00034 std::cerr << "usage: " << argv[0] << " <test-file>"
00035 << std::endl;
00036 std::exit(1);
00037 }
00038
00039
00040 double cpu_time_used = 0;
00041 double validation_cpu_time = 0;
00042 uint32_t info_read = 0;
00043 uint32_t dummy = 0;
00044 uint32_t robs_read = 0;
00045 uint32_t ros_counter = 0;
00046 uint32_t event_counter = 0;
00047 RealTimeClock my_clock;
00048
00049
00050 std::fstream in(argv[1], std::ios::in|std::ios::binary);
00051 if (!in) {
00052 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl;
00053 std::exit(1);
00054 }
00055 size_t offset = 0;
00056
00057 #ifdef PAGED_MEMORY
00058 std::cout << "Working with paged storage with page size = "
00059 << PAGE_SIZE << std::endl;
00060 #else
00061 std::cout << "Working with contiguous storage." << std::endl;
00062 #endif
00063
00064 while (in && in.good() && ! in.eof()) {
00065
00066 uint32_t data[2];
00067 in.read((char*)data, 8);
00068 if (!in.good() || in.eof()) break;
00069 if (data[0] != eformat::FULL_EVENT) {
00070
00071 std::cout << "Word at offset " << HEX(offset) << " is not "
00072 << HEX(eformat::FULL_EVENT) << std::endl;
00073 std::exit(1);
00074 }
00075
00076 #ifdef PAGED_MEMORY
00077
00078 in.seekg(offset);
00079
00080 size_t to_read = data[1]<<2;
00081 size_t page_counter = 0;
00082
00083 uint32_t paged_event[BUFFER_SIZE/PAGE_SIZE][PAGE_SIZE/sizeof(uint32_t)];
00084 while (to_read > 0) {
00085 size_t readnow = (PAGE_SIZE>to_read)?to_read:PAGE_SIZE;
00086 in.read((char*)paged_event[page_counter], readnow);
00087 to_read -= readnow;
00088 ++page_counter;
00089
00090 }
00091
00092 struct iovec myvec[BUFFER_SIZE/PAGE_SIZE];
00093 for (size_t i=0; i<page_counter; ++i) {
00094 myvec[i].iov_base = paged_event[i];
00095 myvec[i].iov_len = PAGE_SIZE;
00096 }
00097
00098 myvec[page_counter-1].iov_len = data[1]<<2 - (page_counter-1)*PAGE_SIZE;
00099 eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE> mem(myvec, page_counter);
00100 #else
00101 in.seekg(offset);
00102 uint32_t event[BUFFER_SIZE/4];
00103 in.read((char*)event, data[1]<<2);
00104 #endif
00105
00106 offset += data[1]<<2;
00107
00108 try {
00109 #ifdef PAGED_MEMORY
00110 FullEventFragment<eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE>::
00111 const_iterator> fe(mem.begin());
00112 typedef eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE>::const_iterator
00113 pointer_t;
00114 #else
00115 FullEventFragment<const uint32_t*> fe(event);
00116 typedef const uint32_t* pointer_t;
00117 #endif
00118
00119 fe.check_tree();
00120 ++event_counter;
00121
00122 Time start = my_clock.time();
00123
00124
00125 pointer_t sdp[64];
00126 uint32_t nsd = fe.children(sdp, 64);
00127 for (size_t i=0; i<nsd; ++i) {
00128 SubDetectorFragment<pointer_t> sd(sdp[i]);
00129
00130 pointer_t rosp[256];
00131 uint32_t nros = sd.children(rosp, 256);
00132 for (size_t j=0; j<nros; ++j) {
00133 ROSFragment<pointer_t> ros(rosp[j]);
00134 ++ros_counter;
00135
00136 pointer_t robp[2048];
00137 uint32_t nrob = ros.children(robp, 2048);
00138 for (size_t k=0; k<nrob; ++k) {
00139 ROBFragment<pointer_t> rob(robp[k]);
00140 dummy += rob.rod_lvl1_id();
00141 ++info_read;
00142 ++robs_read;
00143 }
00144 }
00145 }
00146
00147 Time end = my_clock.time();
00148 Time diff = end - start;
00149 cpu_time_used += diff.as_nanoseconds();
00150 start = my_clock.time();
00151 end = my_clock.time();
00152 diff = end - start;
00153 validation_cpu_time += diff.as_microseconds();
00154
00155
00156
00157 }
00158
00159 catch (eformat::Issue& ex) {
00160 std::cerr << std::endl
00161 << "Uncaught eformat exception: " << ex.what() << std::endl;
00162 }
00163
00164 catch (ers::Issue& ex) {
00165 std::cerr << std::endl
00166 << "Uncaught ERS exception: " << ex.what() << std::endl;
00167 }
00168
00169 catch (std::exception& ex) {
00170 std::cerr << std::endl
00171 << "Uncaught std exception: " << ex.what() << std::endl;
00172 }
00173
00174 catch (...) {
00175 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
00176 }
00177
00178 }
00179
00180 std::cout << " Statistics for ROB Header access:" << std::endl;
00181 std::cout << " ---------------------------------" << std::endl;
00182 std::cout << " - Total reading time: " << cpu_time_used/1e6 << " milisecs"
00183 << std::endl;
00184 std::cout << " - Reading time per Event ("
00185 << event_counter << "): " << cpu_time_used/(event_counter*1e3)
00186 << " usecs" << std::endl;
00187 std::cout << " - Reading time per ROS ("
00188 << ros_counter << "): " << cpu_time_used/(ros_counter*1e3)
00189 << " usecs" << std::endl;
00190 std::cout << " - Reading time per ROB ("
00191 << robs_read << "): " << cpu_time_used/(robs_read)
00192 << " nanosecs" << std::endl;
00193 std::cout << " - Reading time per info ("
00194 << info_read << "): " << cpu_time_used/(info_read)
00195 << " nanosecs" << std::endl;
00196 std::cout << " - Validation per event (after header access): "
00197 << validation_cpu_time/(event_counter)
00198 << " microseconds" << std::endl;
00199
00200 std::exit(0);
00201 }
00202
00203