Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DataExport.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/data/TimeFrequency.h"
25 #include "cheetah/pipeline/DataExport.h"
26 #include "cheetah/sigproc/SigProcWriter.h"
27 #include "cheetah/exporters/OcldFileStreamer.h"
28 #include "cheetah/exporters/SclFileStreamer.h"
29 #include "cheetah/exporters/SpCandidateDataStreamer.h"
30 #include "cheetah/exporters/SpCclFileStreamer.h"
31 #include "cheetah/exporters/SpCclSpeadStreamer.h"
32 #include "cheetah/exporters/SpCclSigProc.h"
33 #include <panda/Log.h>
34 #include <map>
35 #include <memory>
36 #include <iostream>
37 #include <functional>
38 #include <utility>
39 
40 namespace ska {
41 namespace cheetah {
42 namespace pipeline {
43 
44 
45 template<typename T>
47  void operator()(T const&) {
48  PANDA_LOG << "streamer called";// << t;
49  }
50 };
51 
52 /*
53  * Use a shared_ptr pimpl idiom for Writers that have a deleted copy/move constructor
54  */
55 template<typename WriterType, typename T>
57  public:
58  // pass through constructor - only enabled if the first Argument does not match typical signatures for the normal
59  // constructors of DataExportStreamWrapper
60  template<typename Arg1>
61  DataExportStreamWrapper(Arg1&& arg1, typename std::enable_if<!std::is_same<typename std::decay<Arg1>::type, DataExportStreamWrapper>::value, int >::type* = nullptr )
62  : _writer(new WriterType(std::forward<Arg1>(arg1))) {}
63 
65  DataExportStreamWrapper(DataExportStreamWrapper&& s) : _writer(std::move(s._writer)) {}
66 
67  inline
68  void operator()(T const& t) const {
69  *_writer << t;
70  }
71 
72  private:
73  std::shared_ptr<WriterType> _writer;
74 };
75 
76 template<typename T, typename HeaderType>
78  public:
80  : _writer(new sigproc::SigProcWriter<HeaderType>(config)) {}
81 
82  SigProcStreamer(SigProcStreamer const&) = default;
83  SigProcStreamer(SigProcStreamer&& s) : _writer(std::move(s._writer)) {}
84 
85  inline
86  void operator()(T const& t) const {
87  *_writer << t;
88  }
89 
90  private:
91  std::shared_ptr<sigproc::SigProcWriter<HeaderType>> _writer;
92 };
93 
94 template<typename T>
95 struct SpsCandidateStreamer : public DataExportStreamWrapper<exporters::SpCclFileStreamer<typename T::TimeFrequencyType::DataType>, T>
96 {
98 
99  public:
101  : BaseT(config)
102  {
103  }
104 };
105 
106 template<typename T>
107 struct SpsCandidateDataStreamer : public DataExportStreamWrapper<exporters::SpCandidateDataStreamer<typename T::TimeFrequencyType>, T>
108 {
110 
111  public:
113  : BaseT(config)
114  {
115  }
116 };
117 
118 #ifdef ENABLE_SPEAD
119 template<typename T>
120 struct SpsCandidateSpeadStreamer
121 {
122  typedef exporters::SpCclSpeadStreamer WriterType;
123 
124  public:
125  SpsCandidateSpeadStreamer(exporters::SpCclSpeadStreamerConfig const& config, panda::Engine& engine)
126  : _writer(new WriterType(config, engine))
127  {
128  }
129 
130  inline
131  void operator()(T const& t) const {
132  *_writer << t;
133  }
134 
135 
136  private:
137  std::shared_ptr<WriterType> _writer;
138 };
139 #endif //ENABLE_SPEAD
140 
141 template<typename T>
142 struct SiftedCandidateStreamer : public DataExportStreamWrapper<exporters::SclFileStreamer, T>
143 {
145 
147  : BaseT(config)
148  {
149  }
150 };
151 
152 template<typename T>
153 struct SpCclSigProcStreamer : public DataExportStreamWrapper<exporters::SpCclSigProc<typename T::TimeFrequencyType::DataType>, T>
154 {
156 
158  : BaseT(config)
159  {
160  }
161 };
162 
163 template<typename T>
164 struct OptimisedCandidateStreamer : public DataExportStreamWrapper<exporters::OcldFileStreamer, T>
165 {
167 
169  : BaseT(config)
170  {
171  }
172 };
173 
174 template<typename NumRep, typename ExportTraits>
176  : BaseT(config)
177 {
178  // n.b for each factory that takes a configuration add the configuration to pipeline/DataConfig.cpp
179  typedef data::TimeFrequency<Cpu, NumRep> TimeFrequencyType;
180  this->template set_factory<TimeFrequencyType>(exporters::ExporterType("cout"),
182  this->template set_factory<data::TimeFrequency<Cpu, NumRep>>(exporters::ExporterType("sigproc"), [](exporters::DataExportStreamConfig const& c)
183  {
185  }
186  );
187  this->template set_factory<rfim::ampp::Spectrum<NumRep>>(exporters::ExporterType("sigproc"), [](exporters::DataExportStreamConfig const& c)
188  {
189  return SigProcStreamer<rfim::ampp::Spectrum<NumRep>, typename ExportTraits::SigProcHeader>(static_cast<sigproc::WriterConfig const&>(c.sink_config()));
190  }
191  );
192  this->template set_factory<data::SpCcl<NumRep>>(exporters::ExporterType("spccl_files"),
194  {
195  return SpsCandidateStreamer<data::SpCcl<NumRep>>(static_cast<exporters::SpCclFileStreamerConfig const&>(c.sink_config()));
196  }
197  );
198 #ifdef ENABLE_SPEAD
199  this->template set_factory<data::SpCcl<NumRep>>(exporters::ExporterType("spccl_spead"),
201  {
202  return SpsCandidateSpeadStreamer<data::SpCcl<NumRep>>(static_cast<exporters::SpCclSpeadStreamerConfig const&>(c.sink_config()), c.engine());
203  }
204  );
205 #endif // ENABLE_SPEAD
206  this->template set_factory<data::SpCandidateData<TimeFrequencyType>>(exporters::ExporterType("sp_candidate_data"),
208  {
210  }
211  );
212  this->template set_factory<data::Ocld>(exporters::ExporterType("ocld_files"),
214  {
215  return OptimisedCandidateStreamer<data::Ocld>(static_cast<exporters::OcldFileStreamerConfig const&>(c.sink_config()));
216  }
217  );
218  this->template set_factory<data::Scl>(exporters::ExporterType("scl_files"),
220  {
221  return SiftedCandidateStreamer<data::Scl>(static_cast<exporters::SclFileStreamerConfig const&>(c.sink_config()));
222  }
223  );
224  this->template set_factory<data::SpCcl<NumRep>>(exporters::ExporterType("spccl_sigproc_files"),
226  {
227  return SpCclSigProcStreamer<data::SpCcl<NumRep>>(static_cast<exporters::SpCclSigProcConfig const&>(c.sink_config()));
228  }
229  );
230 
231  this->init();
232 }
233 
234 template<typename NumRep, typename ExportTraits>
236 {
237 }
238 
239 } // namespace pipeline
240 } // namespace cheetah
241 } // namespace ska
Configuration settings for the Ocld file Streamer object.
Configuration Object for DataExport module.
Defines the mapping of a sinks configuration block with the sink type, and the channel to associate i...
Configuration options for a SigProcWriter.
Definition: WriterConfig.h:41
A configuration class for the dynamic spectrum of single pulse candidates.
Some limits and constants for FLDO.
Definition: Brdz.h:35
User Configuration of the SpCclStreamer.
Configuration settings for the Scl file Streamer object.
string based tag for refering to the type of Exporter, based on a std::string
Definition: ExporterType.h:36
Writes data types to a sigproc format file.
Definition: SigProcWriter.h:45