File indexing completed on 2025-07-15 08:16:13
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
0032 public:
0033 FilterMatching(std::string_view name)
0034 : FilterMatchingAlgorithm<ToFilterObjectT, FilterByObjectT>{
0035 name,
0036 {"inputCollection", "inputMatchedCollection"},
0037 {"outputMatchedAssociations", "outputUnmatchedAssociations"},
0038 "Filter by matching to a collection"} {};
0039
0040 void init() final{};
0041
0042 void
0043 process(const typename FilterMatchingAlgorithm<ToFilterObjectT, FilterByObjectT>::Input& input,
0044 const typename FilterMatchingAlgorithm<ToFilterObjectT, ToFilterObjectT>::Output& output)
0045 const final {
0046
0047 const auto [toFilterEntries, filterByEntries] = input;
0048 auto [is_matched, is_not_matched] = output;
0049
0050 is_matched->setSubsetCollection();
0051 is_not_matched->setSubsetCollection();
0052
0053 for (const auto& matchedEntry : *toFilterEntries) {
0054
0055 auto ref_value = ToFilterFunction(&matchedEntry);
0056
0057 bool found_match = false;
0058
0059
0060 for (const auto& entry : *filterByEntries) {
0061 auto other_value = FilterByFunction(&entry);
0062 if (other_value == ref_value) {
0063 is_matched->push_back(matchedEntry);
0064 found_match = true;
0065 break;
0066 }
0067 }
0068
0069 if (!found_match) {
0070 is_not_matched->push_back(matchedEntry);
0071 }
0072 }
0073 };
0074 };
0075
0076 }