Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:38

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #pragma once
0006 #include <JANA/JApplicationFwd.h>
0007 
0008 #include <JANA/Services/JServiceLocator.h>
0009 #include <JANA/Services/JParameterManager.h>
0010 
0011 
0012 /// A convenience method which delegates to JParameterManager
0013 template<typename T>
0014 T JApplication::GetParameterValue(std::string name) {
0015     return m_params->GetParameterValue<T>(name);
0016 }
0017 
0018 /// A convenience method which delegates to JParameterManager
0019 template<typename T>
0020 JParameter* JApplication::SetParameterValue(std::string name, T val) {
0021     if (m_initialized) {
0022         throw JException("SetParameterValue() must be called before Initialize(), as otherwise the parameter value won't be used!");
0023     }
0024     return m_params->SetParameter(name, val);
0025 }
0026 
0027 template <typename T>
0028 JParameter* JApplication::SetDefaultParameter(std::string name, T& val, std::string description) {
0029     return m_params->SetDefaultParameter(name.c_str(), val, description);
0030 }
0031 
0032 template <typename T>
0033 T JApplication::RegisterParameter(std::string name, const T default_val, std::string description) {
0034     return m_params->RegisterParameter(name.c_str(), default_val, description);
0035 }
0036 
0037 template <typename T>
0038 JParameter* JApplication::GetParameter(std::string name, T& result) {
0039     return m_params->GetParameter(name, result);
0040 }
0041 
0042 /// A convenience method which delegates to JServiceLocator
0043 template <typename T>
0044 std::shared_ptr<T> JApplication::GetService() {
0045     if (!m_services_available) {
0046         LOG_WARN(m_logger) << "GetService() called before Initialize(): Any parameter values set after this point won't be used!" << LOG_END;
0047         // Eventually, GetService() could trigger Initialize() just like Run() does. 
0048         // In order to make this happen, JTopologyBuilder needs modification.
0049         // The blockers are SubeventExample, TopologyTests, SubeventTests
0050         //throw JException("Application needs initialization before services become available");
0051     }
0052     return m_service_locator->get<T>();
0053 }
0054 
0055 /// A convenience method which delegates to JServiceLocator
0056 template <typename T>
0057 void JApplication::ProvideService(std::shared_ptr<T> service) {
0058     if (m_initialized) {
0059         throw JException("Services need to be provided before JApplication::Initialize(), or inside InitPlugin()");
0060     }
0061     service->SetApplication(this);
0062     m_service_locator->provide(service);
0063 }
0064 
0065 
0066