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 {
33  auto componentName = iConfig.getParameter<std::string>("ComponentName");
34  setWhatProduced(this, componentName);
35 }
36 
39  desc.add<std::string>("ComponentName", "lwtnnESProducer");
40  desc.add<edm::FileInPath>("fileName", edm::FileInPath());
41  descriptions.add("lwtnnESProducer", desc);
42 }
43 
44 std::unique_ptr<lwt::LightweightNeuralNetwork> LwtnnESProducer::produce(const TrackingComponentsRecord& iRecord) {
45  std::ifstream jsonfile(fileName_.fullPath().c_str());
46  auto config = lwt::parse_json(jsonfile);
47  return std::make_unique<lwt::LightweightNeuralNetwork>(config.inputs, config.layers, config.outputs);
48 }
49 
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
Definition: config.py:1
~LwtnnESProducer() override=default
LwtnnESProducer(const edm::ParameterSet &iConfig)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< lwt::LightweightNeuralNetwork > produce(const TrackingComponentsRecord &iRecord)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
edm::FileInPath fileName_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
std::string fullPath() const
Definition: FileInPath.cc:163