Skip to content

Commit

Permalink
Keep backwards compatibility with older podio versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Feb 19, 2025
1 parent e6c2e9b commit a192bb5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 6 additions & 1 deletion k4FWCore/components/IOSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "podio/Frame.h"
#include "podio/FrameCategories.h"
#include "podio/Reader.h"
#include "podio/podioVersion.h"

#include "k4FWCore/FunctionalUtils.h"
#include "k4FWCore/KeepDropSwitch.h"
Expand Down Expand Up @@ -116,7 +117,11 @@ std::tuple<std::vector<podio::CollectionBase*>, std::vector<std::string>, podio:
if (m_nextEntry < m_entries) {
debug() << "Reading event " << m_nextEntry << endmsg;
debug() << "Reading collections " << m_collectionNames << endmsg;
frame = podio::Frame(m_reader->readEvent(m_nextEntry, m_collectionNames));
#if PODIO_BUILD_VERSION <= PODIO_VERSION(1, 2, 0)
frame = m_reader->readEvent(m_nextEntry);
#else
frame = m_reader->readEvent(m_nextEntry, m_collectionNames);
#endif
} else {
return std::make_tuple(std::vector<podio::CollectionBase*>(), std::vector<std::string>(), std::move(frame));
}
Expand Down
17 changes: 17 additions & 0 deletions k4FWCore/src/PodioDataSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "k4FWCore/DataWrapper.h"

#include "podio/CollectionBase.h"
#include "podio/podioVersion.h"

/// Service initialisation
StatusCode PodioDataSvc::initialize() {
Expand Down Expand Up @@ -104,7 +105,15 @@ StatusCode PodioDataSvc::i_setRoot(std::string root_path, IOpaqueAddress* pRootA
// create a new frame
if (m_reading_from_file) {
debug() << "Reading event " << m_eventNum + m_1stEvtEntry << ", using collections: " << m_collsToRead << endmsg;
#if PODIO_BUILD_VERSION <= PODIO_VERSION(1, 2, 0)
if (!m_collsToRead.empty()) {
warning() << "Trying to limit collections that are read, but podio does only support this with version > 1.2"
<< endmsg;
}
m_eventframe = podio::Frame(m_reader.readEntry("events", m_eventNum + m_1stEvtEntry));
#else
m_eventframe = podio::Frame(m_reader.readEntry("events", m_eventNum + m_1stEvtEntry, m_collsToRead));
#endif
} else {
m_eventframe = podio::Frame();
}
Expand All @@ -115,7 +124,15 @@ StatusCode PodioDataSvc::i_setRoot(std::string root_path, DataObject* pRootObj)
// create a new frame
if (m_reading_from_file) {
debug() << "Reading event " << m_eventNum + m_1stEvtEntry << ", using collections: " << m_collsToRead << endmsg;
#if PODIO_BUILD_VERSION <= PODIO_VERSION(1, 2, 0)
if (!m_collsToRead.empty()) {
warning() << "Trying to limit collections that are read, but podio does only support this with version > 1.2"
<< endmsg;
}
m_eventframe = podio::Frame(m_reader.readEntry("events", m_eventNum + m_1stEvtEntry));
#else
m_eventframe = podio::Frame(m_reader.readEntry("events", m_eventNum + m_1stEvtEntry, m_collsToRead));
#endif
} else {
m_eventframe = podio::Frame();
}
Expand Down
5 changes: 3 additions & 2 deletions test/k4FWCoreTest/scripts/CheckOutputFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ def check_metadata(filename, expected_metadata):
],
)

check_collections("output_k4test_exampledata_limited.root", ["MCParticles", "Links"])
check_collections("functional_limited_input.root", ["MCParticles", "Links"])
if podio.version.build_version > podio.version.parse("1.2.0"):
check_collections("output_k4test_exampledata_limited.root", ["MCParticles", "Links"])
check_collections("functional_limited_input.root", ["MCParticles", "Links"])

mix_collections = [
# From file
Expand Down

0 comments on commit a192bb5

Please sign in to comment.