hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.8 -r1.9
--- EventPanel.java 18 Apr 2012 21:06:54 -0000 1.8
+++ EventPanel.java 19 Apr 2012 23:01:28 -0000 1.9
@@ -19,6 +19,7 @@
private JTextField badEventsField; // number of bad events where event event processing failed
private JTextField sessionSuppliedField; // number of events supplied in this session; ignored by reset command
private JTextField totalSuppliedField; // number of events supplied since the application started
+ private JTextField maxEventsField; // maximum number of events to process before disconenct
private DecimalFormat rateFormat = new DecimalFormat("#.##");
@@ -178,33 +179,74 @@
totalSuppliedField.setEditable(false);
totalSuppliedField.setBackground(Color.WHITE);
fieldsPanel.add(totalSuppliedField, c);
+
+ c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 7;
+ c.anchor = GridBagConstraints.WEST;
+ JLabel maxEventsLabel = new JLabel("Max Events:");
+ maxEventsLabel.setHorizontalAlignment(JLabel.LEFT);
+ fieldsPanel.add(maxEventsLabel, c);
+
+ c = new GridBagConstraints();
+ c.gridx = 1;
+ c.gridy = 7;
+ c.anchor = GridBagConstraints.EAST;
+ maxEventsField = new JTextField("-1", 8);
+ maxEventsField.setHorizontalAlignment(JTextField.RIGHT);
+ maxEventsField.setEditable(false);
+ maxEventsField.setBackground(Color.WHITE);
+ fieldsPanel.add(maxEventsField, c);
}
int getEventRefresh() {
return eventRefresh;
}
+ int getMaxEvents() {
+ return Integer.parseInt(maxEventsField.getText());
+ }
+
+ void setMaxEvents(final int maxEvents) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ maxEventsField.setText(Integer.toString(maxEvents));
+ }
+ });
+ }
+
private void checkUpdateEvent() {
updateEvent = ((eventCount % getEventRefresh()) == 0);
}
+ /**
+ * At end of job, all
+ */
+ void endJob() {
+ incrementEventCounts();
+ }
+
void updateEventCount() {
++eventCount;
++sessionSupplied;
++totalSupplied;
checkUpdateEvent();
if (updateEvent) {
- Runnable r = new Runnable() {
- public void run() {
- eventCounterField.setText(Integer.toString(eventCount));
- sessionSuppliedField.setText(Integer.toString(sessionSupplied));
- totalSuppliedField.setText(Integer.toString(totalSupplied));
- }
- };
- SwingUtilities.invokeLater(r);
+ incrementEventCounts();
}
}
+ private void incrementEventCounts() {
+ Runnable r = new Runnable() {
+ public void run() {
+ eventCounterField.setText(Integer.toString(eventCount));
+ sessionSuppliedField.setText(Integer.toString(sessionSupplied));
+ totalSuppliedField.setText(Integer.toString(totalSupplied));
+ }
+ };
+ SwingUtilities.invokeLater(r);
+ }
+
void updateBadEventCount() {
++badEventCount;
SwingUtilities.invokeLater(new Runnable() {
hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.21 -r1.22
--- MonitoringApplication.java 19 Apr 2012 01:34:27 -0000 1.21
+++ MonitoringApplication.java 19 Apr 2012 23:01:28 -0000 1.22
@@ -12,8 +12,10 @@
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.setSteeringFileCmd;
import static org.lcsim.hps.monitoring.MonitoringCommands.terminalCmd;
import static org.lcsim.hps.monitoring.MonitoringCommands.udpateTimeCmd;
+import static org.lcsim.hps.monitoring.MonitoringCommands.setMaxEventsCmd;
import java.awt.AWTException;
import java.awt.Dimension;
@@ -46,6 +48,7 @@
import javax.swing.SwingUtilities;
import javax.swing.Timer;
+import org.jdom.JDOMException;
import org.jlab.coda.et.EtAttachment;
import org.jlab.coda.et.EtEvent;
import org.jlab.coda.et.EtSystem;
@@ -93,6 +96,8 @@
private JMenuItem logItem;
private JMenuItem terminalItem;
private JMenuItem screenshotItem;
+ private JMenuItem steeringItem;
+ private JMenuItem maxEventsItem;
private PrintStream sysOut = System.out;
private PrintStream sysErr = System.err;
@@ -114,7 +119,13 @@
private Timer timer;
private long jobStartTime;
-
+
+ // Number of events processed since reset.
+ private int eventsProcessed = 0;
+
+ // Maximum number of events to process before disconnect; for unlimited -1 is used.
+ private int maxEvents = -1;
+
public static final class JobParameters {
private String detectorName;
private String steeringResource;
@@ -186,9 +197,21 @@
else if (resetConnectionSettingsCmd.equals(e.getActionCommand())) {
app.connectionPanel.reset();
}
+ else if (setSteeringFileCmd.equals(e.getActionCommand())) {
+ app.selectSteeringFile();
+ }
+ else if (setMaxEventsCmd.equals(e.getActionCommand())) {
+ app.setMaxEvents();
+ }
}
}
+ private static final class MaxEventsException extends Exception {
+ MaxEventsException() {
+ super("Maximum number of events was reached.");
+ }
+ }
+
public MonitoringApplication() {
// Create ActionEvent listener.
@@ -288,9 +311,20 @@
eventRefreshItem.addActionListener(actionListener);
eventMenu.add(eventRefreshItem);
+ maxEventsItem = new JMenuItem("Set Max Events...");
+ maxEventsItem.setMnemonic(KeyEvent.VK_M);
+ maxEventsItem.setActionCommand(setMaxEventsCmd);
+ maxEventsItem.addActionListener(actionListener);
+ eventMenu.add(maxEventsItem);
+
JMenu jobMenu = new JMenu("Job");
menuBar.add(jobMenu);
+ steeringItem = new JMenuItem("Set Steering File...");
+ steeringItem.setActionCommand(setSteeringFileCmd);
+ steeringItem.addActionListener(actionListener);
+ jobMenu.add(steeringItem);
+
savePlotsItem = new JMenuItem("Save Plots to AIDA File...");
savePlotsItem.setMnemonic(KeyEvent.VK_P);
savePlotsItem.setActionCommand(savePlotsCmd);
@@ -383,6 +417,22 @@
}
}
+ private void selectSteeringFile() {
+ JFileChooser fc = new JFileChooser();
+ int r = fc.showOpenDialog(mainPanel);
+ if (r == JFileChooser.APPROVE_OPTION) {
+ File fileName = fc.getSelectedFile();
+ try {
+ (new JobControlManager()).setup(fileName);
+ jobPanel.setSteeringFile(fileName.getPath());
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ showDialog("Failed to read the LCSim XML file.");
+ }
+ }
+ }
+
private static String getApplicationTitle() {
return "HPS Monitoring - " + getUserName() + "@"+ getHostname();
}
@@ -466,7 +516,23 @@
eventPanel.setEventRefresh(newEventRefresh);
}
catch (Exception e) {
- showDialog("The value " + inputValue + " is not valid for this field.");
+ showDialog("The value " + inputValue + " is not valid for Event Refresh Rate.");
+ }
+ }
+
+ private void setMaxEvents() {
+ String inputValue = JOptionPane.showInputDialog("Max Events:", eventPanel.getMaxEvents());
+ try {
+ int newMaxEvents = Integer.parseInt(inputValue);
+ if (newMaxEvents < 0) {
+ showDialog("Max Events is set to unlimited.");
+ newMaxEvents = -1;
+ }
+ eventPanel.setMaxEvents(newMaxEvents);
+ maxEvents = newMaxEvents;
+ }
+ catch (Exception e) {
+ showDialog("The value " + inputValue + " is not valid for Max Events.");
}
}
@@ -481,6 +547,7 @@
resetDriversItem.setEnabled(false);
logItem.setEnabled(true);
terminalItem.setEnabled(true);
+ steeringItem.setEnabled(true);
// Re-enable the ConnectionPanel.
connectionPanel.enableConnectionPanel(true);
@@ -506,6 +573,7 @@
resetDriversItem.setEnabled(true);
logItem.setEnabled(false);
terminalItem.setEnabled(false);
+ steeringItem.setEnabled(false);
}
private void exit() {
@@ -580,7 +648,7 @@
// Start the event processing loop.
int status = eventLoop();
- // If event loop stops then disconnect LCSim and the ET system.
+ // If event loop finishes, then disconnect.
disconnect(status);
}
@@ -599,11 +667,20 @@
connectionStatusPanel.setStatus(ConnectionStatus.CONNECTED);
}
- private void stopJob() {
- if (jobManager != null)
+ private void stopJob() {
+ // Call cleanup methods of Drivers.
+ if (jobManager != null)
jobManager.finish();
+
+ // Stop the job timer.
timer.stop();
timer = null;
+
+ // Reset number of events processed.
+ eventsProcessed = 0;
+
+ // Push final event counts to GUI.
+ eventPanel.endJob();
}
private void startEvent() {
@@ -614,6 +691,9 @@
// Update the average event rate.
eventPanel.updateAverageEventRate(jobStartTime);
+
+ // Increment number of events processed.
+ ++eventsProcessed;
}
private void badEvent() {
@@ -731,8 +811,16 @@
eventBuilder.setDetectorName(getDetectorName());
}
- private void processEtEvent(EtEvent mev) {
+ private void processEtEvent(EtEvent mev) throws Exception {
try {
+
+ // Check if max events was reached or exceeded.
+ if (maxEvents != -1 && eventsProcessed >= maxEvents) {
+ //System.out.println("eventsProcessed=" + eventsProcessed);
+ //System.out.println("maxEvents=" + maxEvents);
+ throw new MaxEventsException();
+ }
+
// Start of event GUI hook.
startEvent();
@@ -754,9 +842,13 @@
jobManager.processEvent(lcsimEvent);
// End of event GUI hook.
- endEvent();
+ endEvent();
+ }
+ // Hit max events.
+ catch (MaxEventsException e) {
+ throw e;
}
- // Catch event processing exceptions.
+ // Catch other event processing exceptions.
catch (Exception e) {
// Print a stack trace.
@@ -873,7 +965,7 @@
private int eventLoop() {
while (true) {
- // User wants to disconnect or system went down so need to stop processing loop.
+ // User wants to disconnect or ET connection went down.
if (getConnectionStatus() != ConnectionStatus.CONNECTED) {
return getConnectionStatus();
}
@@ -885,7 +977,12 @@
// The session timed out.
catch (EtTimeoutException e) {
return ConnectionStatus.TIMED_OUT;
- }
+ }
+ // Reached max number of events.
+ catch (MaxEventsException e) {
+ showDialog(e.getMessage());
+ return ConnectionStatus.DISCONNECTING;
+ }
// There was some error processing events.
catch (Exception e) {
e.printStackTrace();
@@ -908,6 +1005,7 @@
private void resetJob() {
jobStartTime = System.currentTimeMillis();
+ eventsProcessed = 0;
eventPanel.reset();
if (getConnectionStatus() == ConnectionStatus.DISCONNECTED) {
eventPanel.resetSessionSupplied();