Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:22:17

0001 // Copyright 2023, Jefferson Science Associates, LLC.
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 // Created by Nathan Brei
0004 
0005 #pragma once
0006 
0007 /**
0008  * Omnifactories are a lightweight layer connecting JANA to generic algorithms
0009  * It is assumed multiple input data (controlled by input tags)
0010  * which might be changed by user parameters.
0011  */
0012 
0013 #include "JANA/Services/JParameterManager.h"
0014 #include "JANA/Utils/JEventLevel.h"
0015 #include <JANA/JEvent.h>
0016 #include <JANA/JMultifactory.h>
0017 #include <JANA/JVersion.h>
0018 
0019 #include <string>
0020 #include <vector>
0021 
0022 namespace jana::components {
0023 
0024 struct EmptyConfig {};
0025 
0026 template <typename AlgoT, typename ConfigT=EmptyConfig>
0027 class JOmniFactory : public JMultifactory {
0028 private:
0029 
0030     ConfigT m_config;
0031 
0032 public:
0033 
0034     inline void PreInit(std::string tag,
0035                         JEventLevel level,
0036                         std::vector<std::string> input_collection_names,
0037                         std::vector<JEventLevel> input_collection_levels,
0038                         std::vector<std::vector<std::string>> variadic_input_collection_names,
0039                         std::vector<JEventLevel> variadic_input_collection_levels, 
0040                         std::vector<std::string> output_collection_names,
0041                         std::vector<std::vector<std::string>> variadic_output_collection_names
0042                         ) {
0043 
0044         m_prefix = (this->GetPluginName().empty()) ? tag : this->GetPluginName() + ":" + tag;
0045         m_level = level;
0046 
0047         // Obtain logger
0048         m_logger = m_app->GetService<JParameterManager>()->GetLogger(m_prefix);
0049 
0050         // Obtain collection name overrides if provided.
0051         // Priority = [JParameterManager, JOmniFactoryGenerator]
0052         m_app->SetDefaultParameter(m_prefix + ":InputTags", input_collection_names, "Input collection names");
0053         m_app->SetDefaultParameter(m_prefix + ":OutputTags", output_collection_names, "Output collection names");
0054 
0055         WireInputs(level, input_collection_levels, input_collection_names, variadic_input_collection_levels, variadic_input_collection_names);
0056         WireOutputs(level, output_collection_names, variadic_output_collection_names, false);
0057 
0058         // Configure logger. Priority = [JParameterManager, system log level]
0059         // std::string default_log_level = eicrecon::LogLevelToString(m_logger->level());
0060         // m_app->SetDefaultParameter(m_prefix + ":LogLevel", default_log_level, "LogLevel: trace, debug, info, warn, err, critical, off");
0061         // m_logger->set_level(eicrecon::ParseLogLevel(default_log_level));
0062     }
0063 
0064     void Init() override {
0065         static_cast<AlgoT*>(this)->Configure();
0066     }
0067 
0068     void ChangeRun(const std::shared_ptr<const JEvent>& event) override {
0069         static_cast<AlgoT*>(this)->ChangeRun(event->GetRunNumber());
0070     }
0071 
0072     void ChangeRun(int32_t) override {};
0073 
0074     void Process(const std::shared_ptr<const JEvent> &event) override {
0075         static_cast<AlgoT*>(this)->Execute(event->GetRunNumber(), event->GetEventNumber());
0076     }
0077 
0078     using ConfigType = ConfigT;
0079 
0080     /// Retrieve reference to already-configured logger
0081     //std::shared_ptr<spdlog::logger> &logger() { return m_logger; }
0082     JLogger& logger() { return m_logger; }
0083 
0084     /// Retrieve reference to embedded config object
0085     ConfigT& config() { return m_config; }
0086 
0087 
0088     /// Generate summary for UI, inspector
0089     void Summarize(JComponentSummary& summary) const override {
0090 
0091         auto* mfs = new JComponentSummary::Component(
0092             "OmniFactory", GetPrefix(), GetTypeName(), GetLevel(), GetPluginName());
0093 
0094         SummarizeInputs(*mfs);
0095         SummarizeOutputs(*mfs);
0096         summary.Add(mfs);
0097     }
0098 
0099 };
0100 
0101 } // namespace jana::components
0102 
0103 using jana::components::JOmniFactory;
0104 
0105