Print

Print


Commit in lcsim/src/org/lcsim/contrib/seedtracker on MAIN
StrategyXMLUtils.java+54-21.3 -> 1.4
digiexample/DigiSeedTrackerDriver.java+7-61.4 -> 1.5
+61-8
2 modified files
CD - fix resource loading

lcsim/src/org/lcsim/contrib/seedtracker
StrategyXMLUtils.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- StrategyXMLUtils.java	17 Jul 2008 00:52:39 -0000	1.3
+++ StrategyXMLUtils.java	17 Jul 2008 21:11:36 -0000	1.4
@@ -8,10 +8,9 @@
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import org.jdom.Comment;
 import org.jdom.Document;
 import org.jdom.Element;
@@ -28,7 +27,28 @@
  */
 public class StrategyXMLUtils {
 
+    /**
+     * Returns the default location in the resource hierarchy of the strategy xml files. 
+     * @return
+     */
+    public static String getDefaultStrategiesPrefix(){
+        return "org/lcsim/contrib/seedtracker/strategybuilder/strategies/"; 
+    }
     
+    /**
+     * Returns a strategy list from an xml file in the default location
+     * in the resource hierarchy given the full path to the resource of the file
+     * (i.e. org/lcsim/contrib/seedtracker/strategybuilder/strategies/strategy.xml)
+     * 
+     * getDefaultStrategiesPrefix() may be helpful here. 
+     * @param resourceName the full name of the resource
+     * @return a list of strategies based on the resource xml file
+     */
+    public static List<SeedStrategy> getStrategyListFromResource(String resourceName) {
+        
+        return getStrategyListFromInputStream(StrategyXMLUtils.class.getClassLoader().
+                getResourceAsStream(resourceName)); 
+    }
     
     /**
      * Attempts to parse the given file as an XML file containing a well-formed
@@ -55,6 +75,38 @@
             io.printStackTrace();
             throw new RuntimeException("IO Exception occurred"); 
         }
+       
+        return getStrategyListFromDocument(doc); 
+        
+    }
+    
+     /**
+     * Attempts to parse the given input stream as an XML file containing a well-formed
+     * list of strategies. If successful, a list of SeedStrategies corresponding
+     * to the strategies defined in the file is generated. This method will 
+     * be useful if you are attempting to load resources using getResourceAsStream(). 
+     * 
+     * @param stream An InputStream object corresponding to the XML file. 
+     * @return the list of strategies corresponding to the input stream
+     */
+    public static List<SeedStrategy> getStrategyListFromInputStream(InputStream stream){
+        
+        Document doc; 
+        SAXBuilder builder = new SAXBuilder(); 
+        try {
+            doc = builder.build(stream); 
+        } catch (JDOMException jdom) {
+            jdom.printStackTrace();
+            throw new RuntimeException("JDOM exception occurred"); 
+        } catch (IOException io ) {
+            io.printStackTrace();
+            throw new RuntimeException("IO Exception occurred"); 
+        }
+       
+        return getStrategyListFromDocument(doc); 
+    }
+    
+    private static List<SeedStrategy> getStrategyListFromDocument(Document doc) {
         
         Element listElement = doc.getRootElement(); 
         List<SeedStrategy> ret = new ArrayList<SeedStrategy>(); 

lcsim/src/org/lcsim/contrib/seedtracker/digiexample
DigiSeedTrackerDriver.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- DigiSeedTrackerDriver.java	17 Jul 2008 19:52:01 -0000	1.4
+++ DigiSeedTrackerDriver.java	17 Jul 2008 21:11:36 -0000	1.5
@@ -5,7 +5,6 @@
 
 package org.lcsim.contrib.seedtracker.digiexample;
 
-import java.io.File;
 import org.lcsim.contrib.seedtracker.SeedTracker;
 import org.lcsim.contrib.seedtracker.StrategyXMLUtils;
 import org.lcsim.contrib.seedtracker.diagnostic.SeedTrackerDiagnostics;
@@ -19,15 +18,17 @@
  */
 public class DigiSeedTrackerDriver extends Driver{
     
-    private static final String strategy_file = "resources/org/lcsim/contrib/seedtracker/strategybuilder" +
-            "/strategies/autogen_100GeV_singleMuon_sid01_planar_tracker.xml";
+    private static final String strategy_file = "autogen_100GeV_singleMuon_sid01_planar_tracker.xml";
     
     public DigiSeedTrackerDriver() {
         add(new DigiHitMaker()); //this actually makes the hits 
 //        SeedTracker st = new SeedTracker(new BetterPlanarStrategy().getStrategies());
-        SeedTracker st = new SeedTracker(StrategyXMLUtils.getStrategyListFromFile(new File(strategy_file))); 
-        //st.setDiagnostics(new SeedTrackerDiagnostics());
+        
+ 
+        SeedTracker st = new SeedTracker(StrategyXMLUtils.getStrategyListFromResource(StrategyXMLUtils.getDefaultStrategiesPrefix() + strategy_file)); 
+//        st.setDiagnostics(new SeedTrackerDiagnostics());
         add(st);
-        //add(new AnalysisDriver());
+//        add(new AnalysisDriver());
+
     }
 }
CVSspam 0.2.8