Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
emulator_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
38 
39 #include "cheetah/rcpt_low/PacketGenerator.h"
40 #include "cheetah/rcpt/PacketGenerator.h"
41 #include "cheetah/data/TimeFrequency.h"
42 #include "cheetah/emulator/EmulatorAppConfig.h"
43 #include "cheetah/emulator/Factory.h"
44 #include "cheetah/emulator/Config.h"
45 #include "panda/BasicAppConfig.h"
46 #include "panda/Log.h"
47 #include <memory>
48 #include <ostream>
49 
50 template<typename PacketGeneratorType>
52 {
53  typedef typename PacketGeneratorType::SampleDataType NumericalRep;
55 
56  public:
57  template<typename EmulatorConfig, typename StreamConfig>
58  inline static
59  int run(EmulatorConfig const& config, StreamConfig&& stream_config) {
60  ska::cheetah::generators::GeneratorFactory<NumericalRep> generator_factory(config.generators_config());
61  FactoryType factory(config, generator_factory);
62  std::unique_ptr<typename FactoryType::EmulatorType> emulator(factory.create(config.generator(), std::forward<StreamConfig>(stream_config)));
63  PANDA_LOG << "emulator using generator: '" << config.generator() << "'";
64 
65  // start the emulator
66  return emulator->run();
67  }
68 };
69 
70 int main(int argc, char** argv)
71 {
72  ska::cheetah::emulator::EmulatorAppConfig app_config("cheetah_emulator", "UDP emulation for cheetah Beamformed Time-Frequecy data");
73  int rv;
74  try {
75 
76  ska::cheetah::emulator::Config& config = app_config.emulator_config();
78  app_config.set_generator_list(generator_factory.available());
79 
80  // parse command line options
81  if( (rv=app_config.parse(argc, argv)) ) return rv;
82 
83  // setup the emulator
84  auto stream_type=app_config.stream_type();
85  typedef ska::cheetah::emulator::EmulatorAppConfig::Stream Stream;
86  if(stream_type == Stream::SkaLow)
87  {
89  rv = EmulatorLauncher<StreamType>::run(config, config.ska_low_config());
90  }
91  if(stream_type == Stream::SkaMid)
92  {
94  rv = EmulatorLauncher<StreamType>::run(config, ska::cheetah::data::DimensionSize<ska::cheetah::data::Frequency>(config.number_of_channels()));
95  }
96 
97  return rv;
98  }
99  catch(std::exception const& e) {
100  std::cerr << "Emulator: " << e.what() << std::endl;;
101  }
102  catch(...) {
103  std::cerr << "Emulator: unknown exception caught" << std::endl;
104  }
105  return 1;
106 }
construct a suitable generatro object
Definition: GeneratorApp.h:38
Packs data into a UDP stream Packet Header format of the BeamFormer.
factory to construct emulators
Definition: Factory.h:45
cheetah::generators::Config const & generators_config() const
the configuration block for generators
Definition: Config.cpp:69
Packs data into a UDP stream Packet Header format of the BeamFormer.
Configuration options for the Emulator.
Definition: Config.h:50
Top level configuration for the emulator app.
Stream stream_type() const
the type of UDP stream to generate
std::size_t number_of_channels() const
the number of channels to generato
Definition: Config.cpp:84
void set_generator_list(std::vector< std::string > const &generator_names)
set the known generators