diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b463de..8b42ae9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,3 +58,7 @@ add_executable(pushback pushback.cpp) # add_executable(nexusopenclose nexusopenclose.cpp) target_link_libraries(nexusopenclose PRIVATE Nexus::nexus Nexus::nexuscpp) + +# +add_executable(eventlistb2 eventlistb2.cpp) +target_link_libraries(eventlistb2 PRIVATE Nexus::nexus Nexus::nexuscpp) diff --git a/eventlistb2.cpp b/eventlistb2.cpp new file mode 100644 index 0000000..9bd2faa --- /dev/null +++ b/eventlistb2.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using std::cout; +using std::endl; +using std::string; +using std::vector; + +// copied from nexus to break out of iteration +static string const NULL_STR("NULL"); +// things we care about +static string const NXEVENT_DATA("NXevent_data"); +static string const GROUP_ERROR("bank_error_events"); +static string const GROUP_UNMAPPED("bank_unmapped_events"); +// event fields +static string const FIELD_TOF("event_time_offset"); +static string const FIELD_DETID("event_id"); +static string const FIELD_PULSE_TIME("event_time_zero"); +static string const FIELD_PULSE_INDEX("event_index"); + +// thing that +template std::unique_ptr> readData(NeXus::File &file, std::string const &fieldname) { + file.openData(fieldname); + auto const info = file.getInfo(); + + auto data = std::make_unique>(info.dims[0]); + file.getData(*data); + file.closeData(); + + return data; +} + +// ------------------------------------------------------------------- +int main(int argc, char *argv[]) { + if (argc != 2) { + cout << "usage: " << argv[0] << " " << endl; + return 1; + } + + string filename(argv[1]); + cout << "Trying with: " << filename << endl; + for (std::size_t i = 0; i < 1; i++) { + NeXus::File file(filename); + file.openGroup("entry", "NXentry"); + + // loop over entries + std::pair temp; + while (true) { + temp = file.getNextEntry(); + // both being null string means there are no more entries + if (temp.first == NULL_STR && temp.second == NULL_STR) + break; + + // only process event data groups + if (temp.second == NXEVENT_DATA) { + if (temp.first == GROUP_ERROR || temp.first == GROUP_UNMAPPED) + continue; + std::cout << "reading " << temp.first << std::endl; + file.openGroup(temp.first, NXEVENT_DATA); + + // these types and names are brittle + auto pulseIndex = readData(file, FIELD_PULSE_INDEX); + auto pulseTimes = readData(file, FIELD_PULSE_TIME); + auto tof = readData(file, FIELD_TOF); + auto detid = readData(file, FIELD_DETID); + + file.closeGroup(); + } + } + file.close(); + } +}