Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:47

0001 #ifndef HeterogeneousCore_SonicCore_SonicEDProducer
0002 #define HeterogeneousCore_SonicCore_SonicEDProducer
0003 
0004 #include "FWCore/Framework/interface/stream/EDProducer.h"
0005 #include "HeterogeneousCore/SonicCore/interface/sonic_utils.h"
0006 #include "HeterogeneousCore/SonicCore/interface/SonicAcquirer.h"
0007 
0008 #include <string>
0009 #include <chrono>
0010 
0011 //this is a stream producer because client operations are not multithread-safe in general
0012 //it is designed such that the user never has to interact with the client or the acquire() callback directly
0013 template <typename Client, typename... Capabilities>
0014 class SonicEDProducer : public SonicAcquirer<Client, edm::stream::EDProducer<edm::ExternalWork, Capabilities...>> {
0015 public:
0016   //typedef to simplify usage
0017   typedef typename Client::Output Output;
0018   //constructor
0019   SonicEDProducer(edm::ParameterSet const& cfg)
0020       : SonicAcquirer<Client, edm::stream::EDProducer<edm::ExternalWork, Capabilities...>>(cfg) {}
0021   //destructor
0022   ~SonicEDProducer() override = default;
0023 
0024   //derived classes use a dedicated produce() interface that incorporates client_->output()
0025   void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) final {
0026     //measure time between acquire and produce
0027     if (this->verbose_)
0028       sonic_utils::printDebugTime(this->debugName_, "dispatch() time: ", this->t_dispatch_);
0029 
0030     auto t0 = std::chrono::high_resolution_clock::now();
0031     produce(iEvent, iSetup, this->client_->output());
0032     if (this->verbose_)
0033       sonic_utils::printDebugTime(this->debugName_, "produce() time: ", t0);
0034 
0035     //reset client data
0036     this->client_->reset();
0037   }
0038   virtual void produce(edm::Event& iEvent, edm::EventSetup const& iSetup, Output const& iOutput) = 0;
0039 };
0040 
0041 #endif