File indexing completed on 2024-04-06 12:15:47
0001 #ifndef HeterogeneousCore_SonicCore_SonicOneEDAnalyzer
0002 #define HeterogeneousCore_SonicCore_SonicOneEDAnalyzer
0003
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "HeterogeneousCore/SonicCore/interface/SonicClientBase.h"
0011 #include "HeterogeneousCore/SonicCore/interface/sonic_utils.h"
0012
0013 #include <string>
0014 #include <chrono>
0015
0016
0017 template <typename Client, typename... Capabilities>
0018 class SonicOneEDAnalyzer : public edm::one::EDAnalyzer<Capabilities...> {
0019 public:
0020
0021 typedef typename Client::Input Input;
0022 typedef typename Client::Output Output;
0023
0024 SonicOneEDAnalyzer(edm::ParameterSet const& cfg, bool verbose = true)
0025 : clientPset_(cfg.getParameterSet("Client")),
0026 debugName_(cfg.getParameter<std::string>("@module_label")),
0027 verbose_(clientPset_.getUntrackedParameter<bool>("verbose")) {
0028
0029 if (clientPset_.getParameter<std::string>("mode") != "Sync") {
0030 edm::LogWarning("ResetClientMode") << "Resetting client mode to Sync for SonicOneEDAnalyzer";
0031 clientPset_.addParameter<std::string>("mode", "Sync");
0032 }
0033 }
0034
0035 ~SonicOneEDAnalyzer() override = default;
0036
0037
0038
0039 void beginJob() override { makeClient(); }
0040
0041
0042 virtual void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, Input& iInput) = 0;
0043
0044 void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) final {
0045 auto t0 = std::chrono::high_resolution_clock::now();
0046 acquire(iEvent, iSetup, client_->input());
0047 if (verbose_)
0048 sonic_utils::printDebugTime(debugName_, "acquire() time: ", t0);
0049
0050
0051 auto t1 = std::chrono::high_resolution_clock::now();
0052 client_->dispatch();
0053
0054
0055 if (verbose_)
0056 sonic_utils::printDebugTime(debugName_, "dispatch() time: ", t1);
0057
0058 auto t2 = std::chrono::high_resolution_clock::now();
0059 analyze(iEvent, iSetup, client_->output());
0060 if (verbose_)
0061 sonic_utils::printDebugTime(debugName_, "analyze() time: ", t2);
0062
0063
0064 client_->reset();
0065 }
0066 virtual void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup, Output const& iOutput) = 0;
0067
0068 protected:
0069
0070 void makeClient() { client_ = std::make_unique<Client>(clientPset_, debugName_); }
0071
0072
0073 edm::ParameterSet clientPset_;
0074 std::unique_ptr<Client> client_;
0075 std::string debugName_;
0076 bool verbose_;
0077 };
0078
0079 #endif