Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpCclSpeadStreamerTest.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/exporters/test/SpCclSpeadStreamerTest.h"
25 #include "cheetah/exporters/SpCclSpeadStreamer.h"
26 #include "cheetah/exporters/SpCclSpeadReader.h"
27 #include "cheetah/utils/ModifiedJulianClock.h"
28 #include <vector>
29 
30 
31 namespace ska {
32 namespace cheetah {
33 namespace exporters {
34 namespace test {
35 
36 
37 template<typename T>
38 SpCclSpeadStreamerTest<T>::SpCclSpeadStreamerTest()
39  : ::testing::Test()
40 {
41 }
42 
43 template<typename T>
44 SpCclSpeadStreamerTest<T>::~SpCclSpeadStreamerTest()
45 {
46 }
47 
48 template<typename T>
49 void SpCclSpeadStreamerTest<T>::SetUp()
50 {
51 }
52 
53 template<typename T>
54 void SpCclSpeadStreamerTest<T>::TearDown()
55 {
56 }
57 
58 template<typename TimeFrequencyType>
59 class TestExporter {
60  public:
61  TestExporter(SpCclSpeadStreamerConfig const& config, SpCclSpeadReaderConfig const& reader_config)
62  : _engine(1)
63  , _writer(config, _engine)
64  , _reader_config(reader_config)
65  , _reader(reader_config, [this](std::shared_ptr<data::SpCandidateData<TimeFrequencyType>> const& d)
66  {
67  _rdata.push_back(d);
68  }
69  )
70  , _expected(1)
71  {
72  _reader.start();
73  }
74 
75  template<typename T>
76  TestExporter& operator<<(data::SpCcl<T> const& data) {
77  _writer << data;
78  return *this;
79  }
80 
81  // returns the next received chunk, blocking
83  {
84  // wait for data transfer
85  while(_rdata.size() < _expected || _rdata[_expected-1].get() == nullptr) {
86  _reader_config.engine().poll_one();
87  }
88  ++_expected;
89  return *_rdata[_expected -2];
90  }
91 
92  private:
93  panda::ProcessingEngine _engine;
94  exporters::SpCclSpeadStreamer _writer;
95  SpCclSpeadReaderConfig const& _reader_config;
96  SpCclSpeadReader<TimeFrequencyType, std::function<void(std::shared_ptr<data::SpCandidateData<TimeFrequencyType>> const&)>> _reader;
97  std::vector<std::shared_ptr<data::SpCandidateData<TimeFrequencyType>>> _rdata;
98  std::size_t _expected;
99 };
100 
101 TYPED_TEST(SpCclSpeadStreamerTest, test_construct_destruct_without_using)
102 {
103  panda::ProcessingEngine engine(1);
105  exporters::SpCclSpeadStreamer writer(config, engine);
106 }
107 
108 TYPED_TEST(SpCclSpeadStreamerTest, test_send_single_candidate)
109 {
110  typedef TypeParam NumericalRep;
111  typedef data::SpCcl<NumericalRep> SpCclType;
112  typedef typename SpCclType::TimeFrequencyType TimeFrequencyType;
113  typedef typename SpCclType::SpCandidateType Candidate;
114 
115  // set up the data
116  typename utils::ModifiedJulianClock::time_point start_time(utils::julian_day(2458179.500000));
117 
118  typename SpCclType::BlocksType blocks;
119  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(
120  data::DimensionSize<data::Time>(1000)
121  , data::DimensionSize<data::Frequency>(10));
122 
123  block->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
124  block->sample_interval(0.001 * boost::units::si::seconds);
125  blocks.push_back(block);
126  blocks.push_back(std::make_shared<TimeFrequencyType>( data::DimensionSize<data::Time>(100)
127  , data::DimensionSize<data::Frequency>(10)));
128 
129  std::shared_ptr<data::SpCcl<NumericalRep>> data(new data::SpCcl<NumericalRep>(blocks));
130 
131  std::size_t cand_duration = 40; // number of bins candidate covers
132  typename Candidate::MsecTimeType cand1_tend(cand_duration * block->sample_interval());
133  typename Candidate::Dm cand1_dm(00.0 * data::parsecs_per_cube_cm);
134  Candidate candidate_1( cand1_dm
135  , typename Candidate::MsecTimeType(0.0 * boost::units::si::seconds)
136  , typename Candidate::MsecTimeType(0.001 * boost::units::si::seconds)
137  , cand1_tend
138  , 2.0
139  );
140  data->push_back(candidate_1);
141 
142  // send and recieve the data
144  SpCclSpeadReaderConfig reader_config;
145  TestExporter<TimeFrequencyType> exporter(config, reader_config);
146  exporter << *data;
147 
148  auto const& rdata = exporter.get();
149 
150  // verify reception
151  // data
152  ASSERT_LE(rdata.data_size(), data->tf_blocks()[0]->data_size());
153  ASSERT_EQ(rdata.number_of_channels(), block->number_of_channels());
154  ASSERT_EQ(rdata.sample_interval(), block->sample_interval());
155  ASSERT_EQ(rdata.number_of_spectra(), cand_duration);
156 
157  // candidates
158  ASSERT_EQ(rdata.number_of_candidates(), data->size());
159  for(std::size_t i=0; i< rdata.number_of_candidates(); ++i) {
160  ASSERT_EQ((rdata).candidate(i).dm(), (*data)[i].dm());
161  ASSERT_EQ((rdata).candidate(i).sigma(), (*data)[i].sigma());
162  ASSERT_EQ((rdata).candidate(i).width(), (*data)[i].width());
163  ASSERT_EQ((rdata).candidate(i).duration(), (*data)[i].tend());
164  }
165  ASSERT_EQ((rdata).candidate(0).start_time(), block->start_time());
166 }
167 
168 TYPED_TEST(SpCclSpeadStreamerTest, test_send_single_candidate_across_blocks)
169 {
170  typedef TypeParam NumericalRep;
171  typedef data::SpCcl<NumericalRep> SpCclType;
172  typedef typename SpCclType::TimeFrequencyType TimeFrequencyType;
173  typedef typename SpCclType::SpCandidateType Candidate;
174 
175  // set up the data
176  typename utils::ModifiedJulianClock::time_point start_time(utils::julian_day(2458179.500000));
177 
178  typename SpCclType::BlocksType blocks;
179  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(
180  data::DimensionSize<data::Time>(1000)
181  , data::DimensionSize<data::Frequency>(10));
182 
183  block->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
184  block->sample_interval(0.001 * boost::units::si::seconds);
185  blocks.push_back(block);
186  std::shared_ptr<TimeFrequencyType> block_2 = std::make_shared<TimeFrequencyType>(
187  data::DimensionSize<data::Time>(100)
188  , data::DimensionSize<data::Frequency>(10));
189 
190  block_2->start_time(block->end_time() + block->sample_interval());
191  block_2->sample_interval(0.001 * boost::units::si::seconds);
192  blocks.push_back(block_2);
193 
194  std::shared_ptr<data::SpCcl<NumericalRep>> data(new data::SpCcl<NumericalRep>(blocks));
195 
196  std::size_t cand_duration = block->number_of_spectra() + 10; // number of bins candidate covers
197  typename Candidate::MsecTimeType cand1_tstart(10.0 * block->sample_interval());
198  typename Candidate::MsecTimeType cand1_tend(cand_duration * block->sample_interval()); cand1_tend += cand1_tstart;
199  typename Candidate::Dm cand1_dm(100.0 * data::parsecs_per_cube_cm);
200  Candidate candidate_1( cand1_dm
201  , cand1_tstart
202  , typename Candidate::MsecTimeType(0.1 * boost::units::si::seconds)
203  , cand1_tend
204  , 2.0
205  );
206  data->push_back(candidate_1);
207 
209  SpCclSpeadReaderConfig reader_config;
210  TestExporter<TimeFrequencyType> exporter(config, reader_config);
211  exporter << *data;
212 
213  auto const& rdata = exporter.get();
214 
215  // verify reception
216  // data
217  ASSERT_EQ(rdata.number_of_channels(), block->number_of_channels());
218  ASSERT_EQ(rdata.sample_interval(), block->sample_interval());
219  ASSERT_EQ(rdata.number_of_spectra(), cand_duration);
220 
221 }
222 
223 TYPED_TEST(SpCclSpeadStreamerTest, test_send_overlapping_candidates_in_first_block)
224 {
225  typedef TypeParam NumericalRep;
226  typedef data::SpCcl<NumericalRep> SpCclType;
227  typedef typename SpCclType::TimeFrequencyType TimeFrequencyType;
228  typedef typename SpCclType::SpCandidateType Candidate;
229 
230  // set up the data
231  typename utils::ModifiedJulianClock::time_point start_time(utils::julian_day(2458179.500000));
232 
233  typename SpCclType::BlocksType blocks;
234  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(
235  data::DimensionSize<data::Time>(1000)
236  , data::DimensionSize<data::Frequency>(10));
237 
238  block->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
239  block->sample_interval(0.001 * boost::units::si::seconds);
240  blocks.push_back(block);
241  std::shared_ptr<TimeFrequencyType> block_2 = std::make_shared<TimeFrequencyType>(
242  data::DimensionSize<data::Time>(600)
243  , data::DimensionSize<data::Frequency>(10));
244 
245  block_2->start_time(block->end_time() + block->sample_interval());
246  block_2->sample_interval(0.001 * boost::units::si::seconds);
247  blocks.push_back(block_2);
248 
249  std::shared_ptr<data::SpCcl<NumericalRep>> data(new data::SpCcl<NumericalRep>(blocks));
250 
251  std::size_t cand_duration = 40; // number of bins candidate covers
252  typename Candidate::MsecTimeType cand1_tend(cand_duration * block->sample_interval());
253  typename Candidate::Dm cand1_dm(10.0 * data::parsecs_per_cube_cm);
254  Candidate candidate_1( cand1_dm
255  , typename Candidate::MsecTimeType(0.0 * boost::units::si::seconds)
256  , typename Candidate::MsecTimeType(0.001 * boost::units::si::seconds)
257  , cand1_tend
258  , 2.0
259  );
260  data->push_back(candidate_1);
261  // candidate 2 starts before the cand1_tend by a single sample and extends to 1 sample beyond it
262  Candidate candidate_2( cand1_dm
263  , cand1_tend - static_cast<typename Candidate::MsecTimeType>(block->sample_interval())
264  , typename Candidate::MsecTimeType(0.001 * boost::units::si::seconds)
265  , cand1_tend + static_cast<typename Candidate::MsecTimeType>(block->sample_interval())
266  , 2.0
267  );
268  data->push_back(candidate_2);
269 
270  // send and recieve the data
272  SpCclSpeadReaderConfig reader_config;
273  TestExporter<TimeFrequencyType> exporter(config, reader_config);
274  exporter << *data;
275 
276  auto const& rdata = exporter.get();
277 
278  // verify reception
279  // data
280  ASSERT_EQ(rdata.number_of_channels(), block->number_of_channels());
281  ASSERT_LE(rdata.data_size(), data->tf_blocks()[0]->data_size());
282  ASSERT_EQ(rdata.sample_interval(), block->sample_interval());
283  ASSERT_EQ(rdata.number_of_spectra(), cand_duration + 1); // enough to cover both candidates
284 
285  // candidates
286  ASSERT_EQ(rdata.number_of_candidates(), data->size());
287  for(std::size_t i=0; i< rdata.number_of_candidates(); ++i) {
288  ASSERT_EQ(rdata.candidate(i).dm(), (*data)[i].dm());
289  ASSERT_EQ(rdata.candidate(i).sigma(), (*data)[i].sigma());
290  ASSERT_EQ(rdata.candidate(i).width(), (*data)[i].width());
291  ASSERT_EQ(rdata.candidate(i).duration(), (*data)[i].tend());
292  }
293  ASSERT_EQ(rdata.candidate(0).start_time(), block->start_time());
294  ASSERT_EQ(rdata.candidate(1).start_time(), data->start_time(candidate_2));
295 }
296 
297 
298 
299 } // namespace test
300 } // namespace exporters
301 } // namespace cheetah
302 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35
SpCandidate list.
Definition: SpCcl.h:52
SpCandidates associated with a single data chank.