Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DataExportTest.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/test/DataExportTest.h"
25 #include "cheetah/pipeline/DataExport.h"
26 #include "cheetah/exporters/SpCclFileStreamerConfig.h"
27 #include "cheetah/exporters/SpCclSigProc.h"
28 #include <panda/test/TestDir.h>
29 
30 
31 namespace ska {
32 namespace cheetah {
33 namespace pipeline {
34 namespace test {
35 
36 
37 DataExportTest::DataExportTest()
38  : ::testing::Test()
39 {
40 }
41 
42 DataExportTest::~DataExportTest()
43 {
44 }
45 
46 void DataExportTest::SetUp()
47 {
48 }
49 
50 void DataExportTest::TearDown()
51 {
52 }
53 
54 // wrapper to monitor calls to the operator()
55 template<class Sink>
56 struct SinkWrapper : public Sink
57 {
58  public:
59  template<typename... Args>
60  SinkWrapper(Args&&... args)
61  : Sink(std::forward<Args>(args)...)
62  , _test_call_count(0)
63  {
64  }
65 
66  template<typename Ret, typename... Args>
67  Ret operator()(Args&&... args) {
68  ++_test_call_count;
69  return Sink::operator()(std::forward<Args>(args)...);
70  }
71 
72  unsigned call_count() const {
73  return _test_call_count;
74  }
75 
76  private:
77  unsigned _test_call_count = 0;
78 
79 };
80 
81 TEST_F(DataExportTest, test_sink_spccl)
82 {
83  panda::test::TestDir dir;
84  dir.create();
87  sink_config.dir(dir.path());
88  std::string const sink_id = sink_config.id();
89  config.add_sink(sink_config);
90 
91  // set up channels
92  panda::ChannelId channel_id("active_channel_spccl");
93  panda::ChannelInfo channel_info(channel_id);
94  channel_info.activate(true);
95  channel_info.sink(sink_id);
96  config.channel(channel_info);
97 
98  panda::ChannelId inactive_channel_id("inactive_channel_spccl");
99  panda::ChannelInfo inactive_channel_info(inactive_channel_id);
100  inactive_channel_info.activate(false);
101  inactive_channel_info.sink(sink_id);
102  config.channel(inactive_channel_info);
103 
104  pipeline::DataExport<uint8_t> exporter(config);
105 
106  // set up spccl config node
107  std::shared_ptr<data::SpCcl<uint8_t>> data = data::SpCcl<uint8_t>::make_shared();
108  ASSERT_TRUE(exporter.is_active<data::SpCcl<uint8_t>>(channel_id));
109  exporter.send(channel_id, data);
110 
111  ASSERT_FALSE(exporter.is_active<data::SpCcl<uint8_t>>(inactive_channel_id));
112  exporter.send(inactive_channel_id, data);
113 }
114 
115 TEST_F(DataExportTest, test_sink_spccl_sigproc_with_data)
116 {
117  panda::test::TestDir dir;
118  dir.create();
120  exporters::SpCclSigProcConfig sink_config;
121  sink_config.dir(dir.path().string());
122  std::string const sink_id = sink_config.id();
123  config.add_sink(sink_config);
124 
125  //set up channels
126  panda::ChannelId channel_id("active_channel_spccl_sigproc");
127  panda::ChannelInfo channel_info(channel_id);
128  channel_info.activate(true);
129  channel_info.sink(sink_id);
130  config.channel(channel_info);
131 
132  pipeline::DataExport<uint8_t> exporter(config);
133 
134 // Generating data
135  typedef typename data::SpCcl<uint8_t>::TimeFrequencyType TimeFrequencyType;
136  data::TimeFrequency<Cpu, uint8_t>::TimeType interval(1.0 * boost::units::si::milli * boost::units::si::seconds);
137  data::SpCcl<uint8_t>::BlocksType blocks;
138  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(data::DimensionSize<data::Time>(100000)
139  ,data::DimensionSize<data::Frequency>(10));
140  (*block).sample_interval(interval);
141  //block->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
142  blocks.push_back(block);
143  blocks.push_back(std::make_shared<TimeFrequencyType>(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(10)));
144  data::SpCcl<uint8_t> d1(blocks);
145  typename data::SpCcl<uint8_t>::SpCandidateType::Dm dm(12.0 * data::parsecs_per_cube_cm);
146  //set the single pulse candidate width to 1.24 ms
147  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType width(0.001 * boost::units::si::seconds);
148  //set the single pulse start time to 2.23 seconds
149  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
150  //set the candidate significance
151  float sigma = 20.0;
152 
153  for (auto idx=0; idx<10; ++idx)
154  {
155  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
156  candidate.duration_end(2000 * boost::units::si::milli * boost::units::si::seconds);
157  d1.push_back(candidate);
158  tstart += data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(4.5 * boost::units::si::seconds);
159  }
160 
161  ASSERT_TRUE(exporter.is_active<data::SpCcl<uint8_t>>(channel_id));
162  exporter.send(channel_id, data::SpCcl<uint8_t>::make_shared(d1));
163 
164 
165  panda::ChannelId inactive_channel_id("inactive_channel_spccl_sigproc");
166  panda::ChannelInfo inactive_channel_info(inactive_channel_id);
167  inactive_channel_info.activate(false);
168  inactive_channel_info.sink(sink_id);
169  config.channel(inactive_channel_info);
170 
171  ASSERT_FALSE(exporter.is_active<data::SpCcl<uint8_t>>(inactive_channel_id));
172  exporter.send(inactive_channel_id, data::SpCcl<uint8_t>::make_shared(d1));
173 }
174 
175 TEST_F(DataExportTest, test_spccl_sigproc_sink_without_data)
176 {
177  panda::test::TestDir dir;
178  dir.create();
180  exporters::SpCclSigProcConfig sink_config;
181  sink_config.dir(dir.path().string());
182  std::string const sink_id = sink_config.id();
183  config.add_sink(sink_config);
184 
185  //set up channels
186  panda::ChannelId channel_id("active_channel_spccl_sigproc");
187  panda::ChannelInfo channel_info(channel_id);
188  channel_info.activate(true);
189  channel_info.sink(sink_id);
190  config.channel(channel_info);
191 
192  pipeline::DataExport<uint8_t> exporter(config);
193 
194  std::shared_ptr<data::SpCcl<uint8_t>> data = data::SpCcl<uint8_t>::make_shared();
195  ASSERT_TRUE(exporter.is_active<data::SpCcl<uint8_t>>(channel_id));
196  exporter.send(channel_id, data);
197 
198 
199  panda::ChannelId inactive_channel_id("inactive_channel_spccl_sigproc");
200  panda::ChannelInfo inactive_channel_info(inactive_channel_id);
201  inactive_channel_info.activate(false);
202  inactive_channel_info.sink(sink_id);
203  config.channel(inactive_channel_info);
204 
205  ASSERT_FALSE(exporter.is_active<data::SpCcl<uint8_t>>(inactive_channel_id));
206  exporter.send(inactive_channel_id, data);
207 
208 
209 }
210 
211 
212 } // namespace test
213 } // namespace pipeline
214 } // namespace cheetah
215 } // namespace ska
A simple record to hold &#39;candidate&#39; proprerties.
Definition: SpCandidate.h:58
void push_back(SpCandidateType const &cand)
Push back method for inserting Single pulse Candidates but without calculating tend They will be ins...
Definition: SpCcl.cpp:98
Configuration Object for DataExport module.
void channel(panda::ChannelInfo const &)
explicity add a channel configuration
boost::filesystem::path const & dir() const
get the directory specified to store files
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.
SpCandidate list.
Definition: SpCcl.h:52
void duration_end(MsecTimeType c_tend)
Set the end time The end time is calculated based on the DM of the candidate and the start and end f...
Definition: SpCandidate.cpp:98