CMS 3D CMS Logo

SonicAcquirer.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_SonicCore_SonicAcquirer
2 #define HeterogeneousCore_SonicCore_SonicAcquirer
3 
9 
10 #include <chrono>
11 #include <memory>
12 #include <string>
13 
14 template <typename Client, typename Module>
15 class SonicAcquirer : public Module {
16 public:
17  //typedef to simplify usage
18  typedef typename Client::Input Input;
19  //constructor
21  : clientPset_(cfg.getParameterSet("Client")),
22  debugName_(cfg.getParameter<std::string>("@module_label")),
23  verbose_(clientPset_.getUntrackedParameter<bool>("verbose")) {}
24  //destructor
25  ~SonicAcquirer() override = default;
26 
27  //construct client at beginning of job
28  //in case client constructor depends on operations happening in derived module constructors
29  void beginStream(edm::StreamID) override { makeClient(); }
30 
31  //derived classes use a dedicated acquire() interface that incorporates client_->input()
32  //(no need to interact with callback holder)
33  void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, edm::WaitingTaskWithArenaHolder holder) final {
35  acquire(iEvent, iSetup, client_->input());
36  if (verbose_)
37  sonic_utils::printDebugTime(debugName_, "acquire() time: ", t0);
39  client_->dispatch(holder);
40  }
41  virtual void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, Input& iInput) = 0;
42 
43 protected:
44  //helper
45  void makeClient() { client_ = std::make_unique<Client>(clientPset_, debugName_); }
46 
47  //members
49  std::unique_ptr<Client> client_;
51  bool verbose_;
52  std::chrono::time_point<std::chrono::high_resolution_clock> t_dispatch_;
53 };
54 
55 #endif
std::chrono::time_point< std::chrono::high_resolution_clock > t_dispatch_
Definition: SonicAcquirer.h:52
SonicAcquirer(edm::ParameterSet const &cfg)
Definition: SonicAcquirer.h:20
~SonicAcquirer() override=default
int iEvent
Definition: GenABIO.cc:224
void makeClient()
Definition: SonicAcquirer.h:45
Client::Input Input
Definition: SonicAcquirer.h:18
void beginStream(edm::StreamID) override
Definition: SonicAcquirer.h:29
std::string debugName_
Definition: SonicAcquirer.h:50
ParameterSet const & getParameterSet(ParameterSetID const &id)
edm::ParameterSet clientPset_
Definition: SonicAcquirer.h:48
void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, edm::WaitingTaskWithArenaHolder holder) final
Definition: SonicAcquirer.h:33
void printDebugTime(std::string_view debugName, std::string_view msg, const TimePoint &t0)
Definition: sonic_utils.cc:8
std::unique_ptr< Client > client_
Definition: SonicAcquirer.h:49