File indexing completed on 2024-09-28 07:02:55
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 = algorithms::Algorithm<
0018 typename algorithms::Input<
0019 typename ToFilterObjectT::collection_type,
0020 typename FilterByObjectT::collection_type
0021 >,
0022 typename algorithms::Output<
0023 typename ToFilterObjectT::collection_type,
0024 typename ToFilterObjectT::collection_type
0025 >
0026 >;
0027
0028
0029
0030
0031
0032
0033 template<typename ToFilterObjectT,auto ToFilterFunction, typename FilterByObjectT,auto FilterByFunction>
0034 class FilterMatching : public FilterMatchingAlgorithm<ToFilterObjectT,FilterByObjectT> {
0035
0036 public:
0037 FilterMatching(std::string_view name)
0038 : FilterMatchingAlgorithm<ToFilterObjectT,FilterByObjectT>{name,
0039 {"inputCollection","inputMatchedCollection"},
0040 {"outputMatchedAssociations","outputUnmatchedAssociations"},
0041 "Filter by matching to a collection"
0042 } {
0043 };
0044
0045 void init() final { };
0046
0047 void process(const typename FilterMatchingAlgorithm<ToFilterObjectT,FilterByObjectT>::Input& input,
0048 const typename FilterMatchingAlgorithm<ToFilterObjectT,ToFilterObjectT>::Output& output) const final{
0049
0050 const auto [toFilterEntries,filterByEntries] = input;
0051 auto [is_matched,is_not_matched] = output;
0052
0053 is_matched->setSubsetCollection();
0054 is_not_matched->setSubsetCollection();
0055
0056 for (const auto& matchedEntry : *toFilterEntries){
0057
0058 auto ref_value = ToFilterFunction(&matchedEntry);
0059
0060 bool found_match = false;
0061
0062
0063 for(const auto& entry : *filterByEntries){
0064 auto other_value = FilterByFunction(&entry);
0065 if(other_value == ref_value){
0066 is_matched->push_back(matchedEntry);
0067 found_match = true;
0068 break;
0069 }
0070 }
0071
0072 if(!found_match){
0073 is_not_matched->push_back(matchedEntry);
0074 }
0075
0076 }
0077
0078 };
0079
0080 };
0081
0082 }