Skip to content

Commit

Permalink
JEventProcessorPODIO: deprecate podio:output_include_collections para…
Browse files Browse the repository at this point in the history
…meter (#1466)

This is a follow up on a resolution from #1323

### What kind of change does this PR introduce?
- [ ] Bug fix (issue #__)
- [x] New feature (issue #__)
- [ ] Documentation update
- [ ] Other: __

### Please check if this PR fulfills the following:
- [ ] Tests for the changes have been added
- [ ] Documentation has been added / updated
- [ ] Changes have been communicated to collaborators

### Does this PR introduce breaking changes? What changes might users
need to make to their code?
No

### Does this PR change default behavior?
No
  • Loading branch information
veprbl authored Jun 3, 2024
1 parent cec2ceb commit 45cfa7e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
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
37 changes: 32 additions & 5 deletions src/services/io/podio/JEventProcessorPODIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <podio/Frame.h>
#include <podio/ROOTWriter.h>
#include <spdlog/common.h>
#include <chrono>
#include <exception>
#include <thread>

#include "services/log/Log_service.h"

Expand Down Expand Up @@ -43,7 +45,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 @@ -300,9 +302,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 @@ -316,8 +329,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 @@ -333,6 +346,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 @@ -341,7 +361,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 @@ -357,7 +377,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 @@ -491,5 +511,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

0 comments on commit 45cfa7e

Please sign in to comment.