Skip to content

Commit ff9028a

Browse files
Checkpointing first working version
1 parent 7079d27 commit ff9028a

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ add_executable(pushback pushback.cpp)
5858
#
5959
add_executable(nexusopenclose nexusopenclose.cpp)
6060
target_link_libraries(nexusopenclose PRIVATE Nexus::nexus Nexus::nexuscpp)
61+
62+
#
63+
add_executable(eventlistb2 eventlistb2.cpp)
64+
target_link_libraries(eventlistb2 PRIVATE Nexus::nexus Nexus::nexuscpp)

eventlistb2.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <iomanip>
2+
#include <iostream>
3+
#include <memory>
4+
#include <nexus/NeXusFile.hpp>
5+
#include <sstream>
6+
#include <stdio.h>
7+
#include <string>
8+
#include <sys/time.h>
9+
#include <vector>
10+
11+
using std::cout;
12+
using std::endl;
13+
using std::string;
14+
using std::vector;
15+
16+
// copied from nexus to break out of iteration
17+
static string const NULL_STR("NULL");
18+
// things we care about
19+
static string const NXEVENT_DATA("NXevent_data");
20+
static string const GROUP_ERROR("bank_error_events");
21+
static string const GROUP_UNMAPPED("bank_unmapped_events");
22+
// event fields
23+
static string const FIELD_TOF("event_time_offset");
24+
static string const FIELD_DETID("event_id");
25+
static string const FIELD_PULSE_TIME("event_time_zero");
26+
static string const FIELD_PULSE_INDEX("event_index");
27+
28+
// thing that
29+
template <typename T> std::unique_ptr<std::vector<T>> readData(NeXus::File &file, std::string const &fieldname) {
30+
file.openData(fieldname);
31+
auto const info = file.getInfo();
32+
33+
auto data = std::make_unique<std::vector<T>>(info.dims[0]);
34+
file.getData(*data);
35+
file.closeData();
36+
37+
return data;
38+
}
39+
40+
// -------------------------------------------------------------------
41+
int main(int argc, char *argv[]) {
42+
if (argc != 2) {
43+
cout << "usage: " << argv[0] << " <filename>" << endl;
44+
return 1;
45+
}
46+
47+
string filename(argv[1]);
48+
cout << "Trying with: " << filename << endl;
49+
for (std::size_t i = 0; i < 1; i++) {
50+
NeXus::File file(filename);
51+
file.openGroup("entry", "NXentry");
52+
53+
// loop over entries
54+
std::pair<string, string> temp;
55+
while (true) {
56+
temp = file.getNextEntry();
57+
// both being null string means there are no more entries
58+
if (temp.first == NULL_STR && temp.second == NULL_STR)
59+
break;
60+
61+
// only process event data groups
62+
if (temp.second == NXEVENT_DATA) {
63+
if (temp.first == GROUP_ERROR || temp.first == GROUP_UNMAPPED)
64+
continue;
65+
std::cout << "reading " << temp.first << std::endl;
66+
file.openGroup(temp.first, NXEVENT_DATA);
67+
68+
// these types and names are brittle
69+
auto pulseIndex = readData<uint64_t>(file, FIELD_PULSE_INDEX);
70+
auto pulseTimes = readData<double>(file, FIELD_PULSE_TIME);
71+
auto tof = readData<float>(file, FIELD_TOF);
72+
auto detid = readData<uint32_t>(file, FIELD_DETID);
73+
74+
file.closeGroup();
75+
}
76+
}
77+
file.close();
78+
}
79+
}

0 commit comments

Comments
 (0)