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
24  SonicOneEDAnalyzer(edm::ParameterSet const& cfg, const std::string& debugName, bool verbose = true)
25  : clientPset_(cfg.getParameterSet("Client")), debugName_(debugName), verbose_(verbose) {
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  if (verbose_)
46  sonic_utils::printDebugTime(debugName_, "acquire() time: ", t0);
47 
48  //pattern similar to ExternalWork, but blocking
50  client_->dispatch();
51 
52  //measure time between acquire and produce
53  if (verbose_)
54  sonic_utils::printDebugTime(debugName_, "dispatch() time: ", t1);
55 
57  analyze(iEvent, iSetup, client_->output());
58  if (verbose_)
59  sonic_utils::printDebugTime(debugName_, "analyze() time: ", t2);
60 
61  //reset client data
62  client_->reset();
63  }
64  virtual void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup, Output const& iOutput) = 0;
65 
66 protected:
67  //helper
68  void makeClient() { client_ = std::make_unique<Client>(clientPset_, debugName_); }
69 
70  //members
72  std::unique_ptr<Client> client_;
74  bool verbose_;
75 };
76 
77 #endif
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
EDAnalyzer.h
MessageLogger.h
SonicOneEDAnalyzer::client_
std::unique_ptr< Client > client_
Definition: SonicOneEDAnalyzer.h:72
sonic_utils.h
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
SonicOneEDAnalyzer::debugName_
std::string debugName_
Definition: SonicOneEDAnalyzer.h:73
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
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
SonicOneEDAnalyzer::clientPset_
edm::ParameterSet clientPset_
Definition: SonicOneEDAnalyzer.h:71
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
edm::ParameterSet
Definition: ParameterSet.h:47
SonicOneEDAnalyzer::makeClient
void makeClient()
Definition: SonicOneEDAnalyzer.h:68
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
SonicOneEDAnalyzer::verbose_
bool verbose_
Definition: SonicOneEDAnalyzer.h:74
edm::EventSetup
Definition: EventSetup.h:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
looper.cfg
cfg
Definition: looper.py:296
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
SonicOneEDAnalyzer::SonicOneEDAnalyzer
SonicOneEDAnalyzer(edm::ParameterSet const &cfg, const std::string &debugName, bool verbose=true)
Definition: SonicOneEDAnalyzer.h:24
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