Commit in lcsim on MAIN
test/org/lcsim/util/aida/AIDATest.java+50added 1.1
src/org/lcsim/util/aida/AIDA.java+33-291.1 -> 1.2
+83-29
1 added + 1 modified, total 2 files
Fix for LCSIM-31, plus test case

lcsim/test/org/lcsim/util/aida
AIDATest.java added at 1.1
diff -N AIDATest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ AIDATest.java	8 Aug 2005 05:22:30 -0000	1.1
@@ -0,0 +1,50 @@
+package org.lcsim.util.aida;
+
+import hep.aida.ICloud1D;
+import java.util.Random;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ *
+ * @author tonyj
+ */
+public class AIDATest extends TestCase
+{
+   public AIDATest(String testName)
+   {
+      super(testName);
+   }
+   
+   protected void setUp()
+   {
+      
+   }
+   
+   protected void tearDown()
+   {
+   }
+   
+   public static junit.framework.Test suite()
+   {
+      return new TestSuite(AIDATest.class);
+   }
+   
+   public void testRewind()
+   {
+      Random r = new Random();
+      AIDA aida = AIDA.defaultInstance();
+      ICloud1D c1 = aida.cloud1D("cloud");
+      for (int i=0; i<10000; i++) c1.fill(r.nextGaussian());
+      assertEquals(10000,c1.entries());
+      
+      aida.tree().mkdir("xyz");
+      ICloud1D c2 = aida.cloud1D("xyz/cloud");
+      for (int i=0; i<10000; i++) c2.fill(r.nextGaussian());
+      assertEquals(10000,c2.entries());
+      
+      aida.clearAll();
+      assertEquals(0,c1.entries());
+      assertEquals(0,c2.entries());
+   }
+}

lcsim/src/org/lcsim/util/aida
AIDA.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- AIDA.java	14 Mar 2005 16:11:35 -0000	1.1
+++ AIDA.java	8 Aug 2005 05:22:31 -0000	1.2
@@ -30,7 +30,7 @@
 
 /**
  * A convenience class for creating and filling histograms.
- * Histograms created using this class will be automcatically 
+ * Histograms created using this class will be automcatically
  * cleared when data is rewound.
  * @author Tony Johnson
  */
@@ -48,7 +48,7 @@
       if (defaultInstance == null) defaultInstance = new AIDA();
       return defaultInstance;
    }
-  
+   
    private AIDA()
    {
       try
@@ -63,7 +63,7 @@
          if (app instanceof Studio)
          {
             SequentialRecordLoop loop = (SequentialRecordLoop) ((Studio) app).getLookup().lookup(SequentialRecordLoop.class);
-            if (loop != null) loop.addRecordLoopListener(new RewindListener(tree));
+            if (loop != null) loop.addRecordLoopListener(new RewindListener(this));
          }
       }
       catch (IOException x)
@@ -87,7 +87,7 @@
       }
       catch (IllegalArgumentException x)
       {
-         return hf.createCloud1D(path, path, nMax); 
+         return hf.createCloud1D(path, path, nMax);
       }
    }
    
@@ -106,7 +106,7 @@
       }
       catch (IllegalArgumentException x)
       {
-         return hf.createCloud2D(path, path, nMax); 
+         return hf.createCloud2D(path, path, nMax);
       }
    }
    
@@ -131,7 +131,7 @@
    
    public IHistogram1D histogram1D(String path)
    {
-      IManagedObject obj = tree.find(path); 
+      IManagedObject obj = tree.find(path);
       if (obj instanceof IHistogram1D) return (IHistogram1D) obj;
       throw new RuntimeException(path +" is not a IHistogram1D");
    }
@@ -146,13 +146,13 @@
       }
       catch (IllegalArgumentException x)
       {
-         return hf.createHistogram1D(path, bins, lowerEdge, upperEdge);  
+         return hf.createHistogram1D(path, bins, lowerEdge, upperEdge);
       }
    }
    
    public IHistogram2D histogram2D(String path)
    {
-      IManagedObject obj = tree.find(path); 
+      IManagedObject obj = tree.find(path);
       if (obj instanceof IHistogram2D) return (IHistogram2D) obj;
       throw new RuntimeException(path +" is not a IHistogram2D");
    }
@@ -173,7 +173,7 @@
    
    public IHistogram3D histogram3D(String path)
    {
-      IManagedObject obj = tree.find(path); 
+      IManagedObject obj = tree.find(path);
       if (obj instanceof IHistogram3D) return (IHistogram3D) obj;
       throw new RuntimeException(path +" is not a IHistogram3D");
    }
@@ -188,9 +188,9 @@
       }
       catch (IllegalArgumentException x)
       {
-         return hf.createHistogram3D(path, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY, nBinsZ, lowerEdgeZ, upperEdgeZ);  
+         return hf.createHistogram3D(path, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY, nBinsZ, lowerEdgeZ, upperEdgeZ);
       }
-
+      
    }
    
    public IHistogramFactory histogramFactory()
@@ -200,7 +200,7 @@
    
    public IProfile1D profile1D(String path)
    {
-      IManagedObject obj = tree.find(path); 
+      IManagedObject obj = tree.find(path);
       if (obj instanceof IProfile1D) return (IProfile1D) obj;
       throw new RuntimeException(path +" is not a IProfile1D");
    }
@@ -221,7 +221,7 @@
    
    public IProfile2D profile2D(String path)
    {
-      IManagedObject obj = tree.find(path); 
+      IManagedObject obj = tree.find(path);
       if (obj instanceof IProfile2D) return (IProfile2D) obj;
       throw new RuntimeException(path +" is not a IProfile2D");
    }
@@ -236,7 +236,7 @@
       }
       catch (IllegalArgumentException x)
       {
-         return hf.createProfile2D(path, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY);  
+         return hf.createProfile2D(path, nBinsX, lowerEdgeX, upperEdgeX, nBinsY, lowerEdgeY, upperEdgeY);
       }
    }
    
@@ -256,8 +256,8 @@
       File dest = new File(name);
       if (dest.exists()) dest.delete();
       boolean rc = tempFile.renameTo(dest);
-      if (!rc) 
-      { 
+      if (!rc)
+      {
          byte[] buffer = new byte[32768];
          OutputStream out = new FileOutputStream(dest);
          InputStream in = new FileInputStream(tempFile);
@@ -285,31 +285,35 @@
          super(message,cause);
       }
    }
+   void clearAll()
+   {
+      String[] type = tree.listObjectNames("/",true);
+      for (int i=0; i<type.length; i++)
+      {
+         System.out.println(type[i]);
+         if (type[i].endsWith("/")) continue;
+         IManagedObject obj = tree.find(type[i]);
+         if (obj instanceof IBaseHistogram) ((IBaseHistogram) obj).reset();
+      }
+   }
    private static class RewindListener extends RecordLoopAdapter
    {
       private Reference weak;
-      RewindListener(ITree tree)
+      RewindListener(AIDA aida)
       {
-         weak = new WeakReference(tree);
+         weak = new WeakReference(aida);
       }
       public void loopReset(LoopEvent loopEvent)
       {
-         ITree tree = (ITree) weak.get();
-         if (tree != null)
+         AIDA aida = (AIDA) weak.get();
+         if (aida != null)
          {
-            String[] type = tree.listObjectNames();
-            for (int i=0; i<type.length; i++)
-            {
-               IManagedObject obj = tree.find(type[i]);
-               if (obj instanceof IBaseHistogram) ((IBaseHistogram) obj).reset();
-            }
+            aida.clearAll();
          }
          else
          {
             SequentialRecordLoop loop = (SequentialRecordLoop) loopEvent.getSource();
-            loop.removeRecordLoopListener(this);
-            
-            
+            loop.removeRecordLoopListener(this);   
          }
       }
    }
CVSspam 0.2.8