AlcapDAQ  1
Functions | Variables
n2fadc_ndet_compress.cpp File Reference
#include <stdio.h>
#include "midas.h"
#include "mucap_compress.h"
#include "mucap_structures.h"

Go to the source code of this file.

Functions

void n2fadc_ndet_dump (int num_fadc_words, unsigned char *data)
 
void n2fadc_ndet_optimize ()
 
void n2fadc_ndet_load ()
 
int encode_n2fadc_ndet (unsigned char *input, int input_size, io_buffer *output, int boardNumber)
 
int n2fadc_ndet_compress (unsigned char *input, int input_size, unsigned char *output, int userParam)
 
int decode_n2fadc_ndet (io_buffer *input, unsigned char *output, int input_size, int boardNumber)
 
int n2fadc_ndet_expand (unsigned char *input, int input_size, unsigned char *output, int userParam)
 

Variables

BOOL should_compress_n2fadc_ndet = TRUE
 
const int num_n2fadc_ndet_channels = 4
 

Function Documentation

int decode_n2fadc_ndet ( io_buffer input,
unsigned char *  output,
int  input_size,
int  boardNumber 
)

Definition at line 114 of file n2fadc_ndet_compress.cpp.

References io_buffer_get().

Referenced by n2fadc_ndet_expand().

115 {
116  int num_fadc_words = input_size/10;
117 
118  // first retrieve the timestamps
119  int j = 0;
120  while(j < num_fadc_words) {
121 
122  int timestamp = io_buffer_get(input, 28);
123  int run_length = io_buffer_get(input, 8);
124 
125  for(int k = 0; k < run_length; k++) {
126  int t2 = timestamp + k;
127  output[(j+k)*10+0] = (t2 >> 20);
128  output[(j+k)*10+1] = (t2 >> 12) & 0xff;
129  output[(j+k)*10+2] = (t2 >> 4) & 0xff;
130  output[(j+k)*10+3] = (t2 & 0xf) << 4;
131  }
132  j += run_length;
133 
134  }
135 
136  // now the FADC codes
137  int lastSample = 0;
138  for(int j = 0; j < num_fadc_words; j++) {
139  int sample[4];
140  for(int k = 0; k < 4; k++) {
141  int encodedDiff = io_buffer_get(input, 4) & 0xf;
142  if(encodedDiff == 0) {
143  sample[k] = io_buffer_get(input, 13) & 0x1fff;
144  } else {
145  sample[k] = lastSample + encodedDiff - 8;
146  }
147  lastSample = sample[k];
148  }
149 
150  int overflows = ((sample[0] & 0x1000) ? 0x01 : 0) |
151  ((sample[1] & 0x1000) ? 0x02 : 0) |
152  ((sample[2] & 0x1000) ? 0x04 : 0) |
153  ((sample[3] & 0x1000) ? 0x08 : 0);
154  output[j*10+3] |= overflows;
155  output[j*10+4] = (sample[3] >> 4) & 0xff;
156  output[j*10+5] = ((sample[3] & 0xf) << 4) | ((sample[2] >> 8) & 0xf);
157  output[j*10+6] = (sample[2] & 0xff);
158  output[j*10+7] = (sample[1] >> 4) & 0xff;
159  output[j*10+8] = ((sample[1] & 0xf) << 4) | ((sample[0] >> 8) & 0xf);
160  output[j*10+9] = (sample[0] & 0xff);
161  }
162 
163  return input_size;
164 }
int encode_n2fadc_ndet ( unsigned char *  input,
int  input_size,
io_buffer output,
int  boardNumber 
)

Definition at line 31 of file n2fadc_ndet_compress.cpp.

References flush_output_buffer(), and io_buffer_put().

Referenced by n2fadc_ndet_compress().

32 {
33  int num_words = input_size/10;
34 
35  // first deal with the timestamps
36  int run_length = 0;
37  int last_timestamp = -2;
38  int island_timestamp = -1;
39  int last_island_timestamp = 0;
40  for(int j = 0; j < num_words; j++) {
41 
42  int timestamp = (input[j*10+0] << 20) |
43  (input[j*10+1] << 12) |
44  (input[j*10+2] << 4) |
45  (input[j*10+3] >> 4);
46 
47  if(timestamp != last_timestamp + 1 || run_length == 255) {
48  if(island_timestamp != -1) {
49  io_buffer_put(output, island_timestamp, 28);
50  io_buffer_put(output, run_length, 8);
51  }
52 
53  island_timestamp = timestamp;
54  run_length = 0;
55  }
56 
57  last_timestamp = timestamp;
58  run_length++;
59  }
60 
61  // final run
62  if(island_timestamp != -1) {
63  io_buffer_put(output, island_timestamp, 28);
64  io_buffer_put(output, run_length, 8);
65  }
66 
67  // now the FADC codes
68  int lastSample = 0;
69  for(int j = 0; j < num_words; j++) {
70  int sample[4];
71  bool overflowB0 = ((input[j*10+3] & 0x08) != 0);
72  bool overflowA0 = ((input[j*10+3] & 0x04) != 0);
73  bool overflowB1 = ((input[j*10+3] & 0x02) != 0);
74  bool overflowA1 = ((input[j*10+3] & 0x01) != 0);
75  sample[3] = (overflowB0 << 12) | (input[j*10+4] << 4) | (input[j*10+5] >> 4);
76  sample[2] = (overflowA0 << 12) | ((input[j*10+5] & 0xf) << 8) | (input[j*10+6]);
77  sample[1] = (overflowB1 << 12) | (input[j*10+7] << 4) | (input[j*10+8] >> 4);
78  sample[0] = (overflowA1 << 12) | ((input[j*10+8] & 0xf) << 8) | (input[j*10+9]);
79 
80  for(int k = 0; k < 4; k++) {
81  int diff = sample[k] - lastSample;
82  lastSample = sample[k];
83 
84 
85  if(diff <= 7 && diff >= -7) {
86  io_buffer_put(output, diff+8, 4);
87  } else {
88  io_buffer_put(output, 0, 4);
89  io_buffer_put(output, sample[k], 13);
90  }
91  }
92  }
93 
94  return flush_output_buffer(output);
95 }
int n2fadc_ndet_compress ( unsigned char *  input,
int  input_size,
unsigned char *  output,
int  userParam 
)

Definition at line 97 of file n2fadc_ndet_compress.cpp.

References encode_n2fadc_ndet(), and start_output_buffer().

Referenced by compress_event(), and compress_event_skim().

98 {
99  io_buffer output_buffer;
100 
101  // store size of input data
102  int *uncompressed_size_p = (int *) output;
103  *uncompressed_size_p = input_size;
104  output += sizeof(int);
105 
106  // compress samples
107  start_output_buffer(&output_buffer, output);
108  int compressed_size = encode_n2fadc_ndet(input, input_size, &output_buffer, userParam);
109  output += compressed_size;
110 
111  return compressed_size + sizeof(int);
112 }
void n2fadc_ndet_dump ( int  num_fadc_words,
unsigned char *  data 
)

Definition at line 186 of file n2fadc_ndet_compress.cpp.

References i, and printf().

187 {
188  for(int i = 0; i < num_fadc_words; i++) {
189  printf("%d: ", i);
190  for(int j = 0; j < 10; j++) {
191  printf("%02x ", data[i*10+j]);
192  }
193  printf("\n");
194  }
195 }
int n2fadc_ndet_expand ( unsigned char *  input,
int  input_size,
unsigned char *  output,
int  userParam 
)

Definition at line 166 of file n2fadc_ndet_compress.cpp.

References decode_n2fadc_ndet(), and start_input_buffer().

Referenced by expand_event().

167 {
168  //
169  // Uncompress the data produced by n2fadc_ndet_compress().
170  //
171 
172  // Get uncompressed data size
173  int *uncompressed_size_p = (int *) input;
174  int uncompressed_size = *uncompressed_size_p;
175  input += sizeof(int);
176  input_size -= sizeof(int);
177 
178  // Uncompress data
179  io_buffer input_buffer;
180  start_input_buffer(&input_buffer, input);
181  decode_n2fadc_ndet(&input_buffer, output, uncompressed_size, userParam);
182 
183  return uncompressed_size;
184 }
void n2fadc_ndet_load ( )

Definition at line 24 of file n2fadc_ndet_compress.cpp.

References hDB, should_compress_n2fadc_ndet, size, and TRUE.

Referenced by compress_load_all().

25 {
26  int size = sizeof(BOOL);
27  db_get_value(hDB, 0, "/Compression/Lossless/NFADC/Enabled", &should_compress_n2fadc_ndet,
28  &size, TID_BOOL, TRUE);
29 }
void n2fadc_ndet_optimize ( )

Definition at line 20 of file n2fadc_ndet_compress.cpp.

Referenced by compress_optimize_all().

21 {
22 }

Variable Documentation

const int num_n2fadc_ndet_channels = 4

Definition at line 16 of file n2fadc_ndet_compress.cpp.

BOOL should_compress_n2fadc_ndet = TRUE

Definition at line 14 of file n2fadc_ndet_compress.cpp.

Referenced by compress_event(), compress_event_skim(), and n2fadc_ndet_load().