Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
CommonDedispersionPlan.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 
25 #include "panda/PoolLimits.h"
26 #include "panda/TupleUtilities.h"
27 
28 
29 namespace ska {
30 namespace cheetah {
31 namespace ddtr {
32 
33 
34 template<typename TraitsT, typename... AlgosT>
35 CommonDedispersionPlan<TraitsT, AlgosT...>::CommonDedispersionPlan(ConfigType const& config)
36  : _plans(typename PlanType<AlgosT>::type(config
37  , panda::PoolLimits::template minimum_memory<typename AlgosT::Architecture>(config.pool())/sizeof(typename TraitsT::value_type))...)
38 {
39 }
40 
41 template<typename TraitsT, typename... AlgosT>
42 CommonDedispersionPlan<TraitsT, AlgosT...>::~CommonDedispersionPlan()
43 {
44 }
45 
46 namespace {
47 
48 class BufferOverlapHelper {
49  public:
50  BufferOverlapHelper()
51  : _max(0)
52  {}
53 
54  template<typename Plan>
55  void operator()(Plan const& plan) {
56  auto bs = plan.buffer_overlap();
57  if(bs > _max) {
58  _max = bs;
59  }
60  }
61 
62  data::DimensionSize<data::Time> const& value() const
63  {
64  return _max;
65  }
66 
67  private:
68  data::DimensionSize<data::Time> _max;
69 };
70 
71 class DispersionStrategyHelper {
72  public:
73  DispersionStrategyHelper()
74  : _min(std::numeric_limits<std::size_t>::max())
75  {}
76 
77  template<typename Plan, typename... Args>
78  void operator()(Plan& plan, Args&&... args) {
79  auto bs = plan.reset(std::forward<Args>(args)...);
80  if(bs < _min) {
81  _min = bs;
82  }
83  }
84 
85  data::DimensionSize<data::Time> const& value() const
86  {
87  return _min;
88  }
89 
90  private:
91  data::DimensionSize<data::Time> _min;
92 };
93 
94 class DispersionStrategySyncer {
95  public:
96  template<typename Plan>
97  void operator()(Plan& plan, data::DimensionSize<data::Time> const& spectra) {
98  if(plan.number_of_spectra()!=spectra)
99  {
100  plan.reset(spectra);
101  if(plan.number_of_spectra()!=spectra)
102  throw panda::Error("Unable to set number of spectra");
103  }
104  }
105 };
106 
107 } // namespace
108 
109 template<typename TraitsT, typename... AlgosT>
110 data::DimensionSize<data::Time> CommonDedispersionPlan<TraitsT, AlgosT...>::buffer_overlap() const
111 {
112  BufferOverlapHelper helper;
113  panda::for_each(_plans, helper);
114  return helper.value();
115 }
116 
117 template<typename TraitsT, typename... AlgosT>
118 data::DimensionSize<data::Time> CommonDedispersionPlan<TraitsT, AlgosT...>::dedispersion_strategy(TimeFrequencyType const& data)
119 {
120  DispersionStrategyHelper helper;
121  panda::for_each(_plans, helper, data);
122 
123  // setting the minimum dedipsersion samples for each plan
124  DispersionStrategySyncer sync_helper;
125  panda::for_each(_plans, sync_helper, helper.value());
126 
127  // propagate dedispersionplans to dedispersion algorithms
128  this->set_plans();
129 
130  return helper.value();
131 }
132 
133 template<typename TraitsT, typename... AlgosT>
134 template<typename AlgoT>
135 typename PlanType<AlgoT>::type const& CommonDedispersionPlan<TraitsT, AlgosT...>::plan() const
136 {
137  return std::get<panda::Index<typename PlanType<AlgoT>::type, decltype(_plans)>::value>(_plans);
138 }
139 
140 } // namespace ddtr
141 } // namespace cheetah
142 } // namespace ska
PlanType< AlgoT >::type const & plan() const
return the plan corresponding to the specified algorithm
Some limits and constants for FLDO.
Definition: Brdz.h:35