Jpp  16.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
puzzled_frame.cc File Reference
#include "puzzled_frame.hh"
#include <DataFormats/clb_common_header.hh>
#include <DataFormats/infoword.hh>
#include "input_buffer_collector.hh"
#include <string.h>
#include <log.hh>
#include <utility>
#include <stdexcept>

Go to the source code of this file.

Functions

uint32_t calculate_number_of_items (Frame const &frame)
 
std::pair< unsigned int,
unsigned int > 
opt_boundaries (CLBDataGram const &dg, std::size_t max_size)
 
void buildOpto (PuzzledFrame::container_t const &c, frame_idx_t frame_idx, Frame &frame)
 
std::pair< unsigned int,
unsigned int > 
acou_boundaries (CLBDataGram const &dg, std::size_t max_size, std::size_t item_size)
 
void buildAcou (PuzzledFrame::container_t const &c, frame_idx_t frame_idx, Frame &frame)
 

Function Documentation

uint32_t calculate_number_of_items ( Frame const &  frame)

Definition at line 35 of file puzzled_frame.cc.

36 {
37  uint32_t nitems = 0;
38  uint32_t const frame_length = frame.size();
39 
40  uint32_t const data_type = frame.getHeader()->DataType;
41 
42  if (is_optical(data_type)) {
43  nitems = (frame_length - sizeof(DAQCommonHeader)) / 6; // 6 is sizeof(hit)
44  } else if (is_acoustic(data_type)) {
45  InfoWord const*const iw = static_cast<const InfoWord*>(
46  static_cast<const void*>(frame.getPayload()));
47 
48  const unsigned int audiowordsize = iw->audioWordSize();
49 
50  nitems = (frame_length
51  - sizeof(DAQCommonHeader)
52  - sizeof(InfoWord))
53  / audiowordsize;
54  } else {
55  throw std::runtime_error("Unknown data type");
56  }
57 
58  return nitems;
59 }
bool is_acoustic(unsigned int dt)
Definition: datatypespec.hh:17
bool is_optical(unsigned int dt)
Definition: datatypespec.hh:12
std::pair<unsigned int, unsigned int> opt_boundaries ( CLBDataGram const &  dg,
std::size_t  max_size 
)

Definition at line 89 of file puzzled_frame.cc.

92 {
93  std::size_t const previous_packets_size =
94  dg.getCLBCommonHeader()->udpSequenceNumber()
95  * (max_size - sizeof(CLBCommonHeader));
96 
97  std::size_t const chunk_in_previous = previous_packets_size % 6;
98 
99  unsigned int const head =
100  chunk_in_previous
101  ? 6 - chunk_in_previous
102  : 0;
103 
104  unsigned int const tail =
105  (dg.size() - sizeof(CLBCommonHeader) - head) % 6;
106 
107  return std::make_pair(head, tail);
108 }
void buildOpto ( PuzzledFrame::container_t const &  c,
frame_idx_t  frame_idx,
Frame frame 
)

Definition at line 116 of file puzzled_frame.cc.

120 {
121  assert(
122  (
123  c.size() > 1
124  || c.begin()->second->getCLBCommonHeader()->udpSequenceNumber() == 0
125  )
126  && "Precondition failed."
127  );
128 
129  uint32_t current_seq_number = 0;
130  unsigned int previous_chunk = 0;
131 
132  std::size_t const max_size = c.begin()->second->size();
133 
134  std::size_t size = sizeof(DAQCommonHeader);
135 
136  for (
137  PuzzledFrame::container_t::const_iterator it = c.begin(), et = c.end();
138  it != et;
139  ++it
140  ) {
141 
142  CLBDataGram const& dg = *it->second;
144  dg,
145  max_size
146  );
147 
148  if (dg.getCLBCommonHeader()->udpSequenceNumber() != current_seq_number) {
149  LOG_DEBUG << "Datagram "
150  << current_seq_number
151  << " not present in optical frame "
152  << frame_idx
153  << ". Packet loss(?)";
154 
155  Log::Counter::get().add("missing odgram");
156 
157  char* const dest = &frame.front() + size - previous_chunk;
158 
159  std::size_t const write_size = dg.getPayloadSize() - bounds.first;
160 
161  std::memcpy(dest, dg.getPayload() + bounds.first, write_size);
162 
163  size += write_size - previous_chunk;
164  } else {
165  char* const dest = &frame.front() + size;
166 
167  std::size_t const write_size = dg.getPayloadSize();
168 
169  std::memcpy(dest, dg.getPayload(), write_size);
170 
171  size += write_size;
172  }
173 
174  current_seq_number = dg.getCLBCommonHeader()->udpSequenceNumber() + 1;
175  previous_chunk = bounds.second;
176  }
177 
178  // check whether size is compatible an integer number of items
179  // and if not strip away the boundary
180 
181  if (previous_chunk != 0) {
182  LOG_DEBUG << "Missing last datagram(s) in optical frame "
183  << frame_idx
184  << ". Packet loss (?).";
185 
186  Log::Counter::get().add("missing odgram");
187  size -= previous_chunk;
188  }
189 
190  // check the presence of the trailer
191 
192  if (!isTrailer(*c.rbegin()->second->getCLBCommonHeader())) {
193  LOG_DEBUG << "Missing trailer in optical frame "
194  << frame_idx;
195 
196  Log::Counter::get().add("missing trailer");
197  }
198 
199  frame.resize(size);
200 }
#define LOG_DEBUG
Definition: log.hh:109
const char * getPayload() const
Definition: clb_datagram.hh:96
const CLBCommonHeader * getCLBCommonHeader() const
Definition: clb_datagram.hh:90
size_t getPayloadSize() const
static Counter & get()
Definition: log.hh:53
void add(std::string const &tag)
Definition: log.hh:60
uint32_t udpSequenceNumber() const
bool isTrailer(CLBCommonHeader const &header)
std::pair< unsigned int, unsigned int > opt_boundaries(CLBDataGram const &dg, std::size_t max_size)
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
std::pair<unsigned int, unsigned int> acou_boundaries ( CLBDataGram const &  dg,
std::size_t  max_size,
std::size_t  item_size 
)

Definition at line 202 of file puzzled_frame.cc.

206 {
207  unsigned int head = 0;
208  unsigned int tail = 0;
209 
210  if (dg.getCLBCommonHeader()->udpSequenceNumber() != 0) {
211  std::size_t const previous_audio_size =
212  dg.getCLBCommonHeader()->udpSequenceNumber()
213  * (max_size - sizeof(CLBCommonHeader))
214  - sizeof(InfoWord);
215 
216  std::size_t const chunk_in_previous = previous_audio_size % item_size;
217 
218  head = chunk_in_previous ? item_size - chunk_in_previous : 0;
219 
220  tail = (dg.size() - sizeof(CLBCommonHeader) - head) % item_size;
221  } else {
222  head = 0;
223  tail = (dg.size() - sizeof(CLBCommonHeader) - sizeof(InfoWord)) % item_size;
224  }
225 
226  return std::make_pair(head, tail);
227 }
void buildAcou ( PuzzledFrame::container_t const &  c,
frame_idx_t  frame_idx,
Frame frame 
)

Definition at line 234 of file puzzled_frame.cc.

238 {
239  uint32_t current_seq_number = 0;
240  unsigned int previous_chunk = 0;
241 
242  std::size_t const max_size = c.begin()->second->size();
243 
244  std::size_t size = sizeof(DAQCommonHeader);
245 
246  InfoWord const& iw = *static_cast<const InfoWord*>(
247  static_cast<const void*>(c.begin()->second->getPayload()));
248 
249  unsigned int const audio_word_size = iw.audioWordSize();
250 
251  for (
252  PuzzledFrame::container_t::const_iterator it = c.begin(), et = c.end();
253  it != et;
254  ++it
255  ) {
256 
257  CLBDataGram const& dg = *it->second;
258 
260  dg,
261  max_size,
262  audio_word_size);
263 
264  if (dg.getCLBCommonHeader()->udpSequenceNumber() != current_seq_number) {
265  LOG_DEBUG << "Datagram "
266  << current_seq_number
267  << " not present in acoustic frame "
268  << frame_idx
269  << ". Packet loss(?)";
270 
271  Log::Counter::get().add("missing adgram");
272 
273  size -= previous_chunk;
274  break;
275  } else {
276  char* const dest = &frame.front() + size;
277 
278  std::size_t const write_size = dg.getPayloadSize();
279 
280  memcpy(dest, dg.getPayload(), write_size);
281 
282  size += write_size;
283  }
284 
285  ++current_seq_number;
286  previous_chunk = bounds.second;
287  }
288 
289  // check whether size is compatible an integer number of items
290  // and if not strip away the boundary
291 
292  if (previous_chunk != 0) {
293  LOG_DEBUG << "Missing last datagram(s) in acoustic frame "
294  << frame_idx
295  << ". Packet loss (?).";
296 
297  Log::Counter::get().add("missing adgram");
298  size -= previous_chunk;
299  }
300 
301  frame.resize(size);
302 }
#define LOG_DEBUG
Definition: log.hh:109
const char * getPayload() const
Definition: clb_datagram.hh:96
const CLBCommonHeader * getCLBCommonHeader() const
Definition: clb_datagram.hh:90
size_t getPayloadSize() const
static Counter & get()
Definition: log.hh:53
void add(std::string const &tag)
Definition: log.hh:60
uint32_t udpSequenceNumber() const
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
std::pair< unsigned int, unsigned int > acou_boundaries(CLBDataGram const &dg, std::size_t max_size, std::size_t item_size)