3 added + 25 modified, total 28 files
lcsim/src/org/lcsim/util/lcio
diff -N LCIOCallback.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LCIOCallback.java 9 Oct 2007 22:56:22 -0000 1.1
@@ -0,0 +1,10 @@
+package org.lcsim.util.lcio;
+
+/**
+ * Allows block handlers to register to be called back at end of event.
+ * @author tonyj
+ */
+interface LCIOCallback
+{
+ void callback();
+}
lcsim/src/org/lcsim/util/lcio
diff -N SIOReferencesBlockHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SIOReferencesBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.1
@@ -0,0 +1,46 @@
+package org.lcsim.util.lcio;
+
+import hep.lcd.io.sio.SIOInputStream;
+import hep.lcd.io.sio.SIOOutputStream;
+import hep.lcd.io.sio.SIORef;
+import java.io.IOException;
+import java.util.ListIterator;
+import org.lcsim.event.MCParticle;
+
+/**
+ *
+ * @author tonyj
+ */
+class SIOReferencesBlockHandler extends AbstractBlockHandler
+{
+ private String type;
+ private Class classForType;
+ SIOReferencesBlockHandler(String type, Class classForType)
+ {
+ this.type = type;
+ this.classForType = classForType;
+ }
+ public String getType() { return type; }
+ public Class getClassForType() { return classForType; }
+
+ LCIOCallback addCollectionElements(LCIOEvent event, final LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ {
+ for (int i = 0; i < n; i++) collection.add(in.readPntr());
+ return new LCIOCallback()
+ {
+ public void callback()
+ {
+ for (ListIterator iter = collection.listIterator(); iter.hasNext(); )
+ {
+ SIORef ref = (SIORef) iter.next();
+ iter.set(ref.getObject());
+ }
+ }
+ };
+ }
+
+ void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
+ {
+ out.writePntr(element);
+ }
+}
lcsim/src/org/lcsim/util/lcio
diff -u -r1.8 -r1.9
--- LCIOWriter.java 12 Jul 2007 18:01:29 -0000 1.8
+++ LCIOWriter.java 9 Oct 2007 22:56:22 -0000 1.9
@@ -15,9 +15,13 @@
import org.lcsim.event.EventHeader;
import org.lcsim.event.EventHeader.LCMetaData;
-
/**
- *
+ * A class for writing out LCIO files
+ * The LCIO writer maintains a list of collections to ignore, and also a list of collections
+ * to write out. If the list of collections to write out is not empty then all collections
+ * are written out except those in the ignore list. If the list of collections to write out
+ * is not empty, then only the specified collections are written out (and the ignore list is
+ * ignored).
* @author Tony Johnson
*/
public class LCIOWriter
@@ -28,6 +32,7 @@
private int lastRunNumber = -1;
private String lastDetectorName = "";
private Set<String> ignore = new HashSet<String>();
+ private Set<String> only = new HashSet<String>();
/**
* Create a writer for writing LCIO files
@@ -73,6 +78,10 @@
{
ignore.add(collection);
}
+ public void addAllIgnore(Collection<String> collections)
+ {
+ ignore.addAll(collections);
+ }
/**
* Remove an entry to the list of collections to ignore (not write out)
* @param collection The collection to remove
@@ -81,6 +90,38 @@
{
ignore.remove(collection);
}
+ /** Clear the list of ignored collections.
+ */
+ public void clearIgnore()
+ {
+ ignore.clear();
+ }
+ /**
+ * Add an entry to the list of collections to write out
+ * @param collection The collection to tadd
+ */
+ public void addWriteOnly(String collection)
+ {
+ only.add(collection);
+ }
+ public void addAllWriteOnly(Collection<String> collections)
+ {
+ only.addAll(collections);
+ }
+ /**
+ * Remove an entry to the list of collections to write out
+ * @param collection The collection to remove
+ */
+ public void removeWriteOnly(String collection)
+ {
+ only.remove(collection);
+ }
+ /** Clear the list of collections to be written out
+ */
+ public void clearWriteOnly()
+ {
+ only.clear();
+ }
public void close() throws IOException
{
writer.close();
@@ -101,20 +142,27 @@
for (List<Object> collection : collections)
{
LCMetaData md = event.getMetaData(collection);
- Class type = md.getType();
- LCIOBlockHandler bh = manager.handlerForClass(type);
- if (bh == null) log.warning("No handler found for block "+md.getName()+" of class "+type.getName());
- else if(!ignore.contains(md.getName()))
+ if (!only.isEmpty() && !only.contains(md.getName())) continue;
+ else if (ignore.contains(md.getName())) continue;
+ else
{
- if (!isValidCollectionName(md.getName())) throw new IOException("Collection name "+md.getName()+" is invalid for LCIO");
- blocks.put(md.getName(),bh.getType());
+ Class type = md.getType();
+ LCIOBlockHandler bh = manager.handlerForClass(type,md.getFlags());
+ if (bh == null) log.warning("No handler found for block "+md.getName()+" of class "+type.getName());
+ else
+ {
+ if (!isValidCollectionName(md.getName())) throw new IOException("Collection name "+md.getName()+" is invalid for LCIO");
+ blocks.put(md.getName(),bh.getType());
+ }
}
}
out.writeInt(blocks.size());
for (Map.Entry<String,String> entry : blocks.entrySet() )
{
- if(!ignore.contains(entry.getKey()))
+ if (!only.isEmpty() && !only.contains(entry.getKey())) continue;
+ else if (ignore.contains(entry.getKey())) continue;
+ else
{
out.writeString(entry.getKey());
out.writeString(entry.getValue());
@@ -131,10 +179,11 @@
for (List<Object> collection : collections)
{
LCMetaData md = event.getMetaData(collection);
- Class type = md.getType();
- if(!ignore.contains(md.getName()))
+ if (!only.isEmpty() && !only.contains(md.getName())) continue;
+ else if (ignore.contains(md.getName())) continue;
+ else
{
- LCIOBlockHandler bh = manager.handlerForClass(type);
+ LCIOBlockHandler bh = manager.handlerForClass(md.getType(),md.getFlags());
if (bh != null) bh.writeBlock(writer,collection,md);
}
}
lcsim/src/org/lcsim/util/lcio
diff -u -r1.9 -r1.10
--- LCIOConstants.java 18 Sep 2007 03:46:26 -0000 1.9
+++ LCIOConstants.java 9 Oct 2007 22:56:22 -0000 1.10
@@ -71,10 +71,16 @@
// LCGenericObject
int GOBIT_FIXED = 31;
+ int BITTransient = 16 ;
+ int BITDefault = 17 ;
+ int BITSubset = 18 ;
+
String runRecordName = "LCRunHeader";
String runBlockName = "RunHeader";
String eventRecordName = "LCEvent";
String eventBlockName = "Event";
String eventHeaderRecordName = "LCEventHeader";
String eventHeaderBlockName = "EventHeader";
+
+ String references = "_References";
}
lcsim/src/org/lcsim/util/lcio
diff -u -r1.3 -r1.4
--- SIOCalorimeterHitBlockHandler.java 5 Apr 2006 18:43:39 -0000 1.3
+++ SIOCalorimeterHitBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.4
@@ -26,12 +26,13 @@
return CalorimeterHit.class;
}
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version)
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version)
throws IOException
{
LCMetaData meta = event.getMetaData(collection);
for (int i = 0; i < n; i++)
collection.add(new SIOCalorimeterHit(in, collection.getFlags(), version, meta));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.2 -r1.3
--- SIOGenericObjectBlockHandler.java 18 Sep 2007 19:04:24 -0000 1.2
+++ SIOGenericObjectBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.3
@@ -14,7 +14,7 @@
{
public String getType() { return "LCGenericObject"; }
public Class getClassForType() { return GenericObject.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
int flags = collection.getFlags();
if (LCIOUtil.bitTest(flags,LCIOConstants.GOBIT_FIXED))
@@ -30,6 +30,7 @@
for (int i = 0; i < n; i++)
collection.add(new SIOGenericObject(in, flags, version));
}
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.4 -r1.5
--- LCIOReader.java 23 Oct 2006 19:42:35 -0000 1.4
+++ LCIOReader.java 9 Oct 2007 22:56:22 -0000 1.5
@@ -7,6 +7,8 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.logging.Logger;
import org.lcsim.event.EventHeader;
@@ -54,15 +56,11 @@
SIOInputStream in = block.getData();
LCIOEvent event = new LCIOEvent(in);
- //if( (major<<16 | minor ) > (1<<16|1) )
- //{
- // parameters = new SIOLCParameters(in) ;
- //}
-
record = reader.readRecord();
name = record.getRecordName();
if (!LCIOConstants.eventRecordName.equals(name)) throw new IOException("LCIO record order problem");
+ List<LCIOCallback> callbacks = new ArrayList<LCIOCallback>();
for (;;)
{
block = record.getBlock();
@@ -72,10 +70,17 @@
if (type != null)
{
LCIOBlockHandler handler = manager.handlerForType(type);
- if (handler != null) handler.readBlock(event,block);
+ if (handler != null)
+ {
+ LCIOCallback callback = handler.readBlock(event,block);
+ if (callback != null) callbacks.add(callback);
+ }
else log.warning("No handler found for "+type);
}
}
+ // Give block handlers chance to clean up after entire event is read
+ for (LCIOCallback callback : callbacks) callback.callback();
+
return event;
}
}
lcsim/src/org/lcsim/util/lcio
diff -u -r1.2 -r1.3
--- SIOTPCHitBlockHandler.java 2 Aug 2005 17:18:06 -0000 1.2
+++ SIOTPCHitBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.3
@@ -14,10 +14,11 @@
{
public String getType() { return "TPCHit"; }
public Class getClassForType() { return TPCHit.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIOTPCHit(in, collection.getFlags(), version));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.2 -r1.3
--- SIOTrackerHitBlockHandler.java 2 Aug 2005 17:18:07 -0000 1.2
+++ SIOTrackerHitBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.3
@@ -15,10 +15,11 @@
{
public String getType() { return "TrackerHit"; }
public Class getClassForType() { return TrackerHit.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIOTrackerHit(in, collection.getFlags(), version));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
{
lcsim/src/org/lcsim/util/lcio
diff -u -r1.4 -r1.5
--- SIOSimCalorimeterHitBlockHandler.java 2 Aug 2005 17:18:06 -0000 1.4
+++ SIOSimCalorimeterHitBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.5
@@ -16,11 +16,12 @@
{
public String getType() { return "SimCalorimeterHit"; }
public Class getClassForType() { return SimCalorimeterHit.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
LCMetaData meta = event.getMetaData(collection);
for (int i = 0; i < n; i++)
collection.add(new SIOSimCalorimeterHit(in, collection.getFlags(), version, meta));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.1 -r1.2
--- LCIOUtil.java 16 Feb 2005 07:28:06 -0000 1.1
+++ LCIOUtil.java 9 Oct 2007 22:56:22 -0000 1.2
@@ -21,5 +21,11 @@
else flag &= ~mask;
return flag;
}
-
+ /**
+ * Create a bitMask for setting the specified bit
+ */
+ public static int bitMask(int bit)
+ {
+ return 1<<bit;
+ }
}
lcsim/src/org/lcsim/util/lcio
diff -u -r1.13 -r1.14
--- HandlerManager.java 18 Sep 2007 03:46:26 -0000 1.13
+++ HandlerManager.java 9 Oct 2007 22:56:22 -0000 1.14
@@ -47,9 +47,16 @@
}
LCIOBlockHandler handlerForType(String type)
{
- return handlerForType.get(type);
+ if (type.endsWith(LCIOConstants.references))
+ {
+ String subType = type.substring(0,type.length()-LCIOConstants.references.length());
+ LCIOBlockHandler subHandler = handlerForType.get(subType);
+ if (subHandler == null) return null;
+ else return new SIOReferencesBlockHandler(subType,subHandler.getClassForType());
+ }
+ else return handlerForType.get(type);
}
- LCIOBlockHandler handlerForClass(Class type)
+ LCIOBlockHandler handlerForClass(Class type, int flags)
{
LCIOBlockHandler handler = handlerForClass.get(type);
@@ -65,6 +72,10 @@
}
}
}
- return handler;
+ if (LCIOUtil.bitTest(flags,LCIOConstants.BITSubset))
+ {
+ return new SIOReferencesBlockHandler(handler.getType()+LCIOConstants.references,type);
+ }
+ else return handler;
}
}
lcsim/src/org/lcsim/util/lcio
diff -u -r1.5 -r1.6
--- SIOSimTrackerHitBlockHandler.java 3 Apr 2006 22:40:20 -0000 1.5
+++ SIOSimTrackerHitBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.6
@@ -23,12 +23,13 @@
return SimTrackerHit.class;
}
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version)
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version)
throws IOException
{
LCMetaData meta = event.getMetaData(collection);
for (int i = 0; i < n; i++)
collection.add(new SIOSimTrackerHit(in, collection.getFlags(), version, meta));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.1 -r1.2
--- SIOTrackerPulseBlockHandler.java 4 Jun 2007 06:50:39 -0000 1.1
+++ SIOTrackerPulseBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.2
@@ -14,10 +14,11 @@
{
public String getType() { return "TrackerPulse"; }
public Class getClassForType() { return TrackerPulse.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIOTrackerPulse(in, collection.getFlags(), version));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
{
lcsim/src/org/lcsim/util/lcio
diff -u -r1.1 -r1.2
--- SIOSiliconTrackerHitBlockHandler.java 19 Jun 2006 19:04:10 -0000 1.1
+++ SIOSiliconTrackerHitBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.2
@@ -4,8 +4,6 @@
import hep.lcd.io.sio.SIOOutputStream;
import java.io.IOException;
import org.lcsim.event.SiliconTrackerHit;
-
-import org.lcsim.event.TPCHit;
import org.lcsim.recon.tracking.digitization.SiliconRawHit;
/**
@@ -16,10 +14,11 @@
{
public String getType() { return "SiliconRawHit"; }
public Class getClassForType() { return SiliconRawHit.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIOSiliconTrackerHit(in, collection.getFlags(), version));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.7 -r1.8
--- AbstractBlockHandler.java 18 Sep 2007 03:46:26 -0000 1.7
+++ AbstractBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.8
@@ -10,12 +10,13 @@
import org.lcsim.event.EventHeader.LCMetaData;
/**
- *
+ * A default implementation of LCIOBlockHandler.
+ * This implementation assumes that the block corresponds to a LCIOCollection
* @author tonyj
*/
abstract class AbstractBlockHandler implements LCIOBlockHandler
{
- public void readBlock(LCIOEvent event, SIOBlock block) throws IOException
+ public LCIOCallback readBlock(LCIOEvent event, SIOBlock block) throws IOException
{
int major = block.getMajorVersion();
int minor = block.getMinorVersion();
@@ -31,9 +32,9 @@
int n = in.readInt();
LCIOCollection collection = new LCIOCollection(getClassForType(), flags, n, colParameters);
event.put(block.getBlockName(),collection);
- addCollectionElements(event,collection,in,n,version);
+ return addCollectionElements(event,collection,in,n,version);
}
- abstract void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException;
+ abstract LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException;
public void writeBlock(SIOWriter writer, List collection, LCMetaData md) throws IOException
{
lcsim/src/org/lcsim/util/lcio
diff -u -r1.2 -r1.3
--- SIORawCalorimeterHitBlockHandler.java 2 Aug 2005 17:18:06 -0000 1.2
+++ SIORawCalorimeterHitBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.3
@@ -10,18 +10,19 @@
* Block handler for raw calorimeter hits.
*
* @author Guilherme Lima
- * @version $Id: SIORawCalorimeterHitBlockHandler.java,v 1.2 2005/08/02 17:18:06 tonyj Exp $
+ * @version $Id: SIORawCalorimeterHitBlockHandler.java,v 1.3 2007/10/09 22:56:22 tonyj Exp $
*/
class SIORawCalorimeterHitBlockHandler extends AbstractBlockHandler
{
public String getType() { return "RawCalorimeterHit"; }
public Class getClassForType() { return RawCalorimeterHit.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection,
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection,
SIOInputStream in, int n, int version)
throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIORawCalorimeterHit(in, collection.getFlags(), version));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags)
lcsim/src/org/lcsim/util/lcio
diff -u -r1.2 -r1.3
--- SIOClusterBlockHandler.java 2 Aug 2005 17:18:06 -0000 1.2
+++ SIOClusterBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.3
@@ -14,10 +14,11 @@
{
public String getType() { return "Cluster"; }
public Class getClassForType() { return Cluster.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIOCluster(in, collection.getFlags(), version));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.5 -r1.6
--- SIOGenericObject.java 18 Sep 2007 19:04:24 -0000 1.5
+++ SIOGenericObject.java 9 Oct 2007 22:56:22 -0000 1.6
@@ -9,14 +9,10 @@
/**
*
* @author gaede
- * @version $Id: SIOGenericObject.java,v 1.5 2007/09/18 19:04:24 lima Exp $
+ * @version $Id: SIOGenericObject.java,v 1.6 2007/10/09 22:56:22 tonyj Exp $
*/
class SIOGenericObject implements GenericObject
{
- private static int[] nullI = new int[0];
- private static float[] nullF = new float[0];
- private static double[] nullD = new double[0];
-
private boolean _isFixedSize ;
private int[] _intVec;
private float[] _floatVec;
@@ -58,9 +54,7 @@
{
_doubleVec[i] = in.readDouble();
}
-
- // update pointer table
- in.readPTag(this);
+ in.readPTag(this);
}
static void write(GenericObject object, SIOOutputStream out, int flag) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.2 -r1.3
--- SIOReconstructedParticleBlockHandler.java 2 Aug 2005 17:18:06 -0000 1.2
+++ SIOReconstructedParticleBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.3
@@ -13,10 +13,11 @@
{
public String getType() { return "ReconstructedParticle"; }
public Class getClassForType() { return ReconstructedParticle.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIOReconstructedParticle(in, collection.getFlags(), version));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.2 -r1.3
--- SIOLCRelationBlockHandler.java 2 Aug 2005 17:18:06 -0000 1.2
+++ SIOLCRelationBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.3
@@ -10,18 +10,19 @@
* Block handler for relation objects.
*
* @author Guilherme Lima
- * @version $Id: SIOLCRelationBlockHandler.java,v 1.2 2005/08/02 17:18:06 tonyj Exp $
+ * @version $Id: SIOLCRelationBlockHandler.java,v 1.3 2007/10/09 22:56:22 tonyj Exp $
*/
class SIOLCRelationBlockHandler extends AbstractBlockHandler
{
public String getType() { return "LCRelation"; }
public Class getClassForType() { return LCRelation.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection,
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection,
SIOInputStream in, int n, int version)
throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIOLCRelation(in, collection.getFlags(), version));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags)
lcsim/src/org/lcsim/util/lcio
diff -u -r1.1 -r1.2
--- SIOTrackerDataBlockHandler.java 4 Jun 2007 06:50:39 -0000 1.1
+++ SIOTrackerDataBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.2
@@ -14,10 +14,11 @@
{
public String getType() { return "TrackerData"; }
public Class getClassForType() { return TrackerData.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIOTrackerData(in, collection.getFlags(), version));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
{
lcsim/src/org/lcsim/util/lcio
diff -u -r1.1 -r1.2
--- SIOVertexBlockHandler.java 18 Sep 2007 03:46:26 -0000 1.1
+++ SIOVertexBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.2
@@ -32,13 +32,15 @@
{
return Vertex.class;
}
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
String[] typeKeys = collection.getParameters().getStringMap().get(ALGORITHM_TYPES);
String[] parameterNames = collection.getParameters().getStringMap().get(PARAMETER_NAMES);
for (int i = 0; i < n; i++)
collection.add(new SIOVertex(in, collection.getFlags(), version, typeKeys, parameterNames));
+
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
{
lcsim/src/org/lcsim/util/lcio
diff -u -r1.1 -r1.2
--- SIORawTrackerHitBlockHandler.java 24 Oct 2006 19:01:49 -0000 1.1
+++ SIORawTrackerHitBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.2
@@ -22,12 +22,13 @@
return RawTrackerHit.class;
}
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version)
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version)
throws IOException
{
LCMetaData meta = event.getMetaData(collection);
for (int i = 0; i < n; i++)
collection.add(new SIORawTrackerHit(in, collection.getFlags(), version, meta));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.4 -r1.5
--- SIOMCParticleBlockHandler.java 2 Aug 2005 17:18:06 -0000 1.4
+++ SIOMCParticleBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.5
@@ -13,12 +13,19 @@
{
public String getType() { return "MCParticle"; }
public Class getClassForType() { return MCParticle.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, final LCIOCollection collection, SIOInputStream in, final int n, final int version) throws IOException
{
for (int i = 0; i < n; i++)
collection.add(new SIOMCParticle(in, collection.getFlags(), version));
- for (int i = 0; i < n; i++)
- ((SIOMCParticle) collection.get(i)).resolve(version);
+
+ return new LCIOCallback()
+ {
+ public void callback()
+ {
+ for (int i = 0; i < n; i++)
+ ((SIOMCParticle) collection.get(i)).resolve(version);
+ }
+ };
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
lcsim/src/org/lcsim/util/lcio
diff -u -r1.2 -r1.3
--- LCIOBlockHandler.java 16 Feb 2005 07:28:06 -0000 1.2
+++ LCIOBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.3
@@ -14,6 +14,10 @@
{
public Class getClassForType();
public String getType();
- public void readBlock(LCIOEvent event, SIOBlock block) throws IOException;
+ /** Called by the event reader to read a single block.
+ * It can return an LCIOCallback which will then be called after the entire
+ * event is read, or <code>null</code> if no callback is required.
+ */
+ public LCIOCallback readBlock(LCIOEvent event, SIOBlock block) throws IOException;
public void writeBlock(SIOWriter out, List collection, LCMetaData md) throws IOException;
}
lcsim/src/org/lcsim/util/lcio
diff -u -r1.3 -r1.4
--- SIOTrackBlockHandler.java 11 Sep 2007 18:18:04 -0000 1.3
+++ SIOTrackBlockHandler.java 9 Oct 2007 22:56:22 -0000 1.4
@@ -18,11 +18,12 @@
private static final Hep3Vector origin = new BasicHep3Vector();
public String getType() { return "Track"; }
public Class getClassForType() { return Track.class; }
- void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
{
double bField = event.getDetector().getFieldMap().getField(origin).z();
for (int i = 0; i < n; i++)
collection.add(new SIOTrack(in, collection.getFlags(), version, bField));
+ return null;
}
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
{
lcsim/test/org/lcsim
diff -N ReferenceIOTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ReferenceIOTest.java 9 Oct 2007 22:56:23 -0000 1.1
@@ -0,0 +1,82 @@
+package org.lcsim;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.TestCase;
+import org.freehep.record.loop.LoopException;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.MCParticle;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.lcio.*;
+import org.lcsim.util.loop.LCIODriver;
+import org.lcsim.util.loop.LCSimLoop;
+import org.lcsim.util.test.TestUtil.TestOutputFile;
+
+/**
+ *
+ * @author tonyj
+ */
+public class ReferenceIOTest extends TestCase
+{
+ public ReferenceIOTest(String testName)
+ {
+ super(testName);
+ }
+ public void testReferences() throws IOException, LoopException
+ {
+ final String detectorName = "sidaug05";
+ URL url = new URL("ftp://ftp-lcd.slac.stanford.edu/lcd/NewData/NLC500/ZZ/stdhep/pythia/pythiaZZ_nunu_bbbar.stdhep");
+ FileCache cache = new FileCache();
+ File stdhep = cache.getCachedFile(url);
+
+ File outputFile = new TestOutputFile("reference.slcio");
+
+ LCSimLoop loop = new LCSimLoop();
+ loop.setStdhepRecordSource(stdhep,detectorName);
+ loop.add(new ReferenceDriver());
+ loop.add(new LCIODriver(outputFile));
+ loop.loop(10, null);
+ assertEquals(10,loop.getTotalCountableSupplied());
+ loop.dispose();
+
+ // Now read it back in
+
+ LCSimLoop loop2 = new LCSimLoop();
+ loop2.setLCIORecordSource(outputFile);
+ loop2.loop(0,null);
+ loop.add(new TestReferenceDriver());
+ }
+ class ReferenceDriver extends Driver
+ {
+ protected void process(EventHeader event)
+ {
+ List<MCParticle> particles = event.getMCParticles();
+ List<MCParticle> half = new ArrayList<MCParticle>();
+ int i = 0;
+ for (MCParticle particle : particles)
+ {
+ if (i++ % 2 == 0)
+ {
+ half.add(particle);
+ }
+ }
+ event.put("SomeParticles",half,MCParticle.class,LCIOUtil.bitMask(LCIOConstants.BITSubset));
+ }
+ }
+ class TestReferenceDriver extends Driver
+ {
+ protected void process(EventHeader event)
+ {
+ List<MCParticle> particles = event.getMCParticles();
+ List<MCParticle> half = event.get(MCParticle.class,"SomeParticles");
+ for (int i=0; i<half.size(); i++)
+ {
+ assertEquals(half.get(i),particles.get(2*i));
+ }
+ }
+ }
+}
CVSspam 0.2.8