AlcapDAQ  1
Functions
io_buffer.cpp File Reference
#include <stdio.h>
#include <assert.h>
#include "midas.h"
#include "mucap_compress.h"

Go to the source code of this file.

Functions

void start_output_buffer (io_buffer *buffer, unsigned char *p)
 
int flush_output_buffer (io_buffer *buffer)
 
void io_buffer_put (io_buffer *buffer, unsigned int code_bits, int code_length)
 
void start_input_buffer (io_buffer *buffer, unsigned char *p)
 
unsigned int io_buffer_get (io_buffer *buffer, int num_bits)
 

Function Documentation

int flush_output_buffer ( io_buffer buffer)

Definition at line 23 of file io_buffer.cpp.

References io_buffer::num_codes, io_buffer::p, io_buffer::start, io_buffer::w, and io_buffer::w_bits.

Referenced by encode_caen(), encode_cmp_times(), encode_fadc(), encode_hits(), encode_n2fadc_ndet(), encode_n2fadc_tpc(), encode_nfadc(), encode_times(), and flush_rle().

24 {
25  // store the last word
26  *((buffer->p)++) = buffer->w << buffer->w_bits;
27 
28  // remember the length of the buffer, in bytes and in codes
29  *(buffer->start) = buffer->num_codes;
30 
31  //return ((unsigned int) buffer->p) - ((unsigned int) buffer->start);
32  return (int) (((char *) buffer->p) - ((char *) buffer->start));
33 }
unsigned int io_buffer_get ( io_buffer buffer,
int  num_bits 
)

Definition at line 70 of file io_buffer.cpp.

References io_buffer_get(), io_buffer::p, io_buffer::w, and io_buffer::w_bits.

Referenced by decode_caen(), decode_cmp_times(), decode_fadc(), decode_hits(), decode_n2fadc_ndet(), decode_n2fadc_tpc(), decode_nfadc(), decode_times(), io_buffer_get(), and rle_get().

71 {
72  if (buffer->w_bits == 0) {
73  buffer->w = *((buffer->p)++);
74  buffer->w_bits = 32;
75  }
76 
77  int w_bits = buffer->w_bits;
78 
79  unsigned int retval;
80  if (num_bits <= w_bits) {
81  retval = buffer->w >> (32 - num_bits);
82  buffer->w = buffer->w << num_bits;
83  buffer->w_bits = w_bits - num_bits;
84 
85  } else {
86  unsigned int first_part =
87  io_buffer_get(buffer, w_bits) << (num_bits - w_bits);
88  retval = first_part | io_buffer_get(buffer, num_bits - w_bits);
89  }
90 
91  return retval;
92 }
void io_buffer_put ( io_buffer buffer,
unsigned int  code_bits,
int  code_length 
)

Definition at line 36 of file io_buffer.cpp.

References io_buffer::p, io_buffer::w, and io_buffer::w_bits.

Referenced by encode_caen(), encode_cmp_times(), encode_fadc(), encode_hits(), encode_n2fadc_ndet(), encode_n2fadc_tpc(), encode_nfadc(), encode_times(), flush_rle(), huffman_put_symbol(), and rle_put().

37 {
38 
39  assert(code_length > 0 && code_length < 32);
40 
41  // Does this symbol fit in our buffer word?
42  if (code_length < buffer->w_bits) {
43  // OK, so put it there...
44  buffer->w = (buffer->w << code_length) | code_bits;
45  buffer->w_bits -= code_length;
46  } else if (code_length == buffer->w_bits) {
47  // Only barely...write out the buffer word
48  buffer->w = (buffer->w << code_length) | code_bits;
49  *((buffer->p)++) = buffer->w;
50  buffer->w_bits = 32;
51  } else {
52  // No, we'll have to split the code across two words.
53  unsigned int first_code_bits =
54  code_bits >> (code_length - buffer->w_bits);
55  *((buffer->p)++) = (buffer->w << buffer->w_bits) | first_code_bits;
56  buffer->w = code_bits;
57  buffer->w_bits = 32 - code_length + buffer->w_bits;
58  }
59 }
void start_input_buffer ( io_buffer buffer,
unsigned char *  p 
)

Definition at line 61 of file io_buffer.cpp.

References io_buffer::num_codes, io_buffer::p, io_buffer::start, io_buffer::w, and io_buffer::w_bits.

Referenced by caen_expand(), cmp_expand(), fadc_expand(), hits_expand(), n2fadc_ndet_expand(), n2fadc_tpc_expand(), nfadc_expand(), stck_expand(), and tdc400_expand().

62 {
63  buffer->w = 0;
64  buffer->w_bits = 0;
65  buffer->start = (unsigned int *) p;
66  buffer->p = buffer->start + 1;
67  buffer->num_codes = *(buffer->start);
68 }
void start_output_buffer ( io_buffer buffer,
unsigned char *  p 
)

Definition at line 14 of file io_buffer.cpp.

References io_buffer::num_codes, io_buffer::p, io_buffer::start, io_buffer::w, and io_buffer::w_bits.

Referenced by caen_compress(), cmp_compress(), fadc_compress(), hits_compress(), n2fadc_ndet_compress(), n2fadc_tpc_compress(), nfadc_compress(), stck_compress(), and tdc400_compress().

15 {
16  buffer->w = 0;
17  buffer->w_bits = 32;
18  buffer->start = (unsigned int *) p;
19  buffer->p = buffer->start + 1;
20  buffer->num_codes = 0;
21 }