File indexing completed on 2026-11-15 09:30:18
0001
0002
0003
0004 #pragma once
0005
0006 #include <spdlog/spdlog.h>
0007 #include <algorithms/algorithm.h>
0008 #include <podio/LinkNavigator.h>
0009 #include <string>
0010 #include <string_view>
0011 #include <type_traits>
0012
0013 #include "algorithms/interfaces/WithPodConfig.h"
0014 #include "services/log/Log_service.h"
0015
0016 namespace eicrecon {
0017
0018 template <class SourceT, class SourceLinkT, class TargetT = SourceT,
0019 class TargetLinkT = SourceLinkT>
0020 using CopyLinksAlgorithm =
0021 algorithms::Algorithm<typename algorithms::Input<const typename SourceT::collection_type,
0022 const typename TargetT::collection_type,
0023 const typename SourceLinkT::collection_type>,
0024 typename algorithms::Output<typename TargetLinkT::collection_type>>;
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 template <typename SourceT, typename SourceLinkT, typename TargetT = SourceT,
0067 typename TargetLinkT = SourceLinkT>
0068 class CopyLinks : public CopyLinksAlgorithm<SourceT, SourceLinkT, TargetT, TargetLinkT>,
0069 public WithPodConfig<NoConfig> {
0070
0071 public:
0072 CopyLinks(std::string_view name)
0073 : CopyLinksAlgorithm<SourceT, SourceLinkT, TargetT, TargetLinkT>{
0074 name,
0075 {"inputSourceCollection", "inputTargetCollection", "inputSourceLinks"},
0076 {"outputTargetLinks"},
0077 "Copies links from source collection onto links from target collection"} {}
0078
0079 void process(
0080 const typename CopyLinksAlgorithm<SourceT, SourceLinkT, TargetT, TargetLinkT>::Input& input,
0081 const typename CopyLinksAlgorithm<SourceT, SourceLinkT, TargetT, TargetLinkT>::Output& output)
0082 const final {
0083
0084 const auto [in_sources, in_targets, in_source_links] = input;
0085 auto [out_target_links] = output;
0086
0087
0088 if (in_source_links->size() == 0) {
0089 this->debug("No links in input link collection.");
0090 return;
0091 }
0092
0093
0094
0095
0096 if (in_sources->size() != in_targets->size()) {
0097 this->error("Size of source collection ({}) not the same as size of target collection ({})",
0098 in_sources->size(), in_targets->size());
0099 return;
0100 }
0101
0102 const auto navigator = podio::LinkNavigator(*in_source_links);
0103 for (std::size_t idx = 0; const auto& source : *in_sources) {
0104 const auto target = in_targets->at(idx);
0105 const auto source_linkees = navigator.getLinked(source);
0106 for (const auto& [source_linkee, source_weight] : source_linkees) {
0107 auto target_link = out_target_links->create();
0108 target_link.template set<TargetT>(target);
0109 target_link.template set<std::remove_cvref_t<decltype(source_linkee)>>(source_linkee);
0110 target_link.setWeight(source_weight);
0111 }
0112 ++idx;
0113 }
0114 }
0115 };
0116
0117 }