raw.cxx
Go to the documentation of this file.
1 /// \file raw.cxx
2 /// \brief raw data utilities
3 /// \author brebel@fnal.gov
4 /// modified by jti3@fnal.gov
5 
7 
8 #include <iostream>
9 #include <bitset>
10 #include <numeric> // std::adjacent_difference()
11 #include <iterator> // std::back_inserter()
12 
13 #include "cetlib_except/exception.h"
15 
16 namespace raw {
17 
18  //----------------------------------------------------------
19  void Compress(std::vector<short> &adc,
20  raw::Compress_t compress)
21  {
22  if(compress == raw::kHuffman) CompressHuffman(adc);
23  else if(compress == raw::kZeroHuffman){
24  unsigned int zerothreshold = 5;
25  ZeroSuppression(adc,zerothreshold);
26  CompressHuffman(adc);
27  }
28  else if(compress == raw::kZeroSuppression){
29  unsigned int zerothreshold = 5;
30  ZeroSuppression(adc,zerothreshold);
31  }
32  else if (compress == raw::kFibonacci) {
33  CompressFibonacci(adc);
34  }
35 
36 
37  return;
38  }
39  //----------------------------------------------------------
40  void Compress(std::vector<short> &adc,
41  raw::Compress_t compress,
42  int &nearestneighbor)
43  {
44  if(compress == raw::kHuffman) CompressHuffman(adc);
45  else if(compress == raw::kZeroHuffman){
46  unsigned int zerothreshold = 5;
47  ZeroSuppression(adc,zerothreshold, nearestneighbor);
48  CompressHuffman(adc);
49  }
50  else if(compress == raw::kZeroSuppression){
51  unsigned int zerothreshold = 5;
52  ZeroSuppression(adc,zerothreshold, nearestneighbor);
53  }
54  else if (compress == raw::kFibonacci) {
55  CompressFibonacci(adc);
56  }
57 
58 
59  return;
60  }
61 
62  //----------------------------------------------------------
63  void Compress(std::vector<short> &adc,
64  raw::Compress_t compress,
65  unsigned int &zerothreshold)
66  {
67  if(compress == raw::kHuffman) CompressHuffman(adc);
68 
69  else if(compress == raw::kZeroSuppression) ZeroSuppression(adc,zerothreshold);
70  else if(compress == raw::kZeroHuffman){
71  ZeroSuppression(adc,zerothreshold);
72  CompressHuffman(adc);
73  }
74  else if (compress == raw::kFibonacci) {
75  CompressFibonacci(adc);
76  }
77 
78  return;
79  }
80  //----------------------------------------------------------
81  void Compress(std::vector<short> &adc,
82  raw::Compress_t compress,
83  unsigned int &zerothreshold,
84  int &nearestneighbor)
85  {
86  if(compress == raw::kHuffman)
87  CompressHuffman(adc);
88  else if(compress == raw::kZeroSuppression)
89  ZeroSuppression(adc,zerothreshold, nearestneighbor);
90  else if(compress == raw::kZeroHuffman){
91  ZeroSuppression(adc,zerothreshold, nearestneighbor);
92  CompressHuffman(adc);
93  }
94  else if (compress == raw::kFibonacci) {
95  CompressFibonacci(adc);
96  }
97 
98  return;
99  }
100 
101  //----------------------------------------------------------
102  void Compress(const boost::circular_buffer<std::vector<short>> &adcvec_neighbors,
103  std::vector<short> &adc,
104  raw::Compress_t compress,
105  unsigned int &zerothreshold,
106  int &nearestneighbor)
107  {
108  if(compress == raw::kHuffman)
109  CompressHuffman(adc);
110  else if(compress == raw::kZeroSuppression)
111  ZeroSuppression(adcvec_neighbors,adc,zerothreshold, nearestneighbor);
112  else if(compress == raw::kZeroHuffman){
113  ZeroSuppression(adcvec_neighbors,adc,zerothreshold, nearestneighbor);
114  CompressHuffman(adc);
115  }
116  else if (compress == raw::kFibonacci) {
117  CompressFibonacci(adc);
118  }
119 
120  return;
121  }
122 
123  //----------------------------------------------------------
124  void Compress(std::vector<short> &adc,
125  raw::Compress_t compress,
126  unsigned int &zerothreshold,
127  int pedestal,
128  int &nearestneighbor,
129  bool fADCStickyCodeFeature)
130  {
131  if(compress == raw::kHuffman)
132  CompressHuffman(adc);
133  else if(compress == raw::kZeroSuppression)
134  ZeroSuppression(adc,zerothreshold, pedestal, nearestneighbor, fADCStickyCodeFeature);
135  else if(compress == raw::kZeroHuffman){
136  ZeroSuppression(adc,zerothreshold, pedestal, nearestneighbor, fADCStickyCodeFeature);
137  CompressHuffman(adc);
138  }
139  else if (compress == raw::kFibonacci) {
140  CompressFibonacci(adc);
141  }
142 
143  return;
144  }
145 
146  //----------------------------------------------------------
147  void Compress(const boost::circular_buffer<std::vector<short>> &adcvec_neighbors,
148  std::vector<short> &adc,
149  raw::Compress_t compress,
150  unsigned int &zerothreshold,
151  int pedestal,
152  int &nearestneighbor,
153  bool fADCStickyCodeFeature)
154  {
155  if(compress == raw::kHuffman)
156  CompressHuffman(adc);
157  else if(compress == raw::kZeroSuppression)
158  ZeroSuppression(adcvec_neighbors,adc,zerothreshold, pedestal, nearestneighbor, fADCStickyCodeFeature);
159  else if(compress == raw::kZeroHuffman){
160  ZeroSuppression(adcvec_neighbors,adc,zerothreshold, pedestal, nearestneighbor, fADCStickyCodeFeature);
161  CompressHuffman(adc);
162  }
163  else if (compress == raw::kFibonacci) {
164  CompressFibonacci(adc);
165  }
166 
167  return;
168  }
169 
170 
171  //----------------------------------------------------------
172  // Zero suppression function
173  void ZeroSuppression(std::vector<short> &adc,
174  unsigned int &zerothreshold)
175  {
176  const int adcsize = adc.size();
177  const int zerothresholdsigned = zerothreshold;
178 
179  std::vector<short> zerosuppressed(adc.size());
180  int maxblocks = adcsize/2 + 1;
181  std::vector<short> blockbegin(maxblocks);
182  std::vector<short> blocksize(maxblocks);
183 
184  unsigned int nblocks = 0;
185  unsigned int zerosuppressedsize = 0;
186 
187  int blockcheck = 0;
188 
189  for(int i = 0; i < adcsize; ++i){
190  int adc_current_value = std::abs(adc[i]);
191 
192  if(adc_current_value > zerothresholdsigned){
193 
194  if(blockcheck == 0){
195 
196  blockbegin[nblocks] = i;
197  blocksize[nblocks] = 0;
198  blockcheck=1;
199  }
200 
201  zerosuppressed[zerosuppressedsize] = adc[i];
202  zerosuppressedsize++;
203  blocksize[nblocks]++;
204 
205  if(i == adcsize-1) nblocks++;
206  }
207 
208  if(adc_current_value <= zerothresholdsigned && blockcheck == 1){
209  zerosuppressed[zerosuppressedsize] = adc[i];
210  zerosuppressedsize++;
211  blocksize[nblocks]++;
212  nblocks++;
213  blockcheck = 0;
214  }
215  }
216 
217 
218 
219  adc.resize(2+nblocks+nblocks+zerosuppressedsize);
220 
221  adc[0] = adcsize; //fill first entry in adc with length of uncompressed vector
222  adc[1] = nblocks;
223 
224 
225 
226  for(unsigned int i = 0; i < nblocks; ++i)
227  adc[i+2] = blockbegin[i];
228 
229  for(unsigned int i = 0; i < nblocks; ++i)
230  adc[i+nblocks+2] = blocksize[i];
231 
232  for(unsigned int i = 0; i < zerosuppressedsize; ++i)
233  adc[i+nblocks+nblocks+2] = zerosuppressed[i];
234 
235 
236  }
237 
238 
239 
240  //----------------------------------------------------------
241  // Zero suppression function which merges blocks if they are
242  // within parameter nearestneighbor of each other
243  void ZeroSuppression(std::vector<short> &adc,
244  unsigned int &zerothreshold,
245  int &nearestneighbor)
246  {
247 
248  const int adcsize = adc.size();
249  const int zerothresholdsigned = zerothreshold;
250 
251  std::vector<short> zerosuppressed(adcsize);
252  int maxblocks = adcsize/2 + 1;
253  std::vector<short> blockbegin(maxblocks);
254  std::vector<short> blocksize(maxblocks);
255 
256  int nblocks = 0;
257  int zerosuppressedsize = 0;
258 
259  int blockstartcheck = 0;
260  int endofblockcheck = 0;
261 
262  for(int i = 0; i < adcsize; ++i){
263  int adc_current_value = std::abs(adc[i]);
264 
265  if(blockstartcheck==0){
266  if(adc_current_value>zerothresholdsigned){
267  if(nblocks>0){
268  if((i-nearestneighbor)<=(blockbegin[nblocks-1]+blocksize[nblocks-1]+1)){
269 
270  nblocks--;
271  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
272  blockstartcheck = 1;
273  }
274  else{
275  blockbegin[nblocks] = (i - nearestneighbor > 0) ? i - nearestneighbor : 0;
276  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
277  blockstartcheck = 1;
278  }
279  }
280  else{
281  blockbegin[nblocks] = (i - nearestneighbor > 0) ? i - nearestneighbor : 0;
282  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
283  blockstartcheck = 1;
284  }
285  }
286  }
287  else if(blockstartcheck==1){
288  if(adc_current_value>zerothresholdsigned){
289  blocksize[nblocks]++;
290  endofblockcheck = 0;
291  }
292  else{
293  if(endofblockcheck<nearestneighbor){
294  endofblockcheck++;
295  blocksize[nblocks]++;
296  }
297  //block has ended
298  else if(i+2<adcsize){ //check if end of adc vector is near
299  if(std::abs(adc[i+1]) <= zerothresholdsigned && std::abs(adc[i+2]) <= zerothresholdsigned){
300  endofblockcheck = 0;
301  blockstartcheck = 0;
302  nblocks++;
303  }
304  }
305 
306 
307  } // end else
308  } // end if blockstartcheck == 1
309  }// end loop over adc size
310 
311  if(blockstartcheck==1){ // we reached the end of the adc vector with the block still going
312  ++nblocks;
313  }
314 
315  for(int i = 0; i < nblocks; ++i)
316  zerosuppressedsize += blocksize[i];
317 
318 
319  adc.resize(2+nblocks+nblocks+zerosuppressedsize);
320  zerosuppressed.resize(2+nblocks+nblocks+zerosuppressedsize);
321 
322 
323  int zerosuppressedcount = 0;
324  for(int i = 0; i < nblocks; ++i){
325  //zerosuppressedsize += blocksize[i];
326  for(int j = 0; j < blocksize[i]; ++j){
327  zerosuppressed[zerosuppressedcount] = adc[blockbegin[i] + j];
328  zerosuppressedcount++;
329  }
330  }
331 
332  adc[0] = adcsize; //fill first entry in adc with length of uncompressed vector
333  adc[1] = nblocks;
334  for(int i = 0; i < nblocks; ++i){
335  adc[i+2] = blockbegin[i];
336  adc[i+nblocks+2] = blocksize[i];
337  }
338 
339 
340 
341  for(int i = 0; i < zerosuppressedsize; ++i)
342  adc[i+nblocks+nblocks+2] = zerosuppressed[i];
343 
344 
345  // for(int i = 0; i < 2 + 2*nblocks + zerosuppressedsize; ++i)
346  // std::cout << adc[i] << std::endl;
347  //adc.resize(2+nblocks+nblocks+zerosuppressedsize);
348  }
349 
350  //----------------------------------------------------------
351  // Zero suppression function which merges blocks if they are
352  // within parameter nearestneighbor of each other
353  // after subtracting pedestal value
354  void ZeroSuppression(std::vector<short> &adc,
355  unsigned int &zerothreshold,
356  int pedestal,
357  int &nearestneighbor,
358  bool fADCStickyCodeFeature)
359  {
360 
361  const int adcsize = adc.size();
362  const int zerothresholdsigned = zerothreshold;
363 
364  std::vector<short> zerosuppressed(adcsize);
365  int maxblocks = adcsize/2 + 1;
366  std::vector<short> blockbegin(maxblocks);
367  std::vector<short> blocksize(maxblocks);
368 
369  int nblocks = 0;
370  int zerosuppressedsize = 0;
371 
372  int blockstartcheck = 0;
373  int endofblockcheck = 0;
374 
375  for(int i = 0; i < adcsize; ++i){
376  int adc_current_value = ADCStickyCodeCheck(adc[i],pedestal,fADCStickyCodeFeature);
377 
378  if(blockstartcheck==0){
379  if(adc_current_value>zerothresholdsigned){
380  if(nblocks>0){
381  if(i-nearestneighbor<=blockbegin[nblocks-1]+blocksize[nblocks-1]+1){
382  nblocks--;
383  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
384  blockstartcheck = 1;
385  }
386  else{
387  blockbegin[nblocks] = (i - nearestneighbor > 0) ? i - nearestneighbor : 0;
388  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
389  blockstartcheck = 1;
390  }
391  }
392  else{
393  blockbegin[nblocks] = (i - nearestneighbor > 0) ? i - nearestneighbor : 0;
394  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
395  blockstartcheck = 1;
396  }
397  }
398  }
399  else if(blockstartcheck==1){
400  if(adc_current_value>zerothresholdsigned){
401  blocksize[nblocks]++;
402  endofblockcheck = 0;
403  }
404  else{
405  if(endofblockcheck<nearestneighbor){
406  endofblockcheck++;
407  blocksize[nblocks]++;
408  }
409  //block has ended
410  else if(i+2<adcsize){ //check if end of adc vector is near
411  if(ADCStickyCodeCheck(adc[i+1],pedestal,fADCStickyCodeFeature) <= zerothresholdsigned && ADCStickyCodeCheck(adc[i+2],pedestal,fADCStickyCodeFeature) <= zerothresholdsigned){
412  endofblockcheck = 0;
413  blockstartcheck = 0;
414  nblocks++;
415  }
416  }
417  } // end else
418  } // end if blockstartcheck == 1
419  }// end loop over adc size
420 
421  if(blockstartcheck==1){ // we reached the end of the adc vector with the block still going
422  ++nblocks;
423  }
424 
425 
426  for(int i = 0; i < nblocks; ++i)
427  zerosuppressedsize += blocksize[i];
428 
429 
430  adc.resize(2+nblocks+nblocks+zerosuppressedsize);
431  zerosuppressed.resize(2+nblocks+nblocks+zerosuppressedsize);
432 
433 
434  int zerosuppressedcount = 0;
435  for(int i = 0; i < nblocks; ++i){
436  //zerosuppressedsize += blocksize[i];
437  for(int j = 0; j < blocksize[i]; ++j){
438  zerosuppressed[zerosuppressedcount] = adc[blockbegin[i] + j];
439  zerosuppressedcount++;
440  }
441  }
442 
443  adc[0] = adcsize; //fill first entry in adc with length of uncompressed vector
444  adc[1] = nblocks;
445  for(int i = 0; i < nblocks; ++i){
446  adc[i+2] = blockbegin[i];
447  adc[i+nblocks+2] = blocksize[i];
448  }
449 
450 
451 
452  for(int i = 0; i < zerosuppressedsize; ++i)
453  adc[i+nblocks+nblocks+2] = zerosuppressed[i];
454 
455 
456  // for(int i = 0; i < 2 + 2*nblocks + zerosuppressedsize; ++i)
457  // std::cout << adc[i] << std::endl;
458  //adc.resize(2+nblocks+nblocks+zerosuppressedsize);
459  }
460 
461  //----------------------------------------------------------
462  // Zero suppression function which merges blocks if they are
463  // within parameter nearest neighbor of each other and makes
464  // blocks if neighboring wires have nonzero blocks there
465  void ZeroSuppression(const boost::circular_buffer<std::vector<short>> &adcvec_neighbors,
466  std::vector<short> &adc,
467  unsigned int &zerothreshold,
468  int &nearestneighbor)
469  {
470 
471  const int adcsize = adc.size();
472  const int zerothresholdsigned = zerothreshold;
473 
474  std::vector<short> zerosuppressed(adcsize);
475  const int maxblocks = adcsize/2 + 1;
476  std::vector<short> blockbegin(maxblocks);
477  std::vector<short> blocksize(maxblocks);
478 
479  int nblocks = 0;
480  int zerosuppressedsize = 0;
481 
482  int blockstartcheck = 0;
483  int endofblockcheck = 0;
484 
485  for(int i = 0; i < adcsize; ++i){
486 
487  //find maximum adc value among all neighboring channels within the nearest neighbor channel distance
488 
489  int adc_current_value = 0;
490 
491  for(boost::circular_buffer<std::vector<short>>::const_iterator adcveciter = adcvec_neighbors.begin(); adcveciter!=adcvec_neighbors.end();++adcveciter){
492  const std::vector<short> &adcvec_current = *adcveciter;
493  const int adcvec_current_single = std::abs(adcvec_current[i]);
494 
495  if(adc_current_value < adcvec_current_single){
496  adc_current_value = adcvec_current_single;
497  }
498 
499  }
500  if(blockstartcheck==0){
501  if(adc_current_value>zerothresholdsigned){
502  if(nblocks>0){
503  if(i-nearestneighbor<=blockbegin[nblocks-1]+blocksize[nblocks-1]+1){
504  nblocks--;
505  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
506  blockstartcheck = 1;
507  }
508  else{
509  blockbegin[nblocks] = (i - nearestneighbor > 0) ? i - nearestneighbor : 0;
510  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
511  blockstartcheck = 1;
512  }
513  }
514  else{
515  blockbegin[nblocks] = (i - nearestneighbor > 0) ? i - nearestneighbor : 0;
516  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
517  blockstartcheck = 1;
518  }
519  }
520  }
521  else if(blockstartcheck==1){
522  if(adc_current_value>zerothresholdsigned){
523  blocksize[nblocks]++;
524  endofblockcheck = 0;
525  }
526  else{
527  if(endofblockcheck<nearestneighbor){
528  endofblockcheck++;
529  blocksize[nblocks]++;
530  }
531  //block has ended
532  else if(i+2<adcsize){ //check if end of adc vector is near
533  if(std::abs(adc[i+1]) <= zerothresholdsigned && std::abs(adc[i+2]) <= zerothresholdsigned){
534  endofblockcheck = 0;
535  blockstartcheck = 0;
536  nblocks++;
537  }
538  }
539 
540  } // end else
541  } // end if blockstartcheck == 1
542  }// end loop over adc size
543 
544  if(blockstartcheck==1){ // we reached the end of the adc vector with the block still going
545  ++nblocks;
546  }
547 
548 
549 
550  for(int i = 0; i < nblocks; ++i)
551  zerosuppressedsize += blocksize[i];
552 
553 
554  adc.resize(2+nblocks+nblocks+zerosuppressedsize);
555  zerosuppressed.resize(2+nblocks+nblocks+zerosuppressedsize);
556 
557 
558  int zerosuppressedcount = 0;
559  for(int i = 0; i < nblocks; ++i){
560  //zerosuppressedsize += blocksize[i];
561  for(int j = 0; j < blocksize[i]; ++j){
562  zerosuppressed[zerosuppressedcount] = adc[blockbegin[i] + j];
563  zerosuppressedcount++;
564  }
565  }
566 
567  adc[0] = adcsize; //fill first entry in adc with length of uncompressed vector
568  adc[1] = nblocks;
569  for(int i = 0; i < nblocks; ++i){
570  adc[i+2] = blockbegin[i];
571  adc[i+nblocks+2] = blocksize[i];
572  }
573 
574 
575 
576  for(int i = 0; i < zerosuppressedsize; ++i)
577  adc[i+nblocks+nblocks+2] = zerosuppressed[i];
578 
579 
580  // for(int i = 0; i < 2 + 2*nblocks + zerosuppressedsize; ++i)
581  // std::cout << adc[i] << std::endl;
582  //adc.resize(2+nblocks+nblocks+zerosuppressedsize);
583  }
584 
585  //----------------------------------------------------------
586  // Zero suppression function which merges blocks if they are
587  // within parameter nearest neighbor of each other and makes
588  // blocks if neighboring wires have nonzero blocks there
589  // after subtracting pedestal values
590  void ZeroSuppression(const boost::circular_buffer<std::vector<short>> &adcvec_neighbors,
591  std::vector<short> &adc,
592  unsigned int &zerothreshold,
593  int pedestal,
594  int &nearestneighbor,
595  bool fADCStickyCodeFeature)
596  {
597 
598  const int adcsize = adc.size();
599  const int zerothresholdsigned = zerothreshold;
600 
601  std::vector<short> zerosuppressed(adcsize);
602  const int maxblocks = adcsize/2 + 1;
603  std::vector<short> blockbegin(maxblocks);
604  std::vector<short> blocksize(maxblocks);
605 
606  int nblocks = 0;
607  int zerosuppressedsize = 0;
608 
609  int blockstartcheck = 0;
610  int endofblockcheck = 0;
611 
612  for(int i = 0; i < adcsize; ++i){
613 
614  //find maximum adc value among all neighboring channels within the nearest neighbor channel distance
615 
616  int adc_current_value = ADCStickyCodeCheck(adc[i],pedestal,fADCStickyCodeFeature);
617 
618  for(boost::circular_buffer<std::vector<short>>::const_iterator adcveciter = adcvec_neighbors.begin(); adcveciter!=adcvec_neighbors.end();++adcveciter){
619  const std::vector<short> &adcvec_current = *adcveciter;
620  const int adcvec_current_single = std::abs(adcvec_current[i] - pedestal);
621 
622  if(adc_current_value < adcvec_current_single){
623  adc_current_value = adcvec_current_single;
624  }
625 
626  }
627  if(blockstartcheck==0){
628  if(adc_current_value>zerothresholdsigned){
629  if(nblocks>0){
630  if(i-nearestneighbor<=blockbegin[nblocks-1]+blocksize[nblocks-1]+1){
631  nblocks--;
632  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
633  blockstartcheck = 1;
634  }
635  else{
636  blockbegin[nblocks] = (i - nearestneighbor > 0) ? i - nearestneighbor : 0;
637  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
638  blockstartcheck = 1;
639  }
640  }
641  else{
642  blockbegin[nblocks] = (i - nearestneighbor > 0) ? i - nearestneighbor : 0;
643  blocksize[nblocks] = i - blockbegin[nblocks] + 1;
644  blockstartcheck = 1;
645  }
646  }
647  }
648  else if(blockstartcheck==1){
649  if(adc_current_value>zerothresholdsigned){
650  blocksize[nblocks]++;
651  endofblockcheck = 0;
652  }
653  else{
654  if(endofblockcheck<nearestneighbor){
655  endofblockcheck++;
656  blocksize[nblocks]++;
657  }
658  //block has ended
659 
660  else if(i+2<adcsize){ //check if end of adc vector is near
661  if(ADCStickyCodeCheck(adc[i+1],pedestal,fADCStickyCodeFeature) <= zerothresholdsigned && ADCStickyCodeCheck(adc[i+2],pedestal,fADCStickyCodeFeature) <= zerothresholdsigned){
662  endofblockcheck = 0;
663  blockstartcheck = 0;
664  nblocks++;
665  }
666  }
667 
668  } // end else
669  } // end if blockstartcheck == 1
670  }// end loop over adc size
671 
672  if(blockstartcheck==1){ // we reached the end of the adc vector with the block still going
673  ++nblocks;
674  }
675 
676 
677 
678  for(int i = 0; i < nblocks; ++i)
679  zerosuppressedsize += blocksize[i];
680 
681 
682  adc.resize(2+nblocks+nblocks+zerosuppressedsize);
683  zerosuppressed.resize(2+nblocks+nblocks+zerosuppressedsize);
684 
685 
686  int zerosuppressedcount = 0;
687  for(int i = 0; i < nblocks; ++i){
688  //zerosuppressedsize += blocksize[i];
689  for(int j = 0; j < blocksize[i]; ++j){
690  zerosuppressed[zerosuppressedcount] = adc[blockbegin[i] + j];
691  zerosuppressedcount++;
692  }
693  }
694 
695  adc[0] = adcsize; //fill first entry in adc with length of uncompressed vector
696  adc[1] = nblocks;
697  for(int i = 0; i < nblocks; ++i){
698  adc[i+2] = blockbegin[i];
699  adc[i+nblocks+2] = blocksize[i];
700  }
701 
702 
703 
704  for(int i = 0; i < zerosuppressedsize; ++i)
705  adc[i+nblocks+nblocks+2] = zerosuppressed[i];
706 
707 
708  // for(int i = 0; i < 2 + 2*nblocks + zerosuppressedsize; ++i)
709  // std::cout << adc[i] << std::endl;
710  //adc.resize(2+nblocks+nblocks+zerosuppressedsize);
711  }
712 
713 
714  //----------------------------------------------------------
715  // Reverse zero suppression function
716  void ZeroUnsuppression(const std::vector<short>& adc,
717  std::vector<short> &uncompressed)
718  {
719  const int lengthofadc = adc[0];
720  const int nblocks = adc[1];
721 
722  uncompressed.resize(lengthofadc);
723  for (int i = 0;i < lengthofadc; ++i){
724  uncompressed[i] = 0;
725  }
726 
727  int zerosuppressedindex = nblocks*2 + 2;
728 
729  for(int i = 0; i < nblocks; ++i){ //loop over each nonzero block of the compressed vector
730 
731  for(int j = 0; j < adc[2+nblocks+i]; ++j){//loop over each block size
732 
733  //set uncompressed value
734  uncompressed[adc[2+i]+j] = adc[zerosuppressedindex];
735  zerosuppressedindex++;
736 
737  }
738  }
739 
740  return;
741  }
742 
743  //----------------------------------------------------------
744  // Reverse zero suppression function with pedestal re-addition
745  void ZeroUnsuppression(const std::vector<short>& adc,
746  std::vector<short> &uncompressed,
747  int pedestal)
748  {
749  const int lengthofadc = adc[0];
750  const int nblocks = adc[1];
751 
752  uncompressed.resize(lengthofadc);
753  for (int i = 0;i < lengthofadc; ++i){
754  uncompressed[i] = pedestal;
755  }
756 
757  int zerosuppressedindex = nblocks*2 + 2;
758 
759  for(int i = 0; i < nblocks; ++i){ //loop over each nonzero block of the compressed vector
760 
761  for(int j = 0; j < adc[2+nblocks+i]; ++j){//loop over each block size
762 
763  //set uncompressed value
764  uncompressed[adc[2+i]+j] = adc[zerosuppressedindex];
765  zerosuppressedindex++;
766 
767  }
768  }
769 
770  return;
771  }
772 
773 
774  //----------------------------------------------------------
775  // if the compression type is kNone, copy the adc vector into the uncompressed vector
776  void Uncompress(const std::vector<short>& adc,
777  std::vector<short> &uncompressed,
778  raw::Compress_t compress)
779  {
780  if(compress == raw::kHuffman) UncompressHuffman(adc, uncompressed);
781  else if(compress == raw::kZeroSuppression){
782  ZeroUnsuppression(adc, uncompressed);
783  }
784  else if(compress == raw::kZeroHuffman){
785  std::vector<short> tmp(2*adc[0]);
786  UncompressHuffman(adc, tmp);
787  ZeroUnsuppression(tmp, uncompressed);
788  }
789  else if(compress == raw::kNone){
790  for(unsigned int i = 0; i < adc.size(); ++i) uncompressed[i] = adc[i];
791  }
792  else if (compress == raw::kFibonacci) {
793  UncompressFibonacci(adc, uncompressed);
794  }
795  else {
796  throw cet::exception("raw")
797  << "raw::Uncompress() does not support compression #"
798  << ((int) compress);
799  }
800  return;
801  }
802 
803  //----------------------------------------------------------
804  // if the compression type is kNone, copy the adc vector into the uncompressed vector
805  void Uncompress(const std::vector<short>& adc,
806  std::vector<short> &uncompressed,
807  int pedestal,
808  raw::Compress_t compress)
809  {
810  if(compress == raw::kHuffman) UncompressHuffman(adc, uncompressed);
811  else if(compress == raw::kZeroSuppression){
812  ZeroUnsuppression(adc, uncompressed, pedestal);
813  }
814  else if(compress == raw::kZeroHuffman){
815  std::vector<short> tmp(2*adc[0]);
816  UncompressHuffman(adc, tmp);
817  ZeroUnsuppression(tmp, uncompressed, pedestal);
818  }
819  else if(compress == raw::kNone){
820  for(unsigned int i = 0; i < adc.size(); ++i) uncompressed[i] = adc[i];
821  }
822  else if (compress == raw::kFibonacci) {
823  UncompressFibonacci(adc, uncompressed);
824  }
825  else {
826  throw cet::exception("raw")
827  << "raw::Uncompress() does not support compression #"
828  << ((int) compress);
829  }
830  return;
831  }
832 
833 
834  // the current Huffman Coding scheme used by uBooNE is
835  // based on differences between adc values in adjacent time bins
836  // the code is
837  // no change for 4 ticks --> 1
838  // no change for 1 tick --> 01
839  // +1 change --> 001
840  // -1 change --> 0001
841  // +2 change --> 00001
842  // -2 change --> 000001
843  // +3 change --> 0000001
844  // -3 change --> 00000001
845  // abs(change) > 3 --> write actual value to short
846  // use 15th bit to set whether a block is encoded or raw value
847  // 1 --> Huffman coded, 0 --> raw
848  // pad out the lowest bits in a word with 0's
849  void CompressHuffman(std::vector<short> &adc)
850  {
851  std::vector<short> const orig_adc(std::move(adc));
852 
853  // diffs contains the difference between an element of adc and the previous
854  // one; the first entry is never used.
855  std::vector<short> diffs;
856  diffs.reserve(orig_adc.size());
857  std::adjacent_difference
858  (orig_adc.begin(), orig_adc.end(), std::back_inserter(diffs));
859 
860  // prepare adc for the new data; we kind-of-expect the size,
861  // so we pre-allocate it; we might want to shrink-to-fit at the end
862  adc.clear();
863  adc.reserve(orig_adc.size());
864  // now loop over the diffs and do the Huffman encoding
865  adc.push_back(orig_adc.front());
866  unsigned int curb = 15U;
867 
868  std::bitset<16> bset;
869  bset.set(15);
870 
871  for(size_t i = 1U; i < diffs.size(); ++i){
872 
873  switch (diffs[i]) {
874  // if the difference is 0, check to see what the next 3 differences are
875  case 0 : {
876  if(i < diffs.size() - 3){
877  // if next 3 are also 0, set the next bit to be 1
878  if(diffs[i+1] == 0 && diffs[i+2] == 0 && diffs[i+3] == 0){
879  if(curb > 0){
880  --curb;
881  bset.set(curb);
882  i += 3;
883  continue;
884  }
885  else{
886  adc.push_back(bset.to_ulong());
887 
888  // reset the bitset to be ready for the next word
889  bset.reset();
890  bset.set(15);
891  bset.set(14); // account for the fact that this is a zero diff
892  curb = 14;
893  i += 3;
894  continue;
895  } // end if curb is not big enough to put current difference in bset
896  } // end if next 3 are also zero
897  else{
898  // 0 diff is encoded as 01, so move the current bit one to the right
899  if(curb > 1){
900  curb -= 2;
901  bset.set(curb);
902  continue;
903  } // end if the current bit is large enough to set this one
904  else{
905  adc.push_back(bset.to_ulong());
906  // reset the bitset to be ready for the next word
907  bset.reset();
908  bset.set(15);
909  bset.set(13); // account for the fact that this is a zero diff
910  curb = 13;
911  continue;
912  } // end if curb is not big enough to put current difference in bset
913  } // end if next 3 are not also 0
914  }// end if able to check next 3
915  else{
916  // 0 diff is encoded as 01, so move the current bit one to the right
917  if(curb > 1){
918  curb -= 2;
919  bset.set(curb);
920  continue;
921  } // end if the current bit is large enough to set this one
922  else{
923  adc.push_back(bset.to_ulong());
924  // reset the bitset to be ready for the next word
925  bset.reset();
926  bset.set(15);
927  bset.set(13); // account for the fact that this is a zero diff
928  curb = 13;
929  continue;
930  } // end if curb is not big enough to put current difference in bset
931  }// end if not able to check the next 3
932  break;
933  }// end if current difference is zero
934  case 1: {
935  if(curb > 2){
936  curb -= 3;
937  bset.set(curb);
938  }
939  else{
940  adc.push_back(bset.to_ulong());
941  // reset the bitset to be ready for the next word
942  bset.reset();
943  bset.set(15);
944  bset.set(12); // account for the fact that this is a +1 diff
945  curb = 12;
946  } // end if curb is not big enough to put current difference in bset
947  break;
948  } // end if difference = 1
949  case -1: {
950  if(curb > 3){
951  curb -= 4;
952  bset.set(curb);
953  }
954  else{
955  adc.push_back(bset.to_ulong());
956  // reset the bitset to be ready for the next word
957  bset.reset();
958  bset.set(15);
959  bset.set(11); // account for the fact that this is a -1 diff
960  curb = 11;
961  } // end if curb is not big enough to put current difference in bset
962  break;
963  }// end if difference = -1
964  case 2: {
965  if(curb > 4){
966  curb -= 5;
967  bset.set(curb);
968  }
969  else{
970  adc.push_back(bset.to_ulong());
971  // reset the bitset to be ready for the next word
972  bset.reset();
973  bset.set(15);
974  bset.set(10); // account for the fact that this is a +2 diff
975  curb = 10;
976  } // end if curb is not big enough to put current difference in bset
977  break;
978  }// end if difference = 2
979  case -2: {
980  if(curb > 5){
981  curb -= 6;
982  bset.set(curb);
983  }
984  else{
985  adc.push_back(bset.to_ulong());
986  // reset the bitset to be ready for the next word
987  bset.reset();
988  bset.set(15);
989  bset.set(9); // account for the fact that this is a -2 diff
990  curb = 9;
991  } // end if curb is not big enough to put current difference in bset
992  break;
993  }// end if difference = -2
994  case 3: {
995  if(curb > 6){
996  curb -= 7;
997  bset.set(curb);
998  }
999  else{
1000  adc.push_back(bset.to_ulong());
1001  // reset the bitset to be ready for the next word
1002  bset.reset();
1003  bset.set(15);
1004  bset.set(8); // account for the fact that this is a +3 diff
1005  curb = 8;
1006  } // end if curb is not big enough to put current difference in bset
1007  break;
1008  }// end if difference = 3
1009  case -3: {
1010  if(curb > 7){
1011  curb -= 8;
1012  bset.set(curb);
1013  }
1014  else{
1015  adc.push_back(bset.to_ulong());
1016  // reset the bitset to be ready for the next word
1017  bset.reset();
1018  bset.set(15);
1019  bset.set(7); // account for the fact that this is a -3 diff
1020  curb = 7;
1021  } // end if curb is not big enough to put current difference in bset
1022  break;
1023  }// end if difference = -3
1024  default: {
1025  // if the difference is too large that we have to put the entire adc value in:
1026  // put the current value into the adc vec unless the current bit is 15, then there
1027  // were multiple large difference values in a row
1028  if(curb != 15){
1029  adc.push_back(bset.to_ulong());
1030  }
1031 
1032  bset.reset();
1033  bset.set(15);
1034  curb = 15;
1035 
1036  // put the current adcvalue in adc, with its bit 15 set to 0
1037  if(orig_adc[i] > 0) adc.push_back(orig_adc[i]);
1038  else{
1039  std::bitset<16> tbit(-orig_adc[i]);
1040  tbit.set(14);
1041  adc.push_back(tbit.to_ulong());
1042  }
1043  break;
1044  } // if |difference| > 3
1045  }// switch diff[i]
1046  }// end loop over differences
1047 
1048  //write out the last bitset
1049  adc.push_back(bset.to_ulong());
1050 
1051  // this would reduce global memory usage,
1052  // at the cost of a new allocation and copy
1053  // adc.shrink_to_fit();
1054 
1055  } // CompressHuffman()
1056  //--------------------------------------------------------
1057  // need to decrement the bit you are looking at to determine the deltas as that is how
1058  // the bits are set
1059  void UncompressHuffman(const std::vector<short>& adc,
1060  std::vector<short> &uncompressed)
1061  {
1062 
1063  //the first entry in adc is a data value by construction
1064  uncompressed[0] = adc[0];
1065 
1066  unsigned int curu = 1;
1067  short curADC = uncompressed[0];
1068 
1069  // loop over the entries in adc and uncompress them according to the
1070  // encoding scheme above the CompressHuffman method
1071  for(unsigned int i = 1; i < adc.size() && curu < uncompressed.size(); ++i){
1072 
1073  std::bitset<16> bset(adc[i]);
1074 
1075  int numu = 0;
1076 
1077  //check the 15 bit to see if this entry is a full data value or not
1078  if( !bset.test(15) ){
1079  curADC = adc[i];
1080  if(bset.test(14)){
1081  bset.set(14, false);
1082  curADC = -1*bset.to_ulong();
1083  }
1084  uncompressed[curu] = curADC;
1085 
1086  ++curu;
1087  }
1088  else{
1089 
1090  int b = 14;
1091  int lowestb = 0;
1092 
1093  // ignore any padding with zeros in the lower order bits
1094  while( !bset.test(lowestb) && lowestb < 15) ++lowestb;
1095 
1096  if(lowestb > 14){
1097  mf::LogWarning("raw.cxx") << "encoded entry has no set bits!!! "
1098  << i << " "
1099  << bset.to_string< char,std::char_traits<char>,std::allocator<char> >();
1100  continue;
1101  }
1102 
1103  while( b >= lowestb){
1104 
1105  // count the zeros between the current bit and the next on bit
1106  int zerocnt = 0;
1107  while( !bset.test(b-zerocnt) && b-zerocnt > lowestb) ++zerocnt;
1108 
1109  b -= zerocnt;
1110 
1111  if(zerocnt == 0){
1112  for(int s = 0; s < 4; ++s){
1113  uncompressed[curu] = curADC;
1114  ++curu;
1115  ++numu;
1116  if(curu > uncompressed.size()-1) break;
1117  }
1118  --b;
1119  }
1120  else if(zerocnt == 1){
1121  uncompressed[curu] = curADC;
1122  ++curu;
1123  ++numu;
1124  --b;
1125  }
1126  else if(zerocnt == 2){
1127  curADC += 1;
1128  uncompressed[curu] = curADC;
1129  ++curu;
1130  ++numu;
1131  --b;
1132  }
1133  else if(zerocnt == 3){
1134  curADC -= 1;
1135  uncompressed[curu] = curADC;
1136  ++curu;
1137  ++numu;
1138  --b;
1139  }
1140  else if(zerocnt == 4){
1141  curADC += 2;
1142  uncompressed[curu] = curADC;
1143  ++curu;
1144  ++numu;
1145  --b;
1146  }
1147  else if(zerocnt == 5){
1148  curADC -= 2;
1149  uncompressed[curu] = curADC;
1150  ++curu;
1151  ++numu;
1152  --b;
1153  }
1154  else if(zerocnt == 6){
1155  curADC += 3;
1156  uncompressed[curu] = curADC;
1157  ++curu;
1158  ++numu;
1159  --b;
1160  }
1161  else if(zerocnt == 7){
1162  curADC -= 3;
1163  uncompressed[curu] = curADC;
1164  ++curu;
1165  ++numu;
1166  --b;
1167  }
1168 
1169  if(curu > uncompressed.size() - 1) break;
1170 
1171  }// end loop over bits
1172 
1173  if(curu > uncompressed.size() - 1) break;
1174 
1175  }// end if this entry in the vector is encoded
1176 
1177  }// end loop over entries in adc
1178 
1179  return;
1180  }
1181 
1182  //--------------------------------------------------------
1183  // need to decrement the bit you are looking at to determine the deltas as that is how
1184  // the bits are set
1185  int ADCStickyCodeCheck(const short adc_value,
1186  const int pedestal,
1187  bool fADCStickyCodeFeature){
1188 
1189  int adc_return_value = std::abs(adc_value - pedestal);
1190 
1191  if(!fADCStickyCodeFeature){
1192  return adc_return_value;
1193  }
1194  // if DUNE 35t ADC sticky code feature is enabled in simulation, skip over ADC codes with LSBs of 0x00 or 0x3f
1195  unsigned int sixlsbs = adc_value & onemask;
1196 
1197  if((sixlsbs==onemask || sixlsbs==0) && std::abs(adc_value - pedestal) < 64){
1198  adc_return_value = 0; //set current adc value to zero if its LSBs are at sticky values and if it is within one MSB cell (64 ADC counts) of the pedestal value
1199  }
1200  return adc_return_value;
1201  }
1202 
1203  inline void add_to_sequence_terminate(std::vector<bool> array, std::vector<bool>& cmp) {
1204  cmp.insert(cmp.end(), array.begin(), array.end());
1205  cmp.push_back(1);
1206  }
1207 
1208  void CompressFibonacci(std::vector<short> &wf,
1209  std::function<void(int, std::vector<std::vector<bool>>&)> add_to_table) {
1210 
1211  std::vector<std::vector<bool>> table;
1212  add_to_table(100, table);
1213 
1214  std::vector<short> comp_short;
1215  // First numbers are not encoded (size and baseline)
1216  assert(not empty(wf));
1217 
1218  unsigned int size_short = sizeof(wf[0])*8-1; // assuming we don't encode over the sign bits
1219  unsigned int max_2_short = (1 << (size_short*2)); //this number is then: 1,073,741,824 (i.e. almost 9min of data at 2MHz)
1220  size_t wf_size = wf.size();
1221 
1222 
1223  if (wf_size > max_2_short) {
1224  throw cet::exception("raw") << "WOW! You are trying to compress a " << wf_size << " long waveform"
1225  << " in a vector of shorts.\nUnfortunately, the encoded waveform needs to store the size"
1226  << " of the wavefom (in its first number) and " << wf_size << " is bigger than the maximum\n"
1227  << " number you can encode with 2 shorts (" << max_2_short << ").\n"
1228  << " Bailing out disgracefully to avoid massive trouble.\n";
1229  }
1230 
1231  short high = (wf_size >> (sizeof(short)*8-1));
1232  short low = wf_size % ((std::numeric_limits<short>::max()+1));
1233  comp_short.push_back(high);
1234  comp_short.push_back(low);
1235  comp_short.push_back(*wf.begin());
1236 
1237  // The format we are working with
1238  std::vector<bool> cmp;
1239  cmp.reserve(wf.size()*sizeof(wf[0])*8);
1240 
1241  // The input is changed to be the difference between ticks
1242  std::vector<short> diff;
1243  diff.reserve(wf.size());
1244  // Fibonacci number are positive, so need a way to get negative number
1245  // We use the ZigZag approach (even numbers are positive, odd are negative)
1246  std::adjacent_difference(wf.begin(), wf.end(),std::back_inserter(diff), [](const short& it1, const short& it2){
1247  short d = it1-it2;
1248  if (d > 0) d = 2 * d;
1249  else d = -2 * d + 1;
1250  return d;
1251  });
1252 
1253  // Start from 1 to avoid the first number
1254  for (size_t iSample=1; iSample<diff.size(); ++iSample) {
1255 
1256  short d = diff[iSample];
1257  if ((unsigned)d < table.size()) {
1258  add_to_sequence_terminate(table[d], cmp);
1259  } else { // catch if the table is too small...
1260  int end = d+1;
1261  // use the user provided function to fill the table
1262  add_to_table(end, table);
1263  // and add again to the sequence
1264  add_to_sequence_terminate(table[d], cmp);
1265  }
1266  }
1267 
1268  // Now convert all this to a vector of short and it's just another day in paradise for larsoft
1269  size_t n_vector = cmp.size();
1270 
1271  // Create a bitset of the size of the short to simplify things
1272  std::bitset<8*sizeof(short)> this_encoded;
1273  // Set the bitset to match the stream
1274  size_t bit_counter=0;
1275 
1276  for (size_t it=0; it<n_vector; ++it) {
1277 
1278  if (bit_counter>=8*sizeof(short)) {
1279  short comp_s = (short)this_encoded.to_ulong();
1280  comp_short.push_back(comp_s);
1281  bit_counter=0;
1282  this_encoded.reset();
1283  }
1284 
1285  if (cmp[it])
1286  this_encoded.set(bit_counter);
1287 
1288  bit_counter++;
1289 
1290  }
1291 
1292  // Deal with the last part
1293  short comp_s = (short)this_encoded.to_ulong();
1294  comp_short.push_back(comp_s);
1295 
1296  wf = comp_short;
1297 
1298  return;
1299  }
1300 
1301  void UncompressFibonacci(const std::vector<short> &adc,
1302  std::vector<short> &uncompressed,
1303  std::function<int(std::vector<bool>&)> decode_table_chunk) {
1304 
1305  // First compressed sample is the size
1306  size_t n_samples = (adc[0]<<(sizeof(short)*8-1))+adc[1];
1307  // The second compressed sample is the first uncompressed sample
1308  uncompressed.push_back(adc[2]);
1309 
1310  // The thing that we want to decode (rather than jumbled short vector)
1311  std::vector<bool> comp;
1312 
1313  for (size_t i=3; i<adc.size(); ++i) {
1314 
1315  std::bitset<8*sizeof(short)> this_encoded(adc[i]);
1316  for (size_t i2=0; i2<this_encoded.size(); ++i2) {
1317  comp.push_back(this_encoded[i2]);
1318  }
1319  }
1320 
1321  // The bit which has to be decoded ("chunk")
1322  std::vector<bool> current_number;
1323  for (size_t it=0; it<comp.size(); ++it) {
1324  current_number.push_back(comp[it]);
1325  // If we have at least 2 numbers in the current chunk
1326  // and if the last 2 number are one
1327  // and if we are not at the end
1328  if ((current_number.size()>=2 && it >= 1 && comp[it-1] == 1 && comp[it] == 1) || it == comp.size()-1) {
1329  current_number.pop_back();
1330  short zigzag_number = decode_table_chunk(current_number);
1331 
1332  short decoded = 0;
1333  if (zigzag_number%2 == 0) decoded = zigzag_number / 2;
1334  else decoded = -(zigzag_number - 1) / 2;
1335  short baseline = uncompressed.back();
1336 
1337  uncompressed.push_back(baseline + decoded);
1338 
1339  current_number.clear();
1340  if (uncompressed.size() == n_samples) break;
1341  }
1342  }
1343  return;
1344  }
1345 
1346  void fibonacci_encode_table(int end, std::vector<std::vector<bool>>& table) {
1347  if ((int)table.size() > end)
1348  return;
1349 
1350  std::map<int, int> fibn; // no need for this to be static
1351  fibn[0] = 0;
1352  fibn[1] = 1;
1353  fibn[2] = 1;
1354 
1355  // if the table was empty, fill it
1356  if (empty(table)) {
1357  table.push_back(std::vector<bool>()); // we need this one so that the index of the vector is the same as the number we want to encode
1358  table.push_back({true });
1359  table.push_back({false,true});
1360  }
1361 
1362  if ((int)table.size() > end)
1363  return;
1364 
1365  // start at the third fibonacci number
1366  for (int i=2; fibn.rbegin()->second<end; ++i) {
1367  fibn[i] = fibn[i-1] + fibn[i-2];
1368  }
1369 
1370 
1371  for (int i=table.size(); i<=end; ++i) {
1372  int current_number = i;
1373  std::vector<bool> seq; // the final sequence of numbers
1374  while (current_number>0) {
1375  // find the biggest fibonacci number that is smaller than the current number
1376  for (auto fib = fibn.rbegin(); fib != fibn.rend(); ++fib) {
1377  if (fib->second<=current_number) {
1378  // if this is the first number, create the vector
1379  if (!seq.size())
1380  seq=std::vector<bool>(fib->first-1, false);
1381  // fill the sequence
1382  seq[fib->first-2] = true;
1383  // subtract the current number
1384  current_number-=fib->second;
1385  break;
1386  }
1387  }
1388  }
1389 
1390  table.push_back(seq);
1391  }
1392  }
1393 
1394  short fibonacci_decode(std::vector<bool>& chunk) {
1395  std::vector<int> FibNumbers={1,2,3,5,8,13,21,34,55,89,144,233,377,610,987};
1396 
1397  if (chunk.size() > FibNumbers.size()) {
1398  for (int i=FibNumbers.size(); i<=(int)chunk.size(); ++i){
1399  FibNumbers.push_back(FibNumbers.at(i-1)+FibNumbers.at(i-2));
1400  }
1401  }
1402  short decoded = 0;
1403  for (size_t it=0; it<chunk.size(); ++it) {
1404  if (chunk[it])
1405  decoded += FibNumbers[it];
1406  }
1407  return decoded;
1408  }
1409 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void CompressHuffman(std::vector< short > &adc)
Definition: raw.cxx:849
Huffman Encoding.
Definition: RawTypes.h:10
enum raw::_compress Compress_t
void UncompressHuffman(const std::vector< short > &adc, std::vector< short > &uncompressed)
Definition: raw.cxx:1059
struct vector vector
const unsigned int onemask
Definition: raw.h:139
int16_t adc
Definition: CRTFragment.hh:202
comp
Definition: dbjson.py:33
Zero Suppression followed by Huffman Encoding.
Definition: RawTypes.h:12
Raw data description.
no compression
Definition: RawTypes.h:9
Zero Suppression algorithm.
Definition: RawTypes.h:11
int ADCStickyCodeCheck(const short adc_value, const int pedestal, bool fADCStickyCodeFeature)
Definition: raw.cxx:1185
T abs(T value)
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
def move(depos, offset)
Definition: depos.py:107
void fibonacci_encode_table(int end, std::vector< std::vector< bool >> &table)
Definition: raw.cxx:1346
Collect all the RawData header files together.
string tmp
Definition: languages.py:63
static int max(int a, int b)
void ZeroUnsuppression(const std::vector< short > &adc, std::vector< short > &uncompressed)
Definition: raw.cxx:716
void add_to_sequence_terminate(std::vector< bool > array, std::vector< bool > &cmp)
Definition: raw.cxx:1203
Fibonacci encoding.
Definition: RawTypes.h:14
void UncompressFibonacci(const std::vector< short > &adc, std::vector< short > &uncompressed, std::function< int(std::vector< bool > &)> decode_table_chunk)
Definition: raw.cxx:1301
void CompressFibonacci(std::vector< short > &wf, std::function< void(int, std::vector< std::vector< bool >> &)> add_to_table)
Definition: raw.cxx:1208
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
static bool * b
Definition: config.cpp:1043
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
Definition: raw.cxx:19
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
void function(int client, int *resource, int parblock, int *test, int p)
void ZeroSuppression(std::vector< short > &adc, unsigned int &zerothreshold)
Definition: raw.cxx:173
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
short fibonacci_decode(std::vector< bool > &chunk)
Definition: raw.cxx:1394