CMS 3D CMS Logo

LwtnnESProducer.cc
Go to the documentation of this file.
4 
6 
7 //from lwtnn
8 #include "lwtnn/LightweightNeuralNetwork.hh"
9 #include "lwtnn/parse_json.hh"
10 #include <fstream>
11 
13 public:
14  LwtnnESProducer(const edm::ParameterSet& iConfig);
15  ~LwtnnESProducer() override = default;
16 
17  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
18 
19  // TODO: Use of TrackingComponentsRecord is as inadequate as the
20  // placement of this ESProducer in RecoTracker/FinalTrackSelectors
21  // (but it works, I tried to create a new record but for some reason
22  // did not get it to work). Especially if this producer gets used
23  // wider we should figure out a better record and package.
24  std::unique_ptr<lwt::LightweightNeuralNetwork> produce(const TrackingComponentsRecord& iRecord);
25 
26 private:
28 };
29 
31  : fileName_(iConfig.getParameter<edm::FileInPath>("fileName")) {
32  auto componentName = iConfig.getParameter<std::string>("ComponentName");
33  setWhatProduced(this, componentName);
34 }
35 
38  desc.add<std::string>("ComponentName", "lwtnnESProducer");
39  desc.add<edm::FileInPath>("fileName", edm::FileInPath());
40  descriptions.add("lwtnnESProducer", desc);
41 }
42 
43 std::unique_ptr<lwt::LightweightNeuralNetwork> LwtnnESProducer::produce(const TrackingComponentsRecord& iRecord) {
44  std::ifstream jsonfile(fileName_.fullPath().c_str());
45  auto config = lwt::parse_json(jsonfile);
46  return std::make_unique<lwt::LightweightNeuralNetwork>(config.inputs, config.layers, config.outputs);
47 }
48 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::string fullPath() const
Definition: FileInPath.cc:161
Definition: config.py:1
~LwtnnESProducer() override=default
LwtnnESProducer(const edm::ParameterSet &iConfig)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
std::unique_ptr< lwt::LightweightNeuralNetwork > produce(const TrackingComponentsRecord &iRecord)
edm::FileInPath fileName_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.