Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 07:54:31

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2024 Simon Gardner
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 =
0020     algorithms::Algorithm<typename algorithms::Input<const typename T::collection_type>,
0021                           typename algorithms::Output<std::vector<typename T::collection_type>>>;
0022 
0023 template <typename T>
0024 class SubDivideCollection : public SubDivideCollectionAlgorithm<T>,
0025                             public WithPodConfig<SubDivideCollectionConfig<T>> {
0026 
0027 public:
0028   SubDivideCollection(std::string_view name)
0029       : SubDivideCollectionAlgorithm<T>{name,
0030                                         {"inputCollection"},
0031                                         {"outputCollection"},
0032                                         "Sub-Divide collection"}
0033       , WithPodConfig<SubDivideCollectionConfig<T>>(){};
0034 
0035   void init() final{};
0036 
0037   void process(const typename SubDivideCollectionAlgorithm<T>::Input& input,
0038                const typename SubDivideCollectionAlgorithm<T>::Output& output) const final {
0039 
0040     const auto [entries]      = input;
0041     auto [subdivided_entries] = output;
0042 
0043     for (auto out : subdivided_entries) {
0044       out->setSubsetCollection();
0045     }
0046 
0047     for (const auto& entry : *entries) {
0048 
0049       auto div_indices = this->m_cfg.function(entry);
0050 
0051       for (auto index : div_indices) {
0052         subdivided_entries[index]->push_back(entry);
0053       }
0054     }
0055 
0056     //Log how the hits were divided between the collection names
0057     this->debug("Divided {} hits between {} collections", entries->size(),
0058                 subdivided_entries.size());
0059     //How many hits in each output collection
0060     for (std::size_t i = 0; i < subdivided_entries.size(); i++) {
0061       this->debug("Collection {} takes {} hits", i, subdivided_entries[i]->size());
0062     }
0063   };
0064 };
0065 
0066 } // namespace eicrecon