Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
CheetahConfig.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/pipeline/CheetahConfig.h"
25 #include "cheetah/version.h"
26 #include "panda/ConfigFile.h"
27 #include "panda/Log.h"
28 #include "panda/PropertyTreeUtils.h"
29 #include <boost/filesystem.hpp>
30 #include <boost/property_tree/xml_parser.hpp>
31 #include <iostream>
32 
33 namespace ska {
34 namespace cheetah {
35 namespace pipeline {
36 
37 template<typename NumericalRep>
38 CheetahConfig<NumericalRep>::CheetahConfig(std::string const& app_name)
39  : utils::Config("")
40  , _desc("Generic Options")
41  , _app_name(app_name)
42  , _system(utils::system())
43  , _stream_name("sigproc")
44  , _handler_timing(false)
45  , _pool_manager(_system, _pool_manager_config)
46  , _acceleration_search_config(_pool_manager)
47  , _fldo_config(_pool_manager)
48  , _rfim_config(_pool_manager)
49  , _sift_config(_pool_manager)
50  , _sps_config(_pool_manager)
51 {
52  // generic options
53  _desc.add_options()
54  //("config,c", boost::program_options::value<std::string>(), "specify the configuration file")
55  ("help,h", "this help message")
56  ("help-config-file", "information about the configuration file and its format")
57  ("help-module", boost::program_options::value<std::vector<std::string>>(), "display help message for the specified modules (see --list-modules)")
58  ("timer", "record execution time for each invocation of the computation part of the pipeline")
59  ("input-stream,s", boost::program_options::value<std::string>()->default_value("sigproc")->required(), "select the input stream for the pipeline (see list-sources)")
60  ("log-level", boost::program_options::value<std::vector<std::string>>()->notifier(
61  [](std::vector<std::string> const& levels) {
62  for(auto const& level : levels) {
63  if(level == "debug") {
64  panda::log_debug.enable(true);
65  }
66  else if(level == "error") {
67  panda::log_error.enable(true);
68  panda::log_warn.enable(false);
69  panda::log.enable(false);
70  }
71  else if(level == "warn") {
72  panda::log_warn.enable(true);
73  panda::log.enable(false);
74  }
75  else if(level == "log") {
76  panda::log_error.enable(true);
77  panda::log_warn.enable(true);
78  panda::log.enable(true);
79  }
80  }
81  }
82  ), "set the level of logging (error, warn, log,debug)")
83  ("list-sources", "list the available input streams for the pipeline and exit")
84  ("list-pipelines", "list the available computational pipelines and exit")
85  ("list-modules", "a list of the configurable modules (see --help-module)")
86  ("pipeline,p", boost::program_options::value<std::string>(&_pipeline_name), "specify the computational pipeline to run (see list-pipelines)")
87  ("config", boost::program_options::value<std::string>(), "specify a configuration file (see --help-configuration-file)")
88  ("version", "print out the program version and exit")
89  ;
90 
91  _options_pod.add("config", 1);
92 
93  // module options
94  add(_pool_manager_config);
95  add(_acceleration_search_config);
96  add(_beam_config);
97  add(_channel_mask_config);
98  add(_fldo_config);
99  add(_psbc_config);
100  add(_rfim_config);
101  add(_scan_config);
102  add(_sift_config);
103  add(_sps_config);
104  add(_spsift_config);
105  add(_sps_clustering_config);
106  add(_empty_config);
107  _all_desc.add(_desc);
108  _all_desc.add(command_line_options());
109 
110  // setup switch (we do not allow these to be user selected)
111  panda::ProcessingEngineConfig engine_config;
112  engine_config.number_of_threads(2);
113  _switch_config.set_engine_config(engine_config);
114 }
115 
116 template<typename NumericalRep>
117 CheetahConfig<NumericalRep>::~CheetahConfig()
118 {
119 }
120 
121 template<typename NumericalRep>
122 void CheetahConfig<NumericalRep>::add_options(OptionsDescriptionEasyInit& )
123 {
124 }
125 
126 template<typename NumericalRep>
128 {
129  return cheetah::version;
130 }
131 
132 template<typename NumericalRep>
134 {
135  return _stream_name;
136 }
137 
138 template<typename NumericalRep>
140 {
141  return _pipeline_name;
142 }
143 
144 template<typename NumericalRep>
146 {
147  return _handler_timing;
148 }
149 
150 template<typename NumericalRep>
151 void CheetahConfig<NumericalRep>::set_pipeline_handlers(std::vector<std::string> const& handler_names)
152 {
153  _pipeline_handler_names = handler_names;
154 }
155 
156 template<typename NumericalRep>
157 int CheetahConfig<NumericalRep>::parse(int argc, char** argv)
158 {
159  if(argc > 0) _app_name= boost::filesystem::basename(argv[0]);
160 
161  // parse the command line
162  boost::program_options::variables_map vm;
163  boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
164  .options(_all_desc)
165  .positional(_options_pod)
166  .run(), vm);
167 
168  if( vm.count("version") ) {
169  std::cout << version() << "\n";
170  return 1;
171  }
172  if( vm.count("help") ) {
173  std::cout << "Name\n\t" << _app_name << " - cheetah pipeline launcher\n\n";
174  std::cout << "Synopsis\n\t" << _app_name << " [OPTIONS] [config_file]\n\n";
175  std::cout << "\tA source and a pipeline must be specfied as a minimum, either through the" << "\n";
176  std::cout << "\toptions or through the config file (--help-config-file).\n" << "\n";
177  std::cout << "\tModule specific help can be accessed via the --help-module flag.\n" << "\n";
178  std::cout << _desc << "\n";
179  return 1;
180  }
181  if( vm.count("help-config-file") ) {
182  std::cout << "Name\n\t" << _app_name << " - cheetah pipeline launcher config files\n\n";
183  std::cout << "Description\n\tconfig files should be in XML format and the filename should have the .xml extension." << "\n";
184  std::cout << "\tAny command line option can be set in the config file using the long name of the option as a tag." << "\n";
185  std::cout << "\tAll tags must be enclosed in the <cheetah> tag scope.\n" << "\n";
186  boost::property_tree::ptree cheetah_config_pt;
187  cheetah_config_pt.put_child("cheetah", config_tree());
188 #if BOOST_VERSION < 105600
189  boost::property_tree::write_xml(std::cout, cheetah_config_pt,boost::property_tree::xml_writer_make_settings(' ', 2));
190 #else
191  boost::property_tree::write_xml(std::cout, cheetah_config_pt,boost::property_tree::xml_writer_make_settings<std::string>(' ', 2));
192 #endif
193  std::cout << "\n";
194  return 1;
195  }
196  if( vm.count("list-modules") ) {
197  for( auto const& mod : subsections() ) {
198  std::cout << mod << "\n";
199  }
200  return 1;
201  }
202  if( vm.count("list-sources") ) {
203  // list the streams
204  std::vector<std::string> s {"sigproc", "udp", "udp_low"};
205 #ifdef ENABLE_PSRDADA
206  s.push_back("psrdada");
207 #endif // ENABLE_PSRDADA
208  for( auto stream : s ) {
209  std::cout << stream << "\n";
210  }
211  return 1;
212  }
213  if( vm.count("list-pipelines") ) {
214  // list the pipelines
215  for( auto pipeline : _pipeline_handler_names ) {
216  std::cout << pipeline << "\n";
217  }
218  return 1;
219  }
220  if( vm.count("config") ) {
221  // configuration file specified
222  panda::ConfigFile config_file(vm["config"].as<std::string>());
223  try {
224  config_file.parse();
225  } catch(std::exception const& e) {
226  PANDA_LOG_ERROR << "exception parsing config file: " << vm["config"].as<std::string>() << " " << e.what();;
227  throw;
228  } catch(...) {
229  PANDA_LOG_ERROR << "exception parsing config file: " << vm["config"].as<std::string>();
230  throw;
231  }
232  // <cheetah> section corresponds to generic options
233  auto top_it = config_file.property_tree().find("cheetah");
234  if(top_it != config_file.property_tree().not_found() ) {
235  boost::program_options::store(panda::parse_property_tree<char>(top_it->second, _desc), vm);
236  parse_property_tree(top_it->second, vm);
237  }
238  }
239  // n/b must come after config file to pick up dynamic options
240  if( vm.count("help-module") ) {
241  for(auto const& module : vm["help-module"].as<std::vector<std::string>>() ) {
242  std::cout << "Name\n\t" << _app_name << " - cheetah pipeline launcher module : " << module << "\n\n";
243  std::cout << help(module) << "\n";
244  }
245  return 1;
246  }
247  if( vm.count("input-stream") ) {
248  _stream_name = vm["input-stream"].as<std::string>();
249  }
250  if( vm.count("timer") ) {
251  _handler_timing = true;
252  }
253 
254  boost::program_options::notify(vm);
255 
256  return 0;
257 }
258 
259 template<typename NumericalRep>
261 {
262  return _beam_config;
263 }
264 
265 // Get a non-const version of the templated acceleration search config from the CheetahConfig
266 template<typename NumericalRep>
268 {
269  return _acceleration_search_config;
270 }
271 
272 // Get a const version of the templated acceleration search config from the CheetahConfig
273 template<typename NumericalRep>
275 {
276  return _acceleration_search_config;
277 }
278 
279 template<typename NumericalRep>
281 {
282  return _channel_mask_config;
283 }
284 
285 template<typename NumericalRep>
287 {
288  return _channel_mask_config;
289 }
290 
291 template<typename NumericalRep>
292 fldo::ConfigType const& CheetahConfig<NumericalRep>::fldo_config() const
293 {
294  return _fldo_config;
295 }
296 
297 template<typename NumericalRep>
299 {
300  return _fldo_config;
301 }
302 
303 template<typename NumericalRep>
305 {
306  return _psbc_config;
307 }
308 
309 template<typename NumericalRep>
311 {
312  return _psbc_config;
313 }
314 
315 template<typename NumericalRep>
316 rfim::ConfigType<typename CheetahConfig<NumericalRep>::PoolManagerType> const& CheetahConfig<NumericalRep>::rfim_config() const
317 {
318  return _rfim_config;
319 }
320 
321 template<typename NumericalRep>
322 sift::ConfigType const& CheetahConfig<NumericalRep>::sift_config() const
323 {
324  return _sift_config;
325 }
326 
327 template<typename NumericalRep>
329 {
330  return _sift_config;
331 }
332 
333 template<typename NumericalRep>
335 {
336  return _spsift_config;
337 }
338 
339 template<typename NumericalRep>
341 {
342  return _sps_clustering_config;
343 }
344 template<typename NumericalRep>
345 sps::ConfigType<typename CheetahConfig<NumericalRep>::PoolManagerType> const& CheetahConfig<NumericalRep>::sps_config() const
346 {
347  return _sps_config;
348 }
349 
350 template<typename NumericalRep>
351 sps::ConfigType<typename CheetahConfig<NumericalRep>::PoolManagerType>& CheetahConfig<NumericalRep>::sps_config()
352 {
353  return _sps_config;
354 }
355 
356 template<typename NumericalRep>
357 panda::DataSwitchConfig& CheetahConfig<NumericalRep>::switch_config() const
358 {
359  return _switch_config;
360 }
361 
362 template<typename NumericalRep>
363 panda::PoolManagerConfig<utils::Config::SystemType> const& CheetahConfig<NumericalRep>::pool_manager_config() const
364 {
365  return _pool_manager_config;
366 }
367 
368 template<typename NumericalRep>
369 typename CheetahConfig<NumericalRep>::PoolManagerType const& CheetahConfig<NumericalRep>::pool_manager() const
370 {
371  return _pool_manager;
372 }
373 
374 template<typename NumericalRep>
375 typename CheetahConfig<NumericalRep>::PoolManagerType& CheetahConfig<NumericalRep>::pool_manager()
376 {
377  return _pool_manager;
378 }
379 
380 template<typename NumericalRep>
382 {
383  return _empty_config;
384 }
385 
386 } // namespace pipeline
387 } // namespace cheetah
388 } // namespace ska
sift::ConfigType const & sift_config() const
return the sift module specific configuration parameters
Parse configuration parameters for a cheetah pipeline application.
Definition: CheetahConfig.h:67
MultiBeamConfig< NumericalRep > const & beams_config() const
return the configuration node with beam configurations
bool time_handler_invocation() const
wether to activte timing between each invocation of the runtime computational pipeline ...
panda::DataSwitchConfig & switch_config() const
return the data switch configuration parameters
rfim::ConfigType< PoolManagerType > const & rfim_config() const
return the rfim module specific configuration parameters
Configuration for the Configurable ChannelMask module.
Configuration parameters for the available acceleration searches.
psbc::Config const & psbc_config() const
return the psbc module specific configuration parameters
int parse(int argc, char **argv)
parse the command line options/config file
AccelerationSearchAlgoConfig & acceleration_search_config()
return the templated acceleration search configuration
Some limits and constants for FLDO.
Definition: Brdz.h:35
panda::PoolManagerConfig< utils::Config::SystemType > const & pool_manager_config() const
return the data switch configuration parameters
PoolManagerType const & pool_manager() const
return the pool manager object
sps::ConfigType< PoolManagerType > const & sps_config() const
return the sps module specific configuration parameters
EmptyConfig const & empty_config() const
return the empty module specific configuration parameters
fldo::ConfigType const & fldo_config() const
return the fldo module specific configuration parameters
std::string const & pipeline_name() const
return the selected pipeline name
std::string version() const
return the cheetah version as a string
void set_pipeline_handlers(std::vector< std::string > const &handler_names)
set the computational unit names available
std::string const & stream_name() const
return the selected stream name
Configuration for the data collection buffer.
Definition: Config.h:41
channel_mask::ConfigurableChannelMaskConfig< NumericalRep > const & channel_mask_config() const
return the channel_mask configuration