Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DmTimeDm.cpp
1 #include "cheetah/data/detail/DmTimeDm.h"
2 #include "cheetah/data/detail/DmTimeSlice.h"
3 #include "cheetah/data/DmTime.h"
4 
5 #include "panda/Copy.h"
6 #include "panda/Log.h"
7 
8 #include <typeinfo>
9 #include <algorithm>
10 
11 namespace ska {
12 namespace cheetah {
13 namespace data {
14 namespace detail {
15 
16 template <typename DmTimeType>
17 DmTimeDm<DmTimeType>::DmTimeDm(std::size_t const dm_idx, std::shared_ptr<const SliceType> parent)
18  : _dm_idx(dm_idx)
19  , _parent(std::move(parent))
20 {
21 }
22 
23 template <typename DmTimeType>
25 {
26 }
27 
28 template <typename DmTimeType>
30 {
31  std::size_t sample_count = 0;
32  for (auto const& block: _parent->blocks())
33  sample_count += block->operator[](_dm_idx).size();
34  return sample_count;
35 }
36 
37 template <typename DmTimeType>
38 data::DedispersionMeasureType<float> DmTimeDm<DmTimeType>::dm() const
39 {
40  if ( _parent->blocks().empty())
41  {
42  throw std::runtime_error("Requested DM from empty DmTime object.");
43  }
44  return _parent->blocks().front()->operator[](_dm_idx).dm();
45 }
46 
47 template <typename DmTimeType>
49 {
50  if ( _parent->blocks().empty())
51  {
52  throw std::runtime_error("Requested sampling interval from empty DmTime object.");
53  }
54  return _parent->blocks().front()->operator[](_dm_idx).sampling_interval();
55 }
56 
57 template <typename DmTimeType>
58 template <typename TimeSeriesType>
59 typename TimeSeriesType::Iterator DmTimeDm<DmTimeType>::copy_to(TimeSeriesType& timeseries) const
60 {
61  if ( _parent->blocks().empty())
62  {
63  throw std::runtime_error("Requested copy from empty DmTime object.");
64  }
65  timeseries.sampling_interval(_parent->blocks().front()->operator[](_dm_idx).sampling_interval());
66  std::size_t count = timeseries.size();
67  std::size_t copied = 0;
68  typename TimeSeriesType::Iterator it;
69  for (auto const& block: _parent->blocks())
70  {
71  auto dmtrial = block->operator[](_dm_idx);
72  std::size_t copy_count = std::min(dmtrial.size(),count-copied);
73  PANDA_LOG_DEBUG << "Copying "<<copy_count<<" samples from DmTime block to timeseries";
74  auto device_it = panda::make_device_iterator<typename TimeSeriesType::ArchitectureType>(timeseries.begin()+copied);
75  it = panda::copy(dmtrial.begin(), dmtrial.begin()+copy_count, device_it);
76  copied = std::distance(timeseries.begin(),it);
77  if (copied == count)
78  break;
79  }
80  return it;
81 }
82 
83 } // namespace detail
84 } // namespace data
85 } // namespace cheetah
86 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35
DmTimeDm(std::size_t const dm_idx, std::shared_ptr< SliceType const > parent)
Create a new instance.
Definition: DmTimeDm.cpp:17
Class that wraps a single DM trial from a DmTime object.
Definition: DmTimeDm.h:47
TimeSeriesType::Iterator copy_to(TimeSeriesType &timeseries) const
Copy the given DM trial to an arbitrary timeseries.
Definition: DmTimeDm.cpp:59
std::size_t number_of_samples() const
Get the number of time samples in the associated DM trial.
Definition: DmTimeDm.cpp:29