test_Tpc2dRoi.cxx
Go to the documentation of this file.
1 // test_Tpc2dRoi.cxx
2 //
3 // David Adams
4 // January 2021
5 //
6 // Test Tpc2dRoi.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <vector>
13 
14 #undef NDEBUG
15 #include <cassert>
16 
17 using std::string;
18 using std::cout;
19 using std::endl;
20 using std::vector;
21 
23 
24 //**********************************************************************
25 
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 }
99 
100 //**********************************************************************
101 
102 int main(int argc, char* argv[]) {
103  if ( argc > 1 ) {
104  cout << "Usage: " << argv[0] << " [ARG]" << endl;
105  return 0;
106  }
107  return test_Tpc2dRoi();
108 }
109 
110 //**********************************************************************
Index sampleSize() const
Definition: Tpc2dRoi.h:41
std::string string
Definition: nybbler.cc:12
struct vector vector
unsigned int Index
int test_Tpc2dRoi()
float value(Index icha, LongIndex itck, float valdef=0.0) const
Definition: Tpc2dRoi.h:55
std::array< Index, 2 > IndexArray
Definition: Real2dData.h:34
unsigned int Index
Definition: Tpc2dRoi.h:22
Index size(Index idim) const
Definition: Real2dData.h:91
Float value(const IndexArray &isams, Index *pchk=nullptr) const
Definition: Real2dData.h:184
Index channelOffset() const
Definition: Tpc2dRoi.h:44
int main(int argc, char *argv[])
const DataArray & data() const
Definition: Tpc2dRoi.h:50
Index channelSize() const
Definition: Tpc2dRoi.h:47
Index setValue(const IndexArray &isams, Float val, Index *pchk=nullptr)
Definition: Real2dData.h:197
LongIndex sampleOffset() const
Definition: Tpc2dRoi.h:38
QTextStream & endl(QTextStream &s)