/
PulseAnalysisDisplay.cpp
418 lines (337 loc) · 12.4 KB
/
PulseAnalysisDisplay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#include "PulseAnalysisDisplay.h"
////////////////////////////////////////////////////////////////////////////////
PulseAnalysisDisplay::PulseAnalysisDisplay (xdaq::Client* c)
{
// copy over the client pointer
client = c;
// setup the window
setup();
// add the channels
char buf[8];
for (unsigned int i=0; i<INDEPENDENT_TRACES; i++)
{
channelSelector[i]->value(0);
traceColorSelector[i]->value(i%8);
for (unsigned int j=0; j<client->nDatatStreams(); j++)
{
sprintf (buf,"%d",j);
channelSelector[i]->add(buf,0,(Fl_Callback*) handleEvent, (void*) this);
}
}
// push the plot selector button to refresh everything
handleEvent(plotSelector);
// hide the window
window->hide();
}
////////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::init ()
{
}
////////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::show ()
{
window->show();
}
////////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::hide ()
{
window->hide();
}
////////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::stop ()
{
hide();
}
////////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::setup ()
{
Fl_Widget* w;
int bigx = 1000;
int bigy = 400;
int xbuffer=5, ybuffer=5;
int xsize0,xsize1,xsize2, xsize3;
int ysize0,ysize1;
int x[5];
int y[INDEPENDENT_TRACES + 3];
window = new Fl_Double_Window(bigx,bigy, "Pulse Analysis Window");
// set the current user data (void *) argument to the instance pointer
window->user_data((void*)(this));
// position the window on screen
window->resizable(window);
// begin the main window group
window->begin();
{
xsize0 = 50; // channel selector
xsize1 = 100; // color selector
xsize2 = xsize1 + xsize0 + xbuffer; // plot selector
ysize0 = 25; // standard size
ysize1 = (bigy - 2*ybuffer); // plotWindow height
x[0] = xbuffer+xbuffer; // channel
x[1] = x[0] + xsize0 + xbuffer; // color
x[2] = x[0]; // plot type
x[3] = x[1] + xsize1 + xbuffer; // plot itself
// plotWindow width
xsize3 = bigx - (x[1] + xsize1 + xbuffer) - xbuffer;
y[0] = ybuffer; // plot selector
y[1] = y[1] + ysize0 + ybuffer; // analysis enable
y[2] = y[1] + 2*ysize0 + ybuffer; // label
for (unsigned int i=0; i<INDEPENDENT_TRACES; i++)
{
y[3+i] = y[2+i] + ysize0 + ybuffer; // top of top plot choice
}
// what kind of plot the user wants to see
Fl_Menu_Item plotPopup[] =
{
{"Pulse Height", 0, (Fl_Callback*) handleEvent, (void*) this},
{"Baseline", 0, (Fl_Callback*) handleEvent, (void*) this},
{0}
};
w = plotSelector = new Fl_Choice (x[0],y[1],xsize2,ysize0,"");
plotSelector->copy(plotPopup,NULL);
w->align(FL_ALIGN_RIGHT);
// enable analysis button
w = performAnalysisFlagButton = new Fl_Light_Button(x[0],y[0],xsize2,ysize0,"Enable Analysis");
w->callback((Fl_Callback*) handleEvent, (void*) this);
// the channel selectors
w = new Fl_Box (x[0],y[2],xsize0,0,"Channel");
w->align(FL_ALIGN_TOP);
w = new Fl_Box (x[1],y[2],xsize0,0,"Color");
w->align(FL_ALIGN_TOP);
Fl_Menu_Item topChanPopup[] =
{
{"-", 0,(Fl_Callback*) handleEvent, (void*) this},
{0}
};
for (unsigned int i=0; i< INDEPENDENT_TRACES; i++)
{
w = channelSelector[i] = new Fl_Choice (x[0],y[i+2],xsize0,ysize0);
channelSelector[i]->copy(topChanPopup,NULL);
w->align(FL_ALIGN_TOP);
}
// color selector
Fl_Menu_Item colorPopup[] =
{
{"Black", 0, NULL, (void*) this},
{"Red", 0, NULL, (void*) this},
{"Blue", 0, NULL, (void*) this},
{"Green", 0, NULL, (void*) this},
{"Dark Red", 0, NULL, (void*) this},
{"Dark Blue", 0, NULL, (void*) this},
{"Dark Green", 0, NULL, (void*) this},
{"Dark Cyan", 0, NULL, (void*) this},
{0}
};
for (unsigned int i=0; i< INDEPENDENT_TRACES; i++)
{
w = traceColorSelector[i] = new Fl_Choice (x[1],y[i+2],xsize1, ysize0);
traceColorSelector[i]->copy(colorPopup,NULL);
w->align(FL_ALIGN_TOP);
}
// the actual plotter widget
plot = new plotWindow (x[3],y[0],xsize3,ysize1);
// set some flags
plot->connectedLineFlag(false);
plot->xDisplayMethod (3); // set x to auto scroll
plot->yDisplayMethod (1); // set y to maximum
} window->end(); // end main window grouping
// now that we are out of the group, init the plot
plot->init();
}
/////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::handleEvent(Fl_Widget *w,void *v)
{
((PulseAnalysisDisplay *)v)->handleEvent(w);
}
/////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::handleEvent(Fl_Widget *w)
{
// plot widgets
for (unsigned int i=0; i< INDEPENDENT_TRACES; i++)
{
if (w==channelSelector[i])
{
// channel[i] = channelSelector[i]->value() - 1; // remember that selection 1 is the '-'
std::cout << "setting channel selector to: " << channelSelector[i]->value() - 1 << std::endl;
if (!plot->xManual()) plot->resetPlotXMax();
if (!plot->yManual()) plot->resetPlotYMax();
return;
}
}
if (w==plotSelector)
{
switch (plotSelector->value())
{
case 0: // regular plot
{
plot->xScale(1.);
plot->yScale(1000.);
plot->xTickLabel("Time");
plot->yTickLabel("Pulse Height");
plot->xTickUnit("S");
plot->yTickUnit("mV");
plot->xLog(false);
plot->yLog(false);
break;
}
case 1: // derivitive plot
{
plot->xScale(1.);
plot->yScale(1000.);
plot->xTickLabel("Time");
plot->yTickLabel("Baseline");
plot->xTickUnit("S");
plot->yTickUnit("mV");
plot->xLog(false);
plot->xLog(false);
break;
}
default:
{
std::cout << "Plot error... no plot type selected" << std::endl;
break;
}
}
plot->resetPlotXMax();
plot->resetPlotYMax();
return;
}
if (w==performAnalysisFlagButton)
{
bool b = performAnalysisFlagButton->value();
for (unsigned int chan = 0; chan < client->nDatatStreams(); chan++)
{
client->performAnalysisFlag(chan,b);
}
return;
}
std::cout << "You didn't handle that very well, now did you?" << std::endl;
}
////////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::userRefresh ()
{
}
////////////////////////////////////////////////////////////////////////////////
inline Fl_Color getColor (int value)
{
Fl_Color color;
switch (value)
{
case 0:
color = FL_BLACK;
break;
case 1:
color = FL_RED;
break;
case 2:
color = FL_BLUE;
break;
case 3:
color = FL_GREEN;
break;
case 4:
color = FL_DARK_RED;
break;
case 5:
color = FL_DARK_BLUE;
break;
case 6:
color = FL_DARK_GREEN;
break;
case 7:
color = FL_DARK_CYAN;
break;
default:
color = FL_BLACK;
break;
}
return color;
}
////////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::loopRefresh ()
{
if (!window->visible()) return;
// some pointers
double *x=NULL;
double *y=NULL;
unsigned int n = 0;
int id;
// loop through all traces
for (unsigned int i=0; i<INDEPENDENT_TRACES; i++)
{
// remember that '0" is the '-' channel
int channel = channelSelector[i]->value() - 1;
// this is where you pick what gets splashed on the plot canvas
if (channel != -1)
{
switch (plotSelector->value())
{
case 0: // pulse height vs time
{
// request a copy of the data
xdaq::StreamChannel *SD = client->streamData[channel];
if (SD != NULL)
{
// request some data
SD->requestPulseHeightCopy(&x,&y,&n);
// test for no data
if (n==0) break;
// pass that to the plotter and tell it to keep it
id = plot->ingestAndKeepData(x,y,n);
if (id == -1) break;
// add the color
Fl_Color color = getColor (traceColorSelector[i]->value());
plot->color(id,color);
}
// release the lock
client->latestTriggeredPulseLock[channel].releaseLock();
break;
}
case 1: // baseline vs time
{
xdaq::StreamChannel *SD = client->streamData[channel];
if (SD != NULL)
{
// request some data
SD->requestBaselineCopy(&x,&y,&n);
// test for no data
if (n==0) break;
// pass that to the plotter and tell it to keep it
id = plot->ingestAndKeepData(x,y,n);
if (id == -1) break;
// add the color
Fl_Color color = getColor (traceColorSelector[i]->value());
plot->color(id,color);
}
client->latestTriggeredPulseLock[channel].releaseLock();
break;
}
default:
{
std::cout << "Plot error... no plot type selected" << std::endl;
break;
}
}
}
}
// now that you have sent all the data to the plots, stick it to the screen
plot->loopRefresh();
}
////////////////////////////////////////////////////////////////////////////////
void PulseAnalysisDisplay::position (int x, int y)
{
window->position(x,y);
}
////////////////////////////////////////////////////////////////////////////////
// boring encapsulation
////////////////////////////////////////////////////////////////////////////////
bool PulseAnalysisDisplay::visible () // only done every once in a while
{
return window->visible();
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////