#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 | |
int | main (int argc, char **argv) |
Variables | |
const size_t | PAGE_SIZE = 8192 |
const size_t | BUFFER_SIZE = 4194304 |
Definition in file header_access.cxx.
int main | ( | int | argc, | |
char ** | argv | |||
) |
Does the exercise itself.
event loop
Definition at line 29 of file header_access.cxx.
References BUFFER_SIZE, deljobs::end, eformat::FULL_EVENT, HEX, genRecEmupikp::i, ganga-rec::j, PAGE_SIZE, deljobs::start, and ers::Issue::what().
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 //time accounting 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 //open normally a file 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 //soft check, so we don't mistake too often 00066 uint32_t data[2]; 00067 in.read((char*)data, 8); 00068 if (!in.good() || in.eof()) break; // end-of-file 00069 if (data[0] != eformat::FULL_EVENT) { 00070 //stop! 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 //data[1] is the fragment size, in words. Take it and read the fragment 00078 in.seekg(offset); 00079 //read the event into my pages 00080 size_t to_read = data[1]<<2; 00081 size_t page_counter = 0; 00082 //std::cout << "Loading page"; 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 //std::cout << " " << page_counter; 00090 } 00091 //std::cout << ": "; 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 //correct last page 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 //max SD's is well bellow 64 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 //max ROS's in system is well bellow 256 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 //max number of ROB's is well bellow 2048 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(); //access 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 //if check is ok, print the lvl1 identifier 00156 //std::cout << fe.lvl1_id() << ".."; 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 }
const size_t BUFFER_SIZE = 4194304 |
Definition at line 24 of file header_access.cxx.
const size_t PAGE_SIZE = 8192 |
Page size used as reference
Definition at line 23 of file header_access.cxx.