File indexing completed on 2024-11-15 09:35:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDDIGI_DIGIPARALLELWORKER_H
0014 #define DDDIGI_DIGIPARALLELWORKER_H
0015
0016
0017 #include <cstdint>
0018
0019
0020 namespace dd4hep {
0021
0022
0023 namespace digi {
0024
0025
0026 class WorkerPredicate;
0027
0028
0029
0030
0031
0032
0033
0034
0035 class ParallelWorker {
0036 public:
0037
0038 ParallelWorker() = default;
0039 ParallelWorker(ParallelWorker&& copy) = default;
0040 ParallelWorker(const ParallelWorker& copy) = default;
0041 ParallelWorker& operator=(ParallelWorker&& copy) = default;
0042 ParallelWorker& operator=(const ParallelWorker& copy) = default;
0043 virtual ~ParallelWorker() = default;
0044 virtual void execute(void* args) const = 0;
0045 };
0046
0047
0048
0049
0050
0051
0052
0053
0054 template <typename ACTION_TYPE, typename CALLDATA, typename OPTIONS=std::size_t, typename PREDICATE=std::size_t>
0055 class DigiParallelWorker : public ParallelWorker {
0056 public:
0057 using action_t = ACTION_TYPE;
0058 using options_t = OPTIONS;
0059 using calldata_t = CALLDATA;
0060 using predicate_t = PREDICATE;
0061
0062 action_t* action { nullptr };
0063 options_t options { nullptr };
0064 predicate_t predicate { nullptr };
0065
0066 public:
0067
0068 DigiParallelWorker(action_t* a, const options_t& opts, const predicate_t& p={});
0069
0070 DigiParallelWorker() = delete;
0071
0072 DigiParallelWorker(DigiParallelWorker&& copy) = default;
0073
0074 DigiParallelWorker(const DigiParallelWorker& copy) = default;
0075
0076 DigiParallelWorker& operator=(DigiParallelWorker&& copy) = delete;
0077
0078 DigiParallelWorker& operator=(const DigiParallelWorker& copy) = delete;
0079
0080 virtual ~DigiParallelWorker();
0081
0082 const char* name() const { return action->name().c_str(); }
0083
0084 virtual void execute(void* data) const override;
0085 };
0086
0087
0088 template <typename ACTION_TYPE, typename CALLDATA, typename OPTIONS, typename PREDICATE>
0089 DigiParallelWorker<ACTION_TYPE, CALLDATA, OPTIONS, PREDICATE>::DigiParallelWorker(action_t* a, const options_t& o, const predicate_t& p)
0090 : ParallelWorker(), action(a), options(o), predicate(p)
0091 {
0092 if ( action ) action->addRef();
0093 }
0094
0095
0096 template <typename ACTION_TYPE, typename CALLDATA, typename OPTIONS, typename PREDICATE>
0097 DigiParallelWorker<ACTION_TYPE, CALLDATA, OPTIONS, PREDICATE>::~DigiParallelWorker() {
0098 if ( action ) {
0099 action->release();
0100 action = nullptr;
0101 }
0102 }
0103
0104 typedef ParallelWorker ParallelCall;
0105 }
0106 }
0107
0108 #include <DDDigi/DigiParallelWorkers.h>
0109 #include <DDDigi/DigiParallelWorkerGroup.h>
0110
0111 #endif