source: tools/ddd/GUI.cpp@ 7977

Last change on this file since 7977 was 198, checked in by ogrimm, 15 years ago
Added chip selection spin box
File size: 11.6 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("DRS channel number");
56
57 // SpinBox for chip number
58 ChipNo = new QSpinBox(Central);
59 ChipNo->setEnabled(false);
60 connect(ChipNo, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
61 ChipNo->setToolTip("DRS chip number");
62
63 // SpinBox for board number
64 BoardNo = new QSpinBox(Central);
65 BoardNo->setEnabled(false);
66 connect(BoardNo, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
67 BoardNo->setToolTip("Mezzanine board number");
68
69 // TextBox for pixel ID
70 PixelID = new QLineEdit(Central);
71 PixelID->setEnabled(false);
72 connect(PixelID, SIGNAL(returnPressed()), this, SLOT(TranslatePixelID()));
73 PixelID->setToolTip("Pixel identification");
74
75 // Layout of pixel addressing widgets
76 FormLayout = new QFormLayout;
77 FormLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
78 FormLayout->addRow("&Channel", ChannelNo);
79 FormLayout->addRow("Chip", ChipNo);
80 FormLayout->addRow("&Board", BoardNo);
81 FormLayout->addRow("Pixel ID", PixelID);
82
83 // Socket button
84 SocketButton = new QPushButton("Socke&t\nInterface", Central);
85 SocketButton->setFont(QFont("Times", 10, QFont::Bold));
86 connect(SocketButton, SIGNAL(clicked()), this, SLOT(OpenSocketWindow()));
87 SocketButton->setToolTip("Open window for socket communication");
88
89 // M0 display button
90 M0Display = new QPushButton("M0 Display",Central);
91 M0Display->setFont(QFont("Times", 10, QFont::Bold));
92 connect(M0Display, SIGNAL(clicked()), this, SLOT(OpenM0Window()));
93 M0Display->setToolTip("Open window for M0 display");
94
95 // Acquire button and Continuous check box
96 GetButton = new QPushButton("&Acquire", Central);
97 GetButton->setFont(QFont("Times", 10, QFont::Bold));
98 GetButton->setEnabled(false);
99 connect(GetButton, SIGNAL(clicked()), this, SLOT(GetSignalFromSocket()));
100 GetButton->setToolTip("Acquire event over socket interface");
101 ContinuousBox = new QCheckBox("Continuous", Central);
102 ContinuousBox->setFont(QFont("Times", 10, QFont::Bold));
103 ContinuousBox->setToolTip("Acquire continuously");
104
105 // Plot area
106 Graph = new QwtPlot(Central);
107 Graph->setAxisTitle(QwtPlot::yLeft, "Signal (mV)");
108 Graph->setAutoReplot(true);
109 Graph->setCanvasBackground(QColor(Qt::yellow));
110 Zoomer = new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yLeft,Graph->canvas());
111 connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(HandleZoom(const QwtDoubleRect &)));
112 Panner = new QwtPlotPanner(Graph->canvas());
113 Panner->setMouseButton(Qt::LeftButton, Qt::ShiftModifier);
114 Grid = new QwtPlotGrid;
115 Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
116 Grid->attach(Graph);
117 Signal = new QwtPlotCurve;
118 Signal->attach(Graph);
119 Signal->setStyle(QwtPlotCurve::Steps);
120
121 // Text boxes for run and event header
122 RunHeaderDisplay = new QPlainTextEdit(Central);
123 EventHeaderDisplay = new QPlainTextEdit(Central);
124 RunHeaderDisplay->setReadOnly(true);
125 EventHeaderDisplay->setReadOnly(true);
126
127 // Browse botton
128 LoadButton = new QToolButton(Central);
129 LoadButton->setToolButtonStyle (Qt::ToolButtonTextOnly);
130 LoadButton->setText("...");
131 connect(LoadButton, SIGNAL(clicked()), this, SLOT(FileDialog()));
132 LoadButton->setToolTip("Open file dialog to select raw data file");
133
134 // Filename box
135 FilenameBox = new QLineEdit(Central);
136 connect(FilenameBox, SIGNAL(returnPressed()), this, SLOT(OpenDatafile()));
137 FilenameBox->setToolTip("Raw data file name");
138
139 // Tab widget
140 TabWidget = new QTabWidget(Central);
141 TabWidget->addTab(Graph, "&Signal");
142 TabWidget->addTab(RunHeaderDisplay, "&Run Header");
143 TabWidget->addTab(EventHeaderDisplay, "&Event Header");
144
145 // Layout of all widgets
146 MainLayout = new QGridLayout(Central);
147 MainLayout->addWidget(FilenameBox, 0, 0, 1, 3);
148 MainLayout->addWidget(LoadButton, 0, 3);
149 MainLayout->addLayout(SpinLayout, 1, 0);
150 MainLayout->addLayout(FormLayout, 2, 0);
151 MainLayout->addWidget(SocketButton, 6,0);
152 MainLayout->addWidget(M0Display, 3,0);
153 MainLayout->addWidget(GetButton, 4,0);
154 MainLayout->addWidget(ContinuousBox, 5,0);
155 MainLayout->addWidget(TabWidget, 1, 1, 6, 5);
156 MainLayout->setColumnStretch(1, 10);
157
158 // Menu bar
159 QMenu* Menu = menuBar()->addMenu("&Menu");
160 OpenAction = Menu->addAction("Open data file", this, SLOT(FileDialog()));
161 OpenAction->setShortcut(Qt::CTRL + Qt::Key_O);
162 QAction* SaveAction = Menu->addAction("Save plot", this, SLOT(MenuSave()));
163 SaveAction->setShortcut(Qt::CTRL + Qt::Key_S);
164 Menu->addAction("Print plot", this, SLOT(MenuPrint()));
165 Menu->addAction("Save waveform to ASCII", this, SLOT(MenuSaveASCII()));
166 Menu->addSeparator();
167 PhysPipeAction = Menu->addAction("Plot physical pipeline", this, SLOT(DisplayEvent()));
168 PhysPipeAction->setCheckable(true);
169 PhysPipeAction->setEnabled(false);
170 Menu->addSeparator();
171 ConnectAction = Menu->addAction("Connect", this, SLOT(MakeConnection()));
172 ConnectAction->setShortcut(Qt::CTRL + Qt::Key_C);
173 Menu->addSeparator();
174 Menu->addAction("Help", this, SLOT(MenuHelp()));
175 Menu->addAction("About", this, SLOT(MenuAbout()));
176 Menu->addSeparator();
177 QAction* QuitAction = Menu->addAction("Quit", qApp, SLOT(quit()));
178 QuitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
179
180 //-----------------------------------------------------------------------
181 //**************************** Socket window ****************************
182 //-----------------------------------------------------------------------
183
184 // Create widget (initially hidden)
185 SocketWindow = new QWidget();
186 SocketWindow->setWindowTitle("ddd - Socket Interface");
187
188 // Edit box for IP Address
189 IPAddress = new QLineEdit(SocketWindow);
190 IPAddress->setText("eth-vme02");
191 IPAddress->setToolTip("Address of socket server");
192 AddressLayout = new QFormLayout;
193 AddressLayout->addRow("&Remote Address", IPAddress);
194
195 // SpinBox for port selection
196 Port = new QSpinBox(SocketWindow);
197 Port->setRange(0,65535);
198 Port->setValue(2000);
199 Port->setToolTip("Port number of socket server");
200 PortLayout = new QFormLayout;
201 PortLayout->addRow("&Port", Port);
202
203 // Button to make connection
204 Connect = new QPushButton("Connect", SocketWindow);
205 Connect->setFont(QFont("Times", 10, QFont::Bold));
206 connect(Connect, SIGNAL(clicked()), this, SLOT(MakeConnection()));
207 Connect->setToolTip("Connect to server");
208
209 // Edit box for command
210 Command = new QLineEdit(SocketWindow);
211 CommandLayout = new QFormLayout;
212 CommandLayout->addRow("&Command", Command);
213 Command->setEnabled(false);
214 connect(Command, SIGNAL(returnPressed()), this, SLOT(SendToSocket()));
215 Command->setToolTip("Command to send to socket server");
216
217 // Text box for socket output
218 SocketOutput= new QPlainTextEdit(SocketWindow);
219 SocketOutput->setReadOnly(true);
220 SocketOutput->setMaximumBlockCount(MAX_OUTPUT_LINES);
221 SocketOutput->setToolTip("Output of socket server");
222
223 // Layout of all widgets
224 SocketLayout = new QGridLayout(SocketWindow);
225 SocketLayout->addLayout(AddressLayout, 0, 0, 0, 1);
226 SocketLayout->addLayout(PortLayout, 0, 2);
227 SocketLayout->addWidget(Connect, 0, 3);
228 SocketLayout->addLayout(CommandLayout, 1, 0, 1, 4);
229 SocketLayout->addWidget(SocketOutput, 2, 0, 4, 4);
230
231 //-----------------------------------------------------------------------
232 //**************************** M0 window ****************************
233 //-----------------------------------------------------------------------
234
235 M0Window = new QWidget();
236 M0Window->setWindowTitle("ddd - M0 Display");
237
238 Graph2D = new QwtPlot(M0Window);
239 Graph2D->setAutoReplot(true);
240 Graph2D->setCanvasBackground(QColor(Qt::white));
241
242 M0Start = new QSpinBox(M0Window);
243 M0Start->setEnabled(false);
244 connect(M0Start, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
245 M0Start->setToolTip("First bin/sample of time window");
246 M0StartLayout = new QFormLayout;
247 M0StartLayout->addRow("First Bin", M0Start);
248
249 M0Stop = new QSpinBox(M0Window);
250 M0Stop->setEnabled(false);
251 M0Stop->setRange(0,1023);
252 M0Stop->setValue(1023);
253 connect(M0Stop, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
254 M0Stop->setToolTip("Last bin/sample of time window");
255 M0StopLayout = new QFormLayout;
256 M0StopLayout->addRow("Last Bin", M0Stop);
257
258 M0Layout = new QGridLayout(M0Window);
259 M0Layout->addWidget(Graph2D, 1,1,3,3);
260 M0Layout->addLayout(M0StartLayout,4,1);
261 M0Layout->addLayout(M0StopLayout,4,2);
262
263 Signal2D = new QwtPlotSpectrogram;
264 Signal2D->attach(Graph2D);
265
266 //initialize raster data of M0 display
267 double z[6][6];
268 for (int i=0; i<6; i++){
269 for (int j=0; j<6; j++){
270 z[i][j]=i+j;
271 }
272 }
273 Signal2D->setData(SpectrogramDataM0(z));
274
275 //color (z-) axis of M0 display
276 colorMap = QwtLinearColorMap(Qt::yellow, Qt::red);
277 Signal2D->setColorMap(colorMap);
278
279 Graph2D->axisWidget(QwtPlot::yRight)->setTitle("Maximum Sample Amplitude (mV)");
280 Graph2D->axisWidget(QwtPlot::yRight)->setColorBarEnabled(true);
281 Graph2D->axisWidget(QwtPlot::yRight)->setColorMap(Signal2D->data().range(),Signal2D->colorMap());
282
283 Graph2D->setAxisScale(QwtPlot::yRight,Signal2D->data().range().minValue(),Signal2D->data().range().maxValue());
284 Graph2D->enableAxis(QwtPlot::yRight);
285 Graph2D->plotLayout()->setAlignCanvasToScales(true);
286 Graph2D->replot();
287
288}
289
290ddd::~ddd() {
291 // Qwt items
292 delete Grid; delete Signal;
293 delete Signal2D;
294 // Layout items
295 delete PortLayout; delete CommandLayout;
296 delete M0StartLayout; delete M0StopLayout;
297 delete AddressLayout; delete FormLayout;
298 delete SpinLayout;
299 // Other items
300 delete SocketWindow;
301 delete M0Window;
302 delete PixMap; delete RD;
303
304 fclose(Tmpfile);
305}
306
307
308//---------------------------------------------------------------------
309//**************************** Main program ***************************
310//---------------------------------------------------------------------
311
312int main(int argc, char *argv[]) {
313 QApplication app(argc, argv);
314
315 ddd MainWindow;
316 MainWindow.setGeometry(100, 100, 800, 500);
317 MainWindow.setWindowTitle("ddd - DRS Data Display");
318 MainWindow.show();
319
320 return app.exec();
321}
Note: See TracBrowser for help on using the repository browser.