Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JEventProcessorPODIO: deprecate podio:output_include_collections parameter #1466

Merged
merged 4 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/iwyu.imp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
{ include: ['<JANA/JApplicationFwd.h>', private, '<JANA/JApplication.h>', public] },

# the rest
{ include: ['<bits/chrono.h>', private, '<chrono>', public] },
{ include: ['<bits/std_abs.h>', private, '<math.h>', public] },
{ include: ['<bits/utility.h>', private, '<tuple>', public] },
# https://github.com/include-what-you-use/include-what-you-use/issues/166
Expand Down
40 changes: 33 additions & 7 deletions src/services/io/podio/JEventProcessorPODIO.cc
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@

#include "JEventProcessorPODIO.h"

#include <edm4eic/EDM4eicVersion.h>

#include <JANA/JApplication.h>
#include <JANA/JLogger.h>
#include <JANA/Services/JParameterManager.h>
#include <JANA/Utils/JTypeInfo.h>
#include <edm4eic/EDM4eicVersion.h>
#include <fmt/core.h>
#include <podio/CollectionBase.h>
#include <podio/Frame.h>
#include <spdlog/common.h>
#include <chrono>
#include <exception>
#include <thread>

#include "services/log/Log_service.h"

Expand Down Expand Up @@ -43,7 +44,7 @@ JEventProcessorPODIO::JEventProcessorPODIO() {
);

// Get the list of output collections to include/exclude
std::vector<std::string> output_include_collections={
std::vector<std::string> output_collections={
// Header and other metadata
"EventHeader",

Expand Down Expand Up @@ -297,9 +298,20 @@ JEventProcessorPODIO::JEventProcessorPODIO() {
"DIRCSeededParticleIDs",
};
std::vector<std::string> output_exclude_collections; // need to get as vector, then convert to set
std::string output_include_collections = "DEPRECATED";
japp->SetDefaultParameter(
"podio:output_include_collections",
output_include_collections,
"DEPRECATED. Use podio:output_collections instead."
);
if (output_include_collections != "DEPRECATED") {
output_collections.clear();
JParameterManager::Parse(output_include_collections, output_collections);
m_output_include_collections_set = true;
}
japp->SetDefaultParameter(
"podio:output_collections",
output_collections,
"Comma separated list of collection names to write out. If not set, all collections will be written (including ones from input file). Don't set this and use PODIO:OUTPUT_EXCLUDE_COLLECTIONS to write everything except a selection."
);
japp->SetDefaultParameter(
Expand All @@ -313,8 +325,8 @@ JEventProcessorPODIO::JEventProcessorPODIO() {
"Comma separated list of collection names to print to screen, e.g. for debugging."
);

m_output_include_collections = std::set<std::string>(output_include_collections.begin(),
output_include_collections.end());
m_output_collections = std::set<std::string>(output_collections.begin(),
output_collections.end());
m_output_exclude_collections = std::set<std::string>(output_exclude_collections.begin(),
output_exclude_collections.end());

Expand All @@ -330,6 +342,13 @@ void JEventProcessorPODIO::Init() {
// TODO: NWB: Verify that output file is writable NOW, rather than after event processing completes.
// I definitely don't trust PODIO to do this for me.

if (m_output_include_collections_set) {
m_log->error("The podio:output_include_collections was provided, but is deprecated. Use podio:output_collections instead.");
// Adding a delay to ensure users notice the deprecation warning.
using namespace std::chrono_literals;
std::this_thread::sleep_for(10s);
}

}


Expand All @@ -338,7 +357,7 @@ void JEventProcessorPODIO::FindCollectionsToWrite(const std::shared_ptr<const JE
// Set up the set of collections_to_write.
std::vector<std::string> all_collections = event->GetAllCollectionNames();

if (m_output_include_collections.empty()) {
if (m_output_collections.empty()) {
// User has not specified an include list, so we include _all_ PODIO collections present in the first event.
for (const std::string& col : all_collections) {
if (m_output_exclude_collections.find(col) == m_output_exclude_collections.end()) {
Expand All @@ -354,7 +373,7 @@ void JEventProcessorPODIO::FindCollectionsToWrite(const std::shared_ptr<const JE
// We match up the include list with what is actually present in the event
std::set<std::string> all_collections_set = std::set<std::string>(all_collections.begin(), all_collections.end());

for (const auto& col : m_output_include_collections) {
for (const auto& col : m_output_collections) {
if (m_output_exclude_collections.find(col) == m_output_exclude_collections.end()) {
// Included and not excluded
if (all_collections_set.find(col) == all_collections_set.end()) {
Expand Down Expand Up @@ -488,5 +507,12 @@ void JEventProcessorPODIO::Process(const std::shared_ptr<const JEvent> &event) {
}

void JEventProcessorPODIO::Finish() {
if (m_output_include_collections_set) {
m_log->error("The podio:output_include_collections was provided, but is deprecated. Use podio:output_collections instead.");
// Adding a delay to ensure users notice the deprecation warning.
using namespace std::chrono_literals;
std::this_thread::sleep_for(10s);
}

m_writer->finish();
}
3 changes: 2 additions & 1 deletion src/services/io/podio/JEventProcessorPODIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ class JEventProcessorPODIO : public JEventProcessor {
bool m_is_first_event = true;
bool m_user_included_collections = false;
std::shared_ptr<spdlog::logger> m_log;
bool m_output_include_collections_set = false;

std::string m_output_file = "podio_output.root";
std::string m_output_file_copy_dir = "";
std::set<std::string> m_output_include_collections; // config. parameter
std::set<std::string> m_output_collections; // config. parameter
std::set<std::string> m_output_exclude_collections; // config. parameter
std::vector<std::string> m_collections_to_write; // derived from above config. parameters
std::vector<std::string> m_collections_to_print;
Expand Down
Loading