3 added + 2 removed + 3 modified, total 8 files
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/algorithms
diff -u -r1.1.1.1 -r1.2
--- ClusteringDriver.java 10 Dec 2008 22:03:06 -0000 1.1.1.1
+++ ClusteringDriver.java 12 Feb 2009 01:32:08 -0000 1.2
@@ -11,7 +11,6 @@
import org.lcsim.contrib.onoprien.util.job.Driver;
-import org.lcsim.contrib.onoprien.crux.auxdrivers.HitMapFilterDriver;
import org.lcsim.contrib.onoprien.crux.infrastructure.*;
/**
@@ -22,7 +21,7 @@
* input hit map from the event,
*
* @author D. Onoprienko
- * @version $Id: ClusteringDriver.java,v 1.1.1.1 2008/12/10 22:03:06 jeremy Exp $
+ * @version $Id: ClusteringDriver.java,v 1.2 2009/02/12 01:32:08 onoprien Exp $
*/
public class ClusteringDriver extends Driver {
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/tests
diff -u -r1.1.1.1 -r1.2
--- TestDriverClustering.java 10 Dec 2008 22:03:06 -0000 1.1.1.1
+++ TestDriverClustering.java 12 Feb 2009 01:32:08 -0000 1.2
@@ -15,7 +15,7 @@
import org.lcsim.contrib.onoprien.util.job.Driver;
import org.lcsim.contrib.onoprien.crux.algorithms.ClusteringDriver;
-import org.lcsim.contrib.onoprien.crux.auxdrivers.HitMapFilterDriver;
+import org.lcsim.contrib.onoprien.crux.recon.HitMapFilterDriver;
import org.lcsim.contrib.onoprien.crux.diagnostics.ClusteringTest;
import org.lcsim.contrib.onoprien.crux.infrastructure.*;
import org.lcsim.contrib.onoprien.crux.mctruth.MCTruthDriverCrux;
@@ -24,7 +24,7 @@
*
*
* @author D. Onoprienko
- * @version $Id: TestDriverClustering.java,v 1.1.1.1 2008/12/10 22:03:06 jeremy Exp $
+ * @version $Id: TestDriverClustering.java,v 1.2 2009/02/12 01:32:08 onoprien Exp $
*/
public class TestDriverClustering extends Driver {
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/tests
diff -u -r1.2 -r1.3
--- TestDriverRosary.java 22 Jan 2009 21:01:56 -0000 1.2
+++ TestDriverRosary.java 12 Feb 2009 01:32:08 -0000 1.3
@@ -21,7 +21,7 @@
import org.lcsim.contrib.onoprien.crux.algorithms.ValidationDriver;
import org.lcsim.contrib.onoprien.crux.algorithms.Validator;
import org.lcsim.contrib.onoprien.crux.algorithms.rosary.RosaryClusterer;
-import org.lcsim.contrib.onoprien.crux.auxdrivers.HitMapFilterDriver;
+import org.lcsim.contrib.onoprien.crux.recon.HitMapFilterDriver;
import org.lcsim.contrib.onoprien.crux.infrastructure.*;
import org.lcsim.contrib.onoprien.crux.mctruth.MCTruthDriverCrux;
import org.lcsim.contrib.onoprien.crux.cheat.CheatTrackFinderDriver;
@@ -31,7 +31,7 @@
*
*
* @author D. Onoprienko
- * @version $Id: TestDriverRosary.java,v 1.2 2009/01/22 21:01:56 onoprien Exp $
+ * @version $Id: TestDriverRosary.java,v 1.3 2009/02/12 01:32:08 onoprien Exp $
*/
public class TestDriverRosary extends Driver {
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/recon
diff -N CalorimeterDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CalorimeterDriver.java 12 Feb 2009 01:32:08 -0000 1.1
@@ -0,0 +1,100 @@
+package org.lcsim.contrib.onoprien.crux.recon;
+
+import org.lcsim.digisim.DigiSimDriver;
+import org.lcsim.digisim.SimCalorimeterHitsDriver;
+import org.lcsim.recon.cluster.util.CalHitMapDriver;
+
+import org.lcsim.contrib.onoprien.util.job.Driver;
+import org.lcsim.contrib.onoprien.util.job.JobEvent;
+import org.lcsim.contrib.onoprien.util.job.JobEventListener;
+import org.lcsim.contrib.onoprien.util.job.JobManager;
+
+import org.lcsim.contrib.onoprien.crux.recon.HitMapFilterDriver;
+import org.lcsim.contrib.onoprien.crux.geom.CalGeometry;
+import org.lcsim.contrib.onoprien.crux.geom.CalGeometryConfig;
+
+/**
+ * Driver that initializes calorimeter geometry and processes hits.
+ * <p>
+ * Runs Digisim to digitize hits, puts them into a {@link CruxHitMap}, adds the map
+ * to the event record.
+ *
+ * @author D. Onoprienko
+ * @version $Id: CalorimeterDriver.java,v 1.1 2009/02/12 01:32:08 onoprien Exp $
+ */
+public class CalorimeterDriver extends Driver implements JobEventListener {
+
+// -- Constructors and initialization : ---------------------------------------
+
+ public CalorimeterDriver() {
+ JobManager.defaultInstance().addListener(this);
+ }
+
+ public void detectorChanged(JobEvent jEvent) {
+
+ if ((_outMapName == null) || (_geomConfig == null)) throw new IllegalStateException(ERR_NS);
+
+ // Output of DigiSim is hit collections: "EcalBarrDigiHits", "EcalEndcapDigiHits",
+ // "HcalBarrDigiHits", "HcalEndcapDigiHits" (added to the event).
+ // FIXME: If those collections are all I need, a lot of large maps in CalHitMapMgr
+ // and LCRelation collections can be discarded to save memory - talk to Guilherme.
+
+ add(new CalHitMapDriver());
+ add(new DigiSimDriver());
+ add(new SimCalorimeterHitsDriver());
+
+ // Initialize geometry
+
+ CalGeometry geom = new CalGeometry(_geomConfig);
+ JobManager.defaultInstance().put(geom, CalGeometry.class);
+
+ // Put hits into map
+
+ HitMapFilterDriver mapMaker = new HitMapFilterDriver();
+ mapMaker.set("INPUT", "EcalBarrDigiHits","EcalEndcapDigiHits","HcalBarrDigiHits","HcalEndcapDigiHits");
+ mapMaker.set("OUTPUT", _outMapName);
+ add(mapMaker);
+ }
+
+
+// -- Setters : ---------------------------------------------------------------
+
+ /**
+ *
+ * Set any parameter.
+ * The following parameters can be set with this method:
+ * <p><dl>
+ * <dt>"OUTPUT_MAP_NAME"</dt> <dd>Name of output collection.<br>
+ * Default: <tt>null</tt> (must be specified before this driver can be used).</dd>
+ * <dt>"GEOMETRY_CONFIG"</dt> <dd>{@link CalGeometryConfig} object to be used by this driver.<br>
+ * Default: <tt>null</tt> (must be set before this driver can be used).</dd>
+ * </dl>
+ *
+ * @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 number of values, or a value
+ * of incorrect type is supplied.
+ */
+ public void set(String name, Object... values) {
+ Object value = values.length == 0 ? null : values[0];
+ try {
+ if (name.equalsIgnoreCase("OUTPUT_MAP_NAME")) {
+ _outMapName = (String) value;
+ } else if (name.equalsIgnoreCase("GEOMETRY_CONFIG")) {
+ _geomConfig = (CalGeometryConfig) value;
+ JobManager.defaultInstance().addListener(this, _geomConfig);
+ } else {
+ super.set(name, values);
+ }
+ } catch (ClassCastException x) {
+ throw new IllegalArgumentException(ERR_VIT, x);
+ }
+ }
+
+
+// -- Private parts : ---------------------------------------------------------
+
+ private String _outMapName;
+ private CalGeometryConfig _geomConfig;
+}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/recon
diff -N HitMapFilterDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HitMapFilterDriver.java 12 Feb 2009 01:32:08 -0000 1.1
@@ -0,0 +1,268 @@
+package org.lcsim.contrib.onoprien.crux.recon;
+
+import java.util.*;
+import java.util.logging.Level;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.hitmap.HitMap;
+
+import org.lcsim.contrib.onoprien.util.job.Driver;
+
+import org.lcsim.contrib.onoprien.crux.infrastructure.*;
+
+/**
+ * Driver that creates new hit maps or lists containing only those hits from the
+ * input maps or lists that pass the filters. Can also be used to combine or split
+ * maps or lists, or to convert maps into lists and vice versa.
+ * <p>
+ * See {@link #set set} method documentation for details.
+ * <p>
+ * Note that as long as accepting or rejecting the hit only depends on the {@link CalorimeterHit}
+ * object itself, there is no need to assign hit map to {@link CruxHitFilter} before processing. In cases where
+ * the decision requires access to a hit map (for example, when the filter need to look up neighbouring
+ * hits), the map can be specified through a call to <tt>set("ID_TO_HIT_MAP", mapName)</tt>.
+ * If no map has been specified in this way, the input map being filtered will also be
+ * used by the filter to look up hits by their <tt>CellID</tt>.
+ *
+ * @author D. Onoprienko
+ * @version $Id: HitMapFilterDriver.java,v 1.1 2009/02/12 01:32:08 onoprien Exp $
+ */
+public class HitMapFilterDriver extends Driver {
+
+// -- Constructors : ----------------------------------------------------------
+
+ public HitMapFilterDriver() {
+ }
+
+// -- Setters : ---------------------------------------------------------------
+
+ /**
+ * Set any parameter.
+ * The following parameters can be set with this method:
+ * <p><dl>
+ * <dt>"INPUT"</dt> <dd>Names of input collections or maps of {@link CalorimeterHit} objects.<br>
+ * Several input sources can be combined by calling this method several times, or
+ * by providing several names in a single call. If a collection with the given name
+ * is not present in the event record, it is assumed to be empty and ignored.</dd>
+ * <dt>"EXCLUDE"</dt> <dd>Names of {@link CalorimeterHit} collections or maps that need to be subtracted
+ * from the input collections. Hits present in these collections will not be included into
+ * the output collections whether or not they pass the filters. If a collection with the given name
+ * is not present in the event record, it is assumed to be empty and ignored.
+ * Several collections can be excluded by calling this method several times,
+ * or by providing several names in a single call.</dd>
+ * <dt>"OUTPUT"</dt> <dd>The first value is the name under which the output collection should
+ * be saved into the event record. If the collection with this name already exists,
+ * its contents will be added to the output collection without any filtering.<br>
+ * The second (optional) value is the {@link CruxHitFilter} object - only hits that
+ * pass the filter will be added to this output collection. If this parameter
+ * is omitted, no filtering is applied.<br>
+ * The third (optional) value is a <tt>String</tt> that defines the type of output
+ * collection (can be "CruxHitMap", "ArrayList", "Map", "HitMap"). If this parameter
+ * is omitted, "CruxHitMap" is assumed.<br>
+ * Several output collections can be created, each with its own filter, by calling
+ * this method repeatedly.</dd>
+ * <dt>"ID_TO_HIT_MAP"</dt> <dd>Name of the map (of type <tt>Map<Long,CalorimeterHit></tt>
+ * or {@link CruxHitMap}) to be fetched from the event record and assigned to filters
+ * before event processing. Only filters that did not have a map previously assigned to
+ * them will be affected.
+ * <br>Default: <tt>null</tt> (input map being filtered is to be used).</dd></dl>
+ *
+ * @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 number of values, or a value
+ * of incorrect type is supplied.
+ */
+ public void set(String name, Object... values) {
+ Object value = values.length == 0 ? null : values[0];
+ try {
+ if (name.equalsIgnoreCase("INPUT")) {
+ for (Object ob : values) {
+ _inNames.add((String) ob);
+ }
+ _inNames.trimToSize();
+ } else if (name.equalsIgnoreCase("EXCLUDE")) {
+ for (Object ob : values) {
+ _excludeNames.add((String) ob);
+ }
+ _excludeNames.trimToSize();
+ } else if (name.equalsIgnoreCase("OUTPUT")) {
+ if (values.length > 3 || values.length < 1) throw new IllegalArgumentException(ERR_INV + name);
+ _outNames.add((String)(values[0])); _outNames.trimToSize();
+ CruxHitFilter filter = CruxHitFilter.ALL;
+ String type = CHM;
+ for (int i=1; i<values.length; i++) {
+ Object v = values[i];
+ if (v instanceof CruxHitFilter) {
+ filter = (CruxHitFilter)v;
+ } else if (v instanceof String) {
+ type = (String)v;
+ if (type.equalsIgnoreCase(CHM)) {
+ type = CHM;
+ } else if (type.equalsIgnoreCase(AL)) {
+ type = AL;
+ } else if (type.equalsIgnoreCase(HM)) {
+ type = HM;
+ } else if (type.equalsIgnoreCase(M)) {
+ type = M;
+ } else {
+ throw new IllegalArgumentException(ERR_IV + name);
+ }
+ }
+ }
+ _filters.add(filter); _filters.trimToSize();
+ _types.add(type); _types.trimToSize();
+ } else if (name.equalsIgnoreCase("ID_TO_HIT_MAP")) {
+ _defMapName = (String) value;
+ } else {
+ super.set(name, values);
+ }
+ } catch (ClassCastException x) {
+ throw new IllegalArgumentException(ERR_VIT, x);
+ }
+ }
+
+// -- Event processing : ------------------------------------------------------
+
+ /** Called by the framework to process an event. */
+ public void process(EventHeader event) {
+
+ super.process(event);
+
+ // Create collection of collections of input hits :
+
+ ArrayList<Collection<CalorimeterHit>> input = new ArrayList<Collection<CalorimeterHit>>(_inNames.size());
+ for (String name : _inNames) {
+ try {
+ Object col = event.get(name);
+ if (col instanceof Collection) {
+ input.add((Collection<CalorimeterHit>)col);
+ } else if (col instanceof Map) {
+ input.add(((Map<Long,CalorimeterHit>)col).values());
+ } else {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException x) {}
+ }
+
+ // Compile a set of hits to exclude
+
+ Set<CalorimeterHit> excludeSet;
+ if (_excludeNames.isEmpty()) {
+ excludeSet = Collections.<CalorimeterHit>emptySet();
+ } else {
+ excludeSet = new HashSet<CalorimeterHit>(200);
+ for (String name : _excludeNames) {
+ try {
+ Object o = event.get(name);
+ if (o instanceof Collection) {
+ excludeSet.addAll((Collection<CalorimeterHit>)o);
+ } else if (o instanceof Map) {
+ excludeSet.addAll(((Map<Long,CalorimeterHit>)o).values());
+ }
+ } catch (IllegalArgumentException x) {break;}
+ }
+ }
+
+ // Fetch default hit map and assign it to filters
+
+ int nOut = _filters.size();
+ boolean[] mapChanged = new boolean[nOut];
+ if (_defMapName != null) {
+ Map<Long, CalorimeterHit> defMap;
+ Object map = event.get(_defMapName);
+ if (map instanceof Map) {
+ defMap = (Map<Long, CalorimeterHit>) map;
+ } else if (map instanceof CruxHitMap) {
+ defMap = ((CruxHitMap)map).asMap();
+ } else {
+ throw new IllegalArgumentException();
+ }
+ for (int i=0; i<nOut; i++) {
+ CruxHitFilter filter = _filters.get(i);
+ if (filter != CruxHitFilter.ALL && filter.getHitMap() == null) {
+ filter.setHitMap(defMap);
+ mapChanged[i] = true;
+ } else {
+ mapChanged[i] = false;
+ }
+ }
+ }
+
+ // Create CruxHitMaps for output collections
+
+ ArrayList<CruxHitMap> outMaps = new ArrayList<CruxHitMap>(nOut);
+ for (int i=0; i<nOut; i++) {
+ try {
+ Object o = event.get(_outNames.get(i));
+ if (o instanceof CruxHitMap) {
+ outMaps.add((CruxHitMap)o);
+ } else if (o instanceof Collection) {
+ outMaps.add(new CruxHitMap((Collection<CalorimeterHit>)o));
+ } else if (o instanceof Map) {
+ outMaps.add(new CruxHitMap(((Map<Long,CalorimeterHit>)o).values()));
+ }
+ } catch (IllegalArgumentException x) {
+ outMaps.add(new CruxHitMap());
+ }
+ }
+
+ // Do filtering
+
+ for (Collection<CalorimeterHit> col : input) {
+ for (CalorimeterHit hit : col) {
+ if (! excludeSet.contains(hit)) {
+ for (int i=0; i<nOut; i++) {
+ if (_filters.get(i).pass(hit)) outMaps.get(i).add(hit);
+ }
+ }
+ }
+ }
+
+ // Reset hit maps associated with filters if necessary
+
+ if (_defMapName != null) {
+ for (int i=0; i<nOut; i++) {
+ if (mapChanged[i]) _filters.get(i).setHitMap(null);
+ }
+ }
+
+ // Save output collections
+
+ for (int i=0; i<nOut; i++) {
+ String type = _types.get(i);
+ if (type == CHM) {
+ event.put(_outNames.get(i), outMaps.get(i), CalorimeterHit.class, 0);
+ } else if (type == HM) {
+ event.put(_outNames.get(i), new HitMap(outMaps.get(i).asMap()));
+ } else if (type == AL) {
+ event.put(_outNames.get(i), new ArrayList(outMaps.get(i)), CalorimeterHit.class, 0);
+ } else if (type == M) {
+ event.put(_outNames.get(i), outMaps.get(i).asMap());
+ }
+ log("Saved "+ _outNames.get(i) +" with "+ outMaps.size() +" hits as "+ type, Level.FINER);
+ }
+
+ }
+
+
+// -- Private parts : ---------------------------------------------------------
+
+ static private final String CHM = "CruxHitMap";
+ static private final String HM = "HitMap";
+ static private final String AL = "ArrayList";
+ static private final String M = "Map";
+
+ private ArrayList<String> _inNames = new ArrayList<String>(1);
+
+ private ArrayList<String> _excludeNames = new ArrayList<String>(0);
+
+ private ArrayList<CruxHitFilter> _filters = new ArrayList<CruxHitFilter>(1);
+ private ArrayList<String> _outNames = new ArrayList<String>(1);
+ private ArrayList<String> _types = new ArrayList<String>(1);
+
+ private String _defMapName;
+
+ private String _err1 = "Requested output type is inconsistent with identically named existing collection";
+}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/recon
diff -N package-info.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ package-info.java 12 Feb 2009 01:32:08 -0000 1.1
@@ -0,0 +1,12 @@
+/**
+ * Miscellaneous drivers implementing various steps and functions in the event reconstruction chain.
+ * <p>
+ * These drivers are intended to be building blocks for assembling the master driver for a
+ * particular reconstruction or analysis job. Most drivers are configurable through their
+ * <tt>set(String parametername, Object... parameterValues)</tt> methods. Assembly and
+ * configuration can be done with an XML steering file.
+ *
+ * @author D. Onoprienko
+ */
+package org.lcsim.contrib.onoprien.crux.recon;
+
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/auxdrivers
diff -N HitMapFilterDriver.java
--- HitMapFilterDriver.java 10 Dec 2008 22:03:06 -0000 1.1.1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,268 +0,0 @@
-package org.lcsim.contrib.onoprien.crux.auxdrivers;
-
-import java.util.*;
-import java.util.logging.Level;
-
-import org.lcsim.event.CalorimeterHit;
-import org.lcsim.event.EventHeader;
-import org.lcsim.util.hitmap.HitMap;
-
-import org.lcsim.contrib.onoprien.util.job.Driver;
-
-import org.lcsim.contrib.onoprien.crux.infrastructure.*;
-
-/**
- * Driver that creates new hit maps or lists containing only those hits from the
- * input maps or lists that pass the filters. Can also be used to combine or split
- * maps or lists, or to convert maps into lists and vice versa.
- * <p>
- * See {@link #set set} method documentation for details.
- * <p>
- * Note that as long as accepting or rejecting the hit only depends on the {@link CalorimeterHit}
- * object itself, there is no need to assign hit map to {@link CruxHitFilter} before processing. In cases where
- * the decision requires access to a hit map (for example, when the filter need to look up neighbouring
- * hits), the map can be specified through a call to <tt>set("ID_TO_HIT_MAP", mapName)</tt>.
- * If no map has been specified in this way, the input map being filtered will also be
- * used by the filter to look up hits by their <tt>CellID</tt>.
- *
- * @author D. Onoprienko
- * @version $Id: HitMapFilterDriver.java,v 1.1.1.1 2008/12/10 22:03:06 jeremy Exp $
- */
-public class HitMapFilterDriver extends Driver {
-
-// -- Constructors : ----------------------------------------------------------
-
- public HitMapFilterDriver() {
- }
-
-// -- Setters : ---------------------------------------------------------------
-
- /**
- * Set any parameter.
- * The following parameters can be set with this method:
- * <p><dl>
- * <dt>"INPUT"</dt> <dd>Names of input collections or maps of {@link CalorimeterHit} objects.<br>
- * Several input sources can be combined by calling this method several times, or
- * by providing several names in a single call. If a collection with the given name
- * is not present in the event record, it is assumed to be empty and ignored.</dd>
- * <dt>"EXCLUDE"</dt> <dd>Names of {@link CalorimeterHit} collections or maps that need to be subtracted
- * from the input collections. Hits present in these collections will not be included into
- * the output collections whether or not they pass the filters. If a collection with the given name
- * is not present in the event record, it is assumed to be empty and ignored.
- * Several collections can be excluded by calling this method several times,
- * or by providing several names in a single call.</dd>
- * <dt>"OUTPUT"</dt> <dd>The first value is the name under which the output collection should
- * be saved into the event record. If the collection with this name already exists,
- * its contents will be added to the output collection without any filtering.<br>
- * The second (optional) value is the {@link CruxHitFilter} object - only hits that
- * pass the filter will be added to this output collection. If this parameter
- * is omitted, no filtering is applied.<br>
- * The third (optional) value is a <tt>String</tt> that defines the type of output
- * collection (can be "CruxHitMap", "ArrayList", "Map", "HitMap"). If this parameter
- * is omitted, "CruxHitMap" is assumed.<br>
- * Several output collections can be created, each with its own filter, by calling
- * this method repeatedly.</dd>
- * <dt>"ID_TO_HIT_MAP"</dt> <dd>Name of the map (of type <tt>Map<Long,CalorimeterHit></tt>
- * or {@link CruxHitMap}) to be fetched from the event record and assigned to filters
- * before event processing. Only filters that did not have a map previously assigned to
- * them will be affected.
- * <br>Default: <tt>null</tt> (input map being filtered is to be used).</dd></dl>
- *
- * @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 number of values, or a value
- * of incorrect type is supplied.
- */
- public void set(String name, Object... values) {
- Object value = values.length == 0 ? null : values[0];
- try {
- if (name.equalsIgnoreCase("INPUT")) {
- for (Object ob : values) {
- _inNames.add((String) ob);
- }
- _inNames.trimToSize();
- } else if (name.equalsIgnoreCase("EXCLUDE")) {
- for (Object ob : values) {
- _excludeNames.add((String) ob);
- }
- _excludeNames.trimToSize();
- } else if (name.equalsIgnoreCase("OUTPUT")) {
- if (values.length > 3 || values.length < 1) throw new IllegalArgumentException(ERR_INV + name);
- _outNames.add((String)(values[0])); _outNames.trimToSize();
- CruxHitFilter filter = CruxHitFilter.ALL;
- String type = CHM;
- for (int i=1; i<values.length; i++) {
- Object v = values[i];
- if (v instanceof CruxHitFilter) {
- filter = (CruxHitFilter)v;
- } else if (v instanceof String) {
- type = (String)v;
- if (type.equalsIgnoreCase(CHM)) {
- type = CHM;
- } else if (type.equalsIgnoreCase(AL)) {
- type = AL;
- } else if (type.equalsIgnoreCase(HM)) {
- type = HM;
- } else if (type.equalsIgnoreCase(M)) {
- type = M;
- } else {
- throw new IllegalArgumentException(ERR_IV + name);
- }
- }
- }
- _filters.add(filter); _filters.trimToSize();
- _types.add(type); _types.trimToSize();
- } else if (name.equalsIgnoreCase("ID_TO_HIT_MAP")) {
- _defMapName = (String) value;
- } else {
- super.set(name, values);
- }
- } catch (ClassCastException x) {
- throw new IllegalArgumentException(ERR_VIT, x);
- }
- }
-
-// -- Event processing : ------------------------------------------------------
-
- /** Called by the framework to process an event. */
- public void process(EventHeader event) {
-
- super.process(event);
-
- // Create collection of collections of input hits :
-
- ArrayList<Collection<CalorimeterHit>> input = new ArrayList<Collection<CalorimeterHit>>(_inNames.size());
- for (String name : _inNames) {
- try {
- Object col = event.get(name);
- if (col instanceof Collection) {
- input.add((Collection<CalorimeterHit>)col);
- } else if (col instanceof Map) {
- input.add(((Map<Long,CalorimeterHit>)col).values());
- } else {
- throw new IllegalArgumentException();
- }
- } catch (IllegalArgumentException x) {}
- }
-
- // Compile a set of hits to exclude
-
- Set<CalorimeterHit> excludeSet;
- if (_excludeNames.isEmpty()) {
- excludeSet = Collections.<CalorimeterHit>emptySet();
- } else {
- excludeSet = new HashSet<CalorimeterHit>(200);
- for (String name : _excludeNames) {
- try {
- Object o = event.get(name);
- if (o instanceof Collection) {
- excludeSet.addAll((Collection<CalorimeterHit>)o);
- } else if (o instanceof Map) {
- excludeSet.addAll(((Map<Long,CalorimeterHit>)o).values());
- }
- } catch (IllegalArgumentException x) {break;}
- }
- }
-
- // Fetch default hit map and assign it to filters
-
- int nOut = _filters.size();
- boolean[] mapChanged = new boolean[nOut];
- if (_defMapName != null) {
- Map<Long, CalorimeterHit> defMap;
- Object map = event.get(_defMapName);
- if (map instanceof Map) {
- defMap = (Map<Long, CalorimeterHit>) map;
- } else if (map instanceof CruxHitMap) {
- defMap = ((CruxHitMap)map).asMap();
- } else {
- throw new IllegalArgumentException();
- }
- for (int i=0; i<nOut; i++) {
- CruxHitFilter filter = _filters.get(i);
- if (filter != CruxHitFilter.ALL && filter.getHitMap() == null) {
- filter.setHitMap(defMap);
- mapChanged[i] = true;
- } else {
- mapChanged[i] = false;
- }
- }
- }
-
- // Create CruxHitMaps for output collections
-
- ArrayList<CruxHitMap> outMaps = new ArrayList<CruxHitMap>(nOut);
- for (int i=0; i<nOut; i++) {
- try {
- Object o = event.get(_outNames.get(i));
- if (o instanceof CruxHitMap) {
- outMaps.add((CruxHitMap)o);
- } else if (o instanceof Collection) {
- outMaps.add(new CruxHitMap((Collection<CalorimeterHit>)o));
- } else if (o instanceof Map) {
- outMaps.add(new CruxHitMap(((Map<Long,CalorimeterHit>)o).values()));
- }
- } catch (IllegalArgumentException x) {
- outMaps.add(new CruxHitMap());
- }
- }
-
- // Do filtering
-
- for (Collection<CalorimeterHit> col : input) {
- for (CalorimeterHit hit : col) {
- if (! excludeSet.contains(hit)) {
- for (int i=0; i<nOut; i++) {
- if (_filters.get(i).pass(hit)) outMaps.get(i).add(hit);
- }
- }
- }
- }
-
- // Reset hit maps associated with filters if necessary
-
- if (_defMapName != null) {
- for (int i=0; i<nOut; i++) {
- if (mapChanged[i]) _filters.get(i).setHitMap(null);
- }
- }
-
- // Save output collections
-
- for (int i=0; i<nOut; i++) {
- String type = _types.get(i);
- if (type == CHM) {
- event.put(_outNames.get(i), outMaps.get(i), CalorimeterHit.class, 0);
- } else if (type == HM) {
- event.put(_outNames.get(i), new HitMap(outMaps.get(i).asMap()));
- } else if (type == AL) {
- event.put(_outNames.get(i), new ArrayList(outMaps.get(i)), CalorimeterHit.class, 0);
- } else if (type == M) {
- event.put(_outNames.get(i), outMaps.get(i).asMap());
- }
- log("Saved "+ _outNames.get(i) +" with "+ outMaps.size() +" hits as "+ type, Level.FINER);
- }
-
- }
-
-
-// -- Private parts : ---------------------------------------------------------
-
- static private final String CHM = "CruxHitMap";
- static private final String HM = "HitMap";
- static private final String AL = "ArrayList";
- static private final String M = "Map";
-
- private ArrayList<String> _inNames = new ArrayList<String>(1);
-
- private ArrayList<String> _excludeNames = new ArrayList<String>(0);
-
- private ArrayList<CruxHitFilter> _filters = new ArrayList<CruxHitFilter>(1);
- private ArrayList<String> _outNames = new ArrayList<String>(1);
- private ArrayList<String> _types = new ArrayList<String>(1);
-
- private String _defMapName;
-
- private String _err1 = "Requested output type is inconsistent with identically named existing collection";
-}
lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/crux/auxdrivers
diff -N package-info.java
--- package-info.java 10 Dec 2008 22:03:06 -0000 1.1.1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,4 +0,0 @@
-/**
- * Auxiliary drivers and tools for Crux PFA.
- */
-package org.lcsim.contrib.onoprien.crux.auxdrivers;
CVSspam 0.2.8