-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into test-on-jug-xl-nightly-and-23.12-alpha
- Loading branch information
Showing
5 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// Copyright (C) 2024 Simon Gardner | ||
|
||
#pragma once | ||
|
||
#include <spdlog/spdlog.h> | ||
#include <algorithms/algorithm.h> | ||
#include <string> | ||
#include <string_view> | ||
|
||
#include "services/log/Log_service.h" | ||
#include "algorithms/interfaces/WithPodConfig.h" | ||
|
||
namespace eicrecon { | ||
|
||
template<class ToFilterObjectT, class FilterByObjectT> | ||
using FilterMatchingAlgorithm = algorithms::Algorithm< | ||
typename algorithms::Input< | ||
typename ToFilterObjectT::collection_type, | ||
typename FilterByObjectT::collection_type | ||
>, | ||
typename algorithms::Output< | ||
typename ToFilterObjectT::collection_type, | ||
typename ToFilterObjectT::collection_type | ||
> | ||
>; | ||
|
||
/// Filters a collection by the members of another collection | ||
/// The first collection is divided up into two collections where its elements either passed the filter or not | ||
/// The second collection provides a filter | ||
/// Functions need to be provided along with the collections to form the link between the data types | ||
/// These functions are envisioned to link the objectIDs of the collection/associations but could be anything | ||
template<typename ToFilterObjectT,auto ToFilterFunction, typename FilterByObjectT,auto FilterByFunction> | ||
class FilterMatching : public FilterMatchingAlgorithm<ToFilterObjectT,FilterByObjectT> { | ||
|
||
public: | ||
FilterMatching(std::string_view name) | ||
: FilterMatchingAlgorithm<ToFilterObjectT,FilterByObjectT>{name, | ||
{"inputCollection","inputMatchedCollection"}, | ||
{"outputMatchedAssociations","outputUnmatchedAssociations"}, | ||
"Filter by matching to a collection" | ||
} { | ||
}; | ||
|
||
void init() final { }; | ||
|
||
void process(const typename FilterMatchingAlgorithm<ToFilterObjectT,FilterByObjectT>::Input& input, | ||
const typename FilterMatchingAlgorithm<ToFilterObjectT,ToFilterObjectT>::Output& output) const final{ | ||
|
||
const auto [toFilterEntries,filterByEntries] = input; | ||
auto [is_matched,is_not_matched] = output; | ||
|
||
is_matched->setSubsetCollection(); | ||
is_not_matched->setSubsetCollection(); | ||
|
||
for (const auto& matchedEntry : *toFilterEntries){ | ||
|
||
auto ref_value = ToFilterFunction(&matchedEntry); | ||
|
||
bool found_match = false; | ||
|
||
// Tries to find the association in the entries | ||
for(const auto& entry : *filterByEntries){ | ||
auto other_value = FilterByFunction(&entry); | ||
if(other_value == ref_value){ | ||
is_matched->push_back(matchedEntry); | ||
found_match = true; | ||
break; | ||
} | ||
} | ||
|
||
if(!found_match){ | ||
is_not_matched->push_back(matchedEntry); | ||
} | ||
|
||
} | ||
|
||
}; | ||
|
||
}; | ||
|
||
} // eicrecon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// Copyright (C) 2024 Simon Gardner | ||
|
||
#pragma once | ||
|
||
#include "algorithms/meta/FilterMatching.h" | ||
#include "extensions/jana/JOmniFactory.h" | ||
|
||
namespace eicrecon { | ||
|
||
template <typename ToFilterObjectT,auto ToFilterMemberFunctionPtr,typename FilterByObjectT,auto FilterByMemberFunctionPtr> | ||
class FilterMatching_factory : public JOmniFactory<FilterMatching_factory<ToFilterObjectT,ToFilterMemberFunctionPtr,FilterByObjectT,FilterByMemberFunctionPtr>> { | ||
|
||
public: | ||
using AlgoT = eicrecon::FilterMatching<ToFilterObjectT,ToFilterMemberFunctionPtr,FilterByObjectT,FilterByMemberFunctionPtr>; | ||
using FactoryT = JOmniFactory<FilterMatching_factory<ToFilterObjectT,ToFilterMemberFunctionPtr,FilterByObjectT,FilterByMemberFunctionPtr>>; | ||
|
||
private: | ||
|
||
std::unique_ptr<AlgoT> m_algo; | ||
|
||
typename FactoryT::template PodioInput<ToFilterObjectT> m_collection_input {this}; | ||
typename FactoryT::template PodioInput<FilterByObjectT> m_matched_input {this}; | ||
typename FactoryT::template PodioOutput<ToFilterObjectT> m_is_matched_output {this}; | ||
typename FactoryT::template PodioOutput<ToFilterObjectT> m_is_not_matched_output {this}; | ||
|
||
public: | ||
void Configure() { | ||
m_algo = std::make_unique<AlgoT>(this->GetPrefix()); | ||
m_algo->init(); | ||
} | ||
|
||
void ChangeRun(int64_t run_number) { | ||
} | ||
|
||
void Process(int64_t run_number, uint64_t event_number) { | ||
m_algo->process({m_collection_input(),m_matched_input()},{m_is_matched_output().get(),m_is_not_matched_output().get()}); | ||
}; | ||
}; // FilterByAssociations_factory | ||
} // eicrecon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters