BOSS 7.1.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:[email protected]>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 <fstream>
17#include <iostream>
18#include <cstdlib>
19
20#include "eformat/old/eformat.h"
22#include "eformat/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{
34 using namespace eformat;
35
36 if ( argc != 3 ) {
37 std::cerr << "usage: " << argv[0] << " <v2.4 file> <v3.0 file>"
38 << std::endl;
39 std::exit(1);
40 }
41
42 //open normally a file
43 std::fstream in(argv[1], std::ios::in|std::ios::binary);
44 if (!in) {
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 std::cerr << "Cannot write to `" << argv[1] << "?!" << std::endl;
52 std::exit(1);
53 }
54
55 uint32_t* fragment = new uint32_t[MAX_ROS_SIZE];
56 uint32_t* nfragment = new uint32_t[MAX_ROS_SIZE];
57
58 while (true) {
59
60 if (!(next_fragment(in, fragment, MAX_ROS_SIZE*4))) break;
61 uint32_t l1id = 0;
62
63 old::ROSFragment ros(fragment);
64
65 try {
66 ros.check_tree();
67 }
68 catch (eformat::BadVersionIssue& ex) {
69 std::cerr << " !! WARNING: found ROS fragment with format version = "
70 << HEX(ex.current()) << std::endl;
71 if (ex.current() != MAJOR_DEFAULT_VERSION) {
72 std::cerr << " -> I cannot cope with this format. Skipping..."
73 << std::endl;
74 continue;
75 }
76 else {
77 std::cout << " -> ROS fragment will be simply copied..." << std::endl;
78 }
79 }
80 catch (eformat::Issue& ex) {
81 std::cerr << "Uncaught eformat issue: " << ex.what() << std::endl;
82 std::cerr << " -> Trying to continue..."
83 << std::endl;
84 continue;
85 }
86 catch (...) {
87 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
88 delete[] fragment;
89 delete[] nfragment;
90 std::exit(1);
91 }
92
93 try {
94 //if check is ok, print the lvl1 identifier
95 std::cout << "ROS #" << ros.lvl1_id() << " [" << HEX(ros.version())
96 << "] -> [" << HEX(0x03000000) << "]" << std::endl;
97 old::convert(fragment, nfragment, MAX_ROS_SIZE);
98 ROSFragment<const uint32_t*> nros(nfragment);
99 nros.check_tree();
100 l1id = nros.lvl1_id();
101 }
102 catch (eformat::Issue& ex) {
103 std::cerr << "Uncaught eformat issue: " << ex.what() << std::endl;
104 std::cerr << " -> Trying to continue..."
105 << std::endl;
106 continue;
107 std::exit(1);
108 }
109 catch (ers::Issue& ex) {
110 std::cerr << "Uncaught ERS issue: " << ex.what() << std::endl;
111 delete[] fragment;
112 delete[] nfragment;
113 std::exit(1);
114 }
115 catch (std::exception& ex) {
116 std::cerr << "Uncaught std exception: " << ex.what() << std::endl;
117 delete[] fragment;
118 delete[] nfragment;
119 std::exit(1);
120 }
121 catch (...) {
122 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
123 delete[] fragment;
124 delete[] nfragment;
125 std::exit(1);
126 }
127 out.write(reinterpret_cast<char*>(nfragment),
128 sizeof(uint32_t)*nfragment[1]);
129 //if check is ok, print the lvl1 identifier
130 std::cout << " -> (new) ROS fragment #" << l1id
131 << " converted, checked and saved."
132 << std::endl;
133 }
134
135 delete[] fragment;
136 delete[] nfragment;
137 return 0;
138}
bool check_tree() const
Definition: ROSFragment.h:144
uint32_t lvl1_id() const
Definition: ROSFragment.h:92
uint32_t version() const
Definition: old/Header.h:83
uint32_t lvl1_id() const
Root Issue class.
const char * what() const
Human description message.
const size_t MAX_ROS_SIZE
Definition: convert_ros.cxx:27
Includes all entities from the Event Format Library (eformat)
Includes all entities from the Event Format Library (eformat)
int main()
Definition: test_IFile.cxx:11
#define HEX(m)
Definition: util.h:107