33 BYTE* out8 =
static_cast<BYTE*
>(out);
34 BYTE* stop = out8 + n8bit;
42 *out8++ = ( v1 >> 4 ) & 0xff;
43 *out8++ = ( (v1 & 0xf) << 4 ) + ( ( v2 >> 8) & 0xf );
54 const BYTE* in8 =
static_cast<const BYTE*
>(in);
55 const BYTE* stop = in8 + n8bit;
65 *out16++ = ((v1 << 4) + ((v2 >> 4) & 0xf)) & 0xfff;
66 *out16++ = (((v2 & 0xf) << 8 ) + (v3 & 0xff)) & 0xfff;
76 size_t vecsize = adc.size();
79 msg_warn<<
"The input vector size is not even. Appending zeros"<<
endl;
85 size_t bufsize = vecsize/2*3;
88 char *buffer =
new char[bufsize];
94 ofstream
fout(fname, ios::out | ios::binary);
95 fout.write(buffer, bufsize);
108 std::ifstream fin(fname, ios::in | ios::binary);
116 size_t bufsize = fin.gcount();
118 fin.seekg( 0, std::ios_base::beg );
121 while( (bufsize+npad) % 3 )
123 msg_warn<<
"The input vector size is not divisible by 3. Appending zeros"<<
endl;
128 char* buffer =
new char[bufsize + npad];
129 for(
size_t i=bufsize;i<bufsize+npad;i++)
133 fin.
read(buffer, bufsize);
137 adc.resize( (bufsize + npad)/3*2, 0 );
149 memset(&rh, 0,
sizeof(rh));
155 rh.
run_num = (((uint32_t)buf[0] << 24) & 0xFF000000);
156 rh.
run_num += (((uint32_t)buf[1] << 16) & 0xFF0000);
157 rh.
run_num += (((uint32_t)buf[2] << 8) & 0xFF00);
158 rh.
run_num += ( (uint32_t)buf[3] & 0xFF);
164 msg_err<<
"Decode runheader exception "<<e.what()<<
endl;
177 memset(&eh, 0,
sizeof(eh));
184 if( !( ((k0 & 0xFF) ==
EVSKEY) && ((k1 & 0xFF) ==
EVSKEY) ) )
186 msg_err<<
"Event delimiting word could not be detected "<<
endl;
191 eh.
trig_info = ConvertToValue<trigger_t>(buf+rval);
195 eh.
dq_flag = (uint8_t)buf[rval++];
198 eh.
ev_num = (((uint32_t)buf[rval++] << 24) & 0xFF000000);
199 eh.
ev_num += (((uint32_t)buf[rval++] << 16) & 0xFF0000);
200 eh.
ev_num += (((uint32_t)buf[rval++] << 8) & 0xFF00);
201 eh.
ev_num += ( (uint32_t)buf[rval++] & 0xFF);
205 eh.
ev_size = (((uint32_t)buf[rval++] << 24) & 0xFF000000);
206 eh.
ev_size += (((uint32_t)buf[rval++] << 16) & 0xFF0000);
207 eh.
ev_size += (((uint32_t)buf[rval++] << 8) & 0xFF00);
208 eh.
ev_size += ( (uint32_t)buf[rval++] & 0xFF);
212 msg_err<<
"Decode event header exception "<<e.what()<<
endl;
224 memset(&rf, 0,
sizeof(rf));
229 if( !( ((buf[0]&0xFF) ==
ENDKEY) && ((buf[1]&0xFF) ==
ENDKEY) ) )
231 msg_err<<
"Delimiting word in footer could not be detected "<<
endl;
234 rf.
num_events = (((uint16_t)buf[2] << 8) & 0xff00) + (buf[3] & 0xff);
238 msg_err<<
"Decode footer info exception "<<e.what()<<
endl;
static LogStream msg_warn(std::cout, _strwarn)
static const size_t FileFootSz
ssize_t decode_evehead(const char *buf, evheader_t &eh)
ssize_t decode_runhead(const char *buf, runheader_t &rh)
static const size_t RunHeadSz
static const size_t EveHeadSz
ssize_t decode_filefoot(const char *buf, footer_t &rf)
static int max(int a, int b)
void unpack12into16(const void *in, void *out, size_t n)
void pack16into12(const void *in, void *out, size_t n)
void read12(const char *fname, std::vector< adc16_t > &adc)
void write12(const char *fname, std::vector< adc16_t > &adc)
static LogStream msg_err(std::cerr, _strerror)
static formatexception fex
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)