ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup server
4 * @copyright ESO - European Southern Observatory
5 * @author
6 *
7 * @brief Config class header file.
8 */
9#ifndef SERVER_CONFIG_HPP_
10#define SERVER_CONFIG_HPP_
11
12#include <chrono>
13#include <optional>
14#include <string>
15
16#include <rad/config.hpp>
17
19#include <daq/dpmClient.hpp>
20
21namespace server {
22
23/**
24 * Rad configuration keys
25 */
26const std::string KEY_CONFIG_PUB_ENDPOINT = rad::KEY_CONFIG + "pub_endpoint";
27const std::string KEY_CONFIG_INSTRUMENT_ID = rad::KEY_CONFIG + "instrument_id";
28const std::string KEY_CONFIG_DATAROOT = rad::KEY_CONFIG + "dataroot";
29const std::string KEY_CONFIG_WORKSPACE = rad::KEY_CONFIG + "daq/workspace";
30const std::string KEY_CONFIG_STALE_DAQ_ACQUIRING = rad::KEY_CONFIG + "daq/stale_acquiring_hours";
31const std::string KEY_CONFIG_STALE_DAQ_MERGING = rad::KEY_CONFIG + "daq/stale_merging_hours";
32const std::string KEY_CONFIG_DICTIONARIES = rad::KEY_CONFIG + "dictionaries";
33
34const std::string KEY_CONFIG_DPM_REQ_ENDPOINT = rad::KEY_CONFIG + "dpm/req_endpoint";
35const std::string KEY_CONFIG_DPM_PUB_ENDPOINT = rad::KEY_CONFIG + "dpm/pub_endpoint";
36const std::string KEY_CONFIG_DPM_TIMEOUT_SEC = rad::KEY_CONFIG + "dpm/timeout_sec";
37
38/**
39 * Default application configuration values.
40 */
41const std::string CONFIG_DEFAULT_PROCNAME = "ocm";
42const std::string CONFIG_DEFAULT_FILENAME = "config/daqOcmServer/config.yaml";
43const std::string CONFIG_DEFAULT_WORKSPACE = "ocm";
44const std::string CONFIG_DEFAULT_SCXML_FILENAME = "config/daqOcmServer/sm.xml";
45const std::string CONFIG_DEFAULT_LOG_LEVEL = "WARN";
47const std::string CONFIG_DEFAULT_REQ_ENDPOINT = "zpb.rr://127.0.0.1:12081/";
48const std::string CONFIG_DEFAULT_PUB_ENDPOINT = "zpb.ps://127.0.0.1:12082/";
49const std::string CONFIG_DEFAULT_OLDB_URI_PREFIX = "cii.oldb:/elt";
51
52/**
53 * Application configuration environment variables
54 */
55const std::string CONFIG_ENVVAR_OUT_PATH = "DATAROOT";
56
57/**
58 * This class provide access to the command line options and
59 * the configuration parameters stored in the configuration file.
60 */
61class Config {
62public:
63 /**
64 * Default constructor.
65 *
66 * Initialize application configuration attributes by
67 * - first use the default constant values defined in the header
68 * - override the constant values with environment variables (if defined)
69 */
70 Config();
71
72 Config(const Config &) = delete; //! Disable copy constructor
73 Config &operator=(const Config &) = delete; //! Disable assignment operator
74
75 /**
76 * This method parses the command line parameters overriding
77 * the initialization done in the constructor.
78 *
79 * @param[in] argc Number of command line options.
80 * @param[in] argv Pointer to the array of command line options.
81 * @return false if the help option has been invoked, true otherwise.
82 */
83 bool ParseOptions(int argc, char *argv[]);
84
85 /**
86 * This method load from a configuration file the application
87 * configuration overriding the initialization done in the constructor
88 * and the command line options.
89 *
90 * @param[in] filename Application configuration filename.
91 */
92 void LoadConfig(const std::string &filename = "");
93
94 /**
95 * @return The network endpoint to send request to this application.
96 * The format is "<middleware>.<protocol>://<ipaddr>:<port>".
97 * For example: "zpb.rr://127.0.0.1:12081/"
98 */
99 const std::string &GetMsgReplierEndpoint() const;
100
101 /**
102 * @return The network endpoint used to publish topics from this application.
103 * The format is "<middleware>.<protocol>://<ipaddr>:<port>".
104 * For example: "zpb.ps://127.0.0.1:12082/"
105 */
106 const std::string &GetPubEndpoint() const;
107
108 /**
109 * @return The DB key prefix and port used to connect to the runtime DB.
110 */
111 const std::string &GetDbPrefix() const;
112
113 /**
114 * @return The timeout used when communicating to the runtime DB.
115 */
116 std::chrono::seconds GetDbTimeout() const;
117
118 /**
119 * @return The SCXML State Machine model filename used by the application.
120 */
121 const std::string &GetSmScxmlFilename() const;
122
123 /**
124 * @return The application configuration filename.
125 */
126 const std::string &GetConfigFilename() const;
127
128 /**
129 * @return The application process name.
130 */
131 const std::string &GetProcName() const;
132
133 /**
134 * @return The configured log level.
135 */
136 const std::string &GetLogLevel() const;
137
138 /**
139 * @return The log properties config filename.
140 */
141 const std::string &GetLogProperties() const;
142
143 /**
144 * @return List of keyword dictionaries.
145 */
146 std::vector<std::string> const& GetDictionaryNames() const;
147
148 /**
149 * @return Workspace root (absolute path)
150 */
151 std::filesystem::path GetWorkspace() const {
152 if (m_workspace.is_relative()) {
153 return m_out_path / m_workspace;
154 }
155 return m_workspace;
156 }
158 return m_mgr;
159 }
161
163 // We must delay initialization until logging has been configured, otherwise it spams
164 // the log.
165 std::optional<elt::configng::CiiConfigDocument> m_config;
166
167 std::string m_proc_name;
168 std::string m_instrument_id;
169 std::string m_log_level;
170 std::string m_log_properties;
171 std::string m_config_filename;
172 std::string m_scxml_filename;
173 std::string m_db_prefix;
175 std::string m_req_endpoint;
176 std::string m_pub_endpoint;
177 std::string m_out_path;
178 std::filesystem::path m_workspace;
180 std::chrono::hours m_stale_acquiring = std::chrono::hours(14);
181 std::chrono::hours m_stale_merging = std::chrono::hours(2 * 24);
182 std::vector<std::string> m_dictionary_names;
183};
184
185} // namespace server
186
187#endif // SERVER_CONFIG_HPP_
Maintains the associativity of configuration attributes with metadata and value origin/priority.
Definition: manager.hpp:161
This class provide access to the command line options and the configuration parameters stored in the ...
Definition: config.hpp:61
const std::string & GetLogLevel() const
Definition: config.cpp:335
std::filesystem::path GetWorkspace() const
Definition: config.hpp:151
std::string m_pub_endpoint
Definition: config.hpp:176
daq::DpmClientParams m_dpm_params
Definition: config.hpp:179
Config(const Config &)=delete
std::string m_out_path
Definition: config.hpp:177
const std::string & GetSmScxmlFilename() const
Definition: config.cpp:320
std::string m_log_properties
Definition: config.hpp:170
bool ParseOptions(int argc, char *argv[])
Disable assignment operator.
Definition: config.cpp:90
Config()
Default constructor.
Definition: config.cpp:39
daq::DpmClientParams const & GetDpmClientParams() const
Definition: config.cpp:349
const std::string & GetMsgReplierEndpoint() const
Definition: config.cpp:297
const std::string & GetConfigFilename() const
Definition: config.cpp:325
int m_db_timeout_sec
Definition: config.hpp:174
void LoadConfig(const std::string &filename="")
This method load from a configuration file the application configuration overriding the initializatio...
Definition: config.cpp:166
std::chrono::seconds GetDbTimeout() const
Definition: config.cpp:316
std::string m_proc_name
Definition: config.hpp:167
std::optional< elt::configng::CiiConfigDocument > m_config
Definition: config.hpp:165
std::chrono::hours m_stale_merging
Definition: config.hpp:181
std::string m_log_level
Definition: config.hpp:169
std::chrono::hours m_stale_acquiring
Definition: config.hpp:180
std::string m_instrument_id
Definition: config.hpp:168
const std::string & GetLogProperties() const
Definition: config.cpp:340
std::string m_req_endpoint
Definition: config.hpp:175
std::vector< std::string > m_dictionary_names
Definition: config.hpp:182
std::string m_config_filename
Definition: config.hpp:171
daq::config::Manager & GetMgr()
Definition: config.hpp:157
daq::config::Manager m_mgr
Definition: config.hpp:162
std::string m_db_prefix
Definition: config.hpp:173
std::filesystem::path m_workspace
Definition: config.hpp:178
const std::string & GetProcName() const
Definition: config.cpp:330
std::vector< std::string > const & GetDictionaryNames() const
Definition: config.cpp:345
const std::string & GetPubEndpoint() const
Definition: config.cpp:302
std::string m_scxml_filename
Definition: config.hpp:172
Config & operator=(const Config &)=delete
Disable copy constructor.
const std::string & GetDbPrefix() const
Definition: config.cpp:307
daq::config::Manager and associated types.
daq::DpmClient
Connection parameters for DPM.
Definition: dpmClient.hpp:93
const std::string CONFIG_DEFAULT_WORKSPACE
Definition: config.hpp:43
const std::string KEY_CONFIG_PUB_ENDPOINT
Rad configuration keys.
Definition: config.hpp:26
const std::string KEY_CONFIG_DPM_TIMEOUT_SEC
Definition: config.hpp:36
const std::string KEY_CONFIG_STALE_DAQ_ACQUIRING
Definition: config.hpp:30
const std::string CONFIG_DEFAULT_SCXML_FILENAME
Definition: config.hpp:44
const std::string KEY_CONFIG_DATAROOT
Definition: config.hpp:28
const std::string KEY_CONFIG_DICTIONARIES
Definition: config.hpp:32
const std::string CONFIG_DEFAULT_REQ_ENDPOINT
Definition: config.hpp:47
const std::string CONFIG_DEFAULT_OLDB_URI_PREFIX
Definition: config.hpp:49
const std::string KEY_CONFIG_DPM_PUB_ENDPOINT
Definition: config.hpp:35
const std::string KEY_CONFIG_WORKSPACE
Definition: config.hpp:29
const int CONFIG_DEFAULT_DB_TIMEOUT_SEC
Definition: config.hpp:46
const std::string CONFIG_DEFAULT_PUB_ENDPOINT
Definition: config.hpp:48
const std::string CONFIG_DEFAULT_LOG_LEVEL
Definition: config.hpp:45
const std::string KEY_CONFIG_INSTRUMENT_ID
Definition: config.hpp:27
const std::string CONFIG_ENVVAR_OUT_PATH
Application configuration environment variables.
Definition: config.hpp:55
const std::string CONFIG_DEFAULT_PROCNAME
Default application configuration values.
Definition: config.hpp:41
const std::string CONFIG_DEFAULT_FILENAME
Definition: config.hpp:42
const std::string KEY_CONFIG_STALE_DAQ_MERGING
Definition: config.hpp:31
const int CONFIG_DEFAULT_OLDB_CONN_TIMEOUT
Definition: config.hpp:50
const std::string KEY_CONFIG_DPM_REQ_ENDPOINT
Definition: config.hpp:34