-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathevio_print_contents_draft.cpp
More file actions
92 lines (76 loc) · 4.27 KB
/
evio_print_contents_draft.cpp
File metadata and controls
92 lines (76 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <string>
#include "eviocc.h" // EVIO C++ API all inside
// Use the EVIO namespace for convenience
using namespace evio;
// TODO: add max_events as command line argument, test for V6 as well
// TODO: and also print more than uint32s
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <evio_file>" << std::endl;
return 1;
}
std::string filename = argv[1];
int maxEvents = 10; // Maximum number of events to read
try {
// Open the EVIO6 file using EvioReader
EvioReader reader(filename);
// Check for an embedded XML dictionary
if (reader.hasDictionaryXML()) {
// Retrieve the raw XML dictionary text
std::string xmlDict = reader.getDictionaryXML();
// Print the XML dictionary to standard output
std::cout << xmlDict;
if (!xmlDict.empty() && xmlDict.back() != '\n') std::cout << std::endl; // ensure a newline at end, if not already present
} else {
// No dictionary present in the file
std::cout << "No XML dictionary found." << std::endl;
}
std::cout << "EVIO Ver: " << reader.getEvioVersion() << std::endl;
std::cout << "File Size: " << reader.fileSize() << std::endl;
std::cout << "Has first event?: " << reader.hasFirstEvent() << std::endl;
std::cout << "Getting event count... this may take a while for large files " << std::endl;
std::cout << "Event count: " << reader.getEventCount() << std::endl;
for (uint32_t i = 1; i < reader.getEventCount(); i++) {
if(i+1 >= maxEvents) {
std::cout << "Reached maximum number of events to read: " << maxEvents << std::endl;
break;
}
std::shared_ptr<EvioEvent> ev = reader.parseEvent(i+1);
std::cout << " got & parsed ev " << (i+1) << std::endl;
std::cout << " event ->\n" << ev->toString() << std::endl;
auto& dataVec = ev->getRawBytes();
std::cout << "Event has tag = " << ev->getHeader()->getTag() << std::endl;
std::cout << "Event structure type = " << ev->getStructureType().toString() << std::endl;
std::vector< std::shared_ptr< BaseStructure > > & children = ev->getChildren();
std::cout << "Event has " << children.size() << " children" << std::endl;
std::shared_ptr< BaseStructure > child1;
if(children.size()>0) child1 = children[0];
for (size_t j = 0; j < children.size(); j++) {
std::cout << "Child " << j << " tag = " << children[j]->getStructureType().toString() << std::endl;
std::cout << "NChildren: " << children[j]->getChildCount() << std::endl;
for (size_t k = 0; k < children[j]->getChildCount(); k++) {
std::cout << "Child " << j << ", subchild " << k << " " << children[j]->getChildAt(k)->getStructureType().toString() << std::endl;
std::cout << "Subchild " << k << " datatype: " << children[j]->getChildAt(k)->getHeader()->getDataType().toString() << std::endl;
std::cout << "nsubchildren: " << children[j]->getChildAt(k)->getChildCount() << std::endl;
std::cout << "num items stored: " << children[j]->getChildAt(k)->getNumberDataItems() << std::endl;
if(children[j]->getChildAt(k)->getHeader()->getDataType() == DataType::UINT32) {
std::cout << "Data: ";
std::vector< uint32_t > data_uint_vec = children[j]->getChildAt(k)->getUIntData();
for (size_t l = 0; l < data_uint_vec.size(); l++) {
std::cout << data_uint_vec[l] << " ";
}
std::cout << std::endl;
}
}
std::cout << std::endl;
}
std::cout << "End of event" << std::endl << std::endl;
// Util::printBytes(dataVec.data(), dataVec.size()," Event #" + std::to_string(i+1));
}
} catch (const std::exception& e) {
std::cerr << "Error: Unable to read EVIO file. " << e.what() << std::endl;
return 1;
}
return 0;
}