File indexing completed on 2025-01-18 10:01:27
0001
0002
0003
0004
0005 #pragma once
0006
0007 #include <JANA/JFactorySet.h>
0008 #include <JANA/JFactoryGenerator.h>
0009 #include <vector>
0010
0011 namespace jana::components {
0012
0013 template<class FactoryT>
0014 class JOmniFactoryGeneratorT : public JFactoryGenerator {
0015 public:
0016 using FactoryConfigType = typename FactoryT::ConfigType;
0017
0018 struct TypedWiring {
0019 std::string tag = "";
0020 JEventLevel level = JEventLevel::PhysicsEvent;
0021 std::vector<std::string> input_names = {};
0022 std::vector<JEventLevel> input_levels = {};
0023 std::vector<std::string> output_names = {};
0024 FactoryConfigType configs = {};
0025 };
0026
0027 struct UntypedWiring {
0028 std::string tag = "";
0029 JEventLevel level = JEventLevel::PhysicsEvent;
0030 std::vector<std::string> input_names = {};
0031 std::vector<JEventLevel> input_levels = {};
0032 std::vector<std::string> output_names = {};
0033 std::map<std::string, std::string> configs = {};
0034 };
0035
0036 public:
0037
0038 explicit JOmniFactoryGeneratorT() = default;
0039
0040 explicit JOmniFactoryGeneratorT(std::string tag,
0041 std::vector<std::string> input_names,
0042 std::vector<std::string> output_names,
0043 FactoryConfigType configs) {
0044 m_typed_wirings.push_back({.tag=tag,
0045 .input_names=input_names,
0046 .output_names=output_names,
0047 .configs=configs
0048 });
0049 };
0050
0051 explicit JOmniFactoryGeneratorT(std::string tag,
0052 std::vector<std::string> input_names,
0053 std::vector<std::string> output_names) {
0054 m_typed_wirings.push_back({.tag=tag,
0055 .input_names=input_names,
0056 .output_names=output_names
0057 });
0058
0059 }
0060
0061 explicit JOmniFactoryGeneratorT(TypedWiring&& wiring) {
0062 m_typed_wirings.push_back(std::move(wiring));
0063 }
0064
0065
0066 void AddWiring(std::string tag,
0067 std::vector<std::string> input_names,
0068 std::vector<std::string> output_names,
0069 FactoryConfigType configs) {
0070
0071 m_typed_wirings.push_back({.tag=tag,
0072 .input_names=input_names,
0073 .output_names=output_names,
0074 .configs=configs
0075 });
0076 }
0077
0078 void AddWiring(std::string tag,
0079 std::vector<std::string> input_names,
0080 std::vector<std::string> output_names,
0081 std::map<std::string, std::string> configs={}) {
0082
0083
0084 FactoryT factory;
0085 factory.ConfigureAllParameters(configs);
0086 auto configs_typed = factory.config();
0087
0088 m_typed_wirings.push_back({.tag=tag,
0089 .input_names=input_names,
0090 .output_names=output_names,
0091 .configs=configs_typed
0092 });
0093
0094 }
0095
0096 void AddWiring(TypedWiring wiring) {
0097 m_typed_wirings.push_back(wiring);
0098 }
0099
0100 void GenerateFactories(JFactorySet *factory_set) override {
0101
0102 for (const auto& wiring : m_typed_wirings) {
0103
0104 FactoryT *factory = new FactoryT;
0105 factory->SetApplication(GetApplication());
0106 factory->SetPluginName(this->GetPluginName());
0107 factory->SetTypeName(JTypeInfo::demangle<FactoryT>());
0108 factory->config() = wiring.configs;
0109
0110
0111
0112
0113 factory->PreInit(wiring.tag, wiring.level, wiring.input_names, wiring.input_levels, wiring.output_names);
0114
0115
0116 factory_set->Add(factory);
0117 }
0118 }
0119
0120 private:
0121 std::vector<TypedWiring> m_typed_wirings;
0122 };
0123
0124 }
0125 using jana::components::JOmniFactoryGeneratorT;