21 modified files
lcsim
diff -u -r1.167 -r1.167.2.1
--- pom.xml 9 Feb 2012 18:37:17 -0000 1.167
+++ pom.xml 14 Feb 2012 01:21:02 -0000 1.167.2.1
@@ -26,7 +26,7 @@
<parent>
<groupId>org.lcsim</groupId>
<artifactId>lcsim-parent</artifactId>
- <version>1.14</version>
+ <version>1.15-SNAPSHOT</version>
</parent>
<distributionManagement>
<site>
lcsim/src/org/lcsim/job
diff -u -r1.52 -r1.52.2.1
--- JobControlManager.java 14 Apr 2011 05:05:07 -0000 1.52
+++ JobControlManager.java 14 Feb 2012 01:21:02 -0000 1.52.2.1
@@ -34,7 +34,7 @@
import org.apache.commons.cli.PosixParser;
import org.freehep.application.studio.Studio;
import org.freehep.jas.services.DynamicClassLoader;
-import org.freehep.record.loop.LoopSourceExhaustedException;
+import org.freehep.record.source.NoSuchRecordException;
import org.freehep.util.FreeHEPLookup;
import org.jdom.Attribute;
import org.jdom.Document;
@@ -79,7 +79,7 @@
* which it should be discarded. If the {@link #run()} method is called twice on
* the same manager, a fatal exception will be thrown.
*
- * @version $Id: JobControlManager.java,v 1.52 2011/04/14 05:05:07 grefe Exp $
+ * @version $Id: JobControlManager.java,v 1.52.2.1 2012/02/14 01:21:02 onoprien Exp $
* @author Jeremy McCormick
*/
public class JobControlManager
@@ -447,7 +447,7 @@
}
// Record source was exhausted before max events was hit. This is probably fine,
// but print message in case more were expected.
- catch (LoopSourceExhaustedException x)
+ catch (NoSuchRecordException x)
{
logStream.println(x.getMessage());
}
lcsim/src/org/lcsim/plugin
diff -u -r1.1 -r1.1.6.1
--- LCSim.java 21 Mar 2006 19:47:27 -0000 1.1
+++ LCSim.java 14 Feb 2012 01:21:02 -0000 1.1.6.1
@@ -1,6 +1,6 @@
package org.lcsim.plugin;
-import org.freehep.record.loop.SequentialRecordLoop;
+import org.freehep.record.loop.RecordLoop;
import org.freehep.util.FreeHEPLookup;
import org.lcsim.event.EventHeader;
@@ -25,7 +25,7 @@
{
try
{
- SequentialRecordLoop loop = (SequentialRecordLoop) lookup.lookup(SequentialRecordLoop.class);
+ RecordLoop loop = (RecordLoop) lookup.lookup(RecordLoop.class);
Object event = loop.getRecordSource().getCurrentRecord();
return (event instanceof EventHeader) ? (EventHeader) event : null;
}
lcsim/src/org/lcsim/plugin
diff -u -r1.1 -r1.1.4.1
--- LCSimDriverTree.java 11 Sep 2007 00:22:47 -0000 1.1
+++ LCSimDriverTree.java 14 Feb 2012 01:21:02 -0000 1.1.4.1
@@ -4,13 +4,12 @@
import java.util.ArrayList;
import java.util.List;
import javax.swing.tree.TreePath;
-import org.freehep.record.loop.SequentialRecordLoop;
-import org.freehep.record.loop.event.LoopEvent;
-import org.freehep.record.loop.event.LoopProgressEvent;
-import org.freehep.record.loop.event.RecordLoopListener;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.freehep.application.studio.Studio;
+import org.freehep.record.loop.LoopEvent;
+import org.freehep.record.loop.LoopListener;
+import org.freehep.record.loop.RecordLoop;
import org.freehep.swing.treetable.AbstractTreeTableModel;
import org.freehep.swing.treetable.JTreeTable;
import org.freehep.swing.treetable.TreeTableModel;
@@ -28,15 +27,15 @@
* @author tonyj
* @author gaede
*/
-public class LCSimDriverTree extends JPanel implements RecordLoopListener, LookupListener
+public class LCSimDriverTree extends JPanel implements LoopListener, LookupListener
{
private Studio app;
- private SequentialRecordLoop loop;
+ private RecordLoop loop;
private Result result;
private List<Driver> drivers = new ArrayList<Driver>();
private DriverTreeModel model;
- public LCSimDriverTree(Studio app, SequentialRecordLoop loop)
+ public LCSimDriverTree(Studio app, RecordLoop loop)
{
super(new BorderLayout());
this.app = app;
@@ -48,7 +47,7 @@
}
public void addNotify()
{
- loop.addRecordLoopListener(this);
+ loop.addLoopListener(this);
// Listen for record sources
// TODO: We use a "wild-card" template to work around a bug in Lookup.
@@ -64,27 +63,14 @@
public void removeNotify()
{
super.removeNotify();
- loop.removeRecordLoopListener(this);
+ loop.removeLoopListener(this);
result.removeLookupListener(this);
}
- public void loopBeginning(LoopEvent loopEvent)
+ public void process(LoopEvent loopEvent)
{
}
- public void loopEnded(LoopEvent loopEvent)
- {
-
- }
-
- public void loopReset(LoopEvent loopEvent)
- {
-
- }
-
- public void progress(LoopProgressEvent loopProgressEvent)
- {
- }
public class DriverTreeModel extends AbstractTreeTableModel
{
private String[] columns = { "Driver", "Events", "Time", "% of parent" };
lcsim/src/org/lcsim/plugin
diff -u -r1.14 -r1.14.2.1
--- LCSimPlugin.java 4 Sep 2008 17:40:51 -0000 1.14
+++ LCSimPlugin.java 14 Feb 2012 01:21:02 -0000 1.14.2.1
@@ -21,10 +21,9 @@
import org.freehep.jas.plugin.console.ConsoleService;
import org.freehep.jas.services.ScriptEngine;
import org.freehep.jas.services.WebBrowser;
-import org.freehep.record.loop.SequentialRecordLoop;
-import org.freehep.record.loop.event.LoopEvent;
-import org.freehep.record.loop.event.LoopProgressEvent;
-import org.freehep.record.loop.event.RecordLoopListener;
+import org.freehep.record.loop.LoopEvent;
+import org.freehep.record.loop.LoopListener;
+import org.freehep.record.loop.RecordLoop;
import org.freehep.util.FreeHEPLookup;
import org.freehep.util.commanddispatcher.CommandProcessor;
import org.freehep.util.commanddispatcher.CommandState;
@@ -38,14 +37,12 @@
import org.lcsim.util.Driver;
import org.lcsim.util.DriverAdapter;
import org.lcsim.util.loop.EventGeneratorRecordSource;
-import org.openide.util.Lookup;
-import org.openide.util.Lookup.Result;
import org.xml.sax.SAXException;
/**
*
* @author tonyj
- * @version $Id: LCSimPlugin.java,v 1.14 2008/09/04 17:40:51 jeremy Exp $
+ * @version $Id: LCSimPlugin.java,v 1.14.2.1 2012/02/14 01:21:02 onoprien Exp $
*/
public class LCSimPlugin extends Plugin implements StudioListener, PageListener
@@ -118,9 +115,10 @@
app.removeToolBar(toolbar);
- SequentialRecordLoop loop = (SequentialRecordLoop) getApplication().getLookup().lookup(SequentialRecordLoop.class);
- loop.removeRecordLoopListener(commands);
+ RecordLoop loop = (RecordLoop) getApplication().getLookup().lookup(RecordLoop.class);
+ loop.removeLoopListener(commands);
}
+
protected void postInit()
{
try
@@ -136,8 +134,8 @@
System.err.println("WARNING: Unable to create LCSimHepRepConverter. The HepRep plugin is probably not installed.");
}
- SequentialRecordLoop loop = (SequentialRecordLoop) getApplication().getLookup().lookup(SequentialRecordLoop.class);
- loop.addRecordLoopListener(commands);
+ RecordLoop loop = (RecordLoop) getApplication().getLookup().lookup(RecordLoop.class);
+ loop.addLoopListener(commands);
try
{
@@ -151,6 +149,7 @@
System.err.println("Warning: Unable to create console output stream");
}
}
+
public void handleEvent(EventObject event)
{
if (event instanceof ClassLoadedEvent)
@@ -211,6 +210,7 @@
engine.registerVariable("lcsim", lcsim);
}
}
+
public void pageChanged(PageEvent e)
{
PageContext page = (PageContext) e.getSource();
@@ -230,7 +230,7 @@
}
}
- class LCSimCommands extends CommandProcessor implements RecordLoopListener
+ class LCSimCommands extends CommandProcessor implements LoopListener
{
public void onLCSimEventBrowser()
{
@@ -239,21 +239,21 @@
}
private void createNewEventBrowser()
{
- SequentialRecordLoop loop = (SequentialRecordLoop) getApplication().getLookup().lookup(SequentialRecordLoop.class);
+ RecordLoop loop = (RecordLoop) getApplication().getLookup().lookup(RecordLoop.class);
LCSimEventBrowser tree = new LCSimEventBrowser(getApplication(),loop);
getApplication().getPageManager().openPage(tree,"LCSim Event",null);
}
private void createNewDriverTree()
{
- SequentialRecordLoop loop = (SequentialRecordLoop) getApplication().getLookup().lookup(SequentialRecordLoop.class);
+ RecordLoop loop = (RecordLoop) getApplication().getLookup().lookup(RecordLoop.class);
LCSimDriverTree tree = new LCSimDriverTree(getApplication(),loop);
getApplication().getPageManager().openPage(tree,"LCSim Drivers",null);
}
public void enableLCSimEventBrowserButton(CommandState state)
{
- SequentialRecordLoop loop = (SequentialRecordLoop) getApplication().getLookup().lookup(SequentialRecordLoop.class);
+ RecordLoop loop = (RecordLoop) getApplication().getLookup().lookup(RecordLoop.class);
try
{
Object record = loop.getRecordSource().getCurrentRecord();
@@ -324,22 +324,14 @@
if (wb != null && help != null) wb.showURL(help);
}
- public void loopBeginning(LoopEvent loopEvent)
- {
- }
-
- public void loopEnded(LoopEvent loopEvent)
- {
- setChanged();
- }
-
- public void loopReset(LoopEvent loopEvent)
- {
- setChanged();
- }
-
- public void progress(LoopProgressEvent loopProgressEvent)
- {
+ public void process(LoopEvent event) {
+ switch (event.getEventType()) {
+ case FINISH:
+ case RESET:
+ setChanged();
+ default:
+ }
}
}
+
}
\ No newline at end of file
lcsim/src/org/lcsim/plugin/browser
diff -u -r1.15 -r1.15.2.1
--- LCSimEventBrowser.java 5 May 2010 18:09:03 -0000 1.15
+++ LCSimEventBrowser.java 14 Feb 2012 01:21:02 -0000 1.15.2.1
@@ -6,11 +6,6 @@
import java.awt.Font;
import java.util.ArrayList;
import java.util.Collections;
-import org.freehep.record.loop.SequentialRecordLoop;
-import org.freehep.record.loop.event.LoopEvent;
-import org.freehep.record.loop.event.LoopProgressEvent;
-import org.freehep.record.loop.event.RecordLoopListener;
-import org.freehep.record.source.SequentialRecordSource;
import org.freehep.util.commanddispatcher.CommandProcessor;
import javax.swing.event.ListSelectionEvent;
@@ -31,6 +26,10 @@
import javax.swing.event.TreeWillExpandListener;
import javax.swing.tree.ExpandVetoException;
import org.freehep.application.studio.Studio;
+import org.freehep.record.loop.LoopEvent;
+import org.freehep.record.loop.LoopListener;
+import org.freehep.record.loop.RecordLoop;
+import org.freehep.record.source.RecordSource;
import org.freehep.util.FreeHEPLookup;
import org.lcsim.event.EventHeader;
import org.lcsim.event.MCParticle;
@@ -42,7 +41,7 @@
* @author tonyj
* @author gaede
*/
-public class LCSimEventBrowser extends JPanel implements RecordLoopListener, TreeSelectionListener, ListSelectionListener, TreeWillExpandListener
+public class LCSimEventBrowser extends JPanel implements LoopListener, TreeSelectionListener, ListSelectionListener, TreeWillExpandListener
{
private static final String noEvent = "No Event";
private static final TreeModel m_empty = new DefaultTreeModel(new DefaultMutableTreeNode(noEvent));
@@ -54,7 +53,7 @@
private CollectionTable m_table;
private CardLayout m_cardLayout = new CardLayout();
private JPanel m_switchPanel = new JPanel(m_cardLayout);
- private SequentialRecordLoop m_loop;
+ private RecordLoop m_loop;
private EventHeader m_lce;
private String m_selectedNode;
private Commands m_commands = new Commands();
@@ -84,7 +83,7 @@
lookup.add(new StringVecTableModel());
}
- public LCSimEventBrowser(Studio app, SequentialRecordLoop loop)
+ public LCSimEventBrowser(Studio app, RecordLoop loop)
{
super(new BorderLayout());
this.app = app;
@@ -107,21 +106,21 @@
}
public void addNotify()
{
- SequentialRecordSource source = m_loop.getRecordSource();
+ RecordSource source = m_loop.getRecordSource();
setSource(source);
- m_loop.addRecordLoopListener(this);
+ m_loop.addLoopListener(this);
super.addNotify();
}
public void removeNotify()
{
super.removeNotify();
- m_loop.removeRecordLoopListener(this);
+ m_loop.removeLoopListener(this);
}
public CommandProcessor getCommands()
{
return m_commands;
}
- private void setSource(SequentialRecordSource source)
+ private void setSource(RecordSource source)
{
try
{
@@ -183,24 +182,14 @@
}
m_commands.setChanged();
}
- public void loopBeginning(LoopEvent loopEvent)
- {
- }
-
- public void loopEnded(LoopEvent loopEvent)
- {
- SequentialRecordLoop loop = (SequentialRecordLoop) loopEvent.getSource();
- setSource(loop.getRecordSource());
- }
- public void loopReset(LoopEvent loopEvent)
- {
- SequentialRecordLoop loop = (SequentialRecordLoop) loopEvent.getSource();
- setSource(loop.getRecordSource());
- }
-
- public void progress(LoopProgressEvent loopProgressEvent)
- {
+ public void process(LoopEvent event) {
+ switch (event.getEventType()) {
+ case FINISH:
+ case RESET:
+ setSource(event.getSource().getRecordSource());
+ default:
+ }
}
public void valueChanged(TreeSelectionEvent e)
lcsim/src/org/lcsim/util
diff -u -r1.7 -r1.7.4.1
--- DriverAdapter.java 11 Sep 2007 00:21:00 -0000 1.7
+++ DriverAdapter.java 14 Feb 2012 01:21:02 -0000 1.7.4.1
@@ -1,12 +1,13 @@
package org.lcsim.util;
import java.io.IOException;
+import javax.swing.JOptionPane;
import org.freehep.jas.plugin.console.ConsoleOutputStream;
import org.freehep.jas.plugin.console.ConsoleService;
-import org.freehep.record.loop.event.ConfigurationEvent;
-import org.freehep.record.loop.event.RecordAdapter;
-import org.freehep.record.loop.event.RecordEvent;
-import org.freehep.record.loop.event.RecordSuppliedEvent;
+import org.freehep.record.loop.AbstractLoopListener;
+import org.freehep.record.loop.LoopEvent;
+import org.freehep.record.loop.RecordEvent;
+import org.freehep.record.loop.RecordListener;
import org.lcsim.event.EventHeader;
import org.lcsim.geometry.Detector;
@@ -14,9 +15,9 @@
/**
* Drive a Driver from a Record loop
* @author Tony Johnson
- * @version $Id: DriverAdapter.java,v 1.7 2007/09/11 00:21:00 tonyj Exp $
+ * @version $Id: DriverAdapter.java,v 1.7.4.1 2012/02/14 01:21:02 onoprien Exp $
*/
-public class DriverAdapter extends RecordAdapter
+public class DriverAdapter extends AbstractLoopListener implements RecordListener
{
private Driver driver;
// The console stuff is here to fix LCSMI-128. More logically this stuff should
@@ -37,28 +38,28 @@
if (cs != null) out = cs.getConsoleOutputStream("Record Loop", null);
}
- public void finish(RecordEvent event)
+ public void finish(LoopEvent event)
{
if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),out);
driver.endOfData();
if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),null);
}
- public void suspend(RecordEvent event)
+ public void suspend(LoopEvent event)
{
if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),out);
driver.suspend();
if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),null);
}
- public void resume(RecordEvent event)
+ public void resume(LoopEvent event)
{
if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),out);
driver.resume();
if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),null);
}
- public void recordSupplied(RecordSuppliedEvent rse)
+ public void recordSupplied(RecordEvent rse)
{
try
{
@@ -86,20 +87,20 @@
driver.detectorChanged(detector);
}
- public void configure(ConfigurationEvent event)
- {
- if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),out);
- driver.startOfData();
- if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),null);
- }
-
- public void reconfigure(ConfigurationEvent event)
+ public void start(LoopEvent event)
{
if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),out);
driver.startOfData();
if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),null);
}
+// public void configure(LoopEvent event)
+// {
+// if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),out);
+// driver.startOfData();
+// if (cs != null) cs.redirectStandardOutputOnThreadToConsole(Thread.currentThread(),null);
+// }
+
public Driver getDriver()
{
return driver;
lcsim/src/org/lcsim/util
diff -u -r1.9 -r1.9.2.1
--- OverlayDriver.java 2 May 2011 09:40:39 -0000 1.9
+++ OverlayDriver.java 14 Feb 2012 01:21:02 -0000 1.9.2.1
@@ -18,7 +18,7 @@
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.DistributionFactory;
import org.apache.commons.math.distribution.PoissonDistribution;
-import org.freehep.record.source.EndOfSourceException;
+import org.freehep.record.source.NoSuchRecordException;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.event.EventHeader;
import org.lcsim.event.GenericObject;
@@ -31,7 +31,6 @@
import org.lcsim.event.base.BaseSimCalorimeterHit;
import org.lcsim.event.base.BaseSimTrackerHit;
import org.lcsim.geometry.Detector;
-import org.lcsim.util.Driver;
import org.lcsim.util.lcio.LCIOConstants;
import org.lcsim.util.lcio.LCIOUtil;
import org.lcsim.util.lcio.SIOMCParticle;
@@ -357,7 +356,7 @@
try {
lcio.next();
event = (EventHeader) lcio.getCurrentRecord();
- } catch (EndOfSourceException e) {
+ } catch (NoSuchRecordException e) {
try {
lcio.rewind();
lcio.next();
lcsim/src/org/lcsim/util/aida
diff -u -r1.9 -r1.9.2.1
--- AIDA.java 30 Jan 2009 00:07:50 -0000 1.9
+++ AIDA.java 14 Feb 2012 01:21:02 -0000 1.9.2.1
@@ -24,9 +24,9 @@
import java.lang.ref.WeakReference;
import org.freehep.application.Application;
import org.freehep.application.studio.Studio;
-import org.freehep.record.loop.SequentialRecordLoop;
-import org.freehep.record.loop.event.LoopEvent;
-import org.freehep.record.loop.event.RecordLoopAdapter;
+import org.freehep.record.loop.AbstractLoopListener;
+import org.freehep.record.loop.LoopEvent;
+import org.freehep.record.loop.RecordLoop;
/**
* A convenience class for creating and filling histograms.
@@ -65,8 +65,8 @@
Application app = Application.getApplication();
if (app instanceof Studio)
{
- SequentialRecordLoop loop = (SequentialRecordLoop) ((Studio) app).getLookup().lookup(SequentialRecordLoop.class);
- if (loop != null) loop.addRecordLoopListener(new RewindListener(this));
+ RecordLoop loop = (RecordLoop) ((Studio) app).getLookup().lookup(RecordLoop.class);
+ if (loop != null) loop.addLoopListener(new RewindListener(this));
}
}
catch (IOException x)
@@ -350,14 +350,15 @@
if (obj instanceof IBaseHistogram) ((IBaseHistogram) obj).reset();
}
}
- private static class RewindListener extends RecordLoopAdapter
+
+ private static class RewindListener extends AbstractLoopListener
{
private Reference weak;
RewindListener(AIDA aida)
{
weak = new WeakReference(aida);
}
- public void loopReset(LoopEvent loopEvent)
+ public void reset(LoopEvent loopEvent)
{
AIDA aida = (AIDA) weak.get();
if (aida != null)
@@ -366,8 +367,8 @@
}
else
{
- SequentialRecordLoop loop = (SequentialRecordLoop) loopEvent.getSource();
- loop.removeRecordLoopListener(this);
+ RecordLoop loop = loopEvent.getSource();
+ loop.removeLoopListener(this);
}
}
}
lcsim/src/org/lcsim/util/loop
diff -u -r1.1 -r1.1.10.1
--- EventGeneratorRecordSource.java 14 Mar 2005 16:11:37 -0000 1.1
+++ EventGeneratorRecordSource.java 14 Feb 2012 01:21:02 -0000 1.1.10.1
@@ -1,27 +1,25 @@
package org.lcsim.util.loop;
-import hep.physics.event.HEPEvent;
-import hep.physics.event.generator.EventGenerator;
-
import java.io.IOException;
-import org.freehep.record.source.NoSuchRecordException;
-import org.freehep.record.source.SequentialRecordSource;
+import hep.physics.event.HEPEvent;
+import hep.physics.event.generator.EventGenerator;
+import org.freehep.record.source.AbstractRecordSource;
+import org.freehep.record.source.RecordSource;
/**
- *
+ * {@link RecordSource} wrapper for {@link EventGenerator}.
* @author Tony Johnson
*/
-public class EventGeneratorRecordSource implements SequentialRecordSource
+public class EventGeneratorRecordSource extends AbstractRecordSource
{
private EventGenerator generator;
- private String name;
private HEPEvent current;
public EventGeneratorRecordSource(EventGenerator generator, String name)
{
+ super(name);
this.generator = generator;
- this.name = name;
}
public void rewind() throws IOException
@@ -29,39 +27,26 @@
generator.reset();
}
- public String getSourceName()
- {
- return name;
- }
-
- public void close() throws IOException
- {
- }
-
- public Class getRecordClass()
+ public Class<?> getRecordClass()
{
return HEPEvent.class;
}
- public long getEstimatedSize()
- {
- return UNKNOWN;
- }
-
- public Object getCurrentRecord() throws NoSuchRecordException
+ public Object getCurrentRecord()
{
- if (current == null) throw new NoSuchRecordException();
+ if (current == null) throw new IllegalStateException();
return current;
}
+
+ public boolean supportsNext() {return true;}
+
+ public boolean hasNext() {return true;}
public void next()
{
current = generator.generate();
}
- public void releaseRecord(Object record)
- {
- }
EventGenerator getGenerator()
{
return generator;
lcsim/src/org/lcsim/util/loop
diff -u -r1.5 -r1.5.2.1
--- LCIOEventSource.java 17 Nov 2009 16:53:49 -0000 1.5
+++ LCIOEventSource.java 14 Feb 2012 01:21:02 -0000 1.5.2.1
@@ -6,25 +6,23 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
-import org.freehep.record.source.EndOfSourceException;
+import org.freehep.record.source.AbstractRecordSource;
import org.freehep.record.source.NoSuchRecordException;
-import org.freehep.record.source.SequentialRecordSource;
import org.lcsim.event.EventHeader;
import org.lcsim.util.lcio.*;
/**
- * Convert an LCIOReader to a SequentialRecordSource
+ * {@link RecordSource} wrapper for {@link LCIOReader}.
* @author tonyj
- * @version $Id: LCIOEventSource.java,v 1.5 2009/11/17 16:53:49 tonyj Exp $
+ * @version $Id: LCIOEventSource.java,v 1.5.2.1 2012/02/14 01:21:02 onoprien Exp $
*/
-public class LCIOEventSource implements SequentialRecordSource
+public class LCIOEventSource extends AbstractRecordSource
{
private List<File> files;
private boolean atEnd;
private LCIOReader reader;
private EventHeader currentEvent;
private int currentFile = 0;
- private String name;
/**
* Create an LCIO event source for reading a single LCIO file
@@ -32,9 +30,9 @@
*/
public LCIOEventSource(File file) throws IOException
{
+ super(file.getName());
this.reader = new LCIOReader(file);
this.files = Collections.singletonList(file);
- this.name = file.getName();
}
/**
* Create an LCIO event source for reading a set of LCIO files.
@@ -43,10 +41,10 @@
*/
public LCIOEventSource(String name, List<File> files) throws IOException
{
+ super(name);
if (files.isEmpty()) throw new IOException("File list is empty");
this.reader = new LCIOReader(files.get(0));
this.files = files;
- this.name = name;
}
/**
* Create an LCIO event source that will read a set of LCIO files
@@ -54,35 +52,29 @@
*/
public LCIOEventSource(FileList list) throws FileNotFoundException, IOException
{
- this.name = list.getTitle();
+ super(list.getTitle());
this.files = list.getFileList();
- if (files.size() == 0) throw new IOException("File list is empty");
+ if (files.isEmpty()) throw new IOException("File list is empty");
this.reader = new LCIOReader(files.get(0));
}
- public Object getCurrentRecord() throws NoSuchRecordException, IOException, EndOfSourceException
+ public Object getCurrentRecord() throws IOException
{
- if (atEnd) throw new EndOfSourceException();
- if (currentEvent == null) throw new NoSuchRecordException();
+ if (atEnd) throw new IllegalStateException();
+ if (currentEvent == null) throw new IllegalStateException();
return currentEvent;
}
- public long getEstimatedSize()
- {
- return SequentialRecordSource.UNKNOWN;
- }
-
- public Class getRecordClass()
+ public Class<?> getRecordClass()
{
return EventHeader.class;
}
-
- public String getSourceName()
- {
- return name;
- }
-
- public void next() throws IOException
+
+ public boolean supportsNext() {return true;}
+
+ public boolean hasNext() {return !atEnd;}
+
+ public void next() throws IOException, NoSuchRecordException
{
for (;;)
{
@@ -94,7 +86,11 @@
catch (EOFException x)
{
currentFile++;
- if (currentFile >= files.size()) atEnd = true;
+ if (currentFile >= files.size())
+ {
+ atEnd = true;
+ throw new NoSuchRecordException();
+ }
else
{
reader.close();
@@ -124,12 +120,13 @@
reader = null;
}
}
- public void finalize()
+ public void finalize() throws Throwable
{
try
{
close();
}
catch (IOException x) {}
+ super.finalize();
}
}
\ No newline at end of file
lcsim/src/org/lcsim/util/loop
diff -u -r1.10 -r1.10.2.1
--- LCSimLoop.java 29 Jan 2009 23:50:32 -0000 1.10
+++ LCSimLoop.java 14 Feb 2012 01:21:02 -0000 1.10.2.1
@@ -3,13 +3,12 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
-import java.util.TooManyListenersException;
-import org.freehep.record.loop.LoopException;
+import org.freehep.record.loop.DefaultRecordLoop;
+
+import org.freehep.record.loop.LoopEvent;
-import org.freehep.record.loop.SequentialRecordLoopImpl;
import org.freehep.record.source.NoSuchRecordException;
-import org.freehep.record.source.RandomAccessRecordSource;
-import org.freehep.record.source.SequentialRecordSource;
+import org.freehep.record.source.RecordSource;
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.conditions.ConditionsManagerImplementation;
import org.lcsim.conditions.ConditionsReader;
@@ -21,9 +20,10 @@
* A main loop which can be used for standalone jobs (run outside of JAS).
* @author Tony Johnson
*/
-public class LCSimLoop extends SequentialRecordLoopImpl
+public class LCSimLoop extends DefaultRecordLoop
{
private Driver top = new Driver();
+ private LoopEvent _suspendEvent;
/**
* Create a new LCSimLoop
@@ -31,14 +31,9 @@
public LCSimLoop()
{
LCSimConditionsManagerImplementation.register();
- try
- {
- super.addRecordListener(new DriverAdapter(top));
- }
- catch (TooManyListenersException x)
- {
- throw new RuntimeException("Can't happen!",x);
- }
+ DriverAdapter da = new DriverAdapter(top);
+ super.addRecordListener(da);
+ super.addLoopListener(da);
}
/**
@@ -110,54 +105,78 @@
*/
public void skip(long recordsToSkip) throws NoSuchRecordException, IOException
{
- SequentialRecordSource rs = getRecordSource();
- if (rs instanceof RandomAccessRecordSource)
- {
- RandomAccessRecordSource rrs = (RandomAccessRecordSource) rs;
- rrs.goToRecord((int) (rrs.currentIndex()+recordsToSkip));
- }
- else
- {
- for (long i=0; i<recordsToSkip; i++)
- {
- rs.next();
+ RecordSource source = getRecordSource();
+ if (source.supportsShift()) {
+ source.shift(recordsToSkip);
+ } else if (source.supportsIndex()) {
+ long index = -1L;
+ try {
+ index = source.getCurrentIndex();
+ } catch (IllegalStateException x) {}
+ source.jump(index + recordsToSkip);
+ } else if (source.supportsNext()) {
+ for (long i=0; i<recordsToSkip; i++) {
+ source.next();
}
+ } else {
+ throw new UnsupportedOperationException();
}
}
/**
* Loop over a given number of events, or until no more events are available.
* Statistics will be printed to standard output the end of the loop.
- * @param number The number of events to loop over, or <CODE>-1</CODE> to loop
- * until no more data is available.
- * @throws org.freehep.record.loop.LoopException If there is a problem iterating over events
- * (for example no event source specified)
- * @throws java.io.IOException If there is an IO exception reading or writing events
+ * @param nEvents The number of events to loop over, or <CODE>-1</CODE> to loop until no more data is available.
+ * @throws IllegalStateException If this loop is not ready to supply events (for example no event source is specified)
+ * @throws IOException If there is an IO exception reading or writing events
* @return The number of events actually iterated over.
*/
- public long loop(long number) throws LoopException, IOException
+ public long loop(long nEvents) throws NoSuchRecordException, IOException
{
- return loop(number,System.out);
+ return loop(nEvents,System.out);
}
/**
* Loop for the given number of events, optionally printing statistics to the
* given output stream
- * @param number The number of events to loop over, or <CODE>-1</CODE> to iterate
+ * @param nEvents The number of events to loop over, or <CODE>-1</CODE> to iterate
* until no more data is available.
* @param out The stream to which statistics should be output at the end of the
* loop, or <CODE>null</CODE> to suppress statistics printing.
- * @throws org.freehep.record.loop.LoopException If the loop cannot run, for instance because no input event source
- * has been set.
- * @throws java.io.IOException If an IOException occurs while reading or writing events.
+ * @throws IllegalStateException If this loop is not ready to supply events (for example no event source is specified)
+ * @throws IOException If an IOException occurs while reading or writing events
+ * @throws NoSuchRecordException If specific number of records was requested but the end of source was reached before
+ * that number of events could be processed.
* @return The number of events actually iterated over.
*/
- public long loop(long number, PrintStream out) throws LoopException, IOException
+ public long loop(long nEvents, PrintStream out) throws NoSuchRecordException, IOException
{
top.clearStatistics();
- long result = super.loop(number);
+ if (nEvents < 0L) {
+ execute(Command.GO);
+ } else if (nEvents == 0L) {
+ return 0L;
+ } else {
+ execute(Command.GO_N, nEvents);
+ }
+ Throwable x = _suspendEvent.getException();
+ if (x != null) {
+ if (x instanceof IOException) {
+ throw (IOException)x;
+ } else if (x instanceof NoSuchRecordException) {
+ if (nEvents > 0L) throw (NoSuchRecordException) x;
+ } else {
+ throw new RuntimeException("Error while processing records", x);
+ }
+ }
if (out != null) printStatistics(out);
- return result;
+ return _suspendEvent.getCountableConsumed();
+ }
+
+ protected LoopEvent createLoopEvent(Event eventType) {
+ LoopEvent event = super.createLoopEvent(eventType);
+ if (eventType == Event.SUSPEND) _suspendEvent = event;
+ return event;
}
/**
lcsim/src/org/lcsim/util/loop
diff -u -r1.8 -r1.8.2.1
--- StdhepEventSource.java 17 Nov 2009 16:53:49 -0000 1.8
+++ StdhepEventSource.java 14 Feb 2012 01:21:02 -0000 1.8.2.1
@@ -9,27 +9,26 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
-import org.freehep.record.source.EndOfSourceException;
+import org.freehep.record.source.AbstractRecordSource;
import org.freehep.record.source.NoSuchRecordException;
-import org.freehep.record.source.RandomAccessRecordSource;
+import org.freehep.record.source.RecordSource;
import org.lcsim.event.EventHeader;
import org.lcsim.event.util.LCSimFactory;
/**
- * Convert an LCIOReader to a SequentialRecordSource
+ * {@link RecordSource} wrapper for {@link StdhepReader}.
* @author tonyj
- * @version $Id: StdhepEventSource.java,v 1.8 2009/11/17 16:53:49 tonyj Exp $
+ * @version $Id: StdhepEventSource.java,v 1.8.2.1 2012/02/14 01:21:02 onoprien Exp $
*/
-public class StdhepEventSource implements RandomAccessRecordSource
+public class StdhepEventSource extends AbstractRecordSource
{
private List<File> files;
- private String name;
private boolean atEnd;
private StdhepReader reader;
private final StdhepConverter converter;
private EventHeader currentEvent;
- private int currentEventNumber;
+ private long currentEventNumber = -1L;
private int currentFile = 0;
/**
@@ -37,46 +36,49 @@
*/
public StdhepEventSource(File file, String detectorName) throws IOException
{
+ super(file.getName());
reader = new StdhepReader(file.getAbsolutePath());
converter = new StdhepConverter(ParticlePropertyManager.getParticlePropertyProvider(),new LCSimFactory(detectorName));
this.files = Collections.singletonList(file);
- this.name = file.getName();
}
/**
* Create an event source from a list of stdhep files
*/
public StdhepEventSource(FileList list, String detectorName) throws IOException
{
- this.name = list.getTitle();
+ super(list.getTitle());
this.files = list.getFileList();
- if (files.size() == 0) throw new IOException("File list is empty");
+ if (files.isEmpty()) throw new IOException("File list is empty");
reader = new StdhepReader(files.get(0).getAbsolutePath());
converter = new StdhepConverter(ParticlePropertyManager.getParticlePropertyProvider(),new LCSimFactory(detectorName));
}
- public Object getCurrentRecord() throws NoSuchRecordException, IOException, EndOfSourceException
+ public Object getCurrentRecord() throws IOException
{
- if (atEnd) throw new EndOfSourceException();
- if (currentEvent == null) throw new NoSuchRecordException();
+ if (atEnd) throw new IllegalStateException();
+ if (currentEvent == null) throw new IllegalStateException();
return currentEvent;
}
public long getEstimatedSize()
{
- return files.size() == 1 ? reader.getNumberOfEvents() : -1;
+ if (files.size() == 1) {
+ return reader.getNumberOfEvents();
+ } else {
+ throw new UnsupportedOperationException();
+ }
}
- public Class getRecordClass()
+ public Class<?> getRecordClass()
{
return EventHeader.class;
}
- public String getSourceName()
- {
- return name;
- }
+ public boolean supportsNext() {return true;}
+
+ public boolean hasNext() {return !atEnd;}
- public void next() throws IOException
+ public void next() throws IOException, NoSuchRecordException
{
for (;;)
{
@@ -97,7 +99,11 @@
catch (EOFException x)
{
currentFile++;
- if (currentFile >= files.size()) atEnd = true;
+ if (currentFile >= files.size())
+ {
+ atEnd = true;
+ throw new NoSuchRecordException();
+ }
else
{
reader.close();
@@ -108,10 +114,12 @@
return;
}
}
+
public void releaseRecord(Object obj)
{
currentEvent = null;
}
+
public void rewind() throws IOException
{
if (currentFile == 0)
@@ -125,8 +133,9 @@
reader = new StdhepReader(files.get(0).getAbsolutePath());
}
atEnd = false;
- currentEventNumber = 0;
+ currentEventNumber = -1L;
}
+
public void close() throws IOException
{
if (reader != null)
@@ -135,7 +144,8 @@
reader = null;
}
}
- public void finalize()
+
+ public void finalize() throws Throwable
{
try
{
@@ -143,18 +153,22 @@
}
catch (IOException x)
{}
+ super.finalize();
}
- public void goToRecord(int target) throws NoSuchRecordException
+ public boolean supportsIndex() {return true;}
+
+ public boolean hasIndex(long index) {return index > -1L && (!atEnd || index <= currentEventNumber);}
+
+ public void jump(long index) throws IOException, NoSuchRecordException
{
- try
- {
+ long currentIndex = currentEventNumber;
for (;;)
{
try
{
- if (target < currentEventNumber) rewind();
- if (target == currentEventNumber) return;
+ if (index < currentEventNumber) rewind();
+ if (index == currentEventNumber) return;
for (;;)
{
@@ -162,7 +176,7 @@
if (record instanceof StdhepEvent)
{
currentEventNumber++;
- if (currentEventNumber == target)
+ if (currentEventNumber == index)
{
currentEvent = (EventHeader) converter.convert((StdhepEvent) record);
break;
@@ -176,10 +190,12 @@
currentFile++;
if (currentFile >= files.size())
{
- atEnd = true;
- NoSuchRecordException xx = new NoSuchRecordException();
- xx.initCause(x);
- throw xx;
+ try {
+ jump(currentIndex);
+ } catch (NoSuchRecordException xx) {
+ throw new IOException(xx);
+ }
+ throw new NoSuchRecordException(x);
}
else
{
@@ -190,17 +206,11 @@
}
return;
}
- }
- catch (IOException x)
- {
- NoSuchRecordException xx = new NoSuchRecordException();
- xx.initCause(x);
- throw xx;
- }
}
- public int currentIndex()
+ public long getCurrentIndex()
{
+ if (currentEventNumber == -1L) throw new IllegalStateException();
return currentEventNumber;
}
}
\ No newline at end of file
lcsim/test/org/lcsim
diff -u -r1.5 -r1.5.2.1
--- HitMixingTest.java 25 Mar 2009 01:01:15 -0000 1.5
+++ HitMixingTest.java 14 Feb 2012 01:21:02 -0000 1.5.2.1
@@ -10,7 +10,7 @@
import junit.framework.TestCase;
-import org.freehep.record.loop.LoopException;
+import org.freehep.record.source.NoSuchRecordException;
import org.lcsim.event.EventHeader;
import org.lcsim.event.EventHeader.LCMetaData;
import org.lcsim.event.SimCalorimeterHit;
@@ -19,14 +19,13 @@
import org.lcsim.util.cache.FileCache;
import org.lcsim.util.loop.LCSimLoop;
-import static java.lang.Math.abs;
public class HitMixingTest extends TestCase
{
private static int nhits;
private static Map<SimCalorimeterHit,LCMetaData> origMeta = new HashMap<SimCalorimeterHit,LCMetaData>();
- public void testMix() throws IOException, LoopException
+ public void testMix() throws IOException, NoSuchRecordException
{
FileCache cache = new FileCache();
File events = cache.getCachedFile(new URL("http://www.lcsim.org/test/lcio/muons10_Theta4-176_1-10GeV_SLIC-v2r5p3_geant4-v9r1p2_LCPhys_sid01.slcio"));
lcsim/test/org/lcsim
diff -u -r1.3 -r1.3.4.1
--- LCIOReadTest.java 11 Sep 2007 00:21:00 -0000 1.3
+++ LCIOReadTest.java 14 Feb 2012 01:21:02 -0000 1.3.4.1
@@ -47,7 +47,7 @@
loop.add(new ReadDriver());
loop.add(new LCIODriver(new TestOutputFile("LCIOReadTest.slcio")));
loop.loop(-1, null);
- assertEquals(200, loop.getTotalCountableSupplied());
+ assertEquals(200, loop.getTotalCountableConsumed());
loop.dispose();
}
@@ -65,7 +65,7 @@
LCSimLoop loop = new LCSimLoop();
loop.setLCIORecordSource(es);
loop.loop(-1, null);
- assertEquals(400, loop.getTotalCountableSupplied());
+ assertEquals(400, loop.getTotalCountableConsumed());
loop.dispose();
}
public void testSkip() throws Exception
@@ -79,7 +79,7 @@
loop.add(new CheatClusterDriver());
loop.skip(150);
loop.loop(-1, null);
- assertEquals(50, loop.getTotalCountableSupplied());
+ assertEquals(50, loop.getTotalCountableConsumed());
loop.dispose();
}
public void testSkip0() throws Exception
@@ -96,7 +96,7 @@
long stop = System.nanoTime();
System.out.println("Skip took "+(stop-start)/1000000.+"ms");
loop.loop(1000, null);
- assertEquals(1000, loop.getTotalCountableSupplied());
+ assertEquals(1000, loop.getTotalCountableConsumed());
loop.dispose();
}
public void testSkipSpeed() throws Exception
@@ -113,7 +113,7 @@
long stop = System.nanoTime();
System.out.println("Skip took "+(stop-start)/1000000.+"ms");
loop.loop(-1, null);
- assertEquals(50, loop.getTotalCountableSupplied());
+ assertEquals(50, loop.getTotalCountableConsumed());
loop.dispose();
}
private class ReadDriver extends Driver
lcsim/test/org/lcsim
diff -u -r1.3 -r1.3.2.1
--- ReferenceIOTest.java 10 Jul 2009 23:22:09 -0000 1.3
+++ ReferenceIOTest.java 14 Feb 2012 01:21:02 -0000 1.3.2.1
@@ -6,12 +6,11 @@
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
-import org.freehep.record.loop.LoopException;
+import org.freehep.record.source.NoSuchRecordException;
import org.lcsim.event.EventHeader;
import org.lcsim.event.MCParticle;
import org.lcsim.util.Driver;
import org.lcsim.util.cache.FileCache;
-import org.lcsim.util.lcio.*;
import org.lcsim.util.loop.LCIODriver;
import org.lcsim.util.loop.LCSimLoop;
import org.lcsim.util.test.TestUtil.TestOutputFile;
@@ -26,7 +25,7 @@
{
super(testName);
}
- public void testReferences() throws IOException, LoopException
+ public void testReferences() throws IOException, NoSuchRecordException
{
final String detectorName = "sidaug05";
URL url = new URL("http://www.lcsim.org/test/stdhep/pythiaZZ_nunu_bbbar-0-1.stdhep");
@@ -40,7 +39,7 @@
loop.add(new ReferenceDriver());
loop.add(new LCIODriver(outputFile));
loop.loop(1, null);
- assertEquals(1,loop.getTotalCountableSupplied());
+ assertEquals(1,loop.getTotalCountableConsumed());
loop.dispose();
// Now read it back in
lcsim/test/org/lcsim
diff -u -r1.4 -r1.4.2.1
--- StdhepFilterTest.java 17 Mar 2009 22:44:51 -0000 1.4
+++ StdhepFilterTest.java 14 Feb 2012 01:21:03 -0000 1.4.2.1
@@ -43,7 +43,7 @@
loop.setStdhepRecordSource(stdhep,detectorName);
loop.add(writer);
loop.loop(-1, null);
- assertEquals(1,loop.getTotalCountableSupplied());
+ assertEquals(1,loop.getTotalCountableConsumed());
loop.dispose();
}
}
lcsim/test/org/lcsim/recon/cluster/fixedcone
diff -u -r1.13 -r1.13.2.1
--- FixedConeClustererTest.java 17 Aug 2011 22:55:20 -0000 1.13
+++ FixedConeClustererTest.java 14 Feb 2012 01:21:03 -0000 1.13.2.1
@@ -7,7 +7,7 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.freehep.record.loop.LoopException;
+import org.freehep.record.source.NoSuchRecordException;
import org.lcsim.util.cache.FileCache;
import org.lcsim.util.loop.LCIODriver;
import org.lcsim.util.loop.LCSimLoop;
@@ -31,7 +31,7 @@
return new TestSuite(FixedConeClustererTest.class);
}
- public static void testNNClusterer() throws IOException, LoopException
+ public static void testNNClusterer() throws IOException, NoSuchRecordException
{
URL url = new URL("http://www.lcsim.org/test/lcio/mu_10GeV_Theta90_SLIC-v2r5p3_geant4-v9r1p2_LCPhys_sid01.slcio");
lcsim/test/org/lcsim/recon/cluster/nn
diff -u -r1.8 -r1.8.4.1
--- NearestNeighborClustererTest.java 11 Sep 2007 00:21:03 -0000 1.8
+++ NearestNeighborClustererTest.java 14 Feb 2012 01:21:03 -0000 1.8.4.1
@@ -11,7 +11,7 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.freehep.record.loop.LoopException;
+import org.freehep.record.source.NoSuchRecordException;
import org.lcsim.util.cache.FileCache;
import org.lcsim.util.loop.LCIODriver;
import org.lcsim.util.loop.LCSimLoop;
@@ -32,7 +32,7 @@
return new TestSuite(NearestNeighborClustererTest.class);
}
- public static void testNNClusterer() throws IOException, LoopException
+ public static void testNNClusterer() throws IOException, NoSuchRecordException
{
URL url = new URL("http://www.lcsim.org/test/lcio/muons_SLIC_v1r9p1_sidmay05.slcio");
FileCache cache = new FileCache();
lcsim/test/org/lcsim/recon/vertexing/billoir
diff -u -r1.7 -r1.7.2.1
--- VertexFitterTest.java 17 Mar 2009 22:44:51 -0000 1.7
+++ VertexFitterTest.java 14 Feb 2012 01:21:03 -0000 1.7.2.1
@@ -1,7 +1,7 @@
package org.lcsim.recon.vertexing.billoir;
/**
- * @version $Id: VertexFitterTest.java,v 1.7 2009/03/17 22:44:51 jeremy Exp $
+ * @version $Id: VertexFitterTest.java,v 1.7.2.1 2012/02/14 01:21:03 onoprien Exp $
*/
@@ -27,6 +27,7 @@
import Jama.Matrix;
import Jama.util.Maths;
+import org.freehep.record.source.NoSuchRecordException;
/**
* @author jstrube
@@ -56,7 +57,7 @@
fitter = new BilloirFitter(5);
}
- public void testFit() throws org.freehep.record.loop.LoopException, java.io.IOException {
+ public void testFit() throws NoSuchRecordException, java.io.IOException {
loop.add(new MCFast());
loop.add(new TrackFitDriver());
loop.loop(-1, null);
lcsim/test/org/lcsim/recon/vertexing/zvtop4
diff -u -r1.8 -r1.8.2.1
--- ZvTrackTest.java 25 Mar 2009 01:01:15 -0000 1.8
+++ ZvTrackTest.java 14 Feb 2012 01:21:03 -0000 1.8.2.1
@@ -5,7 +5,6 @@
import java.net.URL;
import java.util.List;
-import org.freehep.record.loop.LoopException;
import org.lcsim.event.EventHeader;
import org.lcsim.event.Track;
import org.lcsim.mc.fast.MCFast;
@@ -16,6 +15,7 @@
import org.lcsim.util.loop.LCSimLoop;
import junit.framework.TestCase;
+import org.freehep.record.source.NoSuchRecordException;
public class ZvTrackTest extends TestCase {
LCSimLoop loop;
@@ -150,7 +150,7 @@
loop.add(new MCFast());
loop.add(new TransformLocationTest());
loop.loop(-1, null);
- } catch (LoopException e) {
+ } catch (NoSuchRecordException e) {
} catch (IOException e) {
}
}
CVSspam 0.2.12