Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Worker.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 "panda/Log.h"
25 
26 
27 namespace ska {
28 namespace cheetah {
29 namespace ddtr {
30 namespace cpu {
31 
32 
33 template<typename DdtrTraits>
34 Worker<DdtrTraits>::Worker()
35 {
36 }
37 
38 template<typename DdtrTraits>
39 std::shared_ptr<typename Worker<DdtrTraits>::DmTrialsType> Worker<DdtrTraits>::operator()(BufferType const& data, std::shared_ptr<DedispersionPlan<DdtrTraits>> plan)
40 {
41  auto const& tf_obj = *(data.composition().front());
42  std::size_t nchans = tf_obj.number_of_channels();
43  data::DimensionSize<data::Time> nsamples(data.data_size() / nchans);
44 
45  if (data.data_size() % nchans != 0)
46  {
47  throw panda::Error("AggregationBuffer does not contain a whole number of channels");
48  }
49  auto dm_trial_metadata = plan->dm_trials_metadata(tf_obj.metadata(), nsamples);
50 
51  data::DimensionIndex<data::Time> offset_samples(data.offset_first_block()/(nchans * sizeof(typename DdtrTraits::value_type)));
52  auto const& start_time = tf_obj.start_time(offset_samples);
53  std::shared_ptr<DmTrialsType> dmtrials_ptr = DmTrialsType::make_shared(dm_trial_metadata, start_time);
54  if (data.data_size() < plan->buffer_overlap() * nchans)
55  {
56  PANDA_LOG_WARN << "AggregationBuffer is too small to be processed ("
57  << data.data_size() << " < " << plan->buffer_overlap()*nchans << ")\n"<<"Skipping Current Buffer";
58  return dmtrials_ptr;
59  }
60 
61  DmTrialsType& dmtrials = *(dmtrials_ptr);
62  NumericalT const* tf_data = static_cast<NumericalT const*>(data.data());
63 
64  auto const& plan_dm_trials = plan->dm_trials();
65  auto const& plan_dm_factors = plan->dm_factors();
66  for (std::size_t dm_idx = 0; dm_idx < plan->dm_trials().size(); ++dm_idx)
67  {
68  auto& current_trial = dmtrials[dm_idx];
69  auto const& plan_dm_trial = plan_dm_trials[dm_idx].value();
70  for (std::size_t samp_idx=0; samp_idx < current_trial.size(); ++samp_idx)
71  {
72  float sum = 0.0f;
73  for (std::size_t chan_idx=0; chan_idx < nchans; ++chan_idx)
74  {
75  std::size_t delay = static_cast<std::size_t>(plan_dm_factors[chan_idx] * plan_dm_trial);
76  std::size_t input_idx = (samp_idx + delay) * nchans + chan_idx;
77  if (input_idx >= data.data_size())
78  {
79  PANDA_LOG_ERROR << "Input index beyond end of buffer (" << input_idx << " >= " << data.data_size() << ")";
80  }
81  sum += (float) tf_data[input_idx];
82  }
83  current_trial[samp_idx] = sum;
84  }
85  }
86 
87  return dmtrials_ptr;
88 }
89 
90 } // namespace cpu
91 } // namespace ddtr
92 } // namespace cheetah
93 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35