Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpCclFileStreamerTest.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/SpCclFileStreamerTest.h"
25 #include "cheetah/exporters/SpCclFileStreamer.h"
26 #include "cheetah/utils/JulianClock.h"
27 #include "panda/test/TestDir.h"
28 
29 
30 namespace ska {
31 namespace cheetah {
32 namespace exporters {
33 namespace test {
34 
35 
36 SpCclFileStreamerTest::SpCclFileStreamerTest()
37  : ::testing::Test()
38 {
39 }
40 
41 SpCclFileStreamerTest::~SpCclFileStreamerTest()
42 {
43 }
44 
45 void SpCclFileStreamerTest::SetUp()
46 {
47 }
48 
49 void SpCclFileStreamerTest::TearDown()
50 {
51 }
52 
53 TEST_F(SpCclFileStreamerTest, test_write)
54 {
55  // create a tmp directoy name
56  typedef typename data::SpCcl<uint8_t>::TimeFrequencyType TimeFrequencyType;
57 
58  panda::test::TestDir tmp_dir;
59  SpCclFileStreamerConfig config;
60  ASSERT_NO_THROW(tmp_dir.create());
61  config.dir(tmp_dir.dir_name());
62  {
63  typename utils::JulianClock::time_point start_time(utils::julian_day(2458179.500000));
64  data::SpCcl<uint8_t>::BlocksType blocks;
65  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(data::DimensionSize<data::Time>(1000)
66  ,data::DimensionSize<data::Frequency>(10));
67  block->start_time(static_cast<typename TimeFrequencyType::TimePointType>(start_time));
68  blocks.push_back(block);
69  blocks.push_back(std::make_shared<TimeFrequencyType>(data::DimensionSize<data::Time>(100),data::DimensionSize<data::Frequency>(10)));
70  data::SpCcl<uint8_t> d1(blocks);
71  typename data::SpCcl<uint8_t>::SpCandidateType::Dm dm(12.0 * data::parsecs_per_cube_cm);
72  //set the single pulse candidate width to 1.24 ms
73  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType width(0.001 * boost::units::si::seconds);
74  //set the single pulse start time to 2.23 seconds
75  data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType tstart(2.0 * boost::units::si::seconds);
76  //set the candidate significance
77  float sigma = 20.0;
78 
79  for (auto idx=0; idx<10; ++idx)
80  {
81  data::SpCcl<uint8_t>::SpCandidateType candidate(dm, tstart, width, sigma, idx);
82  d1.push_back(candidate);
83  }
84 
85  exporters::SpCclFileStreamer<uint8_t> writer(config);
86  writer << d1;
87  } // should flush buffers to OS on leaving scope
88  sync(); // ensure the OS actually writes to disc
89  auto it = boost::filesystem::directory_iterator(tmp_dir.path());
90  ASSERT_FALSE(it == boost::filesystem::directory_iterator());
91  boost::filesystem::path file = *it;
92  ASSERT_EQ(file.extension().string(), ".spccl");
93  ASSERT_EQ(file.stem().string(), "2018_03_02_00:00:00");
94  ASSERT_TRUE(boost::filesystem::exists(it->path()));
95  ASSERT_EQ(1U, std::distance(it, boost::filesystem::directory_iterator()));
96 }
97 
98 } // namespace test
99 } // namespace exporters
100 } // namespace cheetah
101 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35