Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DmTimeTest.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/data/test_utils/DmTimeTest.h"
25 #include "cheetah/data/test_utils/DmTrialsGeneratorUtil.h"
26 #include "cheetah/data/DmTime.h"
27 #include "cheetah/data/DmTrialsMetadata.h"
28 #include "cheetah/data/DmTrials.h"
29 #include "cheetah/data/TimeSeries.h"
30 #include "panda/Log.h"
31 #include <chrono>
32 
33 namespace ska {
34 namespace cheetah {
35 namespace data {
36 namespace test {
37 
38 template <typename Traits>
39 DmTimeTest<Traits>::DmTimeTest()
40  : ::testing::Test()
41 {
42 }
43 
44 template <typename Traits>
45 DmTimeTest<Traits>::~DmTimeTest()
46 {
47 }
48 
49 template <typename Traits>
50 void DmTimeTest<Traits>::SetUp()
51 {
52 }
53 
54 template <typename Traits>
55 void DmTimeTest<Traits>::TearDown()
56 {
57 }
58 
59 template <typename Arch, typename T>
60 void Tester<Arch,T>::slice_test(std::size_t dms_per_slice, std::size_t ndms, std::size_t nblocks)
61 {
62  typedef typename utils::ModifiedJulianClock::time_point StartTime;
63  typedef data::DmTrials<Arch,T> DmTrialsType;
64  typedef typename DmTrialsType::TimeType TimeType;
65  typedef typename DmTrialsType::DmType Dm;
66  auto buffer = DmTime<DmTrialsType>::make_shared();
67  DmTrialsGeneratorUtil<DmTrialsType> trials_generator;
68 
69  for (std::size_t block_idx=0; block_idx<nblocks; ++block_idx)
70  {
71  buffer->add(trials_generator.generate(TimeType(0.1*data::seconds),10,ndms));
72  }
73 
74  std::size_t slice_count = 0;
75  std::size_t dm_count = 0;
76 
77  for (auto it = buffer->begin(dms_per_slice); it < buffer->end(); ++it )
78  {
79  auto slice = *it;
80  for (auto slice_it = slice->begin(); slice_it != slice->end(); ++slice_it )
81  {
82  ++dm_count;
83  }
84  ++slice_count;
85  }
86  int remainder = (ndms % dms_per_slice != 0);
87  ASSERT_EQ(slice_count,ndms/dms_per_slice + remainder);
88  ASSERT_EQ(dm_count,ndms);
89 }
90 
91 template <typename Arch, typename T>
92 void Tester<Arch,T>::add_test()
93 {
94  typedef typename utils::ModifiedJulianClock::time_point StartTime;
95  typedef data::DmTrials<Arch,T> DmTrialsType;
96  typedef typename DmTrialsType::TimeType TimeType;
97  typedef typename DmTrialsType::DmType Dm;
98  auto buffer = DmTime<DmTrialsType>::make_shared();
99  DmTrialsGeneratorUtil<DmTrialsType> trials_generator;
100  StartTime epoch(utils::julian_day(50000.0));
101  trials_generator.epoch(epoch);
102  buffer->add(trials_generator.generate(TimeType(0.1*data::seconds),10,10));
103  trials_generator.epoch(epoch+std::chrono::microseconds(12312));
104  buffer->add(trials_generator.generate(TimeType(0.1*data::seconds),10,10));
105  trials_generator.epoch(epoch+std::chrono::microseconds(12));
106  buffer->add(trials_generator.generate(TimeType(0.1*data::seconds),10,10));
107  trials_generator.epoch(epoch+std::chrono::microseconds(333));
108  buffer->add(trials_generator.generate(TimeType(0.1*data::seconds),10,10));
109  trials_generator.epoch(epoch+std::chrono::microseconds(111));
110  buffer->add(trials_generator.generate(TimeType(0.1*data::seconds),10,10));
111  trials_generator.epoch(epoch+std::chrono::microseconds(1000));
112  buffer->add(trials_generator.generate(TimeType(0.1*data::seconds),10,10));
113 
114  auto& blocks = buffer->blocks();
115  auto prev = blocks.begin();
116  auto next = blocks.begin();
117  ++next;
118  while (next != blocks.end())
119  {
120  ASSERT_TRUE((*prev)->start_time() < (*next)->start_time());
121  ++prev;
122  ++next;
123  }
124 }
125 
126 } // namespace test
127 } // namespace data
128 } // namespace cheetah
129 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35