source: tools/ddd/GUI.cpp@ 152

Last change on this file since 152 was 129, checked in by ogrimm, 15 years ago
Saving of waveform to text and plotting of physical pipeline added
File size: 11.4 KB
Line 
1/* ============================================================
2
3DRS Data Display
4
5Qt-based graphical user interface for displaying data taken with
6the drsdaq program.
7There are two operation modes: inspection of a raw data file and
8data taking via the socket interface. Connecting to a socket server
9automatically disables raw data file operation and closes any open
10file.
11
12Oliver Grimm
13
14============================================================ */
15
16#include "GUI.h"
17
18ddd::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::yLeft, "Signal (mV)");
101 Graph->setAutoReplot(true);
102 Graph->setCanvasBackground(QColor(Qt::yellow));
103 Zoomer = new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yLeft,Graph->canvas());
104 connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(HandleZoom(const QwtDoubleRect &)));
105 Panner = new QwtPlotPanner(Graph->canvas());
106 Panner->setMouseButton(Qt::LeftButton, Qt::ShiftModifier);
107 Grid = new QwtPlotGrid;
108 Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
109 Grid->attach(Graph);
110 Signal = new QwtPlotCurve;
111 Signal->attach(Graph);
112 Signal->setStyle(QwtPlotCurve::Steps);
113
114 // Text boxes for run and event header
115 RunHeaderDisplay = new QPlainTextEdit(Central);
116 EventHeaderDisplay = new QPlainTextEdit(Central);
117 RunHeaderDisplay->setReadOnly(true);
118 EventHeaderDisplay->setReadOnly(true);
119
120 // Browse botton
121 LoadButton = new QToolButton(Central);
122 LoadButton->setToolButtonStyle (Qt::ToolButtonTextOnly);
123 LoadButton->setText("...");
124 connect(LoadButton, SIGNAL(clicked()), this, SLOT(FileDialog()));
125 LoadButton->setToolTip("Open file dialog to select raw data file");
126
127 // Filename box
128 FilenameBox = new QLineEdit(Central);
129 connect(FilenameBox, SIGNAL(returnPressed()), this, SLOT(OpenDatafile()));
130 FilenameBox->setToolTip("Raw data file name");
131
132 // Tab widget
133 TabWidget = new QTabWidget(Central);
134 TabWidget->addTab(Graph, "&Signal");
135 TabWidget->addTab(RunHeaderDisplay, "&Run Header");
136 TabWidget->addTab(EventHeaderDisplay, "&Event Header");
137
138 // Layout of all widgets
139 MainLayout = new QGridLayout(Central);
140 MainLayout->addWidget(FilenameBox, 0, 0, 1, 3);
141 MainLayout->addWidget(LoadButton, 0, 3);
142 MainLayout->addLayout(SpinLayout, 1, 0);
143 MainLayout->addLayout(FormLayout, 2, 0);
144 MainLayout->addWidget(SocketButton, 6,0);
145 MainLayout->addWidget(M0Display, 3,0);
146 MainLayout->addWidget(GetButton, 4,0);
147 MainLayout->addWidget(ContinuousBox, 5,0);
148 MainLayout->addWidget(TabWidget, 1, 1, 6, 5);
149 MainLayout->setColumnStretch(1, 10);
150
151 // Menu bar
152 QMenu* Menu = menuBar()->addMenu("&Menu");
153 OpenAction = Menu->addAction("Open data file", this, SLOT(FileDialog()));
154 OpenAction->setShortcut(Qt::CTRL + Qt::Key_O);
155 QAction* SaveAction = Menu->addAction("Save plot", this, SLOT(MenuSave()));
156 SaveAction->setShortcut(Qt::CTRL + Qt::Key_S);
157 Menu->addAction("Print plot", this, SLOT(MenuPrint()));
158 Menu->addAction("Save waveform to ASCII", this, SLOT(MenuSaveASCII()));
159 Menu->addSeparator();
160 PhysPipeAction = Menu->addAction("Plot physical pipeline", this, SLOT(DisplayEvent()));
161 PhysPipeAction->setCheckable(true);
162 PhysPipeAction->setEnabled(false);
163 Menu->addSeparator();
164 ConnectAction = Menu->addAction("Connect", this, SLOT(MakeConnection()));
165 ConnectAction->setShortcut(Qt::CTRL + Qt::Key_C);
166 Menu->addSeparator();
167 Menu->addAction("Help", this, SLOT(MenuHelp()));
168 Menu->addAction("About", this, SLOT(MenuAbout()));
169 Menu->addSeparator();
170 QAction* QuitAction = Menu->addAction("Quit", qApp, SLOT(quit()));
171 QuitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
172
173 //-----------------------------------------------------------------------
174 //**************************** Socket window ****************************
175 //-----------------------------------------------------------------------
176
177 // Create widget (initially hidden)
178 SocketWindow = new QWidget();
179 SocketWindow->setWindowTitle("ddd - Socket Interface");
180
181 // Edit box for IP Address
182 IPAddress = new QLineEdit(SocketWindow);
183 IPAddress->setText("eth-vme02");
184 IPAddress->setToolTip("Address of socket server");
185 AddressLayout = new QFormLayout;
186 AddressLayout->addRow("&Remote Address", IPAddress);
187
188 // SpinBox for port selection
189 Port = new QSpinBox(SocketWindow);
190 Port->setRange(0,65535);
191 Port->setValue(2000);
192 Port->setToolTip("Port number of socket server");
193 PortLayout = new QFormLayout;
194 PortLayout->addRow("&Port", Port);
195
196 // Button to make connection
197 Connect = new QPushButton("Connect", SocketWindow);
198 Connect->setFont(QFont("Times", 10, QFont::Bold));
199 connect(Connect, SIGNAL(clicked()), this, SLOT(MakeConnection()));
200 Connect->setToolTip("Connect to server");
201
202 // Edit box for command
203 Command = new QLineEdit(SocketWindow);
204 CommandLayout = new QFormLayout;
205 CommandLayout->addRow("&Command", Command);
206 Command->setEnabled(false);
207 connect(Command, SIGNAL(returnPressed()), this, SLOT(SendToSocket()));
208 Command->setToolTip("Command to send to socket server");
209
210 // Text box for socket output
211 SocketOutput= new QPlainTextEdit(SocketWindow);
212 SocketOutput->setReadOnly(true);
213 SocketOutput->setMaximumBlockCount(MAX_OUTPUT_LINES);
214 SocketOutput->setToolTip("Output of socket server");
215
216 // Layout of all widgets
217 SocketLayout = new QGridLayout(SocketWindow);
218 SocketLayout->addLayout(AddressLayout, 0, 0, 0, 1);
219 SocketLayout->addLayout(PortLayout, 0, 2);
220 SocketLayout->addWidget(Connect, 0, 3);
221 SocketLayout->addLayout(CommandLayout, 1, 0, 1, 4);
222 SocketLayout->addWidget(SocketOutput, 2, 0, 4, 4);
223
224 //-----------------------------------------------------------------------
225 //**************************** M0 window ****************************
226 //-----------------------------------------------------------------------
227
228 M0Window = new QWidget();
229 M0Window->setWindowTitle("ddd - M0 Display");
230
231 Graph2D = new QwtPlot(M0Window);
232 Graph2D->setAutoReplot(true);
233 Graph2D->setCanvasBackground(QColor(Qt::white));
234
235 M0Start = new QSpinBox(M0Window);
236 M0Start->setEnabled(false);
237 connect(M0Start, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
238 M0Start->setToolTip("First bin/sample of time window");
239 M0StartLayout = new QFormLayout;
240 M0StartLayout->addRow("First Bin", M0Start);
241
242 M0Stop = new QSpinBox(M0Window);
243 M0Stop->setEnabled(false);
244 M0Stop->setRange(0,1023);
245 M0Stop->setValue(1023);
246 connect(M0Stop, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
247 M0Stop->setToolTip("Last bin/sample of time window");
248 M0StopLayout = new QFormLayout;
249 M0StopLayout->addRow("Last Bin", M0Stop);
250
251 M0Layout = new QGridLayout(M0Window);
252 M0Layout->addWidget(Graph2D, 1,1,3,3);
253 M0Layout->addLayout(M0StartLayout,4,1);
254 M0Layout->addLayout(M0StopLayout,4,2);
255
256 Signal2D = new QwtPlotSpectrogram;
257 Signal2D->attach(Graph2D);
258
259 //initialize raster data of M0 display
260 double z[6][6];
261 for (int i=0; i<6; i++){
262 for (int j=0; j<6; j++){
263 z[i][j]=i+j;
264 }
265 }
266 Signal2D->setData(SpectrogramDataM0(z));
267
268 //color (z-) axis of M0 display
269 colorMap = QwtLinearColorMap(Qt::yellow, Qt::red);
270 Signal2D->setColorMap(colorMap);
271
272 Graph2D->axisWidget(QwtPlot::yRight)->setTitle("Maximum Sample Amplitude (mV)");
273 Graph2D->axisWidget(QwtPlot::yRight)->setColorBarEnabled(true);
274 Graph2D->axisWidget(QwtPlot::yRight)->setColorMap(Signal2D->data().range(),Signal2D->colorMap());
275
276 Graph2D->setAxisScale(QwtPlot::yRight,Signal2D->data().range().minValue(),Signal2D->data().range().maxValue());
277 Graph2D->enableAxis(QwtPlot::yRight);
278 Graph2D->plotLayout()->setAlignCanvasToScales(true);
279 Graph2D->replot();
280
281}
282
283ddd::~ddd() {
284 // Qwt items
285 delete Grid; delete Signal;
286 delete Signal2D;
287 // Layout items
288 delete PortLayout; delete CommandLayout;
289 delete M0StartLayout; delete M0StopLayout;
290 delete AddressLayout; delete FormLayout;
291 delete SpinLayout;
292 // Other items
293 delete SocketWindow;
294 delete M0Window;
295 delete PixMap; delete RD;
296
297 fclose(Tmpfile);
298}
299
300
301//---------------------------------------------------------------------
302//**************************** Main program ***************************
303//---------------------------------------------------------------------
304
305int main(int argc, char *argv[]) {
306 QApplication app(argc, argv);
307
308 ddd MainWindow;
309 MainWindow.setGeometry(100, 100, 800, 500);
310 MainWindow.setWindowTitle("ddd - DRS Data Display");
311 MainWindow.show();
312
313 return app.exec();
314}
Note: See TracBrowser for help on using the repository browser.