Commit 9a3d0fda authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

added test code and checksum algorithm

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 756
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent eb787bbb
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.1 2002-03-17 21:26:27 forbrig Exp $
# $Id: Makefile,v 1.2 2002-03-25 22:04:06 forbrig Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -31,7 +31,7 @@ edit: flist; vim $<
.PHONY: clean
clean: ;
-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
-/bin/rm -vf flist *.d *.o
-/bin/rm -vf flist *.d *.o gsexx_tests
#======================================================================
# pattern rules
......@@ -66,7 +66,7 @@ install-include: ; newinclude $(INCSRC)
doxyclean: ;/bin/rm -rfv doc docbrief
DOXYSRC=README gsexx.h gsexx.cc
DOXYSRC=README gsexx.h gsexx.cc gsexx_tests.cc
doc/%: doxyfull.cfg $(DOXYSRC); doxygen $<
docbrief/%: doxybrief.cfg $(DOXYSRC); doxygen $<
......@@ -82,4 +82,11 @@ doxyfullview: doxyfull; netscape doc/html/index.html &
doxybriefview: doxybrief; netscape docbrief/html/index.html &
doxyview: doxyfullview doxybrief
#======================================================================
# test code
# ---------
gsexx_tests: gsexx_tests.cc; $(CXX) -o $@ $< -I$(LOCINCLUDEDIR)
tests: gsexx_tests; $<
# ----- END OF Makefile -----
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: gsexx.cc,v 1.1 2002-03-17 21:26:27 forbrig Exp $
* $Id: gsexx.cc,v 1.2 2002-03-25 22:04:06 forbrig Exp $
* \author Thomas Forbriger
* \date 16/03/2002
*
......@@ -20,8 +20,9 @@
#define TF_GSEXX_CC_VERSION \
"TF_GSEXX_CC V1.0 "
#define TF_GSEXX_CC_CVSID \
"$Id: gsexx.cc,v 1.1 2002-03-17 21:26:27 forbrig Exp $"
"$Id: gsexx.cc,v 1.2 2002-03-25 22:04:06 forbrig Exp $"
#include<cmath>
#include <gsexx.h>
namespace GSE2 {
......@@ -52,14 +53,14 @@ namespace differences {
class Tapply_diff {
public:
Tapply_diff(): Mxold(0) { }
int operator()(const int& x)
int operator()(const intT& x)
{
int xold=Mxold;
intT xold=Mxold;
Mxold=x;
return(x-xold);
}
private:
int Mxold;
intT Mxold;
}; // Tapply_diff
......@@ -71,10 +72,10 @@ class Tapply_diff {
class Tremove_diff {
public:
Tremove_diff(): Mxold(0) { }
int operator()(const int& x)
intT operator()(const intT& x)
{ return(Mxold=Mxold+x); }
private:
int Mxold;
intT Mxold;
}; // Tremove_diff
/*! \brief Template to apply or remove differences of any order.
......@@ -89,7 +90,7 @@ class Tremove_diff {
template<int n, class OP>
class Tdiff_operator {
public:
int operator()(const int& val) { return(Mop(Mdiff(val))); }
intT operator()(const intT& val) { return(Mop(Mdiff(val))); }
private:
OP Mop;
Tdiff_operator<n-1, OP> Mdiff;
......@@ -106,19 +107,23 @@ class Tdiff_operator {
template<class OP>
class Tdiff_operator<0, OP> {
public:
int operator()(const int& val) { return(val); }
intT operator()(const intT& val) { return(val); }
}; // Tdiff_operator<0, OP>
} // namespace differences
//! Operator to apply first differences
typedef differences::Tdiff_operator<1, Tapply_diff> apply1stdiffT;
typedef differences::Tdiff_operator<1, differences::Tapply_diff>
apply1stdiffT;
//! Operator to apply second differences
typedef differences::Tdiff_operator<2, Tapply_diff> apply2nddiffT;
typedef differences::Tdiff_operator<2, differences::Tapply_diff>
apply2nddiffT;
//! Operator to remove first differences
typedef differences::Tdiff_operator<1, Tremove_diff> remove1stdiffT;
typedef differences::Tdiff_operator<1, differences::Tremove_diff>
remove1stdiffT;
//! Operator to remove second differences
typedef differences::Tdiff_operator<2, Tremove_diff> remove2nddiffT;
typedef differences::Tdiff_operator<2, differences::Tremove_diff>
remove2nddiffT;
/*======================================================================*/
......@@ -128,6 +133,46 @@ typedef differences::Tdiff_operator<2, Tremove_diff> remove2nddiffT;
* The auxid field should only be used if the channel id non-unique.
*/
/*======================================================================*/
/*! \class TCHK2
*
* This class allows the cumulative calculation of checksums. The code is take
* from the Appendix A.1 from the Conference Room Paper/243 of the Group of
* Scientific Experts.
*/
/*!
* This function adds the sample value to the checksum and increases the
* sample counter.
*
* \param value sample value to add
*/
void TCHK2::add(const intT& value)
{
const intT modulo=100000000; // a one and eight zeros
intT sample_value=value;
// count samples
Mnsamp++;
// check for sample value overflow
if (abs(sample_value) >= modulo)
{
sample_value = sample_value - (sample_value/modulo)*modulo;
}
// add the sample value to the checksum
Msum += sample_value;
// check for checksum overflow
if (abs(Msum) >= modulo)
{
Msum = Msum - (Msum/modulo)*modulo;
}
}
} // namespace waveform
} // namespace GSE2
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: gsexx.h,v 1.1 2002-03-17 21:26:27 forbrig Exp $
* $Id: gsexx.h,v 1.2 2002-03-25 22:04:06 forbrig Exp $
* \author Thomas Forbriger
* \date 16/03/2002
*
......@@ -23,7 +23,7 @@
#define TF_GSEXX_H_VERSION \
"TF_GSEXX_H V1.0 "
#define TF_GSEXX_H_CVSID \
"$Id: gsexx.h,v 1.1 2002-03-17 21:26:27 forbrig Exp $"
"$Id: gsexx.h,v 1.2 2002-03-25 22:04:06 forbrig Exp $"
// #include <libtime++.h>
#include<string>
......@@ -34,6 +34,11 @@ namespace GSE2 {
//! All waveform related stuff.
namespace waveform {
//! All GSE2 waveform data is based on 4 byte integers.
typedef int intT;
/*----------------------------------------------------------------------*/
//! A class to hold and manage the WID2-line.
class TWID2 {
private:
......@@ -43,10 +48,32 @@ class TWID2 {
std::string Mauxid; //!< Auxiliary identification code
}; // class TWID2
/*----------------------------------------------------------------------*/
//! A class to hold and manage the STA2-line.
class TSTA2 {
}; // class TSTA2
/*----------------------------------------------------------------------*/
//! A class for the cumulative calculation of checksums.
class TCHK2 {
public:
//! Default constructor.
TCHK2(): Msum(0), Mnsamp(0) { }
//! Add a value to the checksum.
void add(const intT& value);
//! Return the checksum value.
intT value() const { return(Msum); }
//! Return the number of cumulated samples.
intT nsamples() const { return(Mnsamp); }
private:
intT Msum; //!< checksum value
intT Mnsamp; //!< number of cumulated samples
}; // class TCHK2
/*----------------------------------------------------------------------*/
} // namespace waveform
} // namespace GSE2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment