Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-25 02:40:53

0001 #ifndef HeterogeneousCore_SonicCore_SonicAcquirer
0002 #define HeterogeneousCore_SonicCore_SonicAcquirer
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
0008 #include "HeterogeneousCore/SonicCore/interface/sonic_utils.h"
0009 
0010 #include <chrono>
0011 #include <memory>
0012 #include <string>
0013 
0014 template <typename Client, typename Module>
0015 class SonicAcquirer : public Module {
0016 public:
0017   //typedef to simplify usage
0018   typedef typename Client::Input Input;
0019   //constructor
0020   SonicAcquirer(edm::ParameterSet const& cfg)
0021       : clientPset_(cfg.getParameterSet("Client")),
0022         debugName_(cfg.getParameter<std::string>("@module_label")),
0023         verbose_(clientPset_.getUntrackedParameter<bool>("verbose")) {}
0024   //destructor
0025   ~SonicAcquirer() override = default;
0026 
0027   //construct client at beginning of job
0028   //in case client constructor depends on operations happening in derived module constructors
0029   void beginStream(edm::StreamID) override { makeClient(); }
0030 
0031   //derived classes use a dedicated acquire() interface that incorporates client_->input()
0032   //(no need to interact with callback holder)
0033   void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, edm::WaitingTaskWithArenaHolder holder) final {
0034     auto t0 = std::chrono::high_resolution_clock::now();
0035     acquire(iEvent, iSetup, client_->input());
0036     if (verbose_)
0037       sonic_utils::printDebugTime(debugName_, "acquire() time: ", t0);
0038     t_dispatch_ = std::chrono::high_resolution_clock::now();
0039     client_->dispatch(holder);
0040   }
0041   virtual void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, Input& iInput) = 0;
0042 
0043 protected:
0044   //helper
0045   void makeClient() { client_ = std::make_unique<Client>(clientPset_, debugName_); }
0046 
0047   //members
0048   edm::ParameterSet clientPset_;
0049   std::unique_ptr<Client> client_;
0050   std::string debugName_;
0051   bool verbose_;
0052   std::chrono::time_point<std::chrono::high_resolution_clock> t_dispatch_;
0053 };
0054 
0055 #endif