#include "eformat/eformat.h"
#include "clocks/Clock.h"
#include "clocks/Time.h"
#include <iostream>
#include <fstream>
#include <vector>
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 data_read.cxx.
int main | ( | int | argc, | |
char ** | argv | |||
) |
Does the exercise itself.
Definition at line 30 of file data_read.cxx.
References BUFFER_SIZE, deljobs::end, eformat::FULL_EVENT, HEX, genRecEmupikp::i, ganga-rec::j, PAGE_SIZE, deljobs::start, and ers::Issue::what().
00031 { 00032 using namespace eformat; 00033 00034 if ( argc != 2 ) { 00035 std::cerr << "usage: " << argv[0] << " <test-file>" 00036 << std::endl; 00037 std::exit(1); 00038 } 00039 00040 //time accounting 00041 double cpu_time_used = 0; 00042 uint32_t elements_read = 0; 00043 uint32_t robs_read = 0; 00044 RealTimeClock my_clock; 00045 00046 //open normally a file 00047 std::fstream in(argv[1], std::ios::in|std::ios::binary); 00048 if (!in) { 00049 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl; 00050 std::exit(1); 00051 } 00052 size_t offset = 0; 00053 00054 #ifdef PAGED_MEMORY 00055 std::cout << "Working with paged storage with page size = " 00056 << PAGE_SIZE << " bytes." << std::endl; 00057 #else 00058 std::cout << "Working with contiguous storage." << std::endl; 00059 #endif 00060 00061 while (in && in.good() && ! in.eof()) { 00062 //soft check, so we don't mistake too often 00063 uint32_t data[2]; 00064 in.read((char*)data, 8); 00065 if (!in.good() || in.eof()) break; // end-of-file 00066 if (data[0] != eformat::FULL_EVENT) { 00067 //stop! 00068 std::cout << "Word at offset " << HEX(offset) << " is not " 00069 << HEX(eformat::FULL_EVENT) << std::endl; 00070 std::exit(1); 00071 } 00072 00073 #ifdef PAGED_MEMORY 00074 //data[1] is the fragment size, in words. Take it and read the fragment 00075 in.seekg(offset); 00076 //read the event into my pages 00077 size_t to_read = data[1]<<2; 00078 size_t page_counter = 0; 00079 //std::cout << "Loading page"; 00080 uint32_t paged_event[BUFFER_SIZE/PAGE_SIZE][PAGE_SIZE/sizeof(uint32_t)]; 00081 while (to_read > 0) { 00082 size_t readnow = (PAGE_SIZE>to_read)?to_read:PAGE_SIZE; 00083 in.read((char*)paged_event[page_counter], readnow); 00084 to_read -= readnow; 00085 ++page_counter; 00086 //std::cout << " " << page_counter; 00087 } 00088 //std::cout << ": "; 00089 struct iovec myvec[BUFFER_SIZE/PAGE_SIZE]; 00090 for (size_t i=0; i<page_counter; ++i) { 00091 myvec[i].iov_base = paged_event[i]; 00092 myvec[i].iov_len = PAGE_SIZE; 00093 } 00094 //correct last page 00095 myvec[page_counter-1].iov_len = data[1]<<2 - (page_counter-1)*PAGE_SIZE; 00096 eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE> mem(myvec, page_counter); 00097 #else 00098 in.seekg(offset); 00099 uint32_t event[BUFFER_SIZE/4]; 00100 in.read((char*)event, data[1]<<2); 00101 #endif 00102 00103 offset += data[1]<<2; 00104 00105 try { 00106 #ifdef PAGED_MEMORY 00107 FullEventFragment<eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE>:: 00108 const_iterator> fe(mem.begin()); 00109 typedef eformat::PagedMemory<BUFFER_SIZE/PAGE_SIZE>::const_iterator 00110 pointer_t; 00111 #else 00112 FullEventFragment<const uint32_t*> fe(event); 00113 typedef const uint32_t* pointer_t; 00114 #endif 00115 00116 std::vector<pointer_t> robs; 00117 //max SD's is well bellow 64 00118 pointer_t sdp[64]; 00119 uint32_t nsd = fe.children(sdp, 64); 00120 for (size_t i=0; i<nsd; ++i) { 00121 SubDetectorFragment<pointer_t> sd(sdp[i]); 00122 //max ROS's in system is well bellow 256 00123 pointer_t rosp[256]; 00124 uint32_t nros = sd.children(rosp, 256); 00125 for (size_t j=0; j<nros; ++j) { 00126 ROSFragment<pointer_t> ros(rosp[j]); 00127 //max number of ROB's is well bellow 2048 00128 pointer_t robp[2048]; 00129 uint32_t nrob = ros.children(robp, 2048); 00130 robs.insert(robs.end(), robp, &robp[nrob]); 00131 } 00132 } 00133 00134 uint32_t global_counter = 0; 00135 Time start = my_clock.time(); 00136 for (std::vector<pointer_t>::const_iterator it = robs.begin(); 00137 it != robs.end(); ++it) { 00138 ROBFragment<pointer_t> rob(*it); 00139 pointer_t my; 00140 rob.rod_data(my); 00141 size_t ndata = rob.rod_ndata(); 00142 for (size_t m=0; m<ndata; ++m) { 00143 global_counter += my[m]; 00144 ++elements_read; 00145 } 00146 ++robs_read; 00147 } 00148 Time end = my_clock.time(); 00149 Time diff = end - start; 00150 cpu_time_used += diff.as_milliseconds(); 00151 } 00152 00153 catch (eformat::Issue& ex) { 00154 std::cerr << std::endl 00155 << "Uncaught eformat exception: " << ex.what() << std::endl; 00156 } 00157 00158 catch (ers::Issue& ex) { 00159 std::cerr << std::endl 00160 << "Uncaught ERS exception: " << ex.what() << std::endl; 00161 } 00162 00163 catch (std::exception& ex) { 00164 std::cerr << std::endl 00165 << "Uncaught std exception: " << ex.what() << std::endl; 00166 } 00167 00168 catch (...) { 00169 std::cerr << std::endl << "Uncaught unknown exception" << std::endl; 00170 } 00171 00172 } 00173 00174 std::cout << " Statistics for ROB data access:" << std::endl; 00175 std::cout << " -------------------------------" << std::endl; 00176 std::cout << " - Total reading time: " << cpu_time_used << " millisecs" 00177 << std::endl; 00178 std::cout << " - Reading time per ROB (" 00179 << robs_read << "): " << 1e3*cpu_time_used/robs_read 00180 << " microsecs" << std::endl; 00181 std::cout << " - Reading time per data word in a ROB (" 00182 << elements_read << "): " 00183 << 1e6*cpu_time_used/elements_read << " nanosecs" << std::endl; 00184 00185 std::exit(0); 00186 }
const size_t BUFFER_SIZE = 4194304 |
Definition at line 25 of file data_read.cxx.
const size_t PAGE_SIZE = 8192 |