6 added + 6 modified, total 12 files
lcsim/src/org/lcsim/contrib/onoprien/util
diff -N ListMap.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ListMap.java 25 Nov 2008 21:02:58 -0000 1.1
@@ -0,0 +1,439 @@
+package org.lcsim.contrib.onoprien.util;
+
+import java.util.*;
+
+/**
+ * Map of keys to lists of values.
+ *
+ * @author D. Onoprienko
+ * @version $Id: ListMap.java,v 1.1 2008/11/25 21:02:58 onoprien Exp $
+ */
+public class ListMap<K,V> implements List<V> {
+
+// -- Constructors : ----------------------------------------------------------
+
+ public ListMap() {
+ _map = new LinkedHashMap<K, ArrayList<V>>();
+ }
+
+ public ListMap(int initialCapacity) {
+ _map = new LinkedHashMap<K, ArrayList<V>>(initialCapacity);
+ }
+
+ public ListMap(ListMap<K, V> hitMap) {
+ Set<Map.Entry<K,ArrayList<V>>> entrySet = hitMap._map.entrySet();
+ _map = new LinkedHashMap<K,ArrayList<V>>(Math.round(entrySet.size()*1.5f));
+ for (Map.Entry<K,ArrayList<V>> entry : entrySet) {
+ _map.put(entry.getKey(), new ArrayList<V>(entry.getValue()));
+ }
+ }
+
+// -- Public API : ------------------------------------------------------------
+
+ /**
+ * Returns <tt>true</tt> if this map contains values mapped to the specified key.
+ */
+ public boolean containsKey(Object key) {
+ return _map.containsKey(key) ;
+ }
+
+ /**
+ * Returns <tt>true</tt> if this collection contains the specified value.
+ */
+ public boolean containsValue(V value) {
+ for (Map.Entry<K,ArrayList<V>> entry : _map.entrySet()) {
+ if (entry.getValue().contains(value)) return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns <tt>true</tt> if this collection contains the specified value.
+ */
+ public boolean contains(Object o) {
+ for (Map.Entry<K,ArrayList<V>> entry : _map.entrySet()) {
+ if (entry.getValue().contains(o)) return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns <tt>true</tt> if this <tt>ListMap</tt> contains all of the elements of the
+ * specified collection.
+ */
+ public boolean containsAll(Collection<?> c) {
+ if (c.isEmpty()) return true;
+ LinkedList<Object> list = new LinkedList<Object>();
+ for (Object o : c) list.add(o);
+ for (V value : this) {
+ if (list.remove(value)) {
+ if (list.isEmpty()) return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns the unmodifiable list of values mapped to the specified key.
+ * Returns an empty list if this map contains no mapping for the key.
+ */
+ public List<V> get(Object key) {
+ ArrayList<V> vList = _map.get(key);
+ return (vList == null) ? Collections.<V>emptyList() : Collections.unmodifiableList(vList);
+ }
+
+ /**
+ * Returns an unmodifiable {@link Set} view of the keys contained in this map.
+ */
+ public Set<K> keySet() {return Collections.unmodifiableSet(_map.keySet());}
+
+ /**
+ * Returns a {@link Set} view of the mappings contained in this map.
+ */
+ public Set<Entry<K,V>> entrySet() {
+ return (_entrySet == null) ? (_entrySet = new EntrySet()) : _entrySet ;
+ }
+
+ /**
+ * Removes the mapping for a key from this map if it is present.
+ * Returns the list of values to which this map previously associated the key,
+ * or an empty list if the map contained no mapping for the key.
+ */
+ public List<V> removeKey(Object key) {
+ List<V> list = _map.remove(key);
+ if (list == null) list = Collections.emptyList();
+ return list;
+ }
+
+ /**
+ * Removes all occurrences of the specified value from the map.
+ * Returns <tt>true</tt> if the map contained the value.
+ */
+ public boolean remove(Object value) {
+ boolean hasChanged = false;
+ Iterator<Map.Entry<K,ArrayList<V>>> it = _map.entrySet().iterator();
+ while (it.hasNext()) {
+ ArrayList<V> vList = it.next().getValue();
+ hasChanged = hasChanged || vList.remove(value);
+ if (vList.isEmpty()) it.remove();
+ }
+ return hasChanged;
+ }
+
+ /**
+ * Removes from this list all of its elements that are contained in the specified collection.
+ * Returnes <tt>true</tt> if the collection has changed as a result of this call.
+ */
+ public boolean removeAll(Collection<?> c) {
+ boolean hasChanged = false;
+ Iterator<Map.Entry<K,ArrayList<V>>> it = _map.entrySet().iterator();
+ while (it.hasNext()) {
+ ArrayList<V> vList = it.next().getValue();
+ hasChanged = hasChanged || vList.removeAll(c);
+ if (vList.isEmpty()) it.remove();
+ }
+ return hasChanged;
+ }
+
+ /**
+ * Retains only values in this map that are contained in the specified collection.
+ * In other words, removes all values that are not contained in the specified collection.
+ * Returnes <tt>true</tt> if the collection has changed as a result of this call.
+ */
+ public boolean retainAll(Collection<?> c) {
+ boolean hasChanged = false;
+ Iterator<Map.Entry<K,ArrayList<V>>> it = _map.entrySet().iterator();
+ while (it.hasNext()) {
+ ArrayList<V> vList = it.next().getValue();
+ hasChanged = hasChanged || vList.retainAll(c);
+ if (vList.isEmpty()) it.remove();
+ }
+ return hasChanged;
+ }
+
+ /**
+ * Adds the specified hit to the list mapped to the given key.
+ */
+ public void add(K key, V hit) {
+ ArrayList<V> list = _map.get(key);
+ if (list == null) {
+ list = new ArrayList<V>(1);
+ _map.put(key, list);
+ }
+ list.add(hit);
+ }
+
+ /**
+ * Adds the specified hits to the list mapped to the given key.
+ */
+ public void add(K key, List<? extends V> values) {
+ ArrayList<V> list = _map.get(key);
+ if (list == null) {
+ list = new ArrayList<V>(values);
+ _map.put(key, list);
+ } else {
+ list.addAll(values);
+ }
+ }
+
+ /**
+ * Puts a new mapping into the map.
+ */
+ public List<V> put(K key, List<? extends V> values) {
+ return _map.put(key, new ArrayList<V>(values));
+ }
+
+ /**
+ * Removes all of the mappings from this map.
+ * The map will be empty after this call returns.
+ */
+ public void clear() {
+ _map.clear();
+ }
+
+ /**
+ * Returns a shallow copy of this ListMap instance.
+ */
+ public Object clone() {
+ return new ListMap(this);
+ }
+
+ /** Returns a hash code value for the object. */
+ public int hashCode() {
+ return _map.hashCode();
+ }
+
+ /**
+ * Compares the specified object with this list for equality.
+ */
+ public boolean equals(Object o) {
+ return o instanceof ListMap && ((ListMap) o)._map.equals(this._map);
+ }
+
+ /**
+ * Compact memory used by this map.
+ */
+ public void trimToSize() {
+ Iterator<Map.Entry<K,ArrayList<V>>> it = _map.entrySet().iterator();
+ while (it.hasNext()) {
+ ArrayList<V> vList = it.next().getValue();
+ if (vList.isEmpty()) {
+ it.remove();
+ } else {
+ vList.trimToSize();
+ }
+ }
+ }
+
+// -- Implementing List : -----------------------------------------------------
+
+ /** Returns the number of values in this collection. */
+ public int size() {
+ int size = 0;
+ for (Map.Entry<K,ArrayList<V>> entry : _map.entrySet()) {
+ size += entry.getValue().size();
+ }
+ return size;
+ }
+
+ /** Returns <tt>true</tt> if this collection contains no elements. */
+ public boolean isEmpty() {
+ return _map.isEmpty();
+ }
+
+ /**
+ * Returns an array containing all of the elements in this list in proper
+ * sequence (from first to last element).
+ *
+ * New array is allocated and returned, so the caller can modify it without
+ * affecting this <tt>ListMap</tt>.
+ */
+ public Object[] toArray() {
+ int size = size();
+ Object[] out = new Object[size];
+ int i=0;
+ for (V value : this) {
+ out[i++] = value;
+ }
+ return out;
+ }
+
+ /**
+ * Returns an array containing all of the elements in this list in
+ * proper sequence (from first to last element); the runtime type of
+ * the returned array is that of the specified array. If the list fits
+ * in the specified array, it is returned therein. Otherwise, a new
+ * array is allocated with the runtime type of the specified array and
+ * the size of this list.
+ */
+ public <T> T[] toArray(T[] a) {
+ int size = size();
+ if (a.length < size) {
+ a = (T[])java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size);
+ } else {
+ for (int i=size; i<a.length; i++) a[i] = null;
+ }
+ int i=0;
+ for (V value : this) {
+ a[i++] = (T)value;
+ }
+ return a;
+ }
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public boolean add(V e) {throw new UnsupportedOperationException();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public boolean addAll(Collection<? extends V> c) {throw new UnsupportedOperationException();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public boolean addAll(int index, Collection<? extends V> c) {throw new UnsupportedOperationException();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public V get(int index) {throw new UnsupportedOperationException();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public V set(int index, V element) {throw new UnsupportedOperationException();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public void add(int index, V element) {throw new UnsupportedOperationException();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public V remove(int index) {throw new UnsupportedOperationException();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public int indexOf(Object o) {throw new UnsupportedOperationException();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public int lastIndexOf(Object o) {throw new UnsupportedOperationException();}
+
+ /** Returns an iterator over the elements in this list in proper sequence. */
+ public Iterator<V> iterator() {return new ListItr();}
+
+ /**
+ * Returns an iterator over the elements in this <tt>ListMap</tt> (in proper sequence).
+ * <p>
+ * Note that while the return type of this method is <tt>ListIterator</tt>,
+ * only operations of a basic <tt>Iterator</tt> for an unmodifiable list
+ * (<tt>hasNext()</tt>, <tt>next()</tt>) are supported by the returned object.
+ */
+ public ListIterator<V> listIterator() {return new ListItr();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public ListIterator<V> listIterator(int index) {throw new UnsupportedOperationException();}
+
+ /** Throws <tt>UnsupportedOperationException</tt>. */
+ public List<V> subList(int fromIndex, int toIndex) {throw new UnsupportedOperationException();}
+
+// -- Private parts : ---------------------------------------------------------
+
+ private LinkedHashMap<K,ArrayList<V>> _map;
+ private EntrySet _entrySet;
+
+// -- Helper class: iterator : ------------------------------------------------
+
+ private class ListItr implements ListIterator<V> {
+
+ ListItr() {
+ itList = _map.entrySet().iterator();
+ it = itList.hasNext() ? itList.next().getValue().listIterator() : Collections.<V>emptyList().listIterator() ;
+ }
+
+ public boolean hasNext() {
+ return itList.hasNext() || it.hasNext();
+ }
+
+ public V next() {
+ if (it.hasNext()) {
+ return it.next();
+ } else {
+ it = itList.next().getValue().listIterator();
+ return it.next();
+ }
+ }
+
+ public void remove() {throw new UnsupportedOperationException();}
+ public int previousIndex() {throw new UnsupportedOperationException();}
+ public V previous() {throw new UnsupportedOperationException();}
+ public boolean hasPrevious() {throw new UnsupportedOperationException();}
+ public int nextIndex() {throw new UnsupportedOperationException();}
+ public void set(V value) {throw new UnsupportedOperationException();}
+ public void add(V value) {throw new UnsupportedOperationException();}
+
+ Iterator<Map.Entry<K, ArrayList<V>>> itList;
+ ListIterator<V> it;
+ }
+
+// -- Helper class: entry : ---------------------------------------------------
+
+ /**
+ * Entry in a {@link ListMap}.
+ */
+ static public class Entry<K,V> {
+
+ private Entry(Map.Entry<K, ArrayList<V>> entry) {
+ _entry = entry;
+ }
+
+ /** Returns the key corresponding to this entry. */
+ public K getKey() {
+ return _entry.getKey();
+ }
+
+ /** Returns an unmodifiabele list of values corresponding to this entry. */
+ public List<V> getValues() {
+ return Collections.unmodifiableList(_entry.getValue());
+ }
+
+ /**
+ * Sets the list of values corresponding to this entry, returns the previous list.
+ * If the supplied list is empty, IllegalArgumentException is thrown.
+ */
+ public List<V> setValues(List<? extends V> values) {
+ List<V> out = _entry.getValue();
+ if (! values.isEmpty()) {
+ _entry.setValue(new ArrayList<V>(values));
+ } else {
+ throw new IllegalArgumentException();
+ }
+ return out;
+ }
+
+ /** Compares the specified object with this entry for equality. */
+ public boolean equals(Object o) {
+ return (o instanceof Entry) && _entry.equals(((Entry)o)._entry);
+ }
+ /** Returns the hash code value for this map entry. */
+ public int hashCode() {return _entry.hashCode();}
+
+ private Map.Entry<K, ArrayList<V>> _entry;
+ }
+
+// -- Helper class: entry set : -----------------------------------------------
+
+ private class EntrySet extends AbstractSet<Entry<K,V>> {
+
+ Set<Map.Entry<K,ArrayList<V>>> set;
+ Iterator<Map.Entry<K,ArrayList<V>>> it;
+
+ private EntrySet() {
+ set = _map.entrySet();
+ }
+
+ public Iterator<ListMap.Entry<K, V>> iterator() {
+ return new Iterator() {
+ Iterator<Map.Entry<K,ArrayList<V>>> it = set.iterator();
+ public void remove() {it.remove();}
+ public Object next() {return new Entry<K,V>(it.next());}
+ public boolean hasNext() {return it.hasNext();}
+ };
+ }
+
+ public int size() {
+ return set.size();
+ }
+ }
+
+// -----------------------------------------------------------------------------
+
+}
lcsim/src/org/lcsim/contrib/onoprien/util
diff -u -r1.1 -r1.2
--- Driver.java 5 Nov 2008 03:32:48 -0000 1.1
+++ Driver.java 25 Nov 2008 21:02:58 -0000 1.2
@@ -5,7 +5,7 @@
import org.lcsim.event.EventHeader;
/**
- * Base class for drivers.
+ * Base class for drivers. Adds functionality to {@link org.lcsim.util.Driver}.
* <p>
* Logging facility included in this class simply prints messages to standard output
* when the {@link #log log(String, Level)} method is called with the level greater
@@ -26,7 +26,7 @@
*
*
* @author D. Onoprienko
- * @version $Id: Driver.java,v 1.1 2008/11/05 03:32:48 onoprien Exp $
+ * @version $Id: Driver.java,v 1.2 2008/11/25 21:02:58 onoprien Exp $
*/
public class Driver extends org.lcsim.util.Driver {
@@ -56,7 +56,7 @@
* @param name Name of parameter to be set. Case is ignored.
* @param values List of values to be used for setting the parameter.
* @throws NoSuchParameterException Thrown if the supplied parameter name is unknown.
- * @throws IllegalArgumentException Thrown if incorrect nunber of values, or a value
+ * @throws IllegalArgumentException Thrown if incorrect number of values, or a value
* of incorrect type is supplied.
*/
public void set(String name, Object... values) {
@@ -155,8 +155,7 @@
public void addLog(String message) {
addLog(message, _defLevel);
}
-
-
+
// -- Private parts : ---------------------------------------------------------
lcsim/src/org/lcsim/contrib/onoprien/util/swim
diff -N BField.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BField.java 25 Nov 2008 21:02:58 -0000 1.1
@@ -0,0 +1,53 @@
+package org.lcsim.contrib.onoprien.util.swim;
+
+import hep.physics.vec.Hep3Vector;
+import org.lcsim.geometry.Detector;
+
+import org.lcsim.contrib.onoprien.util.ConstHep3Vector;
+import org.lcsim.contrib.onoprien.util.job.JobEvent;
+import org.lcsim.contrib.onoprien.util.job.JobEventListener;
+import org.lcsim.contrib.onoprien.util.job.JobManager;
+
+/**
+ * Singleton class that keeps the magnetic field related constants and converts
+ * geometrical trajectory parameters into particle momentum.
+ *
+ * @author D. Onoprienko
+ * @version $Id: BField.java,v 1.1 2008/11/25 21:02:58 onoprien Exp $
+ */
+public class BField implements JobEventListener {
+
+// -- Constructors and initialization : ---------------------------------------
+
+ private BField() {
+ JobManager jMan = JobManager.defaultInstance();
+ jMan.addListener(this);
+ }
+
+ /** Initialization - called by the framework. */
+ public void detectorChanged(JobEvent jobEvent) {
+ Detector det = jobEvent.getDetector();
+ _bField = det.getFieldMap().getField(ConstHep3Vector.V000).z();
+ }
+
+ /** Returns default instance of <tt>BField</tt>. */
+ static public BField defaultInstance() {
+ return (_def == null) ? _def = new BField() : _def;
+ }
+
+// -- Conversion : ------------------------------------------------------------
+
+ public double getMomentum(Helix helix) {
+ throw new UnsupportedOperationException(); // FIXME
+ }
+
+ public Helix makeHelix(Hep3Vector position, Hep3Vector momentum, int charge) {
+ throw new UnsupportedOperationException(); // FIXME
+ }
+
+// -- Private parts : ---------------------------------------------------------
+
+ static private BField _def;
+
+ private double _bField;
+}
lcsim/src/org/lcsim/contrib/onoprien/util/swim
diff -u -r1.1 -r1.2
--- Helix.java 5 Nov 2008 03:32:51 -0000 1.1
+++ Helix.java 25 Nov 2008 21:02:58 -0000 1.2
@@ -11,7 +11,7 @@
* Helical {@link Trajectory} with its axis parallel to Z.
*
* @author D. Onoprienko
- * @version $Id: Helix.java,v 1.1 2008/11/05 03:32:51 onoprien Exp $
+ * @version $Id: Helix.java,v 1.2 2008/11/25 21:02:58 onoprien Exp $
*/
public class Helix extends AbstractTrajectory {
@@ -80,6 +80,7 @@
_ro = parameters.get(WRep.RO);
}
+ /** Copy constructor. */
public Helix(Helix helix) {
_orig = helix._orig;
_dir = helix._dir;
lcsim/src/org/lcsim/contrib/onoprien/util/swim
diff -u -r1.1 -r1.2
--- ParVector.java 5 Nov 2008 03:32:51 -0000 1.1
+++ ParVector.java 25 Nov 2008 21:02:58 -0000 1.2
@@ -7,7 +7,7 @@
* described in {@link Helix.CRep} and {@link Helix.WRep} representations).
*
* @author D. Onoprienko
- * @version $Id: ParVector.java,v 1.1 2008/11/05 03:32:51 onoprien Exp $
+ * @version $Id: ParVector.java,v 1.2 2008/11/25 21:02:58 onoprien Exp $
*/
public class ParVector<T extends Enum<T>> {
@@ -32,12 +32,22 @@
// -- Getters : ---------------------------------------------------------------
+ /** Returns the value of the parameter specified by the argument. */
public double get(T parameter) {
return _pars[parameter.ordinal()];
}
+
+ /**
+ * Returns parameter values as an array.
+ * The returned array is owned by this <tt>ParVector</tt> object, any modifications will persist.
+ */
+ public double[] v() {
+ return _pars;
+ }
// -- Setters : ---------------------------------------------------------------
+ /** Sets the value of the parameter specified by the argument. */
public void set(T parameter, double value) {
_pars[parameter.ordinal()] = value;
}
lcsim/src/org/lcsim/contrib/onoprien/vsegment
diff -u -r1.4 -r1.5
--- ExampleDriverSiD01.java 5 Nov 2008 03:32:47 -0000 1.4
+++ ExampleDriverSiD01.java 25 Nov 2008 21:02:58 -0000 1.5
@@ -4,6 +4,8 @@
import org.lcsim.units.clhep.SystemOfUnits;
+import org.lcsim.contrib.onoprien.util.Driver;
+
import org.lcsim.contrib.onoprien.vsegment.algorithm.ChargeCollectorDemo;
import org.lcsim.contrib.onoprien.vsegment.algorithm.ClustererNearestNeighbor;
import org.lcsim.contrib.onoprien.vsegment.algorithm.HitMakerSmear;
@@ -23,15 +25,15 @@
import org.lcsim.contrib.onoprien.vsegment.process.Digitizer;
import org.lcsim.contrib.onoprien.vsegment.process.SensorFilter;
import org.lcsim.contrib.onoprien.vsegment.process.HitMaker;
-import org.lcsim.contrib.onoprien.util.Driver;
-import org.lcsim.contrib.onoprien.vsegment.diagnostics.HitPlotter;
+//import org.lcsim.contrib.onoprien.vsegment.diagnostics.EventDisplay;
+//import org.lcsim.contrib.onoprien.vsegment.diagnostics.HitPlotter;
/**
- *
+ * An example driver that runs tracker hit processing.
*
* @author D. Onoprienko
- * @version $Id: ExampleDriverSiD01.java,v 1.4 2008/11/05 03:32:47 onoprien Exp $
+ * @version $Id: ExampleDriverSiD01.java,v 1.5 2008/11/25 21:02:58 onoprien Exp $
*/
public class ExampleDriverSiD01 extends Driver {
@@ -108,11 +110,15 @@
// Don't forget to comment this out if you run real reconstruction -
// AIDA gobbles up time and memory
- HitPlotter hitPlotter = new HitPlotter();
- hitPlotter.set("LOG_LEVEL", Level.FINE);
- hitPlotter.set("RAW_DATA_MAP_NAME", nameRawTrackerData);
- hitPlotter.set("CLUSTER_MAP_NAME", nameTrackerClusters);
- add(hitPlotter);
+// EventDisplay eventDisplay = new EventDisplay();
+// eventDisplay.set("LOG_LEVEL", Level.FINE);
+// add(eventDisplay);
+//
+// HitPlotter hitPlotter = new HitPlotter();
+// hitPlotter.set("LOG_LEVEL", Level.FINE);
+// hitPlotter.set("RAW_DATA_MAP_NAME", nameRawTrackerData);
+// hitPlotter.set("CLUSTER_MAP_NAME", nameTrackerClusters);
+// add(hitPlotter);
}
lcsim/src/org/lcsim/contrib/onoprien/vsegment
diff -u -r1.3 -r1.4
--- ExampleDriverSiD02.java 5 Nov 2008 03:32:47 -0000 1.3
+++ ExampleDriverSiD02.java 25 Nov 2008 21:02:58 -0000 1.4
@@ -4,6 +4,8 @@
import org.lcsim.units.clhep.SystemOfUnits;
+import org.lcsim.contrib.onoprien.util.Driver;
+
import org.lcsim.contrib.onoprien.vsegment.algorithm.ChargeCollectorDemo;
import org.lcsim.contrib.onoprien.vsegment.algorithm.ClustererNearestNeighbor;
import org.lcsim.contrib.onoprien.vsegment.algorithm.HitMakerSmear;
@@ -23,15 +25,12 @@
import org.lcsim.contrib.onoprien.vsegment.process.Digitizer;
import org.lcsim.contrib.onoprien.vsegment.process.SensorFilter;
import org.lcsim.contrib.onoprien.vsegment.process.HitMaker;
-import org.lcsim.contrib.onoprien.util.Driver;
-
-import org.lcsim.contrib.onoprien.vsegment.diagnostics.HitPlotter;
/**
- *
+ * An example driver that runs tracker hit processing.
*
* @author D. Onoprienko
- * @version $Id: ExampleDriverSiD02.java,v 1.3 2008/11/05 03:32:47 onoprien Exp $
+ * @version $Id: ExampleDriverSiD02.java,v 1.4 2008/11/25 21:02:58 onoprien Exp $
*/
public class ExampleDriverSiD02 extends Driver {
@@ -103,16 +102,6 @@
});
add(clusterDriver);
-
- // -- Diagnostics - plotting hits : ---------------------------------------
- // Don't forget to comment this out if you run real reconstruction -
- // AIDA gobbles up time and memory
-
-// HitPlotter hitPlotter = new HitPlotter();
-// hitPlotter.set("LOG_LEVEL", Level.FINE);
-// hitPlotter.set("RAW_DATA_MAP_NAME", nameRawTrackerData);
-// hitPlotter.set("CLUSTER_MAP_NAME", nameTrackerClusters);
-// add(hitPlotter);
}
lcsim/src/org/lcsim/contrib/onoprien/vsegment
diff -u -r1.2 -r1.3
--- ExampleTrackingDriver.java 5 Nov 2008 03:32:47 -0000 1.2
+++ ExampleTrackingDriver.java 25 Nov 2008 21:02:58 -0000 1.3
@@ -7,14 +7,17 @@
import org.lcsim.recon.tracking.seedtracker.SeedTracker;
import org.lcsim.recon.tracking.seedtracker.StrategyXMLUtils;
-import org.lcsim.contrib.onoprien.vsegment.process.HelicalTrackHitConverter;
import org.lcsim.contrib.onoprien.util.Driver;
+import org.lcsim.contrib.onoprien.vsegment.process.HelicalTrackHitConverter;
+
/**
- *
+ * An example driver that runs virtual segmentation based hit processing, converts hits into
+ * {@link org.lcsim.fit.helicaltrack.HelicalTrackHit} format, then runs <tt>Seedtracker</tt>
+ * track finder.
*
* @author D. Onoprienko
- * @version $Id: ExampleTrackingDriver.java,v 1.2 2008/11/05 03:32:47 onoprien Exp $
+ * @version $Id: ExampleTrackingDriver.java,v 1.3 2008/11/25 21:02:58 onoprien Exp $
*/
public class ExampleTrackingDriver extends Driver {
lcsim/src/org/lcsim/contrib/onoprien/util/job
diff -N JobEvent.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ JobEvent.java 25 Nov 2008 21:02:58 -0000 1.1
@@ -0,0 +1,33 @@
+package org.lcsim.contrib.onoprien.util.job;
+
+import org.lcsim.geometry.Detector;
+import org.lcsim.event.EventHeader;
+
+/**
+ * Class that represents an event dispatched by {@link JobManager}.
+ *
+ * @author D. Onoprienko
+ * @version $Id: JobEvent.java,v 1.1 2008/11/25 21:02:58 onoprien Exp $
+ */
+public class JobEvent {
+
+// -- Constructors : ----------------------------------------------------------
+
+ public JobEvent(JobManager jobManager, Detector detector) {
+ _jMan = jobManager;
+ _det = detector;
+ }
+
+// -- Getters : ---------------------------------------------------------------
+
+ /** Returns <tt>JobManager</tt> object that fired this event. */
+ public JobManager getJobManager() {return _jMan;}
+
+ /** Returns <tt>Detector</tt> object describing the current geometry. */
+ public Detector getDetector() {return _det;}
+
+// -- Private parts : ---------------------------------------------------------
+
+ private JobManager _jMan;
+ private Detector _det;
+}
lcsim/src/org/lcsim/contrib/onoprien/util/job
diff -N JobEventListener.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ JobEventListener.java 25 Nov 2008 21:02:58 -0000 1.1
@@ -0,0 +1,13 @@
+package org.lcsim.contrib.onoprien.util.job;
+
+/**
+ * Interface to be implemented by classes listening to events dispatched by {@link JobManager}.
+ *
+ * @author D. Onoprienko
+ * @version $Id: JobEventListener.java,v 1.1 2008/11/25 21:02:58 onoprien Exp $
+ */
+public interface JobEventListener {
+
+ void detectorChanged(JobEvent jobEvent);
+
+}
lcsim/src/org/lcsim/contrib/onoprien/util/job
diff -N JobManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ JobManager.java 25 Nov 2008 21:02:58 -0000 1.1
@@ -0,0 +1,163 @@
+package org.lcsim.contrib.onoprien.util.job;
+
+import java.lang.ref.WeakReference;
+import java.util.*;
+
+import org.lcsim.conditions.ConditionsListener;
+import org.lcsim.conditions.ConditionsEvent;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException;
+import org.lcsim.contrib.onoprien.crux.geom.CalGeometry;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.aida.AIDA;
+
+import org.lcsim.contrib.onoprien.util.Driver;
+
+/**
+ * Driver that provides miscellaneous services to other classes.
+ * <p>
+ * Current functionality:
+ * <ul>
+ * <li>Accepts listener registration and dispatch events that trigger geometry dependent
+ * initialization in client classes.
+ * <li>Provides access to the default AIDA object that can be used for histogramming, plotting, etc.
+ * </ul>
+ *
+ * @author D. Onoprienko
+ * @version $Id: JobManager.java,v 1.1 2008/11/25 21:02:58 onoprien Exp $
+ */
+public class JobManager extends Driver implements ConditionsListener {
+
+// -- Constructors and initialization : ---------------------------------------
+
+ private JobManager() {
+ _aida = AIDA.defaultInstance();
+ getConditionsManager().addConditionsListener(this);
+ }
+
+ /**
+ * Called before processing the first event after receiving an event from the
+ * ConditionsManager, before calling DetectorChanged() methods of any listeners.
+ */
+ private void detectorChanged(JobEvent jobEvent) {
+ }
+
+// -- Getters : ---------------------------------------------------------------
+
+ /**
+ * Returns default instance of <tt>JobManager</tt>.
+ */
+ static public JobManager defaultInstance() {
+ if (_defInstance == null) _defInstance = new JobManager();
+ return _defInstance;
+ }
+
+ /** Returns default AIDA object that can be used for histogramming, plotting, etc. */
+ public AIDA getAIDA() {
+ return _aida;
+ }
+
+
+// -- Event processing : ------------------------------------------------------
+
+ /** Called by the framework to process event. */
+ public void process(EventHeader event) {
+
+ // Let the listeners know they have to re-validate themselves
+
+ if (_lastEvent == null) {
+ _lastEvent = new JobEvent(this, event.getDetector());
+ fireJobEvent(_lastEvent);
+ }
+
+ // Run daughter Drivers :
+
+ super.process(event);
+ }
+
+// -- Handling of event listeners : -------------------------------------------
+
+ /**
+ * Called by framework whenever an event is dispatched by {@link ConditionsManager}.
+ */
+ public void conditionsChanged(ConditionsEvent event) {
+ _lastEvent = null;
+ }
+
+ private void fireJobEvent(JobEvent jEvent) {
+ detectorChanged(jEvent);
+ ArrayList<JobEventListener> listeners = new ArrayList<JobEventListener>(_listeners.size());
+ for (WeakReference<JobEventListener> ref : _listeners) {
+ JobEventListener listener = ref.get();
+ if (listener != null) listeners.add(listener);
+ }
+ for (JobEventListener listener : listeners) {
+ listener.detectorChanged(jEvent);
+ }
+ }
+
+ /**
+ * Add a listener.
+ * <p>
+ * If the <tt>JobManager</tt> has valid detector information when a new listener is
+ * added, <tt>JobEvent</tt> is dispatched to that listener immediately.
+ * <p>
+ * Listeners are kept through weak references, so being registered with
+ * JobManager as a listener does not prevent objects from being garbage-collected.
+ *
+ * @param listener Listener to be added.
+ * @param prerequisite Zero or more listeners that should receive the event before the listener
+ * specified by the first parameter. Prerequisite listeners that have not been
+ * registered earlier will be added now (in order in which they are listed).
+ * If the listener specified by the first parameter is already registered,
+ * neither it nor its prerequisite will be added.
+ */
+ public void addListener(JobEventListener listener, JobEventListener... prerequisite) {
+
+ LinkedList<JobEventListener> prereq = new LinkedList<JobEventListener>(Arrays.asList(prerequisite));
+
+ Iterator<WeakReference<JobEventListener>> it = _listeners.iterator();
+ boolean newListener = true;
+ while (it.hasNext()) {
+ JobEventListener lstnr = it.next().get();
+ if (lstnr == null) {
+ it.remove();
+ } else if (lstnr == listener) {
+ newListener = false;
+ } else {
+ prereq.remove(lstnr);
+ }
+ }
+ if (newListener) {
+ for (JobEventListener preListener : prereq) {
+ _listeners.add(new WeakReference<JobEventListener>(preListener));
+ if (_lastEvent != null) preListener.detectorChanged(_lastEvent);
+ }
+ _listeners.add(new WeakReference<JobEventListener>(listener));
+ if (_lastEvent != null) listener.detectorChanged(_lastEvent);
+ }
+ _listeners.trimToSize();
+ }
+
+ /** Remove a listener. */
+ public void removeListener(JobEventListener listener) {
+ Iterator<WeakReference<JobEventListener>> it = _listeners.iterator();
+ while (it.hasNext()) {
+ JobEventListener lstnr = it.next().get();
+ if (lstnr == null || lstnr == listener) {
+ it.remove();
+ }
+ }
+ }
+
+// -- Private parts : ---------------------------------------------------------
+
+ static private JobManager _defInstance;
+
+ private JobEvent _lastEvent;
+ private ArrayList<WeakReference<JobEventListener>> _listeners = new ArrayList<WeakReference<JobEventListener>>(1);
+
+ private AIDA _aida;
+}
lcsim/src/org/lcsim/contrib/onoprien/util/job
diff -N package-info.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ package-info.java 25 Nov 2008 21:02:58 -0000 1.1
@@ -0,0 +1,4 @@
+/**
+ * Miscellaneous job management and support services.
+ */
+package org.lcsim.contrib.onoprien.util.job;
CVSspam 0.2.8