File indexing completed on 2026-11-13 09:47:02
0001
0002
0003
0004 #include <catch2/catch_test_macros.hpp>
0005 #include <set>
0006 #include <string>
0007 #include <vector>
0008
0009 #include "services/io/podio/JEventProcessorPODIO.h"
0010
0011 using Names = std::vector<std::string>;
0012
0013 TEST_CASE("JEventProcessorPODIO::MatchCollections: exact names, regexes and exclusions",
0014 "[podio]") {
0015 const std::set<std::string> collections{"EcalBarrelClusters", "EcalEndcapNClusters",
0016 "EcalEndcapPClusters", "EventHeader", "MCParticles"};
0017
0018 SECTION("exact names") {
0019 auto m =
0020 JEventProcessorPODIO::MatchCollections(collections, {"EventHeader", "MCParticles"}, {});
0021 REQUIRE(m.matched == Names{"EventHeader", "MCParticles"});
0022 REQUIRE(m.unmatched_patterns.empty());
0023 }
0024
0025 SECTION("a name that is not present is reported") {
0026 auto m = JEventProcessorPODIO::MatchCollections(collections,
0027 {"EventHeader", "NoSuchCollection"}, {});
0028 REQUIRE(m.matched == Names{"EventHeader"});
0029 REQUIRE(m.unmatched_patterns == Names{"NoSuchCollection"});
0030 }
0031
0032 SECTION("a regex matching several collections") {
0033 auto m = JEventProcessorPODIO::MatchCollections(collections, {"Ecal.*Clusters"}, {});
0034 REQUIRE(m.matched == Names{"EcalBarrelClusters", "EcalEndcapNClusters", "EcalEndcapPClusters"});
0035 REQUIRE(m.unmatched_patterns.empty());
0036 }
0037
0038 SECTION("a regex matching nothing is reported") {
0039 auto m =
0040 JEventProcessorPODIO::MatchCollections(collections, {"Hcal.*Clusters", "EventHeader"}, {});
0041 REQUIRE(m.matched == Names{"EventHeader"});
0042 REQUIRE(m.unmatched_patterns == Names{"Hcal.*Clusters"});
0043 }
0044
0045 SECTION("a collection matched by two patterns uses both") {
0046 auto m = JEventProcessorPODIO::MatchCollections(collections,
0047 {"EcalEndcapPClusters", "Ecal.*Clusters"}, {});
0048 REQUIRE(m.matched == Names{"EcalBarrelClusters", "EcalEndcapNClusters", "EcalEndcapPClusters"});
0049 REQUIRE(m.unmatched_patterns.empty());
0050 }
0051
0052 SECTION("a regex must match the whole name") {
0053 auto m = JEventProcessorPODIO::MatchCollections(collections, {"Ecal"}, {});
0054 REQUIRE(m.matched.empty());
0055 REQUIRE(m.unmatched_patterns == Names{"Ecal"});
0056 }
0057
0058 SECTION("excluded collections are not written but still count as matched") {
0059 auto m = JEventProcessorPODIO::MatchCollections(collections, {"Ecal.*Clusters", "EventHeader"},
0060 {"EcalBarrelClusters", "EventHeader"});
0061 REQUIRE(m.matched == Names{"EcalEndcapNClusters", "EcalEndcapPClusters"});
0062 REQUIRE(m.unmatched_patterns.empty());
0063 }
0064 }