22 void logsigs(
const C& sigs,
int logLevel,
int alllevel,
string myname) {
23 if ( logLevel > 2 ) cout << myname <<
" size: " << sigs.size() <<
endl;
25 for (
unsigned int isig=0; isig<sigs.size(); ++isig ) {
26 if ( logLevel<alllevel && isig > 50 ) {
27 cout << myname <<
" ..." <<
endl;
30 cout << myname <<
" sigs[" << isig <<
"]: " << sigs[isig] <<
endl;
41 : m_UseBlock(useBlock), m_UseHuffman(useHuffman), m_LogLevel(logLevel) { }
48 const string myname =
"LarsoftHuffmanCompressService::ctor: ";
54 cout << myname <<
" UseHuffman: " << m_UseHuffman <<
endl;
64 const string myname =
"LarsoftHuffmanCompressService::compress: ";
65 if ( keep.size() != sigs.size() ) {
66 cout <<
"ERROR: Filter and ADC have different sizes: " << keep.size()
67 <<
" != " << sigs.size() <<
endl;
72 logsigs(sigs,
m_LogLevel, 6, myname +
"Before compression");
73 logsigs(keep,
m_LogLevel, 6, myname +
"Filter");
76 for (
bool val : keep )
if (
val ) ++nkeep;
77 cout << myname <<
"Keeping " << nkeep <<
"/" << keep.size() <<
" ticks" <<
endl;
80 block(sigs, keep, newsigs);
85 repsvc.
compress(sigs, keep, offset, comp);
92 logsigs(sigs,
m_LogLevel, 5, myname +
"After compression");
99 out << prefix <<
"LarsoftHuffmanCompressService";
113 const unsigned int adcsize = sigsin.size();
114 std::vector<short> zerosuppressed(sigsin.size());
115 unsigned int maxblocks = adcsize/2 + 1;
116 std::vector<short> blockbegin(maxblocks);
117 std::vector<short> blocksize(maxblocks);
118 unsigned int nblocks = 0;
119 unsigned int zerosuppressedsize = 0;
120 bool inblock =
false;
121 for (
unsigned int i=0; i<adcsize; ++i ) {
124 blockbegin[nblocks] = i;
125 blocksize[nblocks] = 0;
128 zerosuppressed[zerosuppressedsize] = sigsin[i];
129 ++zerosuppressedsize;
130 ++blocksize[nblocks];
131 if ( i == adcsize-1 ) ++nblocks;
132 }
else if ( inblock ) {
140 sigsout.resize(2+nblocks+nblocks+zerosuppressedsize);
141 sigsout[0] = adcsize;
142 sigsout[1] = nblocks;
143 for (
unsigned int i=0; i<nblocks; ++i ) sigsout[i+2] = blockbegin[i];
144 for (
unsigned int i=0; i<nblocks; ++i ) sigsout[i+nblocks+2] = blocksize[i];
145 for (
unsigned int i=0; i<zerosuppressedsize; ++i ) sigsout[i+nblocks+nblocks+2] = zerosuppressed[i];
void CompressHuffman(std::vector< short > &adc)
LarsoftHuffmanCompressService(bool useBlock, bool useHuffman, int logLevel)
std::vector< AdcCount > AdcCountVector
enum raw::_compress Compress_t
void block(const AdcCountVector &oldsigs, const AdcFilterVector &keep, AdcCountVector &newsigs) const
Zero Suppression followed by Huffman Encoding.
Zero Suppression algorithm.
int compress(AdcCountVector &sigs, const AdcFilterVector &keep, AdcCount offset, raw::Compress_t &comp) const
T get(std::string const &key) const
std::ostream & print(std::ostream &out=std::cout, std::string prefix=" ") const
std::vector< bool > AdcFilterVector
std::optional< T > get_if_present(std::string const &key) const
int compress(AdcCountVector &sigs, const AdcFilterVector &keep, AdcCount offset, raw::Compress_t &comp) const
QTextStream & endl(QTextStream &s)
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)