BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
convert_ros.cxx
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file test/convert_ros.cxx
5 * @author <a href="mailto:Andre.dos.Anjos@cern.ch>André Rabello dos
6 * ANJOS</a>
7 * $Author: zhangy $
8 * $Revision: 1.1.1.1 $
9 * $Date: 2009/06/19 07:35:41 $
10 *
11 * This source code describes a small test program based on the eformat
12 * library. It will read a file containing ROS fragments in v2.4 format and
13 * convert the fragment into v3.0. The output is dumped to an output file.
14 */
15
16#include <cstdlib>
17#include <fstream>
18#include <iostream>
19
20#include "eformat/eformat.h"
21#include "eformat/old/eformat.h"
22#include "eformat/write/eformat.h"
23
24/**
25 * The maximum event size, in words
26 */
27const size_t MAX_ROS_SIZE = 2500000;
28
29/**
30 * Reads a file and check its validity (for the time being)
31 */
32int main( int argc, char** argv ) {
33 using namespace eformat;
34
35 if ( argc != 3 )
36 {
37 std::cerr << "usage: " << argv[0] << " <v2.4 file> <v3.0 file>" << std::endl;
38 std::exit( 1 );
39 }
40
41 // open normally a file
42 std::fstream in( argv[1], std::ios::in | std::ios::binary );
43 if ( !in )
44 {
45 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl;
46 std::exit( 1 );
47 }
48 // open normally a file
49 std::fstream out( argv[2], std::ios::out | std::ios::binary );
50 if ( !out )
51 {
52 std::cerr << "Cannot write to `" << argv[1] << "?!" << std::endl;
53 std::exit( 1 );
54 }
55
56 uint32_t* fragment = new uint32_t[MAX_ROS_SIZE];
57 uint32_t* nfragment = new uint32_t[MAX_ROS_SIZE];
58
59 while ( true )
60 {
61
62 if ( !( next_fragment( in, fragment, MAX_ROS_SIZE * 4 ) ) ) break;
63 uint32_t l1id = 0;
64
65 old::ROSFragment ros( fragment );
66
67 try
68 { ros.check_tree(); } catch ( eformat::BadVersionIssue& ex )
69 {
70 std::cerr << " !! WARNING: found ROS fragment with format version = "
71 << HEX( ex.current() ) << std::endl;
72 if ( ex.current() != MAJOR_DEFAULT_VERSION )
73 {
74 std::cerr << " -> I cannot cope with this format. Skipping..." << std::endl;
75 continue;
76 }
77 else { std::cout << " -> ROS fragment will be simply copied..." << std::endl; }
78 } catch ( eformat::Issue& ex )
79 {
80 std::cerr << "Uncaught eformat issue: " << ex.what() << std::endl;
81 std::cerr << " -> Trying to continue..." << std::endl;
82 continue;
83 } catch ( ... )
84 {
85 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
86 delete[] fragment;
87 delete[] nfragment;
88 std::exit( 1 );
89 }
90
91 try
92 {
93 // if check is ok, print the lvl1 identifier
94 std::cout << "ROS #" << ros.lvl1_id() << " [" << HEX( ros.version() ) << "] -> ["
95 << HEX( 0x03000000 ) << "]" << std::endl;
96 old::convert( fragment, nfragment, MAX_ROS_SIZE );
97 ROSFragment<const uint32_t*> nros( nfragment );
98 nros.check_tree();
99 l1id = nros.lvl1_id();
100 } catch ( eformat::Issue& ex )
101 {
102 std::cerr << "Uncaught eformat issue: " << ex.what() << std::endl;
103 std::cerr << " -> Trying to continue..." << std::endl;
104 continue;
105 std::exit( 1 );
106 } catch ( ers::Issue& ex )
107 {
108 std::cerr << "Uncaught ERS issue: " << ex.what() << std::endl;
109 delete[] fragment;
110 delete[] nfragment;
111 std::exit( 1 );
112 } catch ( std::exception& ex )
113 {
114 std::cerr << "Uncaught std exception: " << ex.what() << std::endl;
115 delete[] fragment;
116 delete[] nfragment;
117 std::exit( 1 );
118 } catch ( ... )
119 {
120 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
121 delete[] fragment;
122 delete[] nfragment;
123 std::exit( 1 );
124 }
125 out.write( reinterpret_cast<char*>( nfragment ), sizeof( uint32_t ) * nfragment[1] );
126 // if check is ok, print the lvl1 identifier
127 std::cout << " -> (new) ROS fragment #" << l1id << " converted, checked and saved."
128 << std::endl;
129 }
130
131 delete[] fragment;
132 delete[] nfragment;
133 return 0;
134}
Root Issue class.
const char * what() const
Human description message.
const size_t MAX_ROS_SIZE
uint32_t convert(const uint32_t *src, uint32_t *dest, uint32_t max)
Definition util24.cxx:244
uint32_t * next_fragment(std::fstream &fs, uint32_t *addr=0, size_t size=0)
Definition util.cxx:24
int main()
Definition phokhara.cc:42