File indexing completed on 2024-09-27 07:02:58
0001
0002
0003
0004 #pragma once
0005
0006 #include <spdlog/spdlog.h>
0007 #include <DD4hep/Detector.h>
0008 #include <algorithms/algorithm.h>
0009 #include <string>
0010 #include <string_view>
0011
0012 #include "services/log/Log_service.h"
0013 #include "algorithms/meta/SubDivideCollectionConfig.h"
0014 #include "algorithms/interfaces/WithPodConfig.h"
0015
0016 namespace eicrecon {
0017
0018 template<class T>
0019 using SubDivideCollectionAlgorithm = algorithms::Algorithm<
0020 typename algorithms::Input<const typename T::collection_type>,
0021 typename algorithms::Output<std::vector<typename T::collection_type>>
0022 >;
0023
0024
0025 template<typename T>
0026 class SubDivideCollection : public SubDivideCollectionAlgorithm<T>, public WithPodConfig<SubDivideCollectionConfig<T>> {
0027
0028 public:
0029 SubDivideCollection(std::string_view name)
0030 : SubDivideCollectionAlgorithm<T>{name,
0031 {"inputCollection"},
0032 {"outputCollection"},
0033 "Sub-Divide collection"
0034 },
0035 WithPodConfig<SubDivideCollectionConfig<T>>() {
0036 };
0037
0038 void init() final { };
0039
0040 void process(const typename SubDivideCollectionAlgorithm<T>::Input& input, const typename SubDivideCollectionAlgorithm<T>::Output& output) const final{
0041
0042 const auto [entries] = input;
0043 auto [subdivided_entries] = output;
0044
0045 for( auto out : subdivided_entries){
0046 out->setSubsetCollection();
0047 }
0048
0049 for (const auto& entry : *entries) {
0050
0051 auto div_indices = this->m_cfg.function(entry);
0052
0053 for (auto index : div_indices){
0054 subdivided_entries[index]->push_back(entry);
0055 }
0056
0057 }
0058
0059
0060 this->debug("Divided {} hits between {} collections", entries->size(), subdivided_entries.size());
0061
0062 for (size_t i = 0; i < subdivided_entries.size(); i++) {
0063 this->debug("Collection {} takes {} hits", i, subdivided_entries[i]->size());
0064 }
0065
0066 };
0067
0068 };
0069
0070 }