File indexing completed on 2025-01-18 09:55:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDDIGI_DIGISEGMENTSPLITTER_H
0014 #define DDDIGI_DIGISEGMENTSPLITTER_H
0015
0016
0017 #include <DDDigi/DigiEventAction.h>
0018 #include <DDDigi/DigiParallelWorker.h>
0019 #include <DDDigi/DigiSegmentationTool.h>
0020 #include <DDDigi/DigiContainerProcessor.h>
0021
0022
0023 namespace dd4hep {
0024
0025
0026 namespace digi {
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 class DigiSegmentProcessContext : public DigiSegmentContext {
0038 public:
0039 using predicate_t = DigiContainerProcessor::predicate_t;
0040 predicate_t predicate;
0041
0042 public:
0043
0044 DigiSegmentProcessContext() = default;
0045
0046 DigiSegmentProcessContext(const DigiSegmentContext& copy);
0047
0048 DigiSegmentProcessContext(DigiSegmentProcessContext&& copy) = default;
0049
0050 DigiSegmentProcessContext(const DigiSegmentProcessContext& copy) = default;
0051
0052 virtual ~DigiSegmentProcessContext() = default;
0053
0054 DigiSegmentProcessContext& operator=(const DigiSegmentContext& copy);
0055
0056 DigiSegmentProcessContext& operator=(DigiSegmentProcessContext&& copy) = default;
0057
0058 DigiSegmentProcessContext& operator=(const DigiSegmentProcessContext& copy) = default;
0059
0060
0061 std::string identifier() const;
0062
0063
0064
0065
0066
0067 bool matches(CellID cell) const {
0068 return this->split_id(cell) == this->predicate.id;
0069 }
0070
0071
0072 bool use_depo(const std::pair<const CellID, EnergyDeposit>& deposit) const {
0073 return this->matches(deposit.first);
0074 }
0075 void enable(uint32_t split_id);
0076 };
0077
0078
0079
0080
0081
0082
0083
0084
0085 struct accept_segment_t : public DigiContainerProcessor::predicate_t {
0086 accept_segment_t(const DigiSegmentContext* s, uint32_t i)
0087 : predicate_t(std::bind(&accept_segment_t::use_depo, this, std::placeholders::_1), i, s) {
0088 }
0089
0090 bool use_depo(const deposit_t& deposit) const {
0091 return this->segmentation->split_id(deposit.first) == this->id;
0092 }
0093 };
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 class DigiSegmentSplitter : public DigiContainerProcessor {
0105 protected:
0106
0107
0108 using self_t = DigiSegmentSplitter;
0109 using tool_t = DigiSegmentationTool;
0110 using splits_t = std::set<uint32_t>;
0111 using segment_t = DigiSegmentProcessContext;
0112 using processor_t = DigiContainerProcessor;
0113
0114 using worker_t = DigiParallelWorker<processor_t, work_t, segment_t>;
0115 using workers_t = DigiParallelWorkers<worker_t>;
0116 friend class DigiParallelWorker<processor_t, work_t, segment_t>;
0117
0118 protected:
0119
0120
0121
0122 std::string m_processor_type;
0123
0124 std::string m_detector_name;
0125
0126 std::string m_split_by;
0127
0128 bool m_parallel { false };
0129
0130 bool m_share_processor { true };
0131
0132
0133
0134 std::vector<Key> m_keys;
0135
0136 segment_t m_split_context;
0137
0138 splits_t m_splits;
0139
0140 workers_t m_workers;
0141
0142
0143 mutable std::mutex m_output_lock;
0144
0145 mutable tool_t m_split_tool;
0146
0147 protected:
0148
0149 virtual ~DigiSegmentSplitter();
0150
0151
0152 void initialize();
0153
0154 public:
0155
0156 virtual void adopt_segment_processor(DigiContainerProcessor* action, int split_id);
0157
0158 virtual void adopt_segment_processor(DigiContainerProcessor* action, const std::vector<int>& ids);
0159
0160 public:
0161
0162 DigiSegmentSplitter(const kernel_t& kernel, const std::string& name);
0163
0164 std::vector<std::string> collection_names() const;
0165
0166 virtual void execute(context_t& context, work_t& work, const predicate_t& predicate) const override;
0167 };
0168 }
0169 }
0170 #endif