Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
BeamFormerDataTraits.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/rcpt_low/BeamFormerDataTraits.h"
25 #include <panda/Log.h>
26 #include <algorithm>
27 
28 
29 namespace ska {
30 namespace cheetah {
31 namespace rcpt_low {
32 
33 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
34 BeamFormerDataTraits<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::BeamFormerDataTraits()
35 {
36 }
37 
38 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
39 BeamFormerDataTraits<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::~BeamFormerDataTraits()
40 {
41 
42 }
43 
44 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
46 {
47  return packet.sequence_number();
48 }
49 
50 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
52 {
53  return chunk.number_of_spectra() * chunk.number_of_channels();
54 }
55 
56 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
58 {
59  return (PacketInspector::Packet::number_of_samples()/2);
60 }
61 
62 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
64 {
65  return PacketInspector::Packet::data_size();
66 }
67 
68 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
70 {
71  return inspector.packet().first_channel_number() == 0;
72 }
73 
74 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
75 void BeamFormerDataTraits<PacketDataType, TimeSamplesPerPacket, ChannelsPerPacket>::packet_stats(uint64_t packets_missing, uint64_t packets_expected)
76 {
77  if(packets_missing > 0)
78  {
79  PANDA_LOG_WARN << "missing packets: " << packets_missing << " in " << packets_expected;
80  }
81 }
82 
83 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
84 template<typename ContextType>
86 {
87  typedef PacketSample<PacketDataType> Sample;
88  unsigned offset = context.offset();
89  auto packet_it=packet.packet().begin() + context.packet_offset();
90  auto weights_it = packet.packet().begin_weights();
91  auto it=context.chunk().begin() + offset;
92 
93  uint32_t number_of_time_samples = packet.packet().number_of_time_samples();
94  uint32_t number_of_channels = packet.packet().number_of_channels();
95 
96 
97  for(uint32_t channel=0;channel<number_of_channels;++channel)
98  {
99  for(uint32_t sample=0; sample<number_of_time_samples; ++sample)
100  {
101  Sample temp_sample0 = (*(packet_it+((channel*number_of_time_samples*2+sample))));
102  Sample temp_sample1 = (*(packet_it+((channel*number_of_time_samples*2+sample+number_of_time_samples))));
103  *(it+(channel*number_of_time_samples+sample)) = (temp_sample0.intensity()+temp_sample1.intensity())*(*(weights_it+channel));
104  }
105  }
106 }
107 
108 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
109 template<typename ContextType>
111 {
112  //essentially replacing the data corresponding to the missing packet to 0. (Dont know what is the best approch here.)
113  unsigned offset = context.offset();
114  auto it=context.chunk().begin() + offset;
115  PANDA_LOG_DEBUG << "processing missing packet: data=" << (void*)&*it << context;
116  for(std::size_t i=0; i < context.size() ; ++i) {
117  *it = 0;
118  assert(it!=context.chunk().end());
119  ++it;
120  }
121 }
122 
123 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
124 template<typename ResizeContextType>
126 {
127  PANDA_LOG_DEBUG << "resizing data: " << context;
128  // drops any incomplete spectra
129  context.chunk().resize(data::DimensionSize<data::Time>(context.size()/context.chunk().number_of_channels()));
130 }
131 
132 template<typename PacketDataType, unsigned TimeSamplesPerPacket, unsigned ChannelsPerPacket>
135 {
136  return PacketInspector::Packet::max_sequence_number();
137 }
138 
139 } // namespace rcpt_low
140 } // namespace cheetah
141 } // namespace ska
static void process_missing_slice(ContextType &context)
perform operations to compenste for a missing packet
static std::size_t packet_size()
return the number of signal samples in a packet (Arun: Need to rename)
PacketNumberType sequence_number() const
return the sequence number embedded in the packet
The incoming RF signal sample from the UDP stream.
Definition: PacketSample.h:42
static uint64_t sequence_number(PacketInspector const &packet)
returns the sequential number of the chunk that the packet belongs to
Some limits and constants for FLDO.
Definition: Brdz.h:35
std::size_t number_of_channels() const
static std::size_t chunk_size(DataType const &data)
return the total number of samples (time_samples * channels) in the data
static void resize_chunk(ContextType &data)
return the total number of samples (time_samples * channels) in the data
Traits describing the BeamFormer Data Stream to the panda::PacketSream system.
static std::size_t data_size()
size of the data in the packet excluding header and weights
static bool align_packet(PacketInspector const &packet)
ignore all packets other than the StokesI
static constexpr PacketNumberType max_sequence_number()
the maximum value a packet sequence number will reach
std::size_t number_of_spectra() const
static void deserialise_packet(ContextType &context, PacketInspector const &)
function responsible for transfering data from the packet in to the data structure ...
BeamFormerPacket inspection and data extraction.