Skip to content

Commit e19a9a4

Browse files
authored
podio-dump: Make -e -1 dump all of the entries (#906)
* podio-dump: Make -e -1 dump all of the entries Many of our other tools support passing -1 as a value to the number of events signifying to simply do all of them. * Add simple test for new option
1 parent 8aa5be0 commit e19a9a4

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

tests/CTestCustom.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ if ((NOT "@FORCE_RUN_ALL_TESTS@" STREQUAL "ON") AND (NOT "@USE_SANITIZER@" STREQ
158158

159159
podio-dump-root
160160
podio-dump-detailed-root
161+
podio-dump-all-events
161162

162163
write_interface_root
163164
read_interface_root

tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ if(BUILD_TESTING)
8888
CREATE_DUMP_TEST(podio-dump-help _dummy_target_ --help)
8989
CREATE_DUMP_TEST(podio-dump-root "podio_write_root_fixture" ${PROJECT_BINARY_DIR}/tests/root_io/example_frame.root)
9090
CREATE_DUMP_TEST(podio-dump-detailed-root "podio_write_root_fixture" --detailed --category other_events --entries 2:3 ${PROJECT_BINARY_DIR}/tests/root_io/example_frame.root)
91+
CREATE_DUMP_TEST(podio-dump-all-events "podio_write_root_fixture" ${PROJECT_BINARY_DIR}/tests/root_io/example_frame.root --entries -1)
9192

9293
CREATE_LEGACY_DUMP_TEST("root" v00-16-06 v00-16-06-example.root)
9394
CREATE_LEGACY_DUMP_TEST("root-detailed" v00-16-06 v00-16-06-example.root --detailed --entries 2:3)

tools/src/podio-dump-tool.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ positional arguments:
4343
-c CATEGORY, --category CATEGORY
4444
Which Frame category to dump
4545
-e ENTRIES, --entries ENTRIES
46-
Which entries to print. A single number, comma-separated list of numbers or "first:last" for an inclusive range of entries. Defaults to the first entry.
46+
Which entries to print. A single number, comma-separated list of numbers or "first:last" for an inclusive range of entries. Defaults to the first entry. Use -1 to print all available entries.
4747
-d, --detailed Dump the full contents, not just the collection info
4848
-s, --size-stats Show size statistics per collection for the whole file (if available for the file format)
4949
--dump-edm DUMP_EDM Dump the specified EDM definition from the file in yaml format
@@ -70,6 +70,12 @@ std::vector<size_t> parseEventRange(const std::string_view evtRange) {
7070
std::exit(1);
7171
};
7272

73+
// We handle this later and for now just emplace a tombstone value that is
74+
// easy to recognize
75+
if (evtRange == "-1") {
76+
return {static_cast<size_t>(-1)};
77+
}
78+
7379
// Split by ',' to see if we have to handle multiple events
7480
auto splitRange = podio::utils::splitString(evtRange, ',');
7581

@@ -102,6 +108,16 @@ std::vector<size_t> parseEventRange(const std::string_view evtRange) {
102108
return {};
103109
}
104110

111+
std::vector<size_t> fullEntryList(const ParsedArgs& args, const podio::Reader& reader) {
112+
if (args.events.size() == 1 && args.events[0] == static_cast<std::size_t>(-1)) {
113+
const auto nEntries = reader.getEntries(args.category);
114+
std::vector<size_t> allEntries(nEntries);
115+
std::iota(allEntries.begin(), allEntries.end(), 0);
116+
return allEntries;
117+
}
118+
return args.events;
119+
}
120+
105121
ParsedArgs parseArgs(std::vector<std::string> argv) {
106122
// find help or version
107123
if (const auto it = findFlags(argv, "-h", "--help", "--version"); it != argv.end()) {
@@ -276,7 +292,7 @@ int main(int argc, char* argv[]) {
276292
stats = reader.getSizeStats(args.category);
277293
}
278294

279-
for (const auto event : args.events) {
295+
for (const auto event : fullEntryList(args, reader)) {
280296
try {
281297
const auto& frame = reader.readFrame(args.category, event);
282298
printFrame(frame, args.category, event, args.detailed, stats);

0 commit comments

Comments
 (0)