lcsim/src/org/lcsim/util/lcio
diff -u -r1.4 -r1.5
--- SIOGenericObjectBlockHandler.java 17 Oct 2007 02:06:23 -0000 1.4
+++ SIOGenericObjectBlockHandler.java 22 Mar 2011 16:48:36 -0000 1.5
@@ -2,7 +2,11 @@
import hep.io.sio.SIOInputStream;
import hep.io.sio.SIOOutputStream;
+import hep.io.sio.SIOWriter;
import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import org.lcsim.event.EventHeader.LCMetaData;
import org.lcsim.event.GenericObject;
@@ -32,6 +36,41 @@
}
return null;
}
+
+ @Override
+ public void writeBlock(SIOWriter writer, List collection, LCMetaData md) throws IOException {
+ SIOOutputStream out = writer.createBlock(md.getName(), LCIOConstants.MAJORVERSION, LCIOConstants.MINORVERSION);
+
+ List<SIOGenericObject> goCollection = collection;
+ // Note: treating empty collections as having variable size saves space
+ boolean isFixedSize = !goCollection.isEmpty();
+ if (isFixedSize) {
+ int nInt = goCollection.get(0).getNInt();
+ int nFloat = goCollection.get(0).getNFloat();
+ int nDouble = goCollection.get(0).getNDouble();
+ for (SIOGenericObject object : goCollection) {
+ isFixedSize &= object.getNInt()==nInt && object.getNFloat()==nFloat && object.getNDouble()==nDouble;
+ }
+ }
+ int flags = md.getFlags();
+ flags = LCIOUtil.bitSet(flags, LCIOConstants.GOBIT_FIXED, isFixedSize);
+ out.writeInt(flags);
+ Map<String,int[]> intMap = md.getIntegerParameters();
+ Map<String,float[]> floatMap = md.getFloatParameters();
+ Map<String,String[]> stringMap = md.getStringParameters();
+ SIOLCParameters.write(intMap,floatMap,stringMap,out);
+ if (isFixedSize) {
+ // We know collection is therefore not empty
+ out.writeInt(goCollection.get(0).getNInt());
+ out.writeInt(goCollection.get(0).getNFloat());
+ out.writeInt(goCollection.get(0).getNDouble());
+ }
+ out.writeInt(collection.size());
+ for (Object element : collection)
+ {
+ writeCollectionElement(element,out,flags);
+ }
+ out.close(); }
void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
{
lcsim/src/org/lcsim/util/lcio
diff -u -r1.7 -r1.8
--- SIOGenericObject.java 17 Oct 2007 02:06:23 -0000 1.7
+++ SIOGenericObject.java 22 Mar 2011 16:48:36 -0000 1.8
@@ -9,7 +9,7 @@
/**
*
* @author gaede
- * @version $Id: SIOGenericObject.java,v 1.7 2007/10/17 02:06:23 tonyj Exp $
+ * @version $Id: SIOGenericObject.java,v 1.8 2011/03/22 16:48:36 tonyj Exp $
*/
class SIOGenericObject implements GenericObject
{
@@ -57,12 +57,14 @@
in.readPTag(this);
}
- static void write(GenericObject object, SIOOutputStream out, int flag) throws IOException
+ static void write(GenericObject object, SIOOutputStream out, int flags) throws IOException
{
- out.writeInt(object.getNInt());
- out.writeInt(object.getNFloat());
- out.writeInt(object.getNDouble());
-
+ if (!LCIOUtil.bitTest(flags, LCIOConstants.GOBIT_FIXED))
+ {
+ out.writeInt(object.getNInt());
+ out.writeInt(object.getNFloat());
+ out.writeInt(object.getNDouble());
+ }
for(int i=0;i<object.getNInt();i++)
out.writeInt( object.getIntVal(i)) ;
for(int i=0;i<object.getNFloat();i++)