#include <fstream>
#include <iostream>
#include <cstdlib>
#include "eformat/old/eformat.h"
#include "eformat/write/eformat.h"
#include "eformat/eformat.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
Variables | |
const size_t | MAX_EVENT_SIZE = 2500000 |
Definition in file convert.cxx.
int main | ( | int | argc, | |
char ** | argv | |||
) |
Reads a file and check its validity (for the time being)
Definition at line 32 of file convert.cxx.
References eformat::old::convert(), eformat::BadVersionIssue::current(), HEX, eformat::MAJOR_DEFAULT_VERSION, MAX_EVENT_SIZE, eformat::next_fragment(), and ers::Issue::what().
00033 { 00034 using namespace eformat; 00035 00036 if ( argc != 3 ) { 00037 std::cerr << "usage: " << argv[0] << " <v2.4 file> <v3.0 file>" 00038 << std::endl; 00039 std::exit(1); 00040 } 00041 00042 //open normally a file 00043 std::fstream in(argv[1], std::ios::in|std::ios::binary); 00044 if (!in) { 00045 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl; 00046 std::exit(1); 00047 } 00048 //open normally a file 00049 std::fstream out(argv[2], std::ios::out|std::ios::binary); 00050 if (!out) { 00051 std::cerr << "Cannot write to `" << argv[1] << "?!" << std::endl; 00052 std::exit(1); 00053 } 00054 00055 uint32_t* event = new uint32_t[MAX_EVENT_SIZE]; 00056 uint32_t* nevent = new uint32_t[MAX_EVENT_SIZE]; 00057 00058 while (true) { 00059 00060 if (!(next_fragment(in, event, MAX_EVENT_SIZE*4))) break; 00061 uint32_t l1id = 0; 00062 00063 old::FullEventFragment fe(event); 00064 00065 try { 00066 fe.check_tree(); 00067 } 00068 catch (eformat::BadVersionIssue& ex) { 00069 std::cerr << " !! WARNING: found event with format version = " 00070 << HEX(ex.current()) << std::endl; 00071 if (ex.current() != MAJOR_DEFAULT_VERSION) { 00072 std::cerr << " -> I cannot cope with this format. Skipping..." 00073 << std::endl; 00074 continue; 00075 } 00076 else { 00077 std::cout << " -> Event will be simply copied..." << std::endl; 00078 } 00079 } 00080 catch (eformat::Issue& ex) { 00081 std::cerr << "Uncaught eformat issue: " << ex.what() << std::endl; 00082 std::cerr << " -> Trying to continue..." 00083 << std::endl; 00084 continue; 00085 } 00086 catch (...) { 00087 std::cerr << std::endl << "Uncaught unknown exception" << std::endl; 00088 delete[] event; 00089 delete[] nevent; 00090 std::exit(1); 00091 } 00092 00093 try { 00094 //if check is ok, print the lvl1 identifier 00095 std::cout << "Event #" << fe.lvl1_id() << " [" << HEX(fe.version()) 00096 << "] -> [" << HEX(0x03000000) << "]" << std::endl; 00097 old::convert(event, nevent, MAX_EVENT_SIZE); 00098 FullEventFragment<const uint32_t*> nfe(nevent); 00099 nfe.check_tree(); 00100 l1id = nfe.lvl1_id(); 00101 } 00102 catch (eformat::Issue& ex) { 00103 std::cerr << "Uncaught eformat issue: " << ex.what() << std::endl; 00104 std::cerr << " -> Trying to continue..." 00105 << std::endl; 00106 continue; 00107 } 00108 catch (ers::Issue& ex) { 00109 std::cerr << "Uncaught ERS issue: " << ex.what() << std::endl; 00110 delete[] event; 00111 delete[] nevent; 00112 std::exit(1); 00113 } 00114 catch (std::exception& ex) { 00115 std::cerr << "Uncaught std exception: " << ex.what() << std::endl; 00116 delete[] event; 00117 delete[] nevent; 00118 std::exit(1); 00119 } 00120 catch (...) { 00121 std::cerr << std::endl << "Uncaught unknown exception" << std::endl; 00122 delete[] event; 00123 delete[] nevent; 00124 std::exit(1); 00125 } 00126 out.write(reinterpret_cast<char*>(nevent), sizeof(uint32_t)*nevent[1]); 00127 //if check is ok, print the lvl1 identifier 00128 std::cout << " -> (new) event #" << l1id 00129 << " converted, checked and saved." 00130 << std::endl; 00131 00132 } 00133 00134 delete[] event; 00135 delete[] nevent; 00136 return 0; 00137 }
const size_t MAX_EVENT_SIZE = 2500000 |
The maximum event size, in words
Definition at line 27 of file convert.cxx.