CMS 3D CMS Logo

SonicOneEDAnalyzer.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_SonicCore_SonicOneEDAnalyzer
2 #define HeterogeneousCore_SonicCore_SonicOneEDAnalyzer
3 
12 
13 #include <string>
14 #include <chrono>
15 
16 //this is a one analyzer to enable writing trees/histograms for analysis users with results from inference as a service
17 template <typename Client, typename... Capabilities>
18 class SonicOneEDAnalyzer : public edm::one::EDAnalyzer<Capabilities...> {
19 public:
20  //typedefs to simplify usage
21  typedef typename Client::Input Input;
22  typedef typename Client::Output Output;
23  //constructor
25  : clientPset_(cfg.getParameterSet("Client")), debugName_(debugName) {
26  //ExternalWork is not compatible with one modules, so Sync mode is enforced
27  if (clientPset_.getParameter<std::string>("mode") != "Sync") {
28  edm::LogWarning("ResetClientMode") << "Resetting client mode to Sync for SonicOneEDAnalyzer";
29  clientPset_.addParameter<std::string>("mode", "Sync");
30  }
31  }
32  //destructor
33  ~SonicOneEDAnalyzer() override = default;
34 
35  //construct client at beginning of job
36  //in case client constructor depends on operations happening in derived module constructors
37  void beginJob() override { makeClient(); }
38 
39  //derived classes still use a dedicated acquire() interface that incorporates client_->input() for consistency
40  virtual void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, Input& iInput) = 0;
41  //derived classes use a dedicated analyze() interface that incorporates client_->output()
42  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) final {
44  acquire(iEvent, iSetup, client_->input());
45  sonic_utils::printDebugTime(debugName_, "acquire() time: ", t0);
46 
47  //pattern similar to ExternalWork, but blocking
49  client_->dispatch();
50 
51  //measure time between acquire and produce
52  sonic_utils::printDebugTime(debugName_, "dispatch() time: ", t1);
53 
55  analyze(iEvent, iSetup, client_->output());
56  sonic_utils::printDebugTime(debugName_, "analyze() time: ", t2);
57 
58  //reset client data
59  client_->reset();
60  }
61  virtual void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup, Output const& iOutput) = 0;
62 
63 protected:
64  //helper
65  void makeClient() { client_ = std::make_unique<Client>(clientPset_, debugName_); }
66 
67  //members
69  std::unique_ptr<Client> client_;
71 };
72 
73 #endif
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
EDAnalyzer.h
MessageLogger.h
SonicOneEDAnalyzer::client_
std::unique_ptr< Client > client_
Definition: SonicOneEDAnalyzer.h:69
sonic_utils.h
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
SonicOneEDAnalyzer::debugName_
std::string debugName_
Definition: SonicOneEDAnalyzer.h:70
sonic_utils::printDebugTime
void printDebugTime(std::string_view debugName, std::string_view msg, const TimePoint &t0)
Definition: sonic_utils.cc:8
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
GetRecoTauVFromDQM_MC_cff.Output
Output
Definition: GetRecoTauVFromDQM_MC_cff.py:12
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
FrontierCondition_GT_autoExpress_cfi.t0
t0
Definition: FrontierCondition_GT_autoExpress_cfi.py:149
SonicOneEDAnalyzer::Input
Client::Input Input
Definition: SonicOneEDAnalyzer.h:21
SonicOneEDAnalyzer
Definition: SonicOneEDAnalyzer.h:18
SonicOneEDAnalyzer::clientPset_
edm::ParameterSet clientPset_
Definition: SonicOneEDAnalyzer.h:68
SonicOneEDAnalyzer::analyze
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) final
Definition: SonicOneEDAnalyzer.h:42
SonicOneEDAnalyzer::Output
Client::Output Output
Definition: SonicOneEDAnalyzer.h:22
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
SonicOneEDAnalyzer::SonicOneEDAnalyzer
SonicOneEDAnalyzer(edm::ParameterSet const &cfg, const std::string &debugName)
Definition: SonicOneEDAnalyzer.h:24
SonicOneEDAnalyzer::makeClient
void makeClient()
Definition: SonicOneEDAnalyzer.h:65
Event.h
WaitingTaskWithArenaHolder.h
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
iEvent
int iEvent
Definition: GenABIO.cc:224
SonicClientBase.h
edm::EventSetup
Definition: EventSetup.h:58
looper.cfg
cfg
Definition: looper.py:297
SonicOneEDAnalyzer::beginJob
void beginJob() override
Definition: SonicOneEDAnalyzer.h:37
edm::getParameterSet
ParameterSet const & getParameterSet(ParameterSetID const &id)
Definition: ParameterSet.cc:862
TrackCandidateTopBottomHitFilter_cfi.Input
Input
Definition: TrackCandidateTopBottomHitFilter_cfi.py:4
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet.h
edm::Event
Definition: Event.h:73
SonicOneEDAnalyzer::acquire
virtual void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, Input &iInput)=0
SonicOneEDAnalyzer::~SonicOneEDAnalyzer
~SonicOneEDAnalyzer() override=default