-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make SIOFrameData work properly with dropped collections (#400)
- Loading branch information
Showing
4 changed files
with
83 additions
and
9 deletions.
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#include "podio/ROOTFrameReader.h" | ||
|
||
#include "read_frame.h" | ||
#include "read_frame_auxiliary.h" | ||
|
||
#include "podio/ROOTFrameReader.h" | ||
|
||
int main() { | ||
return read_frames<podio::ROOTFrameReader>("example_frame.root"); | ||
return read_frames<podio::ROOTFrameReader>("example_frame.root") + | ||
test_frame_aux_info<podio::ROOTFrameReader>("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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef PODIO_TESTS_READ_FRAME_AUXILIARY_H // NOLINT(llvm-header-guard): folder structure not suitable | ||
#define PODIO_TESTS_READ_FRAME_AUXILIARY_H // NOLINT(llvm-header-guard): folder structure not suitable | ||
|
||
#include "write_frame.h" | ||
|
||
#include "podio/Frame.h" | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
bool present(const std::string& elem, const std::vector<std::string>& vec) { | ||
return std::find(vec.begin(), vec.end(), elem) != vec.end(); | ||
} | ||
|
||
int testGetAvailableCollections(const podio::Frame& frame, const std::vector<std::string>& expected) { | ||
const auto& collNames = frame.getAvailableCollections(); | ||
int result = 0; | ||
for (const auto& name : expected) { | ||
if (!present(name, collNames)) { | ||
std::cerr << "Cannot find expected collection " << name << " in collections of Frame" << std::endl; | ||
result = 1; | ||
} | ||
} | ||
|
||
// Get a few collections and make sure that the resutls are unchanged (apart | ||
// from ordering) | ||
frame.get("hitRefs"); | ||
frame.get("mcparticles"); | ||
|
||
const auto& newCollNames = frame.getAvailableCollections(); | ||
for (const auto& name : newCollNames) { | ||
if (!present(name, collNames)) { | ||
std::cerr << "getAvailableCollections returns different collections after getting collections" << std::endl; | ||
return 1; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Test function for testing some auxiliary functionality of the Frame. | ||
* Encapsulates everything, such that a corresponding main function boils down | ||
* to including the reader to test and defining a main that invokes and returns | ||
* this function. | ||
* | ||
* @param fileName the name of the file to read from | ||
* @tparam ReaderT a Frame based I/O capable reader | ||
* @return 0 if all checks pass, non-zero otherwise | ||
* */ | ||
template <typename ReaderT> | ||
int test_frame_aux_info(const std::string& fileName) { | ||
auto reader = ReaderT{}; | ||
reader.openFile(fileName); | ||
|
||
// Test on the first event only here. Additionally, also only testing the | ||
// "events" category, since that is the one where not all collections are | ||
// written | ||
auto event = podio::Frame(reader.readEntry("events", 0)); | ||
|
||
return testGetAvailableCollections(event, collsToWrite); | ||
} | ||
|
||
#endif // PODIO_TESTS_READ_FRAME_AUXILIARY_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#include "podio/SIOFrameReader.h" | ||
|
||
#include "read_frame.h" | ||
#include "read_frame_auxiliary.h" | ||
|
||
#include "podio/SIOFrameReader.h" | ||
|
||
int main() { | ||
return read_frames<podio::SIOFrameReader>("example_frame.sio"); | ||
return read_frames<podio::SIOFrameReader>("example_frame.sio") + | ||
test_frame_aux_info<podio::SIOFrameReader>("example_frame.sio"); | ||
} |