forked from AIDASoft/podio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dedicated test case for only reading partial frames
Reading only part of the collections stored in a frame should not lead to leaked memory (see e.g. AIDASoft#500). The tests that are added in this commit are targetting that, specifically by running them with sanitizers enabled.
- Loading branch information
Showing
7 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef PODIO_TESTS_READ_PARTIAL_H // NOLINT(llvm-header-guard): folder structure not suitable | ||
#define PODIO_TESTS_READ_PARTIAL_H // NOLINT(llvm-header-guard): folder structure not suitable | ||
|
||
#include "podio/Frame.h" | ||
|
||
#include <iostream> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <vector> | ||
|
||
void read_partial_collections(const podio::Frame& event, const std::vector<std::string>& collsToRead) { | ||
for (const auto& name : collsToRead) { | ||
event.get(name); | ||
} | ||
} | ||
|
||
/** | ||
* This is a test case that will always work in normal builds and will only fail | ||
* in builds with sanitizers enabled, where they will start to fail in case of | ||
* e.g. memory leaks. | ||
*/ | ||
template <typename ReaderT> | ||
int read_partial_frames(const std::string& filename) { | ||
auto reader = ReaderT(); | ||
try { | ||
reader.openFile(filename); | ||
} catch (const std::runtime_error& e) { | ||
std::cerr << "File " << filename << " could not be opened. aborting." << std::endl; | ||
return 1; | ||
} | ||
|
||
for (auto i = 0u; i < reader.getEntries(podio::Category::Event); ++i) { | ||
const auto event = podio::Frame(reader.readEntry(podio::Category::Event, i)); | ||
read_partial_collections(event, {"mcparticles", "info", "hits", "clusters"}); | ||
} | ||
|
||
return 0; | ||
} | ||
#endif // PODIO_TESTS_READ_PARTIAL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "read_partial.h" | ||
|
||
#include "podio/RNTupleReader.h" | ||
|
||
int main() { | ||
return read_partial_frames<podio::RNTupleReader>("example_rntuple.root"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "read_partial.h" | ||
|
||
#include "podio/ROOTReader.h" | ||
|
||
int main() { | ||
return read_partial_frames<podio::ROOTReader>("example_frame.root"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "read_partial.h" | ||
|
||
#include "podio/SIOReader.h" | ||
|
||
int main() { | ||
return read_partial_frames<podio::SIOReader>("example_frame.sio"); | ||
} |