Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-01 09:04:34

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>{
0030             name, {"inputCollection"}, {"outputCollection"}, "Sub-Divide collection"}
0031       , WithPodConfig<SubDivideCollectionConfig<T>>() {};
0032 
0033   void init() final {};
0034 
0035   void process(const typename SubDivideCollectionAlgorithm<T>::Input& input,
0036                const typename SubDivideCollectionAlgorithm<T>::Output& output) const final {
0037 
0038     const auto [entries]      = input;
0039     auto [subdivided_entries] = output;
0040 
0041     for (auto out : subdivided_entries) {
0042       out->setSubsetCollection();
0043     }
0044 
0045     for (const auto& entry : *entries) {
0046 
0047       auto div_indices = this->m_cfg.function(entry);
0048 
0049       for (auto index : div_indices) {
0050         subdivided_entries[index]->push_back(entry);
0051       }
0052     }
0053 
0054     //Log how the hits were divided between the collection names
0055     this->debug("Divided {} hits between {} collections", entries->size(),
0056                 subdivided_entries.size());
0057     //How many hits in each output collection
0058     for (std::size_t i = 0; i < subdivided_entries.size(); i++) {
0059       this->debug("Collection {} takes {} hits", i, subdivided_entries[i]->size());
0060     }
0061   };
0062 };
0063 
0064 } // namespace eicrecon