lcsim/src/org/lcsim/util/aida
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);
}
}
}