Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
main.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  */ // end group
41 
42 #include "cheetah/pipeline/CheetahConfig.h"
43 #include "cheetah/pipeline/BeamLauncher.h"
44 #include "cheetah/utils/TerminateException.h"
45 #include "cheetah/rcpt/UdpStream.h"
46 #include "cheetah/rcpt_low/UdpStream.h"
47 #include "cheetah/sigproc/SigProcFileStream.h"
48 #include "cheetah/psrdada/SigProcDadaStream.h"
49 #include "cheetah/pipeline/PipelineHandlerFactory.h"
50 #include "panda/MixInTimer.h"
51 
52 using namespace ska::cheetah;
53 
54 int main(int argc, char** argv) {
55 
56  int rv = 1; // program return value
57 
58  typedef uint8_t NumericalT;
59 
60  try {
61  // -- configuration setup --
63  pipeline::PipelineHandlerFactory pipeline_factory(config);
64  config.set_pipeline_handlers(pipeline_factory.available());
65 
66  // -- parse the command line --
67  if( (rv=config.parse(argc, argv)) ) return rv;
68 
69  // -- create computation unit to run --
70  std::function<pipeline::PipelineHandlerFactory::HandlerType*(pipeline::BeamConfig<NumericalT> const&)> runtime_handler_factory;
71  if(config.time_handler_invocation()) {
72  runtime_handler_factory = [&](pipeline::BeamConfig<NumericalT> const& beam_config) {
73  return pipeline_factory.create_timed(config.pipeline_name(), beam_config);
74  };
75  }
76  else {
77  runtime_handler_factory = [&](pipeline::BeamConfig<NumericalT> const& beam_config) {
78  return pipeline_factory.create(config.pipeline_name(), beam_config);
79  };
80  }
81 
82  // -- create and launch a suitable pipeline --
83 
84  std::string const& stream_name = config.stream_name();
85  if(stream_name == "sigproc") {
86  pipeline::BeamLauncher<sigproc::SigProcFileStream, NumericalT> beam( config.beams_config(), [&](pipeline::BeamConfig<NumericalT> const& config) -> sigproc::Config const& { return config.sigproc_config(); }, runtime_handler_factory);
87  rv = beam.exec();
88  config.pool_manager().wait();
89  }
90 #ifdef ENABLE_PSRDADA
91  else if(stream_name == "psrdada") {
92  pipeline::BeamLauncher<psrdada::SigProcDadaStream, NumericalT> beam( config.beams_config(), [&](pipeline::BeamConfig<NumericalT> const& config) -> psrdada::Config const& { return config.psrdada_config(); }, runtime_handler_factory);
93  rv = beam.exec();
94  config.pool_manager().wait();
95  }
96 #endif
97  else if(stream_name == "udp") {
98  pipeline::BeamLauncher<rcpt::UdpStream, NumericalT> beam( config.beams_config(), [&](pipeline::BeamConfig<NumericalT> const& config) -> rcpt::Config const& { return config.rcpt_config(); }, runtime_handler_factory);
99  rv = beam.exec();
100  config.pool_manager().wait();
101  }
102 
103  else if(stream_name == "udp_low") {
104  pipeline::BeamLauncher<rcpt_low::UdpStream, NumericalT> beam( config.beams_config(), [&](pipeline::BeamConfig<NumericalT> const& config) -> rcpt_low::Config const& { return config.rcpt_low_config(); }, runtime_handler_factory);
105  rv = beam.exec();
106  }
107 
108  else {
109  std::cerr << "unknown source '" << stream_name << "'" << std::endl;
110  }
111  }
112  catch(utils::TerminateException&) {
113  return 0; // terminate with success
114  }
115  catch(std::exception& e) {
116  std::cerr << e.what() << std::endl;
117  }
118 
119  return rv;
120 }
121 
SigProcDadaStream configuration parameters.
Definition: Config.h:90
MultiBeamConfig< NumericalRep > const & beams_config() const
return the configuration node with beam configurations
int exec()
launch the beam pipelines
configurable parameters for the rcpt
Definition: Config.h:42
SigProc configuration parameters.
Definition: Config.h:39
bool time_handler_invocation() const
wether to activte timing between each invocation of the runtime computational pipeline ...
int parse(int argc, char **argv)
parse the command line options/config file
PoolManagerType const & pool_manager() const
return the pool manager object
Parse configuration parameters for a single beam in the pipeline instance of cheetah.
Definition: BeamConfig.h:48
Generates pipeline handler objects by name.
std::string const & pipeline_name() const
return the selected pipeline name
configurable parameters for the rcpt
Definition: Config.h:42
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
Exception to indicate program should terminate, without an error.