File indexing completed on 2025-01-18 10:17:38
0001
0002
0003
0004
0005 #pragma once
0006
0007 #include <string>
0008 #include <atomic>
0009 #include <mutex>
0010 #include <memory>
0011 #include <chrono>
0012
0013 class JEventProcessor;
0014 class JEventSource;
0015 class JEventSourceGenerator;
0016 class JFactoryGenerator;
0017 class JFactorySet;
0018 class JComponentManager;
0019 class JPluginLoader;
0020 class JExecutionEngine;
0021 class JEventUnfolder;
0022 class JServiceLocator;
0023 class JParameter;
0024 class JParameterManager;
0025 class JApplication;
0026 extern JApplication* japp;
0027
0028 #include <JANA/Components/JComponentSummary.h>
0029 #include <JANA/JLogger.h>
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 class JApplication {
0043
0044 public:
0045
0046
0047
0048 enum class ExitCode {Success=0, UnhandledException, Timeout, Segfault=139};
0049
0050 explicit JApplication(JParameterManager* params = nullptr);
0051 explicit JApplication(JLogger::Level verbosity);
0052 ~JApplication();
0053
0054
0055
0056
0057 void AddPlugin(std::string plugin_name);
0058 void AddPluginPath(std::string path);
0059
0060
0061
0062
0063 void Add(std::string event_source_name);
0064 void Add(JEventSourceGenerator* source_generator);
0065 void Add(JFactoryGenerator* factory_generator);
0066 void Add(JEventSource* event_source);
0067 void Add(JEventProcessor* processor);
0068 void Add(JEventUnfolder* unfolder);
0069
0070
0071
0072
0073 void Initialize(void);
0074 void Run(bool wait_until_stopped=true, bool finish=true);
0075 void Scale(int nthreads);
0076 void Stop(bool wait_until_stopped=false, bool finish=true);
0077 void Inspect();
0078 void Quit(bool skip_join = false);
0079 void SetExitCode(int exitCode);
0080 int GetExitCode();
0081
0082
0083 void PrintStatus();
0084 bool IsInitialized(void){return m_initialized;}
0085 bool IsQuitting(void) { return m_quitting; }
0086 bool IsDrainingQueues();
0087
0088 void SetTicker(bool ticker_on = true);
0089 bool IsTickerEnabled();
0090 void SetTimeoutEnabled(bool enabled = true);
0091 bool IsTimeoutEnabled();
0092 uint64_t GetNThreads();
0093 uint64_t GetNEventsProcessed();
0094 float GetIntegratedRate();
0095 float GetInstantaneousRate();
0096
0097 const JComponentSummary& GetComponentSummary();
0098
0099
0100
0101 JParameterManager* GetJParameterManager() { return m_params.get(); }
0102
0103 template<typename T>
0104 T GetParameterValue(std::string name);
0105
0106 template <typename T>
0107 JParameter* GetParameter(std::string name, T& val);
0108
0109 template<typename T>
0110 JParameter* SetParameterValue(std::string name, T val);
0111
0112 template <typename T>
0113 JParameter* SetDefaultParameter(std::string name, T& val, std::string description="");
0114
0115 template <typename T>
0116 T RegisterParameter(std::string name, const T default_val, std::string description="");
0117
0118
0119
0120
0121
0122
0123 template <typename T>
0124 std::shared_ptr<T> GetService();
0125
0126
0127 template <typename T>
0128 void ProvideService(std::shared_ptr<T> service);
0129
0130
0131 private:
0132
0133 JLogger m_logger;
0134
0135 std::unique_ptr<JServiceLocator> m_service_locator;
0136
0137 std::shared_ptr<JParameterManager> m_params;
0138 std::shared_ptr<JPluginLoader> m_plugin_loader;
0139 std::shared_ptr<JComponentManager> m_component_manager;
0140 std::shared_ptr<JExecutionEngine> m_execution_engine;
0141
0142 bool m_inspecting = false;
0143 bool m_quitting = false;
0144 bool m_skip_join = false;
0145 std::atomic_bool m_initialized {false};
0146 std::atomic_bool m_services_available {false};
0147 int m_exit_code = (int) ExitCode::Success;
0148 int m_desired_nthreads;
0149 std::atomic_int m_sigint_count {0};
0150
0151
0152 std::mutex m_inst_rate_mutex;
0153 std::chrono::steady_clock::time_point m_last_measurement_time = std::chrono::steady_clock::now();
0154 size_t m_last_event_count = 0;
0155 };
0156
0157
0158
0159
0160
0161 inline void InitJANAPlugin(JApplication* app) {
0162
0163
0164 japp = app;
0165 }
0166
0167