BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
check-paged.cxx File Reference
#include "eformat/eformat.h"
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sys/uio.h>

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Variables

const size_t PAGE_SIZE = 2500
const size_t BUFFER_SIZE = 10000000

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Reads a file and check its validity (for the time being)

Definition at line 31 of file check-paged.cxx.

31 {
32 using namespace eformat;
33
34 if ( argc != 2 )
35 {
36 std::cerr << "usage: " << argv[0] << " <file>" << std::endl;
37 std::exit( 1 );
38 }
39
40 // open normally a file
41 std::fstream in( argv[1], std::ios::in | std::ios::binary );
42 if ( !in )
43 {
44 std::cerr << "File `" << argv[1] << "' does not exist?!" << std::endl;
45 std::exit( 1 );
46 }
47 size_t offset = 0;
48
49 uint32_t* paged_event[BUFFER_SIZE / PAGE_SIZE];
50 for ( size_t i = 0; i < BUFFER_SIZE / PAGE_SIZE; ++i )
51 paged_event[i] = new uint32_t[PAGE_SIZE / sizeof( uint32_t )];
52
53 while ( in && in.good() && !in.eof() )
54 {
55 // soft check, so we don't mistake too often
56 uint32_t data[2];
57 in.read( (char*)data, 8 );
58 if ( !in.good() || in.eof() ) break; // end-of-file
59 if ( data[0] != eformat::FULL_EVENT )
60 {
61 // stop!
62 std::cout << "Word at offset " << HEX( offset ) << " is not "
63 << HEX( eformat::FULL_EVENT ) << std::endl;
64 std::exit( 1 );
65 }
66
67 // data[1] is the fragment size, in words. Take it and read the fragment
68 in.seekg( offset );
69 // read the event into my pages
70 size_t to_read = data[1] << 2;
71 size_t page_counter = 0;
72 std::cout << "Loading page";
73 while ( to_read > 0 )
74 {
75 size_t readnow = ( PAGE_SIZE > to_read ) ? to_read : PAGE_SIZE;
76 in.read( (char*)paged_event[page_counter], readnow );
77 to_read -= readnow;
78 ++page_counter;
79 std::cout << " " << page_counter;
80 }
81 std::cout << ": ";
82 struct iovec myvec[BUFFER_SIZE / PAGE_SIZE];
83 for ( size_t i = 0; i < page_counter; ++i )
84 {
85 myvec[i].iov_base = paged_event[i];
86 myvec[i].iov_len = PAGE_SIZE;
87 }
88 // correct last page
89 myvec[page_counter - 1].iov_len = data[1] << 2 - ( page_counter - 1 ) * PAGE_SIZE;
90
91 eformat::PagedMemory<1000> mymemory( myvec, page_counter );
92
93 try
94 {
96 fe.check_tree();
97 // if check is ok, print the lvl1 identifier
98 std::cout << "Event " << fe.lvl1_id() << " is Ok." << std::endl;
99
100 // update offset
101 offset += data[1] << 2;
102 } catch ( eformat::Issue& ex )
103 {
104 std::cerr << std::endl << "Uncaught eformat issue: " << ex.what() << std::endl;
105 std::cout << "Trying to continue..." << std::endl;
106 continue;
107 } catch ( ers::Issue& ex )
108 {
109 std::cerr << std::endl << "Uncaught ERS issue: " << ex.what() << std::endl;
110 for ( size_t i = 0; i < BUFFER_SIZE / PAGE_SIZE; ++i ) delete[] paged_event[i];
111 std::exit( 1 );
112 } catch ( std::exception& ex )
113 {
114 std::cerr << std::endl << "Uncaught std exception: " << ex.what() << std::endl;
115 for ( size_t i = 0; i < BUFFER_SIZE / PAGE_SIZE; ++i ) delete[] paged_event[i];
116 std::exit( 1 );
117 } catch ( ... )
118 {
119 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
120 for ( size_t i = 0; i < BUFFER_SIZE / PAGE_SIZE; ++i ) delete[] paged_event[i];
121 std::exit( 1 );
122 }
123 }
124
125 for ( size_t i = 0; i < BUFFER_SIZE / PAGE_SIZE; ++i ) delete[] paged_event[i];
126 return 0;
127}
TTree * data
Root Issue class.
const char * what() const
Human description message.
const size_t PAGE_SIZE
Definition data_read.cxx:24
#define BUFFER_SIZE

Variable Documentation

◆ BUFFER_SIZE

const size_t BUFFER_SIZE = 10000000

Definition at line 26 of file check-paged.cxx.

◆ PAGE_SIZE

const size_t PAGE_SIZE = 2500

Page size used as reference

Definition at line 25 of file check-paged.cxx.