Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpCcl.h
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 #ifndef SKA_CHEETAH_DATA_SPCCL_H
25 #define SKA_CHEETAH_DATA_SPCCL_H
26 
27 #include "cheetah/data/SpCandidate.h"
28 #include "cheetah/data/CandidateWindow.h"
29 #include "cheetah/data/VectorLike.h"
30 #include "cheetah/data/TimeFrequency.h"
31 #include "pss/astrotypes/units/TimeUnits.h"
32 #include "cheetah/utils/Architectures.h"
33 #include "panda/DataChunk.h"
34 #include <vector>
35 #include <utility>
36 #include <deque>
37 
38 namespace ska {
39 namespace cheetah {
40 namespace data {
41 
51 template<typename NumericalRep>
52 class SpCcl
53  : public ska::panda::DataChunk<SpCcl<NumericalRep>>
54  , public VectorLike<std::vector<SpCandidate<Cpu, float>>>
55 {
56  public:
58  typedef SpCandidateType::Dm Dm;
59 
60  private:
61  typedef std::vector<SpCandidateType> InnerType;
63 
64  public:
66  typedef typename TimeFrequencyType::FrequencyType FrequencyType;
67  typedef std::vector<std::shared_ptr<const TimeFrequencyType>> BlocksType;
68  typedef typename BaseT::Iterator CandidateIterator;
69  typedef typename BaseT::ConstIterator ConstCandidateIterator;
70 
71  public:
72  class ConstDataIterator : public std::iterator<std::forward_iterator_tag, typename TimeFrequencyType::SliceType>
73  {
74  private:
75  typedef typename BaseT::ConstIterator ConstCandidateIterator;
76  typedef typename TimeFrequencyType::ConstIterator ConstIterator;
77  typedef typename TimeFrequencyType::SliceType Slice;
78  typedef typename TimeFrequencyType::ConstSliceType ConstSlice;
79 
80  public:
81  typedef Slice value_type;
82  typedef value_type& reference;
83  typedef ConstSlice& const_reference;
84 
85  public:
86  ConstDataIterator( CandidateWindow const& window
87  , ConstCandidateIterator begin
88  , ConstCandidateIterator const& end
89  , BlocksType const&
90  , utils::ModifiedJulianClock::time_point const& epoch);
91 
92  bool operator==(ConstDataIterator const& d) const;
93  bool operator!=(ConstDataIterator const& d) const;
94 
98  utils::ModifiedJulianClock::time_point const& start_time() const;
99 
103  bool end_block() const;
104 
108  ConstCandidateIterator candidate_begin() const;
109  ConstCandidateIterator const& candidate_end() const;
110 
115 
120 
121  const_reference operator*() const;
122 
123 
124  protected:
125  void next_candidate();
126 
127  private:
128  struct CandidateData {
129  friend class SpCcl<NumericalRep>;
130  CandidateData(ConstSlice const& slice, bool is_last=false)
131  : _slice(slice)
132  , _last_block(is_last) {}
133 
134  ConstSlice& slice() { return _slice; }
135  bool last_block() const { return _last_block; };
136 
137  private:
138  ConstSlice _slice;
139  bool _last_block; // marks the last data chunk in a group
140  };
141 
142  private:
143  CandidateWindow const& _window;
144  ConstCandidateIterator _cand_it;
145  ConstCandidateIterator const _cand_it_end;
146  mutable std::deque<CandidateData> _slices;
147  typename BlocksType::const_iterator _tf_it;
148  typename BlocksType::const_iterator _tf_end;
149  typename BlocksType::const_iterator _tf_start_it;
150  utils::ModifiedJulianClock::time_point const _epoch;
151  typename boost::units::quantity<MilliSeconds, double> _duration;
152  typename boost::units::quantity<MilliSeconds, double> _span;
153  utils::ModifiedJulianClock::time_point _start_time;
154  std::deque<std::pair<ConstCandidateIterator, ConstCandidateIterator>> _cands;
155  };
156 
157  public:
158  SpCcl();
159  SpCcl(BlocksType const&, data::DimensionIndex<data::Time> start_offset=data::DimensionIndex<data::Time>(0));
160  ~SpCcl();
161 
168  BlocksType const& tf_blocks() const;
169 
175  void push_back(SpCandidateType const& cand);
176 
182  void push_back_calculate_duration(SpCandidateType const& cand);
183 
189  void emplace(SpCandidateType && cand);
190  void emplace_calculate_duration(SpCandidateType && cand);
191 
195  void emplace(typename SpCandidateType::Dm,
196  boost::units::quantity<MilliSeconds, double> start_time,
197  boost::units::quantity<MilliSeconds, double> pulse_width,
198  float sigma,
199  std::size_t ident = 0
200  );
201 
206  void emplace_back(SpCandidateType && cand);
207 
213  void emplace_back(typename SpCandidateType::Dm,
214  boost::units::quantity<MilliSeconds, double> start_time,
215  boost::units::quantity<MilliSeconds, double> pulse_width,
216  float sigma,
217  std::size_t ident = 0
218  );
219 
226  ConstDataIterator data_begin(CandidateWindow const& window) const;
227 
228  ConstDataIterator data_end() const;
229 
231  utils::ModifiedJulianClock::time_point const& start_time() const;
232 
236  boost::units::quantity<data::MilliSeconds,double> offset_time() const;
237 
241  std::pair<Dm, Dm> const& dm_range() const;
242 
243  /*
244  * @brief the start time of the Candidate
245  */
246  utils::ModifiedJulianClock::time_point start_time(SpCandidateType const&) const;
247 
251  template<typename PredicateT>
252  void remove_if(PredicateT const&);
253 
254  protected:
255  void dm_max_min(Dm);
256 
257  private:
258  std::pair<Dm, Dm> _dm_range;
259  BlocksType _blocks;
260  utils::ModifiedJulianClock::time_point _start_time;
261  boost::units::quantity<data::MilliSeconds,double> _offset_time;
262  typedef decltype(1.0/(FrequencyType() * FrequencyType())) DmFactorType;
263  DmFactorType _dm_delay_factor; // to calculate candidate end time
264 };
265 
266 
267 } // namespace data
268 } // namespace cheetah
269 } // namespace ska
270 #include "detail/SpCcl.cpp"
271 
272 #endif // SKA_CHEETAH_DATA_SPCCL_H
ConstDataIterator data_begin(CandidateWindow const &window) const
Extract data corresponding to the candidates start and end times.
Definition: SpCcl.cpp:197
A simple record to hold &#39;candidate&#39; proprerties.
Definition: SpCandidate.h:58
void push_back(SpCandidateType const &cand)
Push back method for inserting Single pulse Candidates but without calculating tend They will be ins...
Definition: SpCcl.cpp:98
void push_back_calculate_duration(SpCandidateType const &cand)
Push back method for inserting Single pulse Candidates calculating temd based on dispersion and freq ...
Definition: SpCcl.cpp:83
std::pair< Dm, Dm > const & dm_range() const
the max and minimum Dispersion Measure values of the candidates
Definition: SpCcl.cpp:70
BlocksType const & tf_blocks() const
Access the TimeFrequency blocks associated with the single pulse candidtes.
Definition: SpCcl.cpp:64
void emplace(SpCandidateType &&cand)
Emplace back method for inserting Single pulse Candidates, ensuring ordering by start_time. They will be inserted in a sorted order with respect to the start time of each candidate instead of insert to the end.
Definition: SpCcl.cpp:132
bool end_block() const
retunrs true is the current block is the end of contiguous series
Definition: SpCcl.cpp:356
void emplace_back(SpCandidateType &&cand)
Add a Single pulse Candidate to the end of the cand list, without calculating the duration Checking ...
Definition: SpCcl.cpp:112
Class that wraps objects that export the std::vector interface.
Definition: VectorLike.h:44
Some limits and constants for FLDO.
Definition: Brdz.h:35
ConstCandidateIterator candidate_begin() const
retunrs true is the current block is the end of contiguous series
Definition: SpCcl.cpp:386
SpCandidate list.
Definition: SpCcl.h:52
ConstDataIterator & operator++()
pre-increment operator
Definition: SpCcl.cpp:368
define a window of data surrounding a single pulse candidate
Iterator end()
An iterator pointing to the end of the vector.
Definition: VectorLike.cpp:109
boost::units::quantity< data::MilliSeconds, double > offset_time() const
the time duration from the beginning of the first block to start_time()
Definition: SpCcl.cpp:228
void remove_if(PredicateT const &)
remove candidates that meet the specified condition
Definition: SpCcl.cpp:235
utils::ModifiedJulianClock::time_point const & start_time() const
: Get the start time
Definition: SpCcl.cpp:362
Iterator begin()
An iterator pointing to the start of the vector.
Definition: VectorLike.cpp:85