forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSonicClientBase.h
More file actions
79 lines (57 loc) · 2.32 KB
/
Copy pathSonicClientBase.h
File metadata and controls
79 lines (57 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef HeterogeneousCore_SonicCore_SonicClientBase
#define HeterogeneousCore_SonicCore_SonicClientBase
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "HeterogeneousCore/SonicCore/interface/SonicDispatcher.h"
#include "HeterogeneousCore/SonicCore/interface/SonicDispatcherPseudoAsync.h"
#include <string>
#include <vector>
#include <exception>
#include <memory>
#include <optional>
enum class SonicMode { Sync = 1, Async = 2, PseudoAsync = 3 };
class RetryActionBase;
class SonicClientBase {
public:
//constructor
SonicClientBase(const edm::ParameterSet& params, const std::string& debugName, const std::string& clientName);
//destructor
virtual ~SonicClientBase() = default;
const std::string& debugName() const { return debugName_; }
const std::string& clientName() const { return clientName_; }
SonicMode mode() const { return mode_; }
//main operation
virtual void dispatch(edm::WaitingTaskWithArenaHolder holder) { dispatcher_->dispatch(std::move(holder)); }
//alternate operation when ExternalWork is not used
virtual void dispatch() { dispatcher_->dispatch(); }
//helper: does nothing by default
virtual void reset() {}
//provide base params
static void fillBasePSetDescription(edm::ParameterSetDescription& desc, bool allowRetry = true);
protected:
void setMode(SonicMode mode);
virtual void evaluate() = 0;
void start(edm::WaitingTaskWithArenaHolder holder);
void start();
void finish(bool success, std::exception_ptr eptr = std::exception_ptr{});
//members
SonicMode mode_;
bool verbose_;
std::unique_ptr<SonicDispatcher> dispatcher_;
unsigned totalTries_;
std::optional<edm::WaitingTaskWithArenaHolder> holder_;
// Use a unique_ptr with a custom deleter to avoid incomplete type issues
struct RetryDeleter {
void operator()(RetryActionBase* ptr) const;
};
using RetryActionPtr = std::unique_ptr<RetryActionBase, RetryDeleter>;
std::vector<RetryActionPtr> retryActions_;
//for logging/debugging
std::string debugName_, clientName_, fullDebugName_;
friend class SonicDispatcher;
friend class SonicDispatcherPseudoAsync;
friend class RetryActionBase;
};
#endif