Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Buffering.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/ddtr/detail/Buffering.h"
25 #include "panda/ResourcePool.h"
26 #include "panda/TypeTraits.h"
27 #include "panda/Log.h"
28 
29 
30 namespace ska {
31 namespace cheetah {
32 namespace ddtr {
33 
34 
35 template<typename DdtrTraits, typename PlanType>
36 Buffering<DdtrTraits, PlanType>::Buffering(BufferFullCallBack const& callback
37  , PlanType const& plan
38  , std::size_t max_buffer_size)
39  : _max_spectra(max_buffer_size)
40  , _current_number_of_channels(0)
41  , _agg_buf_filler(callback ,0)
42  , _plan(plan)
43 {
44 }
45 
46 
47 template<typename DdtrTraits, typename PlanType>
48 Buffering<DdtrTraits, PlanType>::~Buffering()
49 {
50 }
51 
52 template<typename DdtrTraits, typename PlanType>
53 void Buffering<DdtrTraits, PlanType>::agg_buffer_init(TimeFrequencyType const& data)
54 {
55  if (data.number_of_channels() != _current_number_of_channels)
56  {
57  data::DimensionSize<data::Time> dedisp_samples = _plan.dedispersion_strategy(data);
58  data::DimensionSize<data::Time> number_of_spectra = dedisp_samples;
59  if(dedisp_samples > _max_spectra && _max_spectra != 0) {
60  PANDA_LOG_WARN << "algorithm algo plans ignored mac number of samples";
61  //number_of_spectra = _plan.reset(_max_spectra); // TODO
62  }
63 
64  data::DimensionSize<data::Time> overlap = _plan.buffer_overlap(); // in numbers of spectra
65  if(overlap == 0) {
66  PANDA_LOG_WARN << "buffer overlap is zero";
67  }
68  data::DimensionSize<data::Time> min_number_of_spectra(overlap + 1);
69 
70  if(min_number_of_spectra >= _max_spectra && _max_spectra != 0) {
71  panda::Error e("configuration error: dedispersion plan requires at least ");
72  e << min_number_of_spectra << " spectra. " << "Maximum possible (given algo and pool selection)=" << dedisp_samples;
73  throw e;
74  }
75 
76  if(overlap >= number_of_spectra) {
77  PANDA_LOG_ERROR << "configuration error: samples requested < minimum required for dedispersion plan(" << overlap << ")";
78  throw panda::Error("dedispersion sample buffer size is too small");
79  }
80  PANDA_LOG << "setting dedispersion buffer size to " << number_of_spectra << " spectra";
81  _agg_buf_filler.resize(data.number_of_channels() * number_of_spectra);
82 
83  PANDA_LOG << "setting buffer overlap to " << overlap << " spectra";
84  _agg_buf_filler.set_overlap(data.number_of_channels() * overlap);
85 
86  _current_number_of_channels = data.number_of_channels();
87  }
88 }
89 
90 template<typename DdtrTraits, typename PlanType>
91 template<typename DataT>
92 void Buffering<DdtrTraits, PlanType>::agg_buffer_fill(DataT& data)
93 {
94  TimeFrequencyType const& tf_data = static_cast<TimeFrequencyType const&>(panda::is_pointer_wrapper<typename std::remove_reference<DataT>::type>::extract(data));
95  agg_buffer_init(tf_data);
96  _agg_buf_filler << data;
97 }
98 
99 template<typename DdtrTraits, typename PlanType>
100 template<typename DataT>
101 void Buffering<DdtrTraits, PlanType>::operator()(DataT const& data)
102 {
103  this->template agg_buffer_fill(data);
104 }
105 
106 } // namespace ddtr
107 } // namespace cheetah
108 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35