2 added + 9 modified, total 11 files
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -N EcalMonitoringPlots.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ EcalMonitoringPlots.java 4 Apr 2012 23:26:07 -0000 1.1
@@ -0,0 +1,84 @@
+package org.lcsim.hps.monitoring;
+
+import hep.aida.IHistogram2D;
+import hep.aida.IPlotter;
+import hep.aida.IPlotterStyle;
+import hep.aida.ref.plotter.PlotterRegion;
+
+import java.util.List;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawCalorimeterHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+public class EcalMonitoringPlots extends Driver implements Resettable {
+
+ String ecalName = "Ecal";
+ String rawCalorimeterHitCollectionName = "EcalRawHits";
+
+ AIDA aida = AIDA.defaultInstance();
+ IPlotter plotter;
+ IHistogram2D cellEnergyPlot;
+
+ IDDecoder dec;
+
+ Detector detector;
+
+ public EcalMonitoringPlots()
+ {}
+
+ public void setRawCalorimeterHitCollectionName(String rawCalorimeterHitCollectionName) {
+ this.rawCalorimeterHitCollectionName = rawCalorimeterHitCollectionName;
+ }
+
+ public void setEcalName(String ecalName) {
+ this.ecalName = ecalName;
+ }
+
+ protected void detectorChanged(Detector detector) {
+
+ this.detector = detector;
+
+ if (detector.getSubdetector(ecalName) == null) {
+ throw new RuntimeException("There is no subdetector called " + ecalName + " in this detector");
+ }
+
+ // Cache the IDDecoder for the ECal.
+ dec = detector.getSubdetector(ecalName).getReadout().getIDDecoder();
+
+ // Setup the plotter.
+ plotter = aida.analysisFactory().createPlotterFactory().create("HPS ECal Plots");
+
+ // Setup plots.
+ aida.tree().cd("/");
+ cellEnergyPlot = aida.histogram2D("Crystal Energy", 47, -23.5, 23.5, 11, -5.5, 5.5);
+
+ // Create the plotter regions.
+ plotter.createRegion();
+ plotter.style().statisticsBoxStyle().setVisible(false);
+ IPlotterStyle style = plotter.region(0).style();
+ style.setParameter("hist2DStyle","colorMap");
+ style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+ plotter.region(0).plot(cellEnergyPlot);
+ ((PlotterRegion)plotter.region(0)).getPlot().setAllowUserInteraction(false);
+ ((PlotterRegion)plotter.region(0)).getPlot().setAllowPopupMenus(false);
+ plotter.show();
+ }
+
+ public void process(EventHeader event) {
+ List<RawCalorimeterHit> hits = event.get(RawCalorimeterHit.class, rawCalorimeterHitCollectionName);
+ for (RawCalorimeterHit hit : hits) {
+ dec.setID(hit.getCellID());
+ cellEnergyPlot.fill(dec.getValue("ix"), dec.getValue("iy"));
+ }
+ }
+
+ public void reset() {
+ plotter.hide();
+ cellEnergyPlot.reset();
+ detectorChanged(detector);
+ }
+}
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -N MonitoringExitCallback.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MonitoringExitCallback.java 4 Apr 2012 23:26:07 -0000 1.1
@@ -0,0 +1,15 @@
+package org.lcsim.hps.monitoring;
+
+class MonitoringExitCallback extends Thread {
+
+ EtConnection connection;
+
+ MonitoringExitCallback(EtConnection connection) {
+ this.connection = connection;
+ }
+
+ public void run() {
+ System.out.println(this.getClass().getSimpleName() + ".run");
+ connection.cleanup();
+ }
+}
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.10 -r1.11
--- ConnectionPanel.java 3 Apr 2012 18:37:04 -0000 1.10
+++ ConnectionPanel.java 4 Apr 2012 23:26:07 -0000 1.11
@@ -30,24 +30,24 @@
class ConnectionPanel extends JPanel implements ActionListener {
- private JTextField etNameField;
- private JTextField hostField;
- private JTextField portField;
- private JCheckBox blockingField;
- private JCheckBox verboseField;
- private JTextField statNameField;
- private JTextField chunkField;
- private JTextField qSizeField;
- private JTextField positionField;
- private JTextField ppositionField;
- private JComboBox waitComboBox;
- private JTextField waitTimeField;
- private JTextField prescaleField;
+ JTextField etNameField;
+ JTextField hostField;
+ JTextField portField;
+ JCheckBox blockingField;
+ JCheckBox verboseField;
+ JTextField statNameField;
+ JTextField chunkField;
+ JTextField qSizeField;
+ JTextField positionField;
+ JTextField ppositionField;
+ JComboBox waitComboBox;
+ JTextField waitTimeField;
+ JTextField prescaleField;
- private ConnectionParameters connectionParameters;
+ ConnectionParameters connectionParameters;
- private boolean connectRequested = false;
- private boolean disconnectRequested = false;
+ boolean connectRequested = false;
+ boolean disconnectRequested = false;
static final String[] waitModes = {
Mode.SLEEP.toString(),
@@ -338,6 +338,14 @@
prescaleField.setText(Integer.toString(cn.prescale));
this.connectionParameters = cn;
}
+
+ void setConnectRequested(boolean b) {
+ this.connectRequested = false;
+ }
+
+ void setDisconnectRequested(boolean b) {
+ this.disconnectRequested = false;
+ }
private void setConnectRequested() {
connectRequested = true;
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.4 -r1.5
--- EtConnection.java 3 Apr 2012 18:37:04 -0000 1.4
+++ EtConnection.java 4 Apr 2012 23:26:07 -0000 1.5
@@ -13,23 +13,49 @@
*/
class EtConnection {
- private EtSystem sys;
- private EtAttachment att;
+ EtSystem sys;
+ EtAttachment att;
+ EtStation stat;
+ MonitoringExitCallback shutdownCallback;
- protected EtConnection(EtSystem sys, EtAttachment att) {
+ EtConnection(EtSystem sys, EtAttachment att, EtStation stat) {
this.sys = sys;
this.att = att;
+ this.stat = stat;
+ this.shutdownCallback = new MonitoringExitCallback(this);
+ Runtime.getRuntime().addShutdownHook(shutdownCallback);
}
- public EtSystem getEtSystem() {
+ EtSystem getEtSystem() {
return sys;
}
- public EtAttachment getEtAttachment() {
+ EtAttachment getEtAttachment() {
return att;
- }
+ }
+
+ EtStation getEtStation() {
+ return stat;
+ }
- public static EtConnection makeEtConnection(ConnectionParameters cn) throws Exception {
+ MonitoringExitCallback getShutdownCallback() {
+ return shutdownCallback;
+ }
+
+ void cleanup() {
+ if (sys.alive()) {
+ try {
+ sys.detach(att);
+ sys.removeStation(stat);
+ sys.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ static EtConnection createEtConnection(ConnectionParameters cn) throws Exception {
+
// make a direct connection to ET system's tcp server
EtSystemOpenConfig config = new EtSystemOpenConfig(cn.etName, cn.host, cn.port);
@@ -46,27 +72,19 @@
statConfig.setCue(cn.qSize);
}
}
- // Set prescale. Only values > 1 are used, as 1 means select every event.
- // Invalid values of 0 or negative numbers are simply ignored.
- if (cn.prescale > 1) {
+ // Set prescale.
+ if (cn.prescale > 0) {
System.out.println("setting prescale to " + cn.prescale);
statConfig.setPrescale(cn.prescale);
}
- // create station
- /*
- if (sys.stationExists(cn.statName)) {
- System.out.println("removing existing station");
- EtStation stat = sys.stationNameToObject(cn.statName);
- sys.removeStation(stat);
- System.out.println("station removed");
- }
- */
+ // Create the station.
EtStation stat = sys.createStation(statConfig, cn.statName, cn.position, cn.pposition);
// attach to new station
EtAttachment att = sys.attach(stat);
-
- return new EtConnection(sys, att);
+
+ // Return new connection.
+ return new EtConnection(sys, att, stat);
}
}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.3 -r1.4
--- EventPanel.java 3 Apr 2012 18:37:04 -0000 1.3
+++ EventPanel.java 4 Apr 2012 23:26:07 -0000 1.4
@@ -100,7 +100,7 @@
c.anchor = GridBagConstraints.EAST;
avgEventRateField = new JTextField("0", 6);
avgEventRateField.setHorizontalAlignment(JTextField.RIGHT);
- avgEventRateField.setEditable(false);
+ avgEventRateField.setEditable(false);
avgEventRateField.setBackground(Color.WHITE);
fieldsPanel.add(avgEventRateField, c);
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.2 -r1.3
--- JobPanel.java 3 Apr 2012 18:37:04 -0000 1.2
+++ JobPanel.java 4 Apr 2012 23:26:07 -0000 1.3
@@ -7,7 +7,9 @@
import java.awt.event.ActionListener;
import java.io.File;
import java.io.InputStream;
+import java.io.PrintStream;
+import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
@@ -16,21 +18,23 @@
// TODO Add field for setting the class to do LCSim event building. Use EventBuilder interface to check if given class makes sense.
class JobPanel extends JPanel implements ActionListener {
-
- final static String[] steeringTypes = { "RESOURCE", "FILE", "NONE" };
- final static int RESOURCE = 0;
- final static int FILE = 1;
- final static int NONE = 2;
JComboBox steeringComboBox;
JTextField steeringField;
JTextField detectorNameField;
JTextField eventBuilderField;
+ JCheckBox logCheckBox;
+ JTextField logFileField;
String defaultEventBuilderClassName = "";
+
+ final static String[] steeringTypes = { "RESOURCE", "FILE", "NONE" };
+ final static int RESOURCE = 0;
+ final static int FILE = 1;
+ final static int NONE = 2;
JobPanel() {
-
+
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
@@ -95,7 +99,7 @@
c.anchor = GridBagConstraints.WEST;
JLabel eventBuilderLabel = new JLabel("Event Builder Class:");
eventBuilderLabel.setHorizontalAlignment(JLabel.LEFT);
- eventBuilderLabel.setToolTipText("Fully qualified name of class used to convert to LCSim events from EVIO.");
+ eventBuilderLabel.setToolTipText("Class used to convert to LCSim events from EVIO.");
add(eventBuilderLabel, c);
c = new GridBagConstraints();
@@ -108,6 +112,41 @@
eventBuilderField.addActionListener(this);
eventBuilderField.setActionCommand(MonitoringCommands.eventBuilderCmd);
add(eventBuilderField, c);
+
+ c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 4;
+ c.anchor = GridBagConstraints.WEST;
+ JLabel jobComboBoxLabel = new JLabel("Log to File:");
+ jobComboBoxLabel.setHorizontalAlignment(JLabel.LEFT);
+ add(jobComboBoxLabel, c);
+
+ c = new GridBagConstraints();
+ c.gridx = 1;
+ c.gridy = 4;
+ c.anchor = GridBagConstraints.EAST;
+ logCheckBox = new JCheckBox();
+ logCheckBox.setEnabled(false);
+ add(logCheckBox, c);
+
+ c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 5;
+ c.anchor = GridBagConstraints.WEST;
+ JLabel logFileBoxLabel = new JLabel("Log File:");
+ logFileBoxLabel.setHorizontalAlignment(JLabel.LEFT);
+ logFileBoxLabel.setToolTipText("Full path of log file.");
+ add(logFileBoxLabel, c);
+
+ c = new GridBagConstraints();
+ c.gridx = 1;
+ c.gridy = 5;
+ c.anchor = GridBagConstraints.EAST;
+ logFileField = new JTextField("", 30);
+ logFileField.setHorizontalAlignment(JLabel.RIGHT);
+ logFileField.setEditable(false);
+ logFileField.setBackground(Color.WHITE);
+ add(logFileField, c);
}
public void actionPerformed(ActionEvent e) {
@@ -116,7 +155,7 @@
} else if (MonitoringCommands.eventBuilderCmd == e.getActionCommand()) {
editEventBuilder();
}
- }
+ }
private void editSteering() {
String steering = steeringField.getText();
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.6 -r1.7
--- MonitoringApplication.java 3 Apr 2012 18:37:04 -0000 1.6
+++ MonitoringApplication.java 4 Apr 2012 23:26:07 -0000 1.7
@@ -4,25 +4,38 @@
import static org.lcsim.hps.monitoring.MonitoringCommands.disconnectCmd;
import static org.lcsim.hps.monitoring.MonitoringCommands.exitCmd;
import static org.lcsim.hps.monitoring.MonitoringCommands.loadConnectionCmd;
+import static org.lcsim.hps.monitoring.MonitoringCommands.logCmd;
import static org.lcsim.hps.monitoring.MonitoringCommands.resetConnectionSettingsCmd;
import static org.lcsim.hps.monitoring.MonitoringCommands.resetDriversCmd;
import static org.lcsim.hps.monitoring.MonitoringCommands.resetEventsCmd;
import static org.lcsim.hps.monitoring.MonitoringCommands.saveConnectionCmd;
import static org.lcsim.hps.monitoring.MonitoringCommands.savePlotsCmd;
+import static org.lcsim.hps.monitoring.MonitoringCommands.screenshotCmd;
+import static org.lcsim.hps.monitoring.MonitoringCommands.terminalCmd;
+import java.awt.AWTException;
+import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
+import java.awt.image.BufferedImage;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.PrintStream;
+import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
@@ -33,15 +46,13 @@
public class MonitoringApplication extends JPanel implements ActionListener {
- private JTabbedPane tabs;
-
- private ConnectionPanel connectionPanel;
- private ConnectionStatusPanel connectionStatusPanel;
- private EventPanel eventPanel;
- private JobPanel jobPanel;
-
- private JMenuBar menuBar;
+ JTabbedPane tabs;
+ ConnectionPanel connectionPanel;
+ ConnectionStatusPanel connectionStatusPanel;
+ EventPanel eventPanel;
+ JobPanel jobPanel;
+ JMenuBar menuBar;
JMenuItem connectItem;
JMenuItem disconnectItem;
JMenuItem resetConnectionItem;
@@ -51,13 +62,29 @@
JMenuItem resetEventsItem;
JMenuItem savePlotsItem;
JMenuItem resetDriversItem;
+ JMenuItem logItem;
+ JMenuItem terminalItem;
+ JMenuItem screenshotItem;
- private JobControlManager mgr = null;
+ JobControlManager mgr = null;
+
+ // Saved references to original System PrintStreams.
+ PrintStream sysOut;
+ PrintStream sysErr;
+
+ // Current PrintStreams for logging.
+ PrintStream logOut;
+ PrintStream logErr;
+
+ static final String screenshotFormat = "png";
public MonitoringApplication() {
-
- //super(new BorderLayout());
+
super(new GridBagLayout());
+
+ // Save system's out and err.
+ sysOut = System.out;
+ sysErr = System.err;
// Setup the menus.
createMenu();
@@ -155,46 +182,39 @@
savePlotsItem = new JMenuItem("Save Plots to AIDA File...");
savePlotsItem.setMnemonic(KeyEvent.VK_P);
- savePlotsItem.setActionCommand("savePlots");
+ savePlotsItem.setActionCommand(savePlotsCmd);
savePlotsItem.addActionListener(this);
savePlotsItem.setEnabled(false);
jobMenu.add(savePlotsItem);
resetDriversItem = new JMenuItem("Reset LCSim Drivers");
resetDriversItem.setMnemonic(KeyEvent.VK_D);
- resetDriversItem.setActionCommand("resetDrivers");
+ resetDriversItem.setActionCommand(resetDriversCmd);
resetDriversItem.addActionListener(this);
resetDriversItem.setEnabled(false);
jobMenu.add(resetDriversItem);
- }
-
- public void setJobControlManager(JobControlManager mgr) {
- this.mgr = mgr;
- }
- synchronized void savePlots() {
- JFileChooser fc = new JFileChooser();
- int r = fc.showSaveDialog(this);
- if (r == JFileChooser.APPROVE_OPTION) {
- File fileName = fc.getSelectedFile();
- try {
- AIDA.defaultInstance().saveAs(fileName);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
+ logItem = new JMenuItem("Log to File...");
+ logItem.setMnemonic(KeyEvent.VK_F);
+ logItem.setActionCommand(logCmd);
+ logItem.addActionListener(this);
+ logItem.setEnabled(true);
+ jobMenu.add(logItem);
+
+ terminalItem = new JMenuItem("Log to Terminal");
+ terminalItem.setMnemonic(KeyEvent.VK_T);
+ terminalItem.setActionCommand(terminalCmd);
+ terminalItem.addActionListener(this);
+ terminalItem.setEnabled(false);
+ jobMenu.add(terminalItem);
+
+ screenshotItem = new JMenuItem("Take a screenshot...");
+ screenshotItem.setMnemonic(KeyEvent.VK_N);
+ screenshotItem.setActionCommand(screenshotCmd);
+ screenshotItem.addActionListener(this);
+ jobMenu.add(screenshotItem);
+ }
- synchronized void resetDrivers() {
- if (mgr != null) {
- for (Driver driver : mgr.getDriverExecList()) {
- if (driver instanceof Resettable) {
- ((Resettable) driver).reset();
- }
- }
- }
- }
-
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (connectCmd.equals(cmd)) {
@@ -213,15 +233,118 @@
savePlots();
} else if (resetDriversCmd.equals(cmd)) {
resetDrivers();
- } else if (exitCmd.equals(cmd)) {
+ } else if (logCmd.equals(cmd)) {
+ chooseLogFile();
+ } else if (terminalCmd.equals(cmd)) {
+ logToTerminal();
+ } else if (screenshotCmd.equals(cmd)) {
+ screenshot();
+ }
+ else if (exitCmd.equals(cmd)) {
exit();
}
}
- private void exit() {
- System.exit(0);
+ void setJobControlManager(JobControlManager mgr) {
+ this.mgr = mgr;
+ }
+
+ void showDialog(String m) {
+ JOptionPane.showMessageDialog(this, m);
+ }
+
+ /**
+ * Sets up the frame to run the application.
+ * This should be called using Runnable.run() (see MonitoringExample).
+ */
+ void start() {
+ JFrame frame = new JFrame("HPS Monitoring");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ this.setOpaque(true);
+ frame.setContentPane(this);
+ frame.setJMenuBar(menuBar);
+ frame.setResizable(false);
+ frame.pack();
+ frame.setVisible(true);
+ }
+
+ ConnectionPanel getConnectionPanel() {
+ return connectionPanel;
+ }
+
+ EventPanel getEventPanel() {
+ return eventPanel;
+ }
+
+ JobPanel getJobPanel() {
+ return jobPanel;
}
+ ConnectionStatusPanel getConnectionStatusPanel() {
+ return connectionStatusPanel;
+ }
+
+ private synchronized void savePlots() {
+ JFileChooser fc = new JFileChooser();
+ int r = fc.showSaveDialog(this);
+ if (r == JFileChooser.APPROVE_OPTION) {
+ File fileName = fc.getSelectedFile();
+ try {
+ AIDA.defaultInstance().saveAs(fileName);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private synchronized void resetDrivers() {
+ if (mgr != null) {
+ for (Driver driver : mgr.getDriverExecList()) {
+ if (driver instanceof Resettable) {
+ try {
+ ((Resettable) driver).reset();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ private void chooseLogFile() {
+ JFileChooser fc = new JFileChooser();
+ fc.setDialogTitle("Log File");
+ int r = fc.showSaveDialog(this);
+ if (r == JFileChooser.APPROVE_OPTION) {
+ File logFile = fc.getSelectedFile();
+ if (logFile.exists()) {
+ JOptionPane.showMessageDialog(this, "Log file already exists.");
+ } else {
+ try {
+ if (!logFile.createNewFile()) throw new IOException();
+ jobPanel.logFileField.setText(logFile.getPath());
+ jobPanel.logCheckBox.setSelected(true);
+ PrintStream ps = new PrintStream(new FileOutputStream(logFile.getPath()));
+ System.setOut(ps);
+ System.setErr(ps);
+ terminalItem.setEnabled(true);
+ logItem.setEnabled(false);
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(this, "Error creating log file.");
+ }
+ }
+ }
+ }
+
+ private synchronized void logToTerminal() {
+ System.setOut(sysOut);
+ System.setErr(sysErr);
+ jobPanel.logFileField.setText("");
+ jobPanel.logCheckBox.setSelected(false);
+ terminalItem.setEnabled(false);
+ logItem.setEnabled(true);
+ }
+
synchronized void disconnect() {
// Enable or disable appropriate menu items.
@@ -231,10 +354,15 @@
connectionLoadItem.setEnabled(true);
savePlotsItem.setEnabled(false);
resetDriversItem.setEnabled(false);
+ logItem.setEnabled(true);
+ terminalItem.setEnabled(true);
// Re-enable the ConnectionPanel.
connectionPanel.enableConnectionPanel(true);
+ // Need to reset this or won't get into GUI hook at top of loop.
+ connectionPanel.setConnectRequested(false);
+
// Re-enable the JobPanel.
jobPanel.enableJobPanel(true);
@@ -246,7 +374,7 @@
}
synchronized void connect() {
-
+
// Enable or disable appropriate menu items.
connectItem.setEnabled(false);
disconnectItem.setEnabled(true);
@@ -254,42 +382,48 @@
connectionLoadItem.setEnabled(false);
savePlotsItem.setEnabled(true);
resetDriversItem.setEnabled(true);
+ logItem.setEnabled(false);
+ terminalItem.setEnabled(false);
// Disable JobPanel.
jobPanel.enableJobPanel(false);
+ // Reset this on connect.
+ connectionPanel.setConnectRequested(false);
+
// Set status.
connectionStatusPanel.setStatus(ConnectionStatus.CONNECTED);
}
-
- ConnectionPanel getConnectionPanel() {
- return connectionPanel;
- }
-
- EventPanel getEventPanel() {
- return eventPanel;
+
+ private void exit() {
+ System.exit(0);
}
-
- JobPanel getJobPanel() {
- return jobPanel;
+
+ private void screenshot() {
+ JFileChooser fc = new JFileChooser();
+ fc.setDialogTitle("Save Screenshot");
+ int r = fc.showSaveDialog(this);
+ if (r == JFileChooser.APPROVE_OPTION) {
+ String fileName = fc.getSelectedFile().getPath();
+ int extIndex = fileName.lastIndexOf(".");
+ if ((extIndex == -1) || !(fileName.substring(extIndex+1, fileName.length())).toLowerCase().equals(screenshotFormat)) {
+ fileName = fileName + "." + screenshotFormat;
+ }
+ takeScreenshot(fileName);
+ }
}
- ConnectionStatusPanel getConnectionStatusPanel() {
- return connectionStatusPanel;
+ private void takeScreenshot(String fileName) {
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ Rectangle screenRectangle = new Rectangle(screenSize);
+ try {
+ Robot robot = new Robot();
+ BufferedImage image = robot.createScreenCapture(screenRectangle);
+ ImageIO.write(image, screenshotFormat, new File(fileName));
+ } catch (AWTException e) {
+ showDialog(e.getMessage());
+ } catch (IOException e) {
+ showDialog(e.getMessage());
+ }
}
-
- /**
- * Sets up the frame to run the application.
- * This should be called using Runnable.run() (see MonitoringExample).
- */
- void start() {
- JFrame frame = new JFrame("HPS Monitoring");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setOpaque(true);
- frame.setContentPane(this);
- frame.setJMenuBar(menuBar);
- frame.setResizable(false);
- frame.pack();
- frame.setVisible(true);
- }
}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.1 -r1.2
--- MonitoringApplicationMain.java 29 Mar 2012 03:52:57 -0000 1.1
+++ MonitoringApplicationMain.java 4 Apr 2012 23:26:07 -0000 1.2
@@ -58,7 +58,7 @@
try {
// Setup connection to ET system.
- EtConnection et = EtConnection.makeEtConnection(cn);
+ EtConnection et = EtConnection.createEtConnection(cn);
EtSystem sys = et.getEtSystem();
EtAttachment att = et.getEtAttachment();
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.2 -r1.3
--- MonitoringCommands.java 3 Apr 2012 18:37:04 -0000 1.2
+++ MonitoringCommands.java 4 Apr 2012 23:26:07 -0000 1.3
@@ -1,7 +1,9 @@
package org.lcsim.hps.monitoring;
/**
- * These are used for ActionEvents in the MonitoringApplication.
+ * These strings are used to identify ActionEvents in the MonitoringApplication
+ * and its sub-components.
+ *
* @author Jeremy McCormick <[log in to unmask]>
*/
final class MonitoringCommands {
@@ -17,4 +19,7 @@
static final String eventBuilderCmd = "eventBuilder";
static final String refreshCmd = "eventRefreshEdit";
static final String exitCmd = "exit";
+ static final String logCmd = "editLogFile";
+ static final String terminalCmd = "terminalLog";
+ static final String screenshotCmd = "takeScreenshot";
}
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.8 -r1.9
--- MonitoringExample.java 3 Apr 2012 18:37:04 -0000 1.8
+++ MonitoringExample.java 4 Apr 2012 23:26:07 -0000 1.9
@@ -4,7 +4,6 @@
import java.io.InputStream;
import java.nio.ByteBuffer;
-import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.freehep.record.loop.event.RecordSuppliedEvent;
@@ -18,7 +17,7 @@
import org.jlab.coda.jevio.EvioReader;
import org.lcsim.event.EventHeader;
import org.lcsim.hps.evio.LCSimEventBuilder;
-import org.lcsim.hps.evio.LCSimTestRunEventBuilder;
+import org.lcsim.hps.evio.MCEventBuilder;
import org.lcsim.hps.monitoring.ConnectionStatusPanel.ConnectionStatus;
import org.lcsim.job.JobControlManager;
import org.lcsim.util.DriverAdapter;
@@ -29,168 +28,167 @@
*/
// TODO Allow interrupt of sleep mode using EtWakeUpException. Probably need a separate thread to do this. To
// set the connection status to "sleeping", would probably also need a separate thread that checks for this state.
-// TODO Calling 'Exit' on the GUI should disconnect the station properly from the ET server.
+// TODO Calling 'Exit' on the GUI should disconnect the station properly from the ET server using a shutdown hook.
public class MonitoringExample {
+ // Default detector name.
static final String detectorName = "HPS-Test-JLAB-v4pt0";
- // TODO Change to EtTest or something that has ECal and SVT plots.
- static final String steering = "/org/lcsim/hps/steering/EtSensorOccupancy.lcsim";
- //static final String steering = "/u1/hps/trackerTest/EtEcalTest.lcsim";
- //static final String eventBuilderClassName = MCEventBuilder.class.getCanonicalName();
- static final String eventBuilderClassName = LCSimTestRunEventBuilder.class.getCanonicalName();
+
+ // Default steering resource.
+ static final String steering = "/org/lcsim/hps/steering/TestRunMonitoring.lcsim";
+
+ // Default event builder.
+ static final String eventBuilderClassName = MCEventBuilder.class.getCanonicalName();
+ //static final String eventBuilderClassName = LCSimTestRunEventBuilder.class.getCanonicalName();
+ // The LCSim job manager for running Drivers.
JobControlManager jobManager;
-
- boolean debug = true;
+
+ // The driver adapter for wrapping event loop calls.
+ DriverAdapter driverAdapter;
+
+ // The GUI monitoring application.
+ MonitoringApplication app;
+
+ // The ET connection parameters.
+ EtConnection et;
public MonitoringExample()
{}
-
+
public static void main(String [] args) {
MonitoringExample app = new MonitoringExample();
app.run();
}
-
- public void run()
- {
- // Start the GUI.
- final MonitoringApplication gui = new MonitoringApplication();
+
+ final void createMonitoringApplication() {
+ final MonitoringApplication app = new MonitoringApplication();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
- gui.start();
+ app.start();
}
});
+ this.app = app;
+ }
+
+ void run()
+ {
+ // Setup the MonitoringApplication GUI.
+ createMonitoringApplication();
// Push default settings to JobPanel.
- JobPanel jobPanel = gui.getJobPanel();
+ JobPanel jobPanel = app.getJobPanel();
jobPanel.setDetectorName(detectorName);
jobPanel.setSteeringResource(steering);
jobPanel.setDefaultEventBuilder(eventBuilderClassName);
// Get ConnectionPanel which will have user connection settings.
- ConnectionPanel connectionPanel = gui.getConnectionPanel();
-
- if (debug)
- System.out.println("about to enter GUI loop");
-
- // GUI loop. Use 'Exit' command from GUI to quit the application.
+ ConnectionPanel connectionPanel = app.getConnectionPanel();
+
+ // GUI loop. The 'Exit' command will cause the applicatino to quit.
while (true) {
-
- if (debug)
- System.out.println("top of GUI loop");
// Wait for connection request from GUI.
while (!connectionPanel.connectRequested()) {
try { Thread.sleep(1000); } catch (InterruptedException e) {};
}
ConnectionParameters cn = connectionPanel.getConnectionParameters();
-
- if (debug)
- System.out.println("user requested connection");
-
- // This makes sure applicable menu items are enabled/disabled while connected.
- gui.connect();
+
+ // Make sure applicable menu items are enabled or disabled.
+ app.connect();
// Set the GUI status.
- gui.getConnectionStatusPanel().setStatus(ConnectionStatus.CONNECTING);
+ app.getConnectionStatusPanel().setStatus(ConnectionStatus.CONNECTING);
// Try block is mostly for EtExceptions and friends.
try {
-
- if (debug)
- System.out.println("setting up ET system");
// Setup connection to ET system.
- EtConnection et = EtConnection.makeEtConnection(cn);
+ et = EtConnection.createEtConnection(cn);
EtSystem sys = et.getEtSystem();
- EtAttachment att = et.getEtAttachment();
-
- if (debug)
- System.out.println("done setting up ET system");
-
- // Setup LCSim if a valid steering file and event builder were selected.
- // Otherwise, the monitoring job will run without LCSim.
- if (debug)
- System.out.println("initializing lcsim for job");
- DriverAdapter driverAdapter = null;
- String eventBuilderClassName = gui.getJobPanel().getEventBuilderClassName();
+ EtAttachment att = et.getEtAttachment();
+
+ // Setup the EventBuilder to create LCSim events from EVIO data.
+ String eventBuilderClassName = app.getJobPanel().getEventBuilderClassName();
LCSimEventBuilder eventBuilder = null;
try {
eventBuilder = (LCSimEventBuilder)Class.forName(eventBuilderClassName).newInstance();
} catch (Exception e) {
- JOptionPane.showMessageDialog(gui, "Failed to create event builder. Job will run without LCSim.");
+ app.showDialog("Failed to create event builder. Job will run without LCSim.");
}
+
+ // Reset the DriverAdapter.
+ driverAdapter = null;
+
+ // Check for valid LCSim setup.
if (jobPanel.validSteering() && (eventBuilder != null)) {
// Get steering resource or file.
String steering = jobPanel.getSteering();
- // Create job manager and configure based on steering type of resource or file.
- jobManager = new JobControlManager();
- jobManager.checkInputFiles(false);
- if (gui.getJobPanel().getSteeringType() == JobPanel.RESOURCE) {
- InputStream is = this.getClass().getResourceAsStream(steering);
- jobManager.setup(is);
- } else if (gui.getJobPanel().getSteeringType() == JobPanel.FILE) {
- jobManager.setup(new File(steering));
- }
-
- // Set job manager in GUI so resetting Drivers works.
- gui.setJobControlManager(jobManager);
-
- // Make a DriverAdapter for wrapping the event loop calls.
- driverAdapter = jobManager.getDriverAdapter();
-
- // Call wrapper to startOfData() on DriverAdapter.
- // FIXME This might happen automatically later. Need to check.
- driverAdapter.configure(null);
-
- // Set the detector name on the event builder so it can find conditions data.
- eventBuilder.setDetectorName(jobPanel.getDetectorName());
+ // Try to setup LCSim. If it fails, we get disconnected.
+ try {
+ // Create job manager and configure based on steering type of resource or file.
+ jobManager = new JobControlManager();
+ jobManager.checkInputFiles(false);
+ if (app.getJobPanel().getSteeringType() == JobPanel.RESOURCE) {
+ InputStream is = this.getClass().getResourceAsStream(steering);
+ jobManager.setup(is);
+ } else if (app.getJobPanel().getSteeringType() == JobPanel.FILE) {
+ jobManager.setup(new File(steering));
+ }
+
+ // Set job manager in GUI so resetting Drivers works.
+ app.setJobControlManager(jobManager);
+
+ // Make a DriverAdapter for wrapping the event loop calls.
+ driverAdapter = jobManager.getDriverAdapter();
+
+ // Call wrapper to startOfData() on DriverAdapter.
+ driverAdapter.configure(null);
+
+ // Set the detector name on the event builder so it can find conditions data.
+ eventBuilder.setDetectorName(jobPanel.getDetectorName());
+ } catch (Exception e) {
+ error(e, "Failed to setup LCSim. You will be disconnected.");
+ continue;
+ }
}
- if (debug)
- System.out.println("done initializing lcsim");
-
// Start job timer.
- EventPanel eventPanel = gui.getEventPanel();
+ EventPanel eventPanel = app.getEventPanel();
eventPanel.updateJobStartTime();
// Array of events.
EtEvent[] mevs = null;
- // Parameters to fetch events from ET ring. These won't change unless we disconnect
- // and start a new session.
+ // Parameters for getting events from ET server.
Mode waitMode = cn.waitMode;
int waitTime = cn.waitTime;
int chunk = cn.chunk;
// Set status to connected.
- gui.getConnectionStatusPanel().setStatus(ConnectionStatus.CONNECTED);
+ app.getConnectionStatusPanel().setStatus(ConnectionStatus.CONNECTED);
// Reset the event panel in case there have been multiple jobs.
- gui.getEventPanel().reset();
+ try {
+ app.getEventPanel().reset();
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
// EtEvent loop.
while (true) {
- if (debug)
- System.out.println("top of event loop");
try {
- if (debug)
- System.out.println("waiting for events");
+
// Get EtEvents.
mevs = sys.getEvents(att, waitMode, Modify.NOTHING, waitTime, chunk);
- if (debug)
- System.out.println("got " + mevs.length + " events");
-
+
// Loop over retrieved EtEvents.
for (EtEvent mev : mevs) {
// Update GUI's event count.
eventPanel.updateEventCount();
-
- if (debug)
- System.out.println("about to create EVIO event");
// Get EvioEvent and check for errors.
ByteBuffer buf = mev.getDataBuffer();
@@ -199,43 +197,21 @@
try {
evioEvent = reader.parseNextEvent();
} catch (java.nio.BufferUnderflowException e) {
- // This error will be handled by subsequent check for null event.
+ e.printStackTrace();
}
- if (debug)
- System.out.println("made EVIO event");
if (evioEvent == null) {
- if (debug)
- System.out.println("got a bad event");
eventPanel.updateBadEventCount();
continue;
}
-
- // Only run LCSim if JobControlManager was setup successfully.
- if (jobManager != null) {
-
- if (debug)
- System.out.println("creating lcsim event");
-
- // Create LCSim event from EVIO data.
- EventHeader lcsimEvent = eventBuilder.makeLCSimEvent(evioEvent);
-
- if (debug)
- System.out.println("done creating lcsim event");
-
- // Supply record to Driver Adapter.
- try {
- if (debug)
- System.out.println("running lcsim drivers");
- driverAdapter.recordSupplied(new RecordSuppliedEvent(new Object(), lcsimEvent));
- if (debug)
- System.out.println("done running lcsim drivers");
- } catch (Exception e) {
- if (debug)
- System.out.println("caught exception while running lcsim");
- System.err.println(e.getLocalizedMessage());
- }
- if (debug)
- System.out.println("done running lcsim");
+
+ // Create LCSim event from EVIO data.
+ EventHeader lcsimEvent = eventBuilder.makeLCSimEvent(evioEvent);
+
+ // Supply record to Driver Adapter.
+ try {
+ driverAdapter.recordSupplied(new RecordSuppliedEvent(new Object(), lcsimEvent));
+ } catch (Exception e) {
+ e.printStackTrace();
}
// Update the average event rate.
@@ -246,44 +222,46 @@
}
// Put events back into the ET system.
- if (debug)
- System.out.println("putting events back into ET system");
sys.putEvents(att, mevs);
- if (debug)
- System.out.println("done with putEvents");
- // Break out of event loop if GUI wants disconnect.
+ // User requested disconnect in GUI.
if (connectionPanel.disconnectRequested()) {
- if (debug)
- System.out.println("in disconnect");
- gui.getConnectionStatusPanel().setStatus(ConnectionStatus.DISCONNECTING);
- if (driverAdapter != null)
- driverAdapter.finish(null);
- sys.detach(att);
- sys.removeStation(att.getStation());
- gui.disconnect();
- if (debug)
- System.out.println("suceessfully disconnected");
+ disconnect(ConnectionStatus.DISCONNECTING);
break;
}
- // Session timed out.
+ // The session timed out.
} catch (EtTimeoutException e) {
- if (debug)
- System.out.println("timeout occurred");
- gui.getConnectionStatusPanel().setStatus(ConnectionStatus.TIMED_OUT);
- if (driverAdapter != null)
- driverAdapter.finish(null);
- sys.detach(att);
- sys.removeStation(att.getStation());
- if (debug)
- System.out.println("done handling timeout");
+ disconnect(ConnectionStatus.TIMED_OUT);
break;
}
}
- // This catches A LOT of different exception types. Might want to make this more granular at some point.
+ // Top-level exception catcher.
} catch (Exception e) {
- System.err.println(e.getLocalizedMessage());
+ error(e, null);
}
}
}
+
+ private void error(Exception e, String mesg) {
+ e.printStackTrace();
+ if (mesg != null)
+ app.showDialog(mesg);
+ else
+ app.showDialog(e.getMessage());
+ et.cleanup();
+ Runtime.getRuntime().removeShutdownHook(et.getShutdownCallback());
+ app.disconnect();
+ }
+
+ private void disconnect(int status) {
+ app.getConnectionStatusPanel().setStatus(status);
+ if (status == ConnectionStatus.TIMED_OUT) {
+ app.showDialog("ET session timed out. You will be disconnected.");
+ }
+ if (driverAdapter != null)
+ driverAdapter.finish(null);
+ et.cleanup();
+ Runtime.getRuntime().removeShutdownHook(et.getShutdownCallback());
+ app.disconnect();
+ }
}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.9 -r1.10
--- SensorOccupancyPlotsDriver.java 3 Apr 2012 18:37:04 -0000 1.9
+++ SensorOccupancyPlotsDriver.java 4 Apr 2012 23:26:07 -0000 1.10
@@ -4,15 +4,18 @@
import hep.aida.IHistogram1D;
import hep.aida.IPlotter;
import hep.aida.IPlotterStyle;
+import hep.aida.ref.plotter.PlotterRegion;
+import jas.hist.JASHist;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.detector.tracker.silicon.SiSensor;
import org.lcsim.event.EventHeader;
import org.lcsim.event.RawTrackerHit;
-import org.lcsim.detector.identifier.*;
import org.lcsim.geometry.Detector;
import org.lcsim.util.Driver;
import org.lcsim.util.aida.AIDA;
@@ -23,7 +26,7 @@
* as the number of sensors, and hence plotter regions, is hardcoded to 20.
*
* @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: SensorOccupancyPlotsDriver.java,v 1.9 2012/04/03 18:37:04 jeremy Exp $
+ * @version $Id: SensorOccupancyPlotsDriver.java,v 1.10 2012/04/04 23:26:07 jeremy Exp $
*
*/
public class SensorOccupancyPlotsDriver extends Driver implements Resettable {
@@ -32,7 +35,7 @@
private String trackerName = "Tracker";
private AIDA aida = AIDA.defaultInstance();
- private IPlotter occuPlotter;
+ private IPlotter plotter;
private Detector detector;
private List<SiSensor> sensors;
@@ -79,15 +82,15 @@
// Setup the plotter.
IAnalysisFactory fac = aida.analysisFactory();
- occuPlotter = fac.createPlotterFactory().create(detector.getDetectorName() + " : HPS SVT Sensor Occupancy Plots");
- IPlotterStyle pstyle = occuPlotter.style();
+ plotter = fac.createPlotterFactory().create(detector.getDetectorName() + " : HPS SVT Sensor Occupancy Plots");
+ IPlotterStyle pstyle = plotter.style();
pstyle.dataStyle().fillStyle().setColor("green");
pstyle.dataStyle().markerStyle().setColor("green");
pstyle.dataStyle().errorBarStyle().setVisible(false);
pstyle.statisticsBoxStyle().setVisible(false);
// Create regions.
- occuPlotter.createRegions(5, 4);
+ plotter.createRegions(5, 4);
// Cache Detector object.
this.detector = detector;
@@ -115,9 +118,13 @@
for (SiSensor sensor : sensors) {
IHistogram1D occupancyPlot = aida.histogram1D(sensor.getName(), 640, 0, 639);
occupancyPlot.reset();
- occuPlotter.region(sensorRegionMap.get(sensor)).plot(occupancyPlot);
+ int region = sensorRegionMap.get(sensor);
+ plotter.region(region).plot(occupancyPlot);
+ JASHist hist = ((PlotterRegion)plotter.region(region)).getPlot();
+ hist.setAllowUserInteraction(false);
+ hist.setAllowPopupMenus(false);
}
- occuPlotter.show();
+ plotter.show();
}
public void process(EventHeader event) {
@@ -135,7 +142,7 @@
}
// Plot strip occupancies.
- if (eventCount % this.eventRefreshRate == 0) {
+ if (eventCount % eventRefreshRate == 0) {
for (SiSensor sensor : sensors) {
IHistogram1D sensorHist = aida.histogram1D(sensor.getName());
sensorHist.reset();
@@ -156,13 +163,13 @@
occupancyMap.put(sensor, new int[640]);
}
}
-
+
public void endOfData() {
- occuPlotter.hide();
+ plotter.hide();
}
public void reset() {
eventCount = 0;
resetOccupancyMap();
- }
+ }
}
\ No newline at end of file
CVSspam 0.2.12