File indexing completed on 2025-12-21 09:06:06
0001
0002
0003
0004 #pragma once
0005
0006 #include <spdlog/spdlog.h>
0007 #include <algorithms/algorithm.h>
0008 #include <string>
0009 #include <string_view>
0010
0011 #include "services/log/Log_service.h"
0012 #include "algorithms/interfaces/WithPodConfig.h"
0013
0014 namespace eicrecon {
0015
0016 template <class ToFilterObjectT, class FilterByObjectT>
0017 using FilterMatchingAlgorithm =
0018 algorithms::Algorithm<typename algorithms::Input<typename ToFilterObjectT::collection_type,
0019 typename FilterByObjectT::collection_type>,
0020 typename algorithms::Output<typename ToFilterObjectT::collection_type,
0021 typename ToFilterObjectT::collection_type>>;
0022
0023
0024
0025
0026
0027
0028 template <typename ToFilterObjectT, auto ToFilterFunction, typename FilterByObjectT,
0029 auto FilterByFunction>
0030 class FilterMatching : public FilterMatchingAlgorithm<ToFilterObjectT, FilterByObjectT>,
0031 public WithPodConfig<NoConfig> {
0032
0033 public:
0034 FilterMatching(std::string_view name)
0035 : FilterMatchingAlgorithm<ToFilterObjectT, FilterByObjectT>{
0036 name,
0037 {"inputCollection", "inputMatchedCollection"},
0038 {"outputMatchedAssociations", "outputUnmatchedAssociations"},
0039 "Filter by matching to a collection"} {};
0040
0041 void init() final {};
0042
0043 void
0044 process(const typename FilterMatchingAlgorithm<ToFilterObjectT, FilterByObjectT>::Input& input,
0045 const typename FilterMatchingAlgorithm<ToFilterObjectT, ToFilterObjectT>::Output& output)
0046 const final {
0047
0048 const auto [toFilterEntries, filterByEntries] = input;
0049 auto [is_matched, is_not_matched] = output;
0050
0051 is_matched->setSubsetCollection();
0052 is_not_matched->setSubsetCollection();
0053
0054 for (const auto& matchedEntry : *toFilterEntries) {
0055
0056 auto ref_value = ToFilterFunction(&matchedEntry);
0057
0058 bool found_match = false;
0059
0060
0061 for (const auto& entry : *filterByEntries) {
0062 auto other_value = FilterByFunction(&entry);
0063 if (other_value == ref_value) {
0064 is_matched->push_back(matchedEntry);
0065 found_match = true;
0066 break;
0067 }
0068 }
0069
0070 if (!found_match) {
0071 is_not_matched->push_back(matchedEntry);
0072 }
0073 }
0074 };
0075 };
0076
0077 }