BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
diff.cxx
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file diff.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 implements a comparison application that can be used to
12 * show differences in event-formatted files, at the ROB level
13 */
14
15#include "eformat/eformat.h"
16#include <algorithm>
17
18/**
19 * The maximum event size, in words
20 */
21const size_t MAX_EVENT_SIZE = 2500000;
22
23/**
24 * The maximum number of ROBS
25 */
26const size_t MAX_ROBS = 2048;
27
28/**
29 * Compares two ROB fragments for equality
30 *
31 * @param p1 The first ROB fragment
32 * @param p2 The second ROB fragment
33 */
34int cmp_source_id (const uint32_t* p1, const uint32_t* p2)
35{
38 return rob1.rod_source_id() < rob2.rod_source_id();
39}
40
41/**
42 * Shows differences between to event-formatted files at the ROB level.
43 */
44int main (int argc, char** argv)
45{
46 using namespace eformat;
47
48 if ( argc != 3 ) {
49 std::cerr << "usage: " << argv[0] << " <file1> <file2>"
50 << std::endl;
51 std::cerr << "OBS: The event order should be the same on both files"
52 << std::endl;
53 std::exit(1);
54 }
55
56 //open normally a file
57 size_t event_counter = 0;
58 std::fstream in1(argv[1], std::ios::in|std::ios::binary);
59 std::fstream in2(argv[2], std::ios::in|std::ios::binary);
60 const uint32_t* robp1[MAX_ROBS];
61 const uint32_t* robp2[MAX_ROBS];
62
63 uint32_t* event1 = new uint32_t[MAX_EVENT_SIZE];
64 uint32_t* event2 = new uint32_t[MAX_EVENT_SIZE];
65
66 while (true) {
67 if (!(next_fragment(in1, event1, MAX_EVENT_SIZE*4)) ||
68 !(next_fragment(in2, event2, MAX_EVENT_SIZE*4))) break;
69 ++event_counter;
70 try {
73 fe1.check_tree(); // no checks, so we dump all
74 fe2.check_tree(); // no checks, so we dump all
75 size_t s1 = get_robs(event1, robp1, MAX_ROBS);
76 size_t s2 = get_robs(event2, robp2, MAX_ROBS);
77 if (s1 != s2) {
78 std::cerr << "The number of ROB's of event " << event_counter
79 << " is different in file `" << argv[1]
80 << "' (" << s1 << ") and in file `" << argv[2]
81 << "' (" << s2 << "). Skipping comparison." << std::endl;
82 continue;
83 }
84 //if we get here, the number of ROD's is the same
85 std::sort(robp1, robp1+s1, cmp_source_id);
86 std::sort(robp2, robp2+s2, cmp_source_id);
87 bool mark = false;
88 for (size_t i=0; i<s1; ++i) {
91 if (rob1.rod_source_id() != rob2.rod_source_id()) {
92 std::cerr << "! ROB[" << i << "]" << std::endl
93 << "- " << HEX(rob1.rod_source_id()) << std::endl
94 << "+ " << HEX(rob2.rod_source_id()) << std::endl;
95 mark = true;
96 }
97 }
98 if (mark) {
99 std::cerr << "Event #" << fe1.lvl1_id() << " differ." << std::endl;
100 }
101 }
102 catch (eformat::Issue& ex) {
103 std::cerr << std::endl
104 << "Uncaught eformat issue: " << ex.what() << std::endl;
105 std::cout << "Trying to continue..." << std::endl;
106 continue;
107 }
108 catch (ers::Issue& ex) {
109 std::cerr << std::endl
110 << "Uncaught ERS issue: " << ex.what() << std::endl;
111 delete[] event1;
112 delete[] event2;
113 std::exit(1);
114 }
115 catch (std::exception& ex) {
116 std::cerr << std::endl
117 << "Uncaught std exception: " << ex.what() << std::endl;
118 delete[] event1;
119 delete[] event2;
120 std::exit(1);
121 }
122 catch (...) {
123 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
124 delete[] event1;
125 delete[] event2;
126 std::exit(1);
127 }
128
129 }
130
131 std::cerr << "In the absence of remarks, files do NOT differ." << std::endl;
132
133 delete[] event1;
134 delete[] event2;
135 return 0;
136}
const char * what() const
Human description message.
int cmp_source_id(const uint32_t *p1, const uint32_t *p2)
Definition: diff.cxx:34
const size_t MAX_ROBS
Definition: diff.cxx:26
const size_t MAX_EVENT_SIZE
Definition: diff.cxx:21
int main()
Definition: test_IFile.cxx:11