1 | /* ============================================================
|
---|
2 |
|
---|
3 | DRS Data Display
|
---|
4 |
|
---|
5 | Qt-based graphical user interface for displaying data taken with
|
---|
6 | the drsdaq program.
|
---|
7 | There are two operation modes: inspection of a raw data file and
|
---|
8 | data taking via the socket interface. Connecting to a socket server
|
---|
9 | automatically disables raw data file operation and closes any open
|
---|
10 | file.
|
---|
11 |
|
---|
12 | Oliver Grimm
|
---|
13 |
|
---|
14 | ============================================================ */
|
---|
15 |
|
---|
16 | #include "GUI.h"
|
---|
17 |
|
---|
18 | ddd::ddd() {
|
---|
19 |
|
---|
20 | WaitForData = false;
|
---|
21 |
|
---|
22 | // Instantiate without console output
|
---|
23 | RD = new RawDataCTX(true);
|
---|
24 | PixMap = new PixelMap("../../config/PixelMap.txt", false);
|
---|
25 |
|
---|
26 | Tmpfile = tmpfile();
|
---|
27 | if(Tmpfile==NULL) {
|
---|
28 | QMessageBox::warning(this, "ddd Message","Could not open temporary file.",QMessageBox::Ok);
|
---|
29 | }
|
---|
30 |
|
---|
31 | //---------------------------------------------------------------------
|
---|
32 | //**************************** Main window ****************************
|
---|
33 | //---------------------------------------------------------------------
|
---|
34 |
|
---|
35 | Central = new QWidget(this);
|
---|
36 | setCentralWidget(Central);
|
---|
37 |
|
---|
38 | Socket = new QTcpSocket(Central);
|
---|
39 | connect(Socket, SIGNAL(readyRead()), this, SLOT(ReadFromSocket()));
|
---|
40 | connect(Socket, SIGNAL(disconnected()), this, SLOT(GotDisconnected()));
|
---|
41 |
|
---|
42 | // SpinBox for event number
|
---|
43 | EventNo = new QSpinBox(Central);
|
---|
44 | EventNo->setEnabled(false);
|
---|
45 | connect(EventNo, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
|
---|
46 | EventNo->setToolTip("Event number in file");
|
---|
47 | SpinLayout = new QFormLayout();
|
---|
48 | SpinLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
|
---|
49 | SpinLayout->addRow("E&vent #", EventNo);
|
---|
50 |
|
---|
51 | // SpinBox for channel number
|
---|
52 | ChannelNo = new QSpinBox(Central);
|
---|
53 | ChannelNo->setEnabled(false);
|
---|
54 | connect(ChannelNo, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
|
---|
55 | ChannelNo->setToolTip("Channels 0-19 for 2 DRS chips per mezzanine board");
|
---|
56 |
|
---|
57 | // SpinBox for board number
|
---|
58 | BoardNo = new QSpinBox(Central);
|
---|
59 | BoardNo->setEnabled(false);
|
---|
60 | connect(BoardNo, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
|
---|
61 | BoardNo->setToolTip("Mezzanine board number");
|
---|
62 |
|
---|
63 | // TextBox for pixel ID
|
---|
64 | PixelID = new QLineEdit(Central);
|
---|
65 | PixelID->setEnabled(false);
|
---|
66 | connect(PixelID, SIGNAL(returnPressed()), this, SLOT(TranslatePixelID()));
|
---|
67 | PixelID->setToolTip("Pixel identification");
|
---|
68 |
|
---|
69 | // Layout of pixel addressing widgets
|
---|
70 | FormLayout = new QFormLayout;
|
---|
71 | FormLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
|
---|
72 | FormLayout->addRow("&Channel #", ChannelNo);
|
---|
73 | FormLayout->addRow("&Board #", BoardNo);
|
---|
74 | FormLayout->addRow("Pixel ID", PixelID);
|
---|
75 |
|
---|
76 | // Socket button
|
---|
77 | SocketButton = new QPushButton("Socke&t\nInterface", Central);
|
---|
78 | SocketButton->setFont(QFont("Times", 10, QFont::Bold));
|
---|
79 | connect(SocketButton, SIGNAL(clicked()), this, SLOT(OpenSocketWindow()));
|
---|
80 | SocketButton->setToolTip("Open window for socket communication");
|
---|
81 |
|
---|
82 | // M0 display button
|
---|
83 | M0Display = new QPushButton("M0 Display",Central);
|
---|
84 | M0Display->setFont(QFont("Times", 10, QFont::Bold));
|
---|
85 | connect(M0Display, SIGNAL(clicked()), this, SLOT(OpenM0Window()));
|
---|
86 | M0Display->setToolTip("Open window for M0 display");
|
---|
87 |
|
---|
88 | // Acquire button and Continuous check box
|
---|
89 | GetButton = new QPushButton("&Acquire", Central);
|
---|
90 | GetButton->setFont(QFont("Times", 10, QFont::Bold));
|
---|
91 | GetButton->setEnabled(false);
|
---|
92 | connect(GetButton, SIGNAL(clicked()), this, SLOT(GetSignalFromSocket()));
|
---|
93 | GetButton->setToolTip("Acquire event over socket interface");
|
---|
94 | ContinuousBox = new QCheckBox("Continuous", Central);
|
---|
95 | ContinuousBox->setFont(QFont("Times", 10, QFont::Bold));
|
---|
96 | ContinuousBox->setToolTip("Acquire continuously");
|
---|
97 |
|
---|
98 | // Plot area
|
---|
99 | Graph = new QwtPlot(Central);
|
---|
100 | Graph->setAxisTitle(QwtPlot::xBottom, "Time (ns)");
|
---|
101 | Graph->setAxisTitle(QwtPlot::yLeft, "Signal (mV)");
|
---|
102 | Graph->setAutoReplot(true);
|
---|
103 | Graph->setCanvasBackground(QColor(Qt::yellow));
|
---|
104 | Zoomer = new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yLeft,Graph->canvas());
|
---|
105 | connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(HandleZoom(const QwtDoubleRect &)));
|
---|
106 | Panner = new QwtPlotPanner(Graph->canvas());
|
---|
107 | Panner->setMouseButton(Qt::LeftButton, Qt::ShiftModifier);
|
---|
108 | Grid = new QwtPlotGrid;
|
---|
109 | Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
|
---|
110 | Grid->attach(Graph);
|
---|
111 | Signal = new QwtPlotCurve;
|
---|
112 | Signal->attach(Graph);
|
---|
113 | Signal->setStyle(QwtPlotCurve::Steps);
|
---|
114 |
|
---|
115 | // Text boxes for run and event header
|
---|
116 | RunHeaderDisplay = new QPlainTextEdit(Central);
|
---|
117 | EventHeaderDisplay = new QPlainTextEdit(Central);
|
---|
118 | RunHeaderDisplay->setReadOnly(true);
|
---|
119 | EventHeaderDisplay->setReadOnly(true);
|
---|
120 |
|
---|
121 | // Browse botton
|
---|
122 | LoadButton = new QToolButton(Central);
|
---|
123 | LoadButton->setToolButtonStyle (Qt::ToolButtonTextOnly);
|
---|
124 | LoadButton->setText("...");
|
---|
125 | connect(LoadButton, SIGNAL(clicked()), this, SLOT(FileDialog()));
|
---|
126 | LoadButton->setToolTip("Open file dialog to select raw data file");
|
---|
127 |
|
---|
128 | // Filename box
|
---|
129 | FilenameBox = new QLineEdit(Central);
|
---|
130 | connect(FilenameBox, SIGNAL(returnPressed()), this, SLOT(OpenDatafile()));
|
---|
131 | FilenameBox->setToolTip("Raw data file name");
|
---|
132 |
|
---|
133 | // Tab widget
|
---|
134 | TabWidget = new QTabWidget(Central);
|
---|
135 | TabWidget->addTab(Graph, "&Signal");
|
---|
136 | TabWidget->addTab(RunHeaderDisplay, "&Run Header");
|
---|
137 | TabWidget->addTab(EventHeaderDisplay, "&Event Header");
|
---|
138 |
|
---|
139 | // Layout of all widgets
|
---|
140 | MainLayout = new QGridLayout(Central);
|
---|
141 | MainLayout->addWidget(FilenameBox, 0, 0, 1, 3);
|
---|
142 | MainLayout->addWidget(LoadButton, 0, 3);
|
---|
143 | MainLayout->addLayout(SpinLayout, 1, 0);
|
---|
144 | MainLayout->addLayout(FormLayout, 2, 0);
|
---|
145 | MainLayout->addWidget(SocketButton, 6,0);
|
---|
146 | MainLayout->addWidget(M0Display, 3,0);
|
---|
147 | MainLayout->addWidget(GetButton, 4,0);
|
---|
148 | MainLayout->addWidget(ContinuousBox, 5,0);
|
---|
149 | MainLayout->addWidget(TabWidget, 1, 1, 6, 5);
|
---|
150 | MainLayout->setColumnStretch(1, 10);
|
---|
151 |
|
---|
152 | // Menu bar
|
---|
153 | QMenu* Menu = menuBar()->addMenu("&Menu");
|
---|
154 | OpenAction = Menu->addAction("Open data file", this, SLOT(FileDialog()));
|
---|
155 | OpenAction->setShortcut(Qt::CTRL + Qt::Key_O);
|
---|
156 | QAction* SaveAction = Menu->addAction("Save plot", this, SLOT(MenuSave()));
|
---|
157 | SaveAction->setShortcut(Qt::CTRL + Qt::Key_S);
|
---|
158 | Menu->addAction("Print plot", this, SLOT(MenuPrint()));
|
---|
159 | Menu->addSeparator();
|
---|
160 | ConnectAction = Menu->addAction("Connect", this, SLOT(MakeConnection()));
|
---|
161 | ConnectAction->setShortcut(Qt::CTRL + Qt::Key_C);
|
---|
162 | Menu->addSeparator();
|
---|
163 | Menu->addAction("Help", this, SLOT(MenuHelp()));
|
---|
164 | Menu->addAction("About", this, SLOT(MenuAbout()));
|
---|
165 | Menu->addSeparator();
|
---|
166 | QAction* QuitAction = Menu->addAction("Quit", qApp, SLOT(quit()));
|
---|
167 | QuitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
|
---|
168 |
|
---|
169 | //-----------------------------------------------------------------------
|
---|
170 | //**************************** Socket window ****************************
|
---|
171 | //-----------------------------------------------------------------------
|
---|
172 |
|
---|
173 | // Create widget (initially hidden)
|
---|
174 | SocketWindow = new QWidget();
|
---|
175 | SocketWindow->setWindowTitle("ddd - Socket Interface");
|
---|
176 |
|
---|
177 | // Edit box for IP Address
|
---|
178 | IPAddress = new QLineEdit(SocketWindow);
|
---|
179 | IPAddress->setText("eth-vme02");
|
---|
180 | IPAddress->setToolTip("Address of socket server");
|
---|
181 | AddressLayout = new QFormLayout;
|
---|
182 | AddressLayout->addRow("&Remote Address", IPAddress);
|
---|
183 |
|
---|
184 | // SpinBox for port selection
|
---|
185 | Port = new QSpinBox(SocketWindow);
|
---|
186 | Port->setRange(0,65535);
|
---|
187 | Port->setValue(2000);
|
---|
188 | Port->setToolTip("Port number of socket server");
|
---|
189 | PortLayout = new QFormLayout;
|
---|
190 | PortLayout->addRow("&Port", Port);
|
---|
191 |
|
---|
192 | // Button to make connection
|
---|
193 | Connect = new QPushButton("Connect", SocketWindow);
|
---|
194 | Connect->setFont(QFont("Times", 10, QFont::Bold));
|
---|
195 | connect(Connect, SIGNAL(clicked()), this, SLOT(MakeConnection()));
|
---|
196 | Connect->setToolTip("Connect to server");
|
---|
197 |
|
---|
198 | // Edit box for command
|
---|
199 | Command = new QLineEdit(SocketWindow);
|
---|
200 | CommandLayout = new QFormLayout;
|
---|
201 | CommandLayout->addRow("&Command", Command);
|
---|
202 | Command->setEnabled(false);
|
---|
203 | connect(Command, SIGNAL(returnPressed()), this, SLOT(SendToSocket()));
|
---|
204 | Command->setToolTip("Command to send to socket server");
|
---|
205 |
|
---|
206 | // Text box for socket output
|
---|
207 | SocketOutput= new QPlainTextEdit(SocketWindow);
|
---|
208 | SocketOutput->setReadOnly(true);
|
---|
209 | SocketOutput->setMaximumBlockCount(MAX_OUTPUT_LINES);
|
---|
210 | SocketOutput->setToolTip("Output of socket server");
|
---|
211 |
|
---|
212 | // Layout of all widgets
|
---|
213 | SocketLayout = new QGridLayout(SocketWindow);
|
---|
214 | SocketLayout->addLayout(AddressLayout, 0, 0, 0, 1);
|
---|
215 | SocketLayout->addLayout(PortLayout, 0, 2);
|
---|
216 | SocketLayout->addWidget(Connect, 0, 3);
|
---|
217 | SocketLayout->addLayout(CommandLayout, 1, 0, 1, 4);
|
---|
218 | SocketLayout->addWidget(SocketOutput, 2, 0, 4, 4);
|
---|
219 |
|
---|
220 | //-----------------------------------------------------------------------
|
---|
221 | //**************************** M0 window ****************************
|
---|
222 | //-----------------------------------------------------------------------
|
---|
223 |
|
---|
224 | M0Window = new QWidget();
|
---|
225 | M0Window->setWindowTitle("ddd - M0 Display");
|
---|
226 |
|
---|
227 | Graph2D = new QwtPlot(M0Window);
|
---|
228 | Graph2D->setAutoReplot(true);
|
---|
229 | Graph2D->setCanvasBackground(QColor(Qt::white));
|
---|
230 |
|
---|
231 | M0Start = new QSpinBox(M0Window);
|
---|
232 | M0Start->setEnabled(false);
|
---|
233 | connect(M0Start, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
|
---|
234 | M0Start->setToolTip("First bin/sample of time window");
|
---|
235 | M0StartLayout = new QFormLayout;
|
---|
236 | M0StartLayout->addRow("First Bin", M0Start);
|
---|
237 |
|
---|
238 | M0Stop = new QSpinBox(M0Window);
|
---|
239 | M0Stop->setEnabled(false);
|
---|
240 | M0Stop->setRange(0,1023);
|
---|
241 | M0Stop->setValue(1023);
|
---|
242 | connect(M0Stop, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
|
---|
243 | M0Stop->setToolTip("Last bin/sample of time window");
|
---|
244 | M0StopLayout = new QFormLayout;
|
---|
245 | M0StopLayout->addRow("Last Bin", M0Stop);
|
---|
246 |
|
---|
247 | M0Layout = new QGridLayout(M0Window);
|
---|
248 | M0Layout->addWidget(Graph2D, 1,1,3,3);
|
---|
249 | M0Layout->addLayout(M0StartLayout,4,1);
|
---|
250 | M0Layout->addLayout(M0StopLayout,4,2);
|
---|
251 |
|
---|
252 | Signal2D = new QwtPlotSpectrogram;
|
---|
253 | Signal2D->attach(Graph2D);
|
---|
254 |
|
---|
255 | //initialize raster data of M0 display
|
---|
256 | double z[6][6];
|
---|
257 | for (int i=0; i<6; i++){
|
---|
258 | for (int j=0; j<6; j++){
|
---|
259 | z[i][j]=i+j;
|
---|
260 | }
|
---|
261 | }
|
---|
262 | Signal2D->setData(SpectrogramDataM0(z));
|
---|
263 |
|
---|
264 | //color (z-) axis of M0 display
|
---|
265 | colorMap = QwtLinearColorMap(Qt::yellow, Qt::red);
|
---|
266 | Signal2D->setColorMap(colorMap);
|
---|
267 |
|
---|
268 | Graph2D->axisWidget(QwtPlot::yRight)->setTitle("Maximum Sample Amplitude (mV)");
|
---|
269 | Graph2D->axisWidget(QwtPlot::yRight)->setColorBarEnabled(true);
|
---|
270 | Graph2D->axisWidget(QwtPlot::yRight)->setColorMap(Signal2D->data().range(),Signal2D->colorMap());
|
---|
271 |
|
---|
272 | Graph2D->setAxisScale(QwtPlot::yRight,Signal2D->data().range().minValue(),Signal2D->data().range().maxValue());
|
---|
273 | Graph2D->enableAxis(QwtPlot::yRight);
|
---|
274 | Graph2D->plotLayout()->setAlignCanvasToScales(true);
|
---|
275 | Graph2D->replot();
|
---|
276 |
|
---|
277 | }
|
---|
278 |
|
---|
279 | ddd::~ddd() {
|
---|
280 | // Qwt items
|
---|
281 | delete Grid; delete Signal;
|
---|
282 | delete Signal2D;
|
---|
283 | // Layout items
|
---|
284 | delete PortLayout; delete CommandLayout;
|
---|
285 | delete M0StartLayout; delete M0StopLayout;
|
---|
286 | delete AddressLayout; delete FormLayout;
|
---|
287 | delete SpinLayout;
|
---|
288 | // Other items
|
---|
289 | delete SocketWindow;
|
---|
290 | delete M0Window;
|
---|
291 | delete PixMap; delete RD;
|
---|
292 |
|
---|
293 | fclose(Tmpfile);
|
---|
294 | }
|
---|
295 |
|
---|
296 |
|
---|
297 | //---------------------------------------------------------------------
|
---|
298 | //**************************** Main program ***************************
|
---|
299 | //---------------------------------------------------------------------
|
---|
300 |
|
---|
301 | int main(int argc, char *argv[]) {
|
---|
302 | QApplication app(argc, argv);
|
---|
303 |
|
---|
304 | ddd MainWindow;
|
---|
305 | MainWindow.setGeometry(100, 100, 800, 500);
|
---|
306 | MainWindow.setWindowTitle("ddd - DRS Data Display");
|
---|
307 | MainWindow.show();
|
---|
308 |
|
---|
309 | return app.exec();
|
---|
310 | }
|
---|