15 #include "cetlib_except/exception.h" 29 <<
"Compress method called for kZeroHuffman but no threshold or pedestal value";
33 <<
"Compress method called with compression type: " << compress <<
" but no threshold or pedestal value";
68 size_t ticksbefore_in,
71 const size_t adcsize = adc.size();
72 if (adcsize == 0)
return 0;
74 size_t ticksbefore = ticksbefore_in;
75 if (adcsize < ticksbefore_in) ticksbefore = adcsize;
76 size_t ticksafter = ticksafter_in;
77 if (adcsize < ticksafter_in) ticksafter = adcsize;
80 std::vector<int> inablock(adcsize,0);
81 std::vector<int> blockbegin;
82 std::vector<int> blocksize;
86 for (
size_t i=0; i<adcsize; ++i)
88 if (adc[i] >= zerothreshold)
91 if (i >= ticksbefore) jmin = i-ticksbefore;
92 size_t jmax = adcsize - 1;
93 if (i+ticksafter < jmax) jmax = i+ticksafter;
94 for (
size_t j=jmin; j<=jmax; ++j)
103 bool curblock =
false;
104 for (
size_t i=0; i<adcsize; ++i)
106 if (!curblock && inablock[i] != 0)
109 blockbegin.push_back(i);
111 if (curblock && (inablock[i] == 0 || i+1 == adcsize))
114 blocksize.push_back(i - blockbegin.back() + 1);
118 size_t nblocks = blockbegin.size();
123 for(
size_t i = 0; i < nblocks; ++i)
124 adc[i+2] = blockbegin[i];
126 for(
size_t i = 0; i < nblocks; ++i)
127 adc[i+nblocks+2] = blocksize[i];
130 for(
size_t i = 0; i < nblocks; ++i)
132 for (
int j=0; j < blocksize[i]; ++j)
134 zerosuppressed[zsi] = adc[blockbegin[i]+j];
139 adc.resize(2+nblocks+nblocks+zsi);
140 for (
size_t i=0; i<zsi; ++i)
142 adc[i+nblocks+nblocks+2] = zerosuppressed[i];
156 const int lengthofadc = adc[0];
157 const int nblocks = adc[1];
159 uncompressed.resize(lengthofadc);
160 for (
int i = 0;i < lengthofadc; ++i){
161 uncompressed[i] = pedestal;
164 int zerosuppressedindex = nblocks*2 + 2;
166 for(
int i = 0; i < nblocks; ++i){
168 for(
int j = 0; j < adc[2+nblocks+i]; ++j){
171 uncompressed[adc[2+i]+j] = adc[zerosuppressedindex];
172 zerosuppressedindex++;
189 for(
unsigned int i = 0; i < adc.size(); ++i) uncompressed[i] = adc[i];
193 <<
"raw::Uncompress() does not support compression #" 194 << ((
int) compress) <<
" without a pedestal specified";
217 for(
unsigned int i = 0; i < adc.size(); ++i) uncompressed[i] = adc[i];
221 <<
"raw::Uncompress() does not support compression #" 249 std::vector<short> diffs;
250 diffs.reserve(orig_adc.size());
251 std::adjacent_difference
252 (orig_adc.begin(), orig_adc.end(), std::back_inserter(diffs));
257 adc.reserve(orig_adc.size());
259 adc.push_back(orig_adc.front());
260 unsigned int curb = 15U;
262 std::bitset<16> bset;
265 for(
size_t i = 1U; i < diffs.size(); ++i){
270 if(i < diffs.size() - 3){
272 if(diffs[i+1] == 0 && diffs[i+2] == 0 && diffs[i+3] == 0){
280 adc.push_back(bset.to_ulong());
299 adc.push_back(bset.to_ulong());
317 adc.push_back(bset.to_ulong());
334 adc.push_back(bset.to_ulong());
349 adc.push_back(bset.to_ulong());
364 adc.push_back(bset.to_ulong());
379 adc.push_back(bset.to_ulong());
394 adc.push_back(bset.to_ulong());
409 adc.push_back(bset.to_ulong());
423 adc.push_back(bset.to_ulong());
431 if(orig_adc[i] > 0) adc.push_back(orig_adc[i]);
433 std::bitset<16> tbit(-orig_adc[i]);
435 adc.push_back(tbit.to_ulong());
443 adc.push_back(bset.to_ulong());
458 uncompressed[0] = adc[0];
460 unsigned int curu = 1;
461 short curADC = uncompressed[0];
465 for(
unsigned int i = 1; i < adc.size() && curu < uncompressed.size(); ++i){
467 std::bitset<16> bset(adc[i]);
472 if( !bset.test(15) ){
476 curADC = -1*bset.to_ulong();
478 uncompressed[curu] = curADC;
488 while( !bset.test(lowestb) && lowestb < 15) ++lowestb;
493 << bset.to_string< char,std::char_traits<char>,std::allocator<char> >();
497 while( b >= lowestb){
501 while( !bset.test(b-zerocnt) && b-zerocnt > lowestb) ++zerocnt;
506 for(
int s = 0;
s < 4; ++
s){
507 uncompressed[curu] = curADC;
510 if(curu > uncompressed.size()-1)
break;
514 else if(zerocnt == 1){
515 uncompressed[curu] = curADC;
520 else if(zerocnt == 2){
522 uncompressed[curu] = curADC;
527 else if(zerocnt == 3){
529 uncompressed[curu] = curADC;
534 else if(zerocnt == 4){
536 uncompressed[curu] = curADC;
541 else if(zerocnt == 5){
543 uncompressed[curu] = curADC;
548 else if(zerocnt == 6){
550 uncompressed[curu] = curADC;
555 else if(zerocnt == 7){
557 uncompressed[curu] = curADC;
563 if(curu > uncompressed.size() - 1)
break;
567 if(curu > uncompressed.size() - 1)
break;
std::vector< ADC_t > ADCvector_t
void CompressHuffman(gar::raw::ADCvector_t &adc)
void ZeroUnsuppression(const gar::raw::ADCvector_t &adc, gar::raw::ADCvector_t &uncompressed, gar::raw::ADC_t pedestal)
int ZeroSuppression(gar::raw::ADCvector_t &adc, gar::raw::ADC_t zerothreshold, size_t ticksbefore_in, size_t ticksafter_in)
Zero Suppression followed by Huffman Encoding.
void UncompressHuffman(const gar::raw::ADCvector_t &adc, gar::raw::ADCvector_t &uncompressed)
enum gar::raw::_compress Compress_t
Zero Suppression algorithm.
General GArSoft Utilities.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void Uncompress(const gar::raw::ADCvector_t &adc, gar::raw::ADCvector_t &uncompressed, gar::raw::Compress_t compress)
Uncompresses a raw data buffer.
void Compress(gar::raw::ADCvector_t &adc, gar::raw::Compress_t compress)
In-place compression of raw data buffer.
cet::coded_exception< error, detail::translate > exception