/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/eformat/eformat-00-00-04/test/convert_ros.cxx

Go to the documentation of this file.
00001 //Dear emacs, this is -*- c++ -*-
00002 
00016 #include <fstream>
00017 #include <iostream>
00018 #include <cstdlib>
00019 
00020 #include "eformat/old/eformat.h"
00021 #include "eformat/write/eformat.h"
00022 #include "eformat/eformat.h"
00023 
00027 const size_t MAX_ROS_SIZE = 2500000;
00028 
00032 int main (int argc, char** argv)
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* fragment = new uint32_t[MAX_ROS_SIZE];
00056   uint32_t* nfragment = new uint32_t[MAX_ROS_SIZE];
00057   
00058   while (true) {
00059     
00060     if (!(next_fragment(in, fragment, MAX_ROS_SIZE*4))) break;
00061     uint32_t l1id = 0;
00062     
00063     old::ROSFragment ros(fragment);
00064 
00065     try {
00066       ros.check_tree();
00067     }
00068     catch (eformat::BadVersionIssue& ex) {
00069       std::cerr << " !! WARNING: found ROS fragment 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 << " -> ROS fragment 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[] fragment;
00089       delete[] nfragment;
00090       std::exit(1);
00091     }
00092     
00093     try {
00094       //if check is ok, print the lvl1 identifier
00095       std::cout << "ROS #" << ros.lvl1_id() << " [" << HEX(ros.version())
00096                 << "] -> [" << HEX(0x03000000) << "]" << std::endl;
00097       old::convert(fragment, nfragment, MAX_ROS_SIZE);
00098       ROSFragment<const uint32_t*> nros(nfragment);
00099       nros.check_tree();
00100       l1id = nros.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       std::exit(1);
00108     }
00109     catch (ers::Issue& ex) {
00110       std::cerr << "Uncaught ERS issue: " << ex.what() << std::endl;
00111       delete[] fragment;
00112       delete[] nfragment;
00113       std::exit(1);
00114     }
00115     catch (std::exception& ex) {
00116       std::cerr << "Uncaught std exception: " << ex.what() << std::endl;
00117       delete[] fragment;
00118       delete[] nfragment;
00119       std::exit(1);
00120     }
00121     catch (...) {
00122       std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
00123       delete[] fragment;
00124       delete[] nfragment;
00125       std::exit(1);
00126     }
00127     out.write(reinterpret_cast<char*>(nfragment),
00128               sizeof(uint32_t)*nfragment[1]);
00129     //if check is ok, print the lvl1 identifier
00130     std::cout << " -> (new) ROS fragment #" << l1id 
00131               << " converted, checked and saved."
00132               << std::endl;
00133   }
00134 
00135   delete[] fragment;
00136   delete[] nfragment;
00137   return 0;
00138 }

Generated on Tue Nov 29 22:58:26 2016 for BOSS_7.0.2 by  doxygen 1.4.7