test_AdcChannelTool.cxx
Go to the documentation of this file.
1 // test_AdcChannelTool.cxx
2 //
3 // David Adams
4 // April 2018
5 //
6 // Test AdcChannelTool.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <vector>
15 
16 #undef NDEBUG
17 #include <cassert>
18 
19 using std::string;
20 using std::cout;
21 using std::endl;
22 using std::ostringstream;
23 using std::ofstream;
25 using std::vector;
26 using Index = unsigned int;
27 
28 //**********************************************************************
29 
31  AdcChannelDataMap acds;
32  for ( Index icha=0; icha<10; ++icha ) {
33  acds[icha].setChannelInfo(icha, icha%4);
34  }
35  return acds;
36 }
37 
38 //**********************************************************************
39 
40 // Tool that modfies data.
41 // Sets femb = 100+channel.
42 
44 public:
45  DataMap update(AdcChannelData& acd) const override;
46  bool viewWithUpdate() const override { return true; }
47 };
48 
50  cout << "AdcChannelTool_update::update: Modifying channel " << acd.channel() << endl;
51  acd.setChannelInfo(acd.channel(), 100 + acd.channel());
52  int fembchan = 1000*acd.fembID() + acd.channel();
53  std::vector<int> fembchans(1, fembchan);
54  DataMap ret;
55  ret.setInt("fembchan", fembchan);
56  ret.setIntVector("fembchans", fembchans);
57  return ret;
58 }
59 
60 //**********************************************************************
61 
62 // Test with all default methods.
63 
65  const string myname = "test_AdcChannelTool_default: ";
66 #ifdef NDEBUG
67  cout << myname << "NDEBUG must be off." << endl;
68  abort();
69 #endif
70  string line = "-----------------------------";
71 
72  cout << endl;
73  cout << myname << line << endl;
74  cout << myname << "Instantiate tool." << endl;
75  AdcChannelTool act;
76  Index ncha = 10;
77  AdcChannelDataMap acds = makeAdcData(ncha);
78  AdcChannelData acd = acds[1];
79 
80  DataMap ret(111);
81 
82  cout << myname << line << endl;
83  cout << myname << "Call update." << endl;
84  ret = act.update(acd);
85  assert( ret == act.interfaceNotImplemented() );
86  ret.print();
87 
88  cout << myname << line << endl;
89  cout << myname << "Call view." << endl;
90  ret = act.view(acd);
91  assert( ret == act.interfaceNotImplemented() );
92  ret.print();
93 
94  cout << myname << line << endl;
95  cout << myname << "Call updateMap." << endl;
96  ret = act.updateMap(acds);
97  assert( ret == act.interfaceNotImplemented() );
98  ret.print();
99 
100  cout << myname << line << endl;
101  cout << myname << "Call viewMap." << endl;
102  ret = act.viewMap(acds);
103  assert( ret == act.interfaceNotImplemented() );
104  ret.print();
105 
106  cout << myname << line << endl;
107  cout << myname << "Test complete." << endl;
108 
109  return 0;
110 }
111 
112 //**********************************************************************
113 
114 // Test with update.
115 
117  const string myname = "test_AdcChannelTool_update: ";
118 #ifdef NDEBUG
119  cout << myname << "NDEBUG must be off." << endl;
120  abort();
121 #endif
122  string line = "-----------------------------";
123 
124  cout << endl;
125  cout << myname << line << endl;
126  cout << myname << "Instantiate tool." << endl;
128  Index ncha = 10;
129  AdcChannelDataMap acds = makeAdcData(ncha);
130  AdcChannelData acd1 = acds[1];
131 
132  DataMap ret(111);
133 
134  cout << myname << line << endl;
135  cout << myname << "Call update." << endl;
136  acd1.setChannelInfo(1);
137  ret = act.update(acd1);
138  ret.print();
139  assert( ret == 0 );
140  assert( acd1.channel() == 1 );
141  assert( acd1.fembID() == 101 );
142 
143  cout << myname << line << endl;
144  cout << myname << "Call view." << endl;
145  acd1.setChannelInfo(1, 200);
146  ret = act.view(acd1);
147  ret.print();
148  assert( ! ret );
149  assert( acd1.channel() == 1 );
150  assert( acd1.fembID() == 200 );
151 
152  cout << myname << line << endl;
153  cout << myname << "Call updateMap." << endl;
154  ret = act.updateMap(acds);
155  ret.print();
156  assert( ! ret );
157  for ( const auto& iacd : acds ) {
158  Index icha = iacd.first;
159  const AdcChannelData& acd = iacd.second;
160  cout << myname << " icha, femb = " << acd.channel() << ", " << acd.fembID() << endl;
161  assert(acd.channel() == icha);
162  assert(acd.fembID() == 100 + acd.channel());
163  }
164 
165  cout << myname << line << endl;
166  cout << myname << "Call viewMap." << endl;
167  for ( auto& iacd : acds ) iacd.second.setChannelInfo(iacd.second.channel(), 200);
168  ret = act.viewMap(acds);
169  ret.print();
170  assert( ! ret );
171  for ( const auto& iacd : acds ) {
172  Index icha = iacd.first;
173  const AdcChannelData& acd = iacd.second;
174  cout << myname << " icha, femb = " << acd.channel() << ", " << acd.fembID() << endl;
175  assert(acd.channel() == icha);
176  assert(acd.fembID() == 200);
177  }
178  cout << myname << line << endl;
179  cout << myname << "Test complete." << endl;
180  return 0;
181 }
182 
183 //**********************************************************************
184 
185 int main(int argc, char* argv[]) {
188  return 0;
189 }
190 
191 //**********************************************************************
std::string string
Definition: nybbler.cc:12
AdcChannelDataMap makeAdcData(Index ncha=10)
virtual DataMap viewMap(const AdcChannelDataMap &acds) const
struct vector vector
static int interfaceNotImplemented()
unsigned int Index
bool viewWithUpdate() const override
void print(std::ostream *pout) const
Definition: DataMap.h:245
virtual DataMap view(const AdcChannelData &acd) const
virtual DataMap update(AdcChannelData &) const
Index fembID() const
void setIntVector(Name name, const IntVector &val)
Definition: DataMap.h:132
int test_AdcChannelTool_update()
void setChannelInfo(ChannelInfoPtr pchi)
DataMap update(AdcChannelData &acd) const override
int test_AdcChannelTool_default()
void setInt(Name name, int val)
Definition: DataMap.h:131
virtual DataMap updateMap(AdcChannelDataMap &acds) const
Channel channel() const
void line(double t, double *p, double &x, double &y, double &z)
int main(int argc, char *argv[])
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
QTextStream & endl(QTextStream &s)