Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef HeterogeneousCore_SonicCore_SonicEDFilter
0002 #define HeterogeneousCore_SonicCore_SonicEDFilter
0003 
0004 #include "FWCore/Framework/interface/stream/EDFilter.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 filter 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 SonicEDFilter : public SonicAcquirer<Client, edm::stream::EDFilter<edm::ExternalWork, Capabilities...>> {
0015 public:
0016   //typedef to simplify usage
0017   typedef typename Client::Output Output;
0018   //constructor
0019   SonicEDFilter(edm::ParameterSet const& cfg)
0020       : SonicAcquirer<Client, edm::stream::EDFilter<edm::ExternalWork, Capabilities...>>(cfg) {}
0021   //destructor
0022   ~SonicEDFilter() override = default;
0023 
0024   //derived classes use a dedicated produce() interface that incorporates client_->output()
0025   bool filter(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     bool result = filter(iEvent, iSetup, this->client_->output());
0032     if (this->verbose_)
0033       sonic_utils::printDebugTime(this->debugName_, "filter() time: ", t0);
0034 
0035     //reset client data
0036     this->client_->reset();
0037 
0038     return result;
0039   }
0040   virtual bool filter(edm::Event& iEvent, edm::EventSetup const& iSetup, Output const& iOutput) = 0;
0041 };
0042 
0043 #endif