GSE++ library: reading and writing GSE waveforms
gsexx_TDAT2.cc
Go to the documentation of this file.
1 
35 #define TF_GSEXX_TDAT2_CC_VERSION \
36  "TF_GSEXX_TDAT2_CC V1.1"
37 #define TF_GSEXX_TDAT2_CC_CVSID \
38  "$Id$"
39 
40 #include <gsexx.h>
41 #include "gsexx_TDAT2.h"
42 
43 namespace GSE2 {
44 namespace waveform {
45 
46 /*
47  * documentation for class TDAT2sum
48  * --------------------------------
49  * all functions are inline
50  */
51 
62 const char* const TDAT2sum::GSEID="DAT2";
64 
65 /*----------------------------------------------------------------------*/
66 
81 /*======================================================================*/
82 
83 /*
84  * documentation for class TDAT2read
85  * ---------------------------------
86  * all functions are inline
87  */
88 
121 // conversion wrapper function
122 intT TDAT2read::operator()(std::istream& is)
123 {
124  intT retval;
125  // check for DAT2 line
126  if (this->TDAT2sum::nread() == 0)
127  {
128  std::string lineID;
129  is >> lineID;
130  if (!GSEIDmatch<TDAT2sum>(lineID)) throw
131  Terror("ERROR (TDAT2::read): missing DAT2 line!");
132  char c=' ';
133  while (c != '\n') { is.get(c); }
134  }
135 
136  if (!this->TDAT2sum::hot()) throw
137  Terror("ERROR (TDAT2::read): requesting more samples than specified!");
138  retval=convert(is);
139  this->TDAT2sum::add(retval);
140 
141  // check checksum
142  if (!TDAT2sum::hot()) {
143  TCHK2 checksum;
144  checksum.read(is);
145  if (this->TDAT2sum::checksum().value()!=checksum.value())
146  {
147  if (!Terror::silent)
148  {
149  std::cerr << "checksum read: " << checksum.value()
150  << " calculated: " << this->TDAT2sum::checksum().value()
151  << std::endl;
152  }
153  throw
154  Terror("ERROR (TDAT2::read): conflicting checksum in CHK2 line!");
155  }
156  }
157  return(retval);
158 }
159 
160 /*======================================================================*/
161 
162 /*
163  * documentation for class TDAT2write
164  * ----------------------------------
165  * all functions are inline
166  */
167 
202 // conversion wrapper function
203 std::string TDAT2write::operator()(const intT& value)
204 {
205  std::string retval;
206  if (this->TDAT2sum::nread() == 0)
207  {
208  retval+=TDAT2sum::GSEID;
209  retval+=" \n";
210  }
211  if (!this->TDAT2sum::hot()) throw
212  Terror("ERROR (TDAT2write): writing more samples than specified!");
213  this->TDAT2sum::add(value);
214  retval+=convert(value);
215  if (!TDAT2sum::hot()) {
216  retval+='\n';
217  retval+=this->TDAT2sum::checksum().write();
218  }
219  return(retval);
220 }
221 
222 /*======================================================================*/
223 
224 /*
225  * documentation and function code for class TDAT2readCM6
226  * ------------------------------------------------------
227  */
228 
252 /*----------------------------------------------------------------------*/
253 
254 /*
255  * documentation and function code for class TDAT2writeCM6
256  * -------------------------------------------------------
257  */
258 
266 intT TDAT2readCM6::convert(std::istream& is)
267 {
268  // it's simple :-)
269  return(Mremovediff(CM6::decode(is)));
270 }
271 
272 /*======================================================================*/
273 
299 /*----------------------------------------------------------------------*/
300 
308 std::string TDAT2writeCM6::convert(const intT& value)
309 {
310  std::string charcode;
311  try {
312  charcode=CM6::encode(Mapplydiff(value));
313  }
314  catch (Terror e)
315  {
316  std::cerr.setf(std::ios_base::dec,std::ios_base::basefield);
317  std::cerr << "TDAT2writeCM6::convert caught exception" << std::endl;
318  Mapplydiff.report_status(std::cerr);
319  std::cerr << "current value: " << value << std::endl;
320  throw e;
321  }
322  std::string retval;
323  // iterate through all characters
324  for (std::string::const_iterator c=charcode.begin(); c!=charcode.end(); c++)
325  {
326  // next line if full
327  if (Mlinelength <= Mcpos)
328  {
329  retval+='\n';
330  Mcpos=0;
331  }
332  retval+=*c;
333  Mcpos++;
334  }
335  return(retval);
336 }
337 
338 } // namespace waveform
339 } // names(all sophistipace GSE2
340 
341 /* ----- END OF gsexx_TDAT2.cc ----- */
GSE++ library: read and write GSE waveform data (prototypes).
virtual intT convert(std::istream &is)=0
get from stream: user must define
intT convert(std::istream &is)
get from stream: user must define
Definition: gsexx_TDAT2.cc:266
int intT
All GSE2 waveform data is based on 4 byte integers.
Definition: gsexx.h:89
static const char *const GSEID
GSE line idetifier.
Definition: gsexx.h:306
std::string convert(const intT &value)
put to stream: user must define
Definition: gsexx_TDAT2.cc:308
std::string encode(const intT &invalue)
CM6 subformat encoding function.
Definition: gsexx_cm6.cc:77
std::string write() const
write CHK2 line to string
void read(std::istream &is)
read CHK2 line from istream
All stuff defined by the GSE2 standard.
intT operator()(std::istream &is)
get another value from the stream
Definition: gsexx_TDAT2.cc:122
void add(const intT &value)
count a sample
Definition: gsexx.h:322
helper function prototypes for TDAT2 (prototypes)
bool hot() const
return true if not all samples are processed
Definition: gsexx.h:304
intT Mcpos
character position in line
Definition: gsexx.h:369
Base class for all exceptions in this module.
Definition: gsexx.h:68
virtual std::string convert(const intT &value)=0
put to stream: user must define
void report_status(std::ostream &os) const
report status (for debugging)
Definition: gsexx.h:247
intT Mlinelength
linelength in output file
Definition: gsexx.h:367
const TCHK2 & checksum() const
return the checksum
Definition: gsexx.h:298
intT nread() const
return the number of samples read
Definition: gsexx.h:300
apply2nddiffT Mapplydiff
only compression formats apply differences.
Definition: gsexx.h:407
intT value() const
Return the checksum value.
Definition: gsexx.h:181
A class for the cumulative calculation of checksums.
Definition: gsexx.h:173
std::string operator()(const intT &value)
write another value to the stream
Definition: gsexx_TDAT2.cc:203
static bool silent
be silent?
Definition: gsexx.h:77
remove2nddiffT Mremovediff
only compression formats apply differences.
Definition: gsexx.h:388
intT decode(std::istream &is)
CM6 subformat decoding function.
Definition: gsexx_cm6.cc:191