LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  December 2014

HPS-SVN December 2014

Subject:

r1769 - /java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClustererFactory.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Wed, 17 Dec 2014 01:01:31 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (106 lines)

Author: [log in to unmask]
Date: Tue Dec 16 17:01:27 2014
New Revision: 1769

Log:
Attempt to create a Clusterer by canonical class name if it is not found by its short name.

Modified:
    java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClustererFactory.java

Modified: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClustererFactory.java
 =============================================================================
--- java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClustererFactory.java	(original)
+++ java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClustererFactory.java	Tue Dec 16 17:01:27 2014
@@ -4,11 +4,23 @@
 import org.lcsim.conditions.ConditionsManager;
 
 /**
- * This is a convenience class for creating different kinds of clustering algorithms.
+ * <p>
+ * This is a convenience class for creating different kinds of clustering algorithms via their name.
+ * <p>
+ * The currently available types include:
+ * <ul>
+ * <li>{@link LegacyClusterer}</li>
+ * <li>{@link SimpleClasInnerCalClusterer}</li>
+ * <li>{@link ClasInnerCalClusterer</li>
+ * </ul>
+ * 
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public final class ClustererFactory {
     
+    /**
+     * We don't want this class to be instantiated.
+     */
     private ClustererFactory() {        
     }
     
@@ -21,17 +33,29 @@
      */
     public static Clusterer create(String name, double[] cuts) {
         Clusterer clusterer;
-        System.out.println("simple name:" + LegacyClusterer.class.getSimpleName());
-        if (LegacyClusterer.class.getSimpleName().equals(name)) {            
+        if (LegacyClusterer.class.getSimpleName().equals(name)) {
+            // Test Run legacy clusterer.
             clusterer = new LegacyClusterer();
         } else if (SimpleClasInnerCalClusterer.class.getSimpleName().equals(name)) {
+            // Simple IC clusterer.
             clusterer = new SimpleClasInnerCalClusterer();
+        } else if (ClasInnerCalClusterer.class.getSimpleName().equals(name)) {
+            // Full IC algorithm.
+            clusterer = new ClasInnerCalClusterer();
         } else {
-            throw new IllegalArgumentException("Unknown clusterer type: " + name);
+            // Try to instantiate the class from the name argument, assuming it is a canonical class name.
+            try {
+                clusterer = fromCanonicalClassName(name);
+            } catch (Exception e) {
+                // Okay nothing worked, so we have a problem!
+                throw new IllegalArgumentException("Unknown Clusterer type " + name + " cannot be instantiated.", e);
+            }
         }
+        // Add the Clusterer as a conditions listener so it can set itself up via the conditions system.
         if (clusterer instanceof ConditionsListener) {
             ConditionsManager.defaultInstance().addConditionsListener((ConditionsListener) clusterer);
         }
+        // Set cuts if they were provided.
         if (cuts != null) {
             clusterer.setCuts(cuts);
         }
@@ -40,10 +64,32 @@
     
     /**
      * Create a clustering algorithm with default cut values.
+     * This is just a simple wrapper to {@link #create(String, double[])}.
      * @param name The name of the clustering algorithm.
      * @return The clustering algorithm.
      */
     public static Clusterer create(String name) {
         return create(name, null);
     }
+    
+    /**
+     * Attempt to create a Clusterer object from the canonical class name.
+     * @param canonicalName
+     * @return
+     * @throw IllegalArgumentException if the class does not implement the Clusterer interface.
+     */
+    private static Clusterer fromCanonicalClassName(String canonicalName) {
+        Clusterer clusterer = null;
+        try {
+            Class<?> clustererClass = Class.forName(canonicalName);
+            Object object = clustererClass.newInstance();
+            if (!(object instanceof Clusterer)) { 
+                throw new IllegalArgumentException("The class " + canonicalName + " does not implement the Clusterer interface.");
+            } 
+            clusterer = (Clusterer) object;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return clusterer;
+    }
 }

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use