Typedefs | Functions
test_Tpc2dRoi.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "dunecore/DuneInterface/Data/Tpc2dRoi.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using Index = Tpc2dRoi::Index
 

Functions

int test_Tpc2dRoi ()
 
int main (int argc, char *argv[])
 

Typedef Documentation

Definition at line 22 of file test_Tpc2dRoi.cxx.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 102 of file test_Tpc2dRoi.cxx.

102  {
103  if ( argc > 1 ) {
104  cout << "Usage: " << argv[0] << " [ARG]" << endl;
105  return 0;
106  }
107  return test_Tpc2dRoi();
108 }
int test_Tpc2dRoi()
QTextStream & endl(QTextStream &s)
int test_Tpc2dRoi ( )

Definition at line 26 of file test_Tpc2dRoi.cxx.

26  {
27  const string myname = "test_Tpc2dRoi: ";
28 #ifdef NDEBUG
29  cout << myname << "NDEBUG must be off." << endl;
30  abort();
31 #endif
32  string myline = myname + "-----------------------------";
33 
34  cout << myline << endl;
35  cout << myname << "Checking default roi." << endl;
36  Tpc2dRoi roi0;
37  assert( roi0.data().size() == 0 );
38  assert( roi0.sampleSize() == 0 );
39  assert( roi0.channelSize() == 0 );
40  assert( roi0.sampleOffset() == 0 );
41  assert( roi0.channelOffset() == 0 );
42 
43  cout << myline << endl;
44  cout << myname << "Checking finite roi." << endl;
45  Index nsam = 100;
46  Index ncha = 20;
47  Index ndat = ncha*nsam;
48  Index isam0 = 10;
49  Index icha0 = 500;
50  Tpc2dRoi roi1(20, 100, 500, 10);
51  assert( roi1.data().size() == ndat );
52  assert( roi1.sampleSize() == nsam );
53  assert( roi1.channelSize() == ncha );
54  assert( roi1.sampleOffset() == isam0 );
55  assert( roi1.channelOffset() == icha0 );
56 
57  cout << myline << endl;
58  cout << myname << "Set values." << endl;
60  Index& kcha = idxs[0];
61  Index& ksam = idxs[1];
62  Index ichk = 0;
63  Index ntst = 0;
64  for ( kcha=0; kcha<ncha; ++kcha ) {
65  for ( ksam=0; ksam<nsam; ++ksam ) {
66  float val = nsam*kcha + ksam + 1;
67  roi1.data().setValue(idxs, val, &ichk);
68  assert( ichk == 0 );
69  float chkval = roi1.data().value(idxs, &ichk);
70  assert( chkval == val );
71  ++ntst;
72  }
73  }
74  cout << myname << "Test count: " << ntst << endl;
75 
76  cout << myline << endl;
77  cout << myname << "Retrieve values." << endl;
78  ichk = 0;
79  ntst = 0;
80  for ( kcha=0; kcha<ncha; ++kcha ) {
81  for ( ksam=0; ksam<nsam; ++ksam ) {
82  float expval = nsam*kcha + ksam + 1;
83  float chkval1 = roi1.data().value(idxs, &ichk);
84  assert( ichk == 0 );
85  assert( chkval1 == expval );
86  Index icha = icha0 + kcha;
87  Index isam = isam0 + ksam;
88  float chkval2 = roi1.value(icha, isam);
89  assert( chkval2 == expval );
90  ++ntst;
91  }
92  }
93  cout << myname << "Test count: " << ntst << endl;
94 
95  cout << myline << endl;
96  cout << myname << "All tests passed." << endl;
97  return 0;
98 }
Index sampleSize() const
Definition: Tpc2dRoi.h:41
unsigned int Index
std::array< Index, 2 > IndexArray
Definition: Real2dData.h:34
Index size(Index idim) const
Definition: Real2dData.h:91
Index channelOffset() const
Definition: Tpc2dRoi.h:44
const DataArray & data() const
Definition: Tpc2dRoi.h:50
Index channelSize() const
Definition: Tpc2dRoi.h:47
LongIndex sampleOffset() const
Definition: Tpc2dRoi.h:38
QTextStream & endl(QTextStream &s)