BOSS 8.0.0
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: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 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 ) {
37 return rob1.rod_source_id() < rob2.rod_source_id();
38}
39
40/**
41 * Shows differences between to event-formatted files at the ROB level.
42 */
43int main( int argc, char** argv ) {
44 using namespace eformat;
45
46 if ( argc != 3 )
47 {
48 std::cerr << "usage: " << argv[0] << " <file1> <file2>" << std::endl;
49 std::cerr << "OBS: The event order should be the same on both files" << std::endl;
50 std::exit( 1 );
51 }
52
53 // open normally a file
54 size_t event_counter = 0;
55 std::fstream in1( argv[1], std::ios::in | std::ios::binary );
56 std::fstream in2( argv[2], std::ios::in | std::ios::binary );
57 const uint32_t* robp1[MAX_ROBS];
58 const uint32_t* robp2[MAX_ROBS];
59
60 uint32_t* event1 = new uint32_t[MAX_EVENT_SIZE];
61 uint32_t* event2 = new uint32_t[MAX_EVENT_SIZE];
62
63 while ( true )
64 {
65 if ( !( next_fragment( in1, event1, MAX_EVENT_SIZE * 4 ) ) ||
66 !( next_fragment( in2, event2, MAX_EVENT_SIZE * 4 ) ) )
67 break;
68 ++event_counter;
69 try
70 {
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 {
79 std::cerr << "The number of ROB's of event " << event_counter
80 << " is different in file `" << argv[1] << "' (" << s1 << ") and in file `"
81 << argv[2] << "' (" << 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 )
89 {
92 if ( rob1.rod_source_id() != rob2.rod_source_id() )
93 {
94 std::cerr << "! ROB[" << i << "]" << std::endl
95 << "- " << HEX( rob1.rod_source_id() ) << std::endl
96 << "+ " << HEX( rob2.rod_source_id() ) << std::endl;
97 mark = true;
98 }
99 }
100 if ( mark ) { std::cerr << "Event #" << fe1.lvl1_id() << " differ." << std::endl; }
101 } catch ( eformat::Issue& ex )
102 {
103 std::cerr << std::endl << "Uncaught eformat issue: " << ex.what() << std::endl;
104 std::cout << "Trying to continue..." << std::endl;
105 continue;
106 } catch ( ers::Issue& ex )
107 {
108 std::cerr << std::endl << "Uncaught ERS issue: " << ex.what() << std::endl;
109 delete[] event1;
110 delete[] event2;
111 std::exit( 1 );
112 } catch ( std::exception& ex )
113 {
114 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
115 delete[] event1;
116 delete[] event2;
117 std::exit( 1 );
118 } catch ( ... )
119 {
120 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
121 delete[] event1;
122 delete[] event2;
123 std::exit( 1 );
124 }
125 }
126
127 std::cerr << "In the absence of remarks, files do NOT differ." << std::endl;
128
129 delete[] event1;
130 delete[] event2;
131 return 0;
132}
double p2[4]
double p1[4]
const size_t MAX_EVENT_SIZE
Definition check-old.cxx:26
Root Issue class.
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
uint32_t * next_fragment(std::fstream &fs, uint32_t *addr=0, size_t size=0)
Definition util.cxx:24
size_t get_robs(const uint32_t *fragment, const uint32_t **rob, size_t max_count)
Definition util.cxx:104
int main()
Definition phokhara.cc:42