Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpCclSpeadReaderTest.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/SpCclSpeadReaderTest.h"
25 #include "cheetah/exporters/SpCclSpeadReader.h"
26 #include "cheetah/exporters/SpCclSpeadStreamer.h"
27 #include <memory>
28 
29 
30 namespace ska {
31 namespace cheetah {
32 namespace exporters {
33 namespace test {
34 
35 
36 SpCclSpeadReaderTest::SpCclSpeadReaderTest()
37  : ::testing::Test()
38 {
39 }
40 
41 SpCclSpeadReaderTest::~SpCclSpeadReaderTest()
42 {
43 }
44 
45 void SpCclSpeadReaderTest::SetUp()
46 {
47 }
48 
49 void SpCclSpeadReaderTest::TearDown()
50 {
51 }
52 
53 template<typename NumericalRep>
54 std::shared_ptr<data::SpCcl<NumericalRep>> spccl_data()
55 {
56  typedef data::SpCcl<NumericalRep> SpCclType;
57  typedef typename SpCclType::TimeFrequencyType TimeFrequencyType;
58  typedef typename SpCclType::SpCandidateType Candidate;
59 
60  // set up the data
61  typename utils::ModifiedJulianClock::time_point start_time(utils::julian_day(2458179.500000));
62 
63  typename SpCclType::BlocksType blocks;
64  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(
65  data::DimensionSize<data::Time>(1000)
66  , data::DimensionSize<data::Frequency>(10));
67 
68  block->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
69  block->sample_interval(0.001 * boost::units::si::seconds);
70  blocks.push_back(block);
71  blocks.push_back(std::make_shared<TimeFrequencyType>( data::DimensionSize<data::Time>(100)
72  , data::DimensionSize<data::Frequency>(10)));
73 
74  std::shared_ptr<data::SpCcl<NumericalRep>> data(new data::SpCcl<NumericalRep>(blocks));
75 
76  std::size_t cand_duration = 40; // number of bins candidate covers
77  typename Candidate::MsecTimeType cand1_tend(cand_duration * block->sample_interval());
78  typename Candidate::Dm cand1_dm(00.0 * data::parsecs_per_cube_cm);
79  Candidate candidate_1( cand1_dm
80  , typename Candidate::MsecTimeType(0.0 * boost::units::si::seconds)
81  , typename Candidate::MsecTimeType(0.001 * boost::units::si::seconds)
82  , cand1_tend
83  , 2.0
84  );
85  data->push_back(candidate_1);
86  return data;
87 }
88 
89 /*
90  * The client should listen until it is stopped by the owner
91  * Spead2 allows the send side to emiat an end of stream marker.
92  * We use this marker to reset the stream so it is cabable of receiving
93  * any new data.
94  */
95 TEST_F(SpCclSpeadReaderTest, test_reset)
96 {
97  typedef uint8_t NumericalRep;
98 
99  SpCclSpeadStreamerConfig writer_config;
100  SpCclSpeadReaderConfig reader_config;
101  panda::ProcessingEngine engine(2);
102 
103  // generate some data
104  auto data = spccl_data<NumericalRep>();
105  typedef typename std::remove_reference<decltype(*data)>::type::TimeFrequencyType TimeFrequencyType;
106 
107  std::vector<std::shared_ptr<data::SpCandidateData<TimeFrequencyType>>> recv_data;
108  SpCclSpeadReader<TimeFrequencyType> reader(reader_config
109  , [&](std::shared_ptr<data::SpCandidateData<TimeFrequencyType>> const& d)
110  {
111  std::cout << "hello" << std::endl;
112  recv_data.push_back(d);
113  }
114  );
115  bool stopped = false;
116  reader.add_stop_callback([&]() { stopped = true; });
117  reader.start();
118  bool started = false;
119  reader.add_start_callback([&]() { started = true; });
120  {
121  exporters::SpCclSpeadStreamer writer(writer_config, engine);
122  writer << *data;
123  }
124  // wait for us to get data before sending more data.
125  while(!(stopped && started)) {
126  reader_config.engine().poll_one();
127  }
128  {
129  exporters::SpCclSpeadStreamer writer(writer_config, engine);
130  writer << *data;
131  }
132  // we expect to get all our data despite the reset
133  while(recv_data.size() < 2 ) {
134  reader_config.engine().poll_one();
135  }
136  // verify data transfered correctly
137  //for(auto const& d : recv_data) {
138  //ASSERT_TRUE((*d) == *data);
139  //}
140 }
141 
142 } // namespace test
143 } // namespace exporters
144 } // namespace cheetah
145 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35