Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpCandidateDataStreamerTest.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/SpCandidateDataStreamerTest.h"
25 #include "cheetah/exporters//SpCandidateDataStreamer.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 template<typename TimeFrequencyType>
37 SpCandidateDataStreamerTest<TimeFrequencyType>::SpCandidateDataStreamerTest()
38  : ::testing::Test()
39 {
40 }
41 
42 TYPED_TEST(SpCandidateDataStreamerTest, test_write)
43 {
44  typedef TypeParam TimeFrequencyType;
45  typedef data::SpCandidateData<TimeFrequencyType> DataType;
46  typedef typename DataType::CandidateType CandidateType;
47  typedef typename CandidateType::Dm Dm;
48  typedef typename CandidateType::MsecTimeType MsecTimeType;
49  typedef typename CandidateType::Duration Duration;
50 
51  typename utils::ModifiedJulianClock::time_point start_time(utils::julian_day(58179.0000000));
52 
53  // create some candidates
54  CandidateType cand1( Dm(12.0 * data::parsecs_per_cube_cm)
55  , start_time
56  , MsecTimeType(0.001 * boost::units::si::seconds)
57  , Duration(0.003 * boost::units::si::seconds)
58  , 2.0
59  );
60 
61 
62  SpCandidateDataStreamerConfig config;
63 
64  panda::test::TestDir tmp_dir;
65  ASSERT_NO_THROW(tmp_dir.create());
66  config.dir(tmp_dir.dir_name());
67 
68  {
69  // create some data to write
70  std::shared_ptr<TimeFrequencyType> block = std::make_shared<TimeFrequencyType>(data::DimensionSize<data::Time>(1000)
71  ,data::DimensionSize<data::Frequency>(10));
72  block->start_time(start_time);
73  DataType data(block);
74 
75  // Add some condidates
76  for(unsigned i=0; i<3; ++i) {
77  data.add(CandidateType(cand1));
78  }
79 
80 
81  exporters::SpCandidateDataStreamer<TimeFrequencyType> writer(config);
82  writer << data;
83  } // destructor should be called here, flushing buffers etc
84  sync(); // ensure the OS actually writes to disc
85  auto it = boost::filesystem::directory_iterator(tmp_dir.path());
86  ASSERT_FALSE(it == boost::filesystem::directory_iterator());
87  boost::filesystem::path file = *it;
88  ASSERT_EQ(file.extension().string(), ".spccl");
89  ASSERT_EQ(file.stem().string(), "2018_03_02_00:00:00");
90 }
91 
92 } // namespace test
93 } // namespace exporters
94 } // namespace cheetah
95 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35