test_TpcDataTool.cxx
Go to the documentation of this file.
1 // test_TpcDataTool.cxx
2 //
3 // David Adams
4 // January 2021
5 //
6 // Test TpcDataTool.
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 
30 void fillAdcData(AdcChannelDataMap* pacm, Index ncha =10) {
31  for ( Index icha=0; icha<10; ++icha ) {
32  (*pacm)[icha].setChannelInfo(icha, icha%4);
33  }
34 }
35 
36 //**********************************************************************
37 
38 // Tool that modfies data.
39 // Sets femb = 100+channel.
40 
42 public:
43  DataMap update(AdcChannelData& acd) const override;
44  bool viewWithUpdate() const override { return true; }
45 };
46 
48  cout << "TpcDataTool_update::update: Modifying channel " << acd.channel() << endl;
49  acd.setChannelInfo(acd.channel(), 100 + acd.channel());
50  int fembchan = 1000*acd.fembID() + acd.channel();
51  std::vector<int> fembchans(1, fembchan);
52  DataMap ret;
53  ret.setInt("fembchan", fembchan);
54  ret.setIntVector("fembchans", fembchans);
55  return ret;
56 }
57 
58 //**********************************************************************
59 
60 // Test with all default methods.
61 
63  const string myname = "test_TpcDataTool_default: ";
64 #ifdef NDEBUG
65  cout << myname << "NDEBUG must be off." << endl;
66  abort();
67 #endif
68  string line = "-----------------------------";
69 
70  cout << endl;
71  cout << myname << line << endl;
72  cout << myname << "Instantiate tool." << endl;
73  TpcDataTool act;
74 
75  cout << endl;
76  cout << myname << line << endl;
77  cout << myname << "Create data." << endl;
78  TpcData tpd;
80  assert( pacm->size() == 0 );
81  Index ncha = 10;
82  fillAdcData(pacm.get(), ncha);
83  assert( pacm->size() == ncha );
84  AdcChannelData acd = (*pacm)[1];
85 
86  DataMap ret(111);
87 
88  cout << myname << line << endl;
89  cout << myname << "Call update." << endl;
90  ret = act.update(acd);
91  assert( ret == act.interfaceNotImplemented() );
92  ret.print();
93 
94  cout << myname << line << endl;
95  cout << myname << "Call view." << endl;
96  ret = act.view(acd);
97  assert( ret == act.interfaceNotImplemented() );
98  ret.print();
99 
100  cout << myname << line << endl;
101  cout << myname << "Call update TPC." << endl;
102  ret = act.updateTpcData(tpd);
103  assert( ret == act.interfaceNotImplemented() );
104  ret.print();
105 
106  cout << myname << line << endl;
107  cout << myname << "Call view TPC." << endl;
108  ret = act.viewTpcData(tpd);
109  assert( ret == act.interfaceNotImplemented() );
110  ret.print();
111 
112  cout << myname << line << endl;
113  cout << myname << "Test complete." << endl;
114 
115  return 0;
116 }
117 
118 //**********************************************************************
119 
120 // Test with update.
121 
123  const string myname = "test_TpcDataTool_update: ";
124 #ifdef NDEBUG
125  cout << myname << "NDEBUG must be off." << endl;
126  abort();
127 #endif
128  string line = "-----------------------------";
129 
130  cout << endl;
131  cout << myname << line << endl;
132  cout << myname << "Instantiate tool." << endl;
133  TpcDataTool_update act;
134 
135  cout << endl;
136  cout << myname << line << endl;
137  cout << myname << "Create data." << endl;
138  TpcData tpd;
139  TpcData::AdcDataPtr pacm = tpd.createAdcData();
140  assert( pacm->size() == 0 );
141  Index ncha = 10;
142  fillAdcData(pacm.get(), ncha);
143  assert( pacm->size() == ncha );
144  AdcChannelData acd = (*pacm)[1];
145 
146  cout << myname << line << endl;
147  cout << myname << "Call update TPC." << endl;
148  DataMap ret(111);
149  ret = act.updateTpcData(tpd);
150  ret.print();
151  assert( ! ret );
152  assert( tpd.getAdcData().size() == 1 );
153  for ( const auto& iacd : *tpd.getAdcData()[0] ) {
154  Index icha = iacd.first;
155  const AdcChannelData& acd = iacd.second;
156  cout << myname << " icha, femb = " << acd.channel() << ", " << acd.fembID() << endl;
157  assert(acd.channel() == icha);
158  assert(acd.fembID() == 100 + acd.channel());
159  }
160 
161  cout << myname << line << endl;
162  cout << myname << "Call view TPC." << endl;
163  for ( auto& iacd : *tpd.getAdcData()[0] ) iacd.second.setChannelInfo(iacd.second.channel(), 200);
164  ret = act.viewTpcData(tpd);
165  ret.print();
166  assert( ! ret );
167  for ( const auto& iacd : *tpd.getAdcData()[0] ) {
168  Index icha = iacd.first;
169  const AdcChannelData& acd = iacd.second;
170  cout << myname << " icha, femb = " << acd.channel() << ", " << acd.fembID() << endl;
171  assert(acd.channel() == icha);
172  assert(acd.fembID() == 200);
173  }
174  cout << myname << line << endl;
175  cout << myname << "Test complete." << endl;
176  return 0;
177 }
178 
179 //**********************************************************************
180 
181 int main(int argc, char* argv[]) {
184  return 0;
185 }
186 
187 //**********************************************************************
int main(int argc, char *argv[])
int test_TpcDataTool_default()
std::string string
Definition: nybbler.cc:12
struct vector vector
DataMap update(AdcChannelData &acd) const override
static int interfaceNotImplemented()
std::shared_ptr< AdcChannelDataMap > AdcDataPtr
Definition: TpcData.h:35
unsigned int Index
virtual DataMap viewTpcData(const TpcData &) const
Definition: TpcDataTool.h:55
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
AdcDataVector & getAdcData()
Definition: TpcData.h:55
void setChannelInfo(ChannelInfoPtr pchi)
void fillAdcData(AdcChannelDataMap *pacm, Index ncha=10)
void setInt(Name name, int val)
Definition: DataMap.h:131
virtual DataMap updateTpcData(TpcData &) const
Definition: TpcDataTool.h:39
Channel channel() const
void line(double t, double *p, double &x, double &y, double &z)
AdcDataPtr createAdcData(bool updateParent=true)
Definition: TpcData.cxx:99
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
int test_TpcDataTool_update()
bool viewWithUpdate() const override
QTextStream & endl(QTextStream &s)