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

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

Variable Documentation

◆ BUFFER_SIZE

const size_t BUFFER_SIZE = 10000000

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

Referenced by main().

◆ PAGE_SIZE

const size_t PAGE_SIZE = 2500

Page size used as reference

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

Referenced by main().