BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
convert.cxx File Reference
#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
 

Detailed Description

Author
<a href="Andre.nosp@m..dos.nosp@m..Anjo.nosp@m.s@ce.nosp@m.rn.ch>Andr� Rabello dos ANJOS
Author
zhangy
Revision
1.1.1.1
Date
2009/06/19 07:35:41

This source code describes a small test program based on the eformat library. It will read a file containing complete events in v2.4 format and convert the events into v3.0. The output is dumped to an output file.

Definition in file convert.cxx.

Function Documentation

◆ main()

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.

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* event = new uint32_t[MAX_EVENT_SIZE];
56 uint32_t* nevent = new uint32_t[MAX_EVENT_SIZE];
57
58 while (true) {
59
60 if (!(next_fragment(in, event, MAX_EVENT_SIZE*4))) break;
61 uint32_t l1id = 0;
62
63 old::FullEventFragment fe(event);
64
65 try {
66 fe.check_tree();
67 }
68 catch (eformat::BadVersionIssue& ex) {
69 std::cerr << " !! WARNING: found event 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 << " -> Event 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[] event;
89 delete[] nevent;
90 std::exit(1);
91 }
92
93 try {
94 //if check is ok, print the lvl1 identifier
95 std::cout << "Event #" << fe.lvl1_id() << " [" << HEX(fe.version())
96 << "] -> [" << HEX(0x03000000) << "]" << std::endl;
97 old::convert(event, nevent, MAX_EVENT_SIZE);
99 nfe.check_tree();
100 l1id = nfe.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 }
108 catch (ers::Issue& ex) {
109 std::cerr << "Uncaught ERS issue: " << ex.what() << std::endl;
110 delete[] event;
111 delete[] nevent;
112 std::exit(1);
113 }
114 catch (std::exception& ex) {
115 std::cerr << "Uncaught std exception: " << ex.what() << std::endl;
116 delete[] event;
117 delete[] nevent;
118 std::exit(1);
119 }
120 catch (...) {
121 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
122 delete[] event;
123 delete[] nevent;
124 std::exit(1);
125 }
126 out.write(reinterpret_cast<char*>(nevent), sizeof(uint32_t)*nevent[1]);
127 //if check is ok, print the lvl1 identifier
128 std::cout << " -> (new) event #" << l1id
129 << " converted, checked and saved."
130 << std::endl;
131
132 }
133
134 delete[] event;
135 delete[] nevent;
136 return 0;
137}
Root Issue class.
const char * what() const
Human description message.
const size_t MAX_EVENT_SIZE
Definition: convert.cxx:27
uint32_t * next_fragment(std::fstream &fs, uint32_t *addr=0, size_t size=0)
Definition: util.cxx:22
#define HEX(m)
Definition: util.h:107

Variable Documentation

◆ MAX_EVENT_SIZE

const size_t MAX_EVENT_SIZE = 2500000

The maximum event size, in words

Definition at line 27 of file convert.cxx.

Referenced by main().