File indexing completed on 2025-01-30 09:18:52
0001
0002
0003
0004 #pragma once
0005
0006 #include "algorithms/onnx/ONNXInference.h"
0007 #include "services/algorithms_init/AlgorithmsInit_service.h"
0008 #include "extensions/jana/JOmniFactory.h"
0009
0010
0011 namespace eicrecon {
0012
0013 class ONNXInference_factory : public JOmniFactory<ONNXInference_factory, ONNXInferenceConfig> {
0014
0015 public:
0016 using AlgoT = eicrecon::ONNXInference;
0017 private:
0018 std::unique_ptr<AlgoT> m_algo;
0019
0020 VariadicPodioInput<edm4eic::Tensor> m_input_tensors {this};
0021
0022 VariadicPodioOutput<edm4eic::Tensor> m_output_tensors {this};
0023
0024 ParameterRef<std::string> m_modelPath {this, "modelPath", config().modelPath};
0025
0026 Service<AlgorithmsInit_service> m_algorithmsInit {this};
0027
0028 public:
0029 void Configure() {
0030 m_algo = std::make_unique<AlgoT>(GetPrefix());
0031 m_algo->level(static_cast<algorithms::LogLevel>(logger()->level()));
0032 m_algo->applyConfig(config());
0033 m_algo->init();
0034 }
0035
0036 void ChangeRun(int64_t run_number) {
0037 }
0038
0039 void Process(int64_t run_number, uint64_t event_number) {
0040 std::vector<gsl::not_null<const edm4eic::TensorCollection*>> in_collections;
0041 for (const auto& in_collection : m_input_tensors()) {
0042 in_collections.push_back(gsl::not_null<const edm4eic::TensorCollection*>{in_collection});
0043 }
0044
0045 std::vector<gsl::not_null<edm4eic::TensorCollection*>> out_collections;
0046 for (const auto& out_collection : m_output_tensors()) {
0047 out_collections.push_back(gsl::not_null<edm4eic::TensorCollection*>{out_collection.get()});
0048 }
0049
0050 m_algo->process(in_collections,
0051 out_collections);
0052 }
0053 };
0054
0055 }