#include <fstream>
#include <iostream>
#include <cstdlib>
#include <sys/uio.h>
#include "eformat/eformat.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
Variables | |
const size_t | PAGE_SIZE = 2500 |
const size_t | BUFFER_SIZE = 10000000 |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Reads a file and check its validity (for the time being)
Definition at line 31 of file check-paged.cxx.
References BUFFER_SIZE, eformat::FULL_EVENT, HEX, genRecEmupikp::i, PAGE_SIZE, and ers::Issue::what().
00032 { 00033 using namespace eformat; 00034 00035 if ( argc != 2 ) { 00036 std::cerr << "usage: " << argv[0] << " <file>" << std::endl; 00037 std::exit(1); 00038 } 00039 00040 //open normally a file 00041 std::fstream in(argv[1], std::ios::in|std::ios::binary); 00042 if (!in) { 00043 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl; 00044 std::exit(1); 00045 } 00046 size_t offset = 0; 00047 00048 uint32_t* paged_event[BUFFER_SIZE/PAGE_SIZE]; 00049 for (size_t i=0; i<BUFFER_SIZE/PAGE_SIZE; ++i) 00050 paged_event[i] = new uint32_t[PAGE_SIZE/sizeof(uint32_t)]; 00051 00052 while (in && in.good() && ! in.eof()) { 00053 //soft check, so we don't mistake too often 00054 uint32_t data[2]; 00055 in.read((char*)data, 8); 00056 if (!in.good() || in.eof()) break; // end-of-file 00057 if (data[0] != eformat::FULL_EVENT) { 00058 //stop! 00059 std::cout << "Word at offset " << HEX(offset) << " is not " 00060 << HEX(eformat::FULL_EVENT) << std::endl; 00061 std::exit(1); 00062 } 00063 00064 //data[1] is the fragment size, in words. Take it and read the fragment 00065 in.seekg(offset); 00066 //read the event into my pages 00067 size_t to_read = data[1]<<2; 00068 size_t page_counter = 0; 00069 std::cout << "Loading page"; 00070 while (to_read > 0) { 00071 size_t readnow = (PAGE_SIZE>to_read)?to_read:PAGE_SIZE; 00072 in.read((char*)paged_event[page_counter], readnow); 00073 to_read -= readnow; 00074 ++page_counter; 00075 std::cout << " " << page_counter; 00076 } 00077 std::cout << ": "; 00078 struct iovec myvec[BUFFER_SIZE/PAGE_SIZE]; 00079 for (size_t i=0; i<page_counter; ++i) { 00080 myvec[i].iov_base = paged_event[i]; 00081 myvec[i].iov_len = PAGE_SIZE; 00082 } 00083 //correct last page 00084 myvec[page_counter-1].iov_len = data[1]<<2 - (page_counter-1)*PAGE_SIZE; 00085 00086 00087 eformat::PagedMemory<1000> mymemory(myvec, page_counter); 00088 00089 try { 00090 FullEventFragment<eformat::PagedMemory<1000>::const_iterator> 00091 fe(mymemory.begin()); 00092 fe.check_tree(); 00093 //if check is ok, print the lvl1 identifier 00094 std::cout << "Event " << fe.lvl1_id() << " is Ok." << std::endl; 00095 00096 //update offset 00097 offset += data[1]<<2; 00098 } 00099 catch (eformat::Issue& ex) { 00100 std::cerr << std::endl 00101 << "Uncaught eformat issue: " << ex.what() << std::endl; 00102 std::cout << "Trying to continue..." << std::endl; 00103 continue; 00104 } 00105 catch (ers::Issue& ex) { 00106 std::cerr << std::endl 00107 << "Uncaught ERS issue: " << ex.what() << std::endl; 00108 for (size_t i=0; i<BUFFER_SIZE/PAGE_SIZE; ++i) delete[] paged_event[i]; 00109 std::exit(1); 00110 } 00111 catch (std::exception& ex) { 00112 std::cerr << std::endl 00113 << "Uncaught std exception: " << ex.what() << std::endl; 00114 for (size_t i=0; i<BUFFER_SIZE/PAGE_SIZE; ++i) delete[] paged_event[i]; 00115 std::exit(1); 00116 } 00117 catch (...) { 00118 std::cerr << std::endl << "Uncaught unknown exception" << std::endl; 00119 for (size_t i=0; i<BUFFER_SIZE/PAGE_SIZE; ++i) delete[] paged_event[i]; 00120 std::exit(1); 00121 } 00122 00123 } 00124 00125 for (size_t i=0; i<BUFFER_SIZE/PAGE_SIZE; ++i) delete[] paged_event[i]; 00126 return 0; 00127 }
const size_t BUFFER_SIZE = 10000000 |
Definition at line 26 of file check-paged.cxx.
const size_t PAGE_SIZE = 2500 |
Page size used as reference
Definition at line 25 of file check-paged.cxx.