lcsim/src/org/lcsim/contrib/timb/util/lcio
diff -N AbstractBlockHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AbstractBlockHandler.java 26 May 2006 07:21:42 -0000 1.1
@@ -0,0 +1,59 @@
+package org.lcsim.util.lcio;
+
+import hep.lcd.io.sio.SIOBlock;
+import hep.lcd.io.sio.SIOInputStream;
+import hep.lcd.io.sio.SIOOutputStream;
+import hep.lcd.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.ReconstructedParticle;
+
+/**
+ *
+ * @author tonyj
+ */
+abstract class AbstractBlockHandler implements LCIOBlockHandler
+{
+ public void readBlock(LCIOEvent event, SIOBlock block) throws IOException
+ {
+ int major = block.getMajorVersion();
+ int minor = block.getMinorVersion();
+ int version = major*1000 + minor;
+ if (version < 8)
+ throw new IOException("Sorry: files created with versions older than v00-08" + " are no longer supported !");
+
+ SIOInputStream in = block.getData();
+
+ int flags = in.readInt();
+
+ SIOLCParameters colParameters = version > 1001 ? new SIOLCParameters(in) : new SIOLCParameters();
+ int n = in.readInt();
+ LCIOCollection collection = new LCIOCollection(getClassForType(), flags, n, colParameters);
+ event.put(block.getBlockName(),collection);
+ addCollectionElements(event,collection,in,n,version);
+ }
+ abstract void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException;
+
+ public void writeBlock(SIOWriter writer, List collection, LCMetaData md) throws IOException
+ {
+ SIOOutputStream out = writer.createBlock(md.getName(), LCIOConstants.MAJORVERSION, LCIOConstants.MINORVERSION);
+ int flags = md.getFlags();
+ out.writeInt(flags);
+ Map<String,int[]> intMap = md.getIntegerParameters();
+ Map<String,float[]> floatMap = md.getFloatParameters();
+ Map<String,String[]> stringMap = md.getStringParameters();
+ SIOLCParameters colParameters = null;
+ SIOLCParameters.write(intMap,floatMap,stringMap,out);
+ out.writeInt(collection.size());
+ // System.out.println(" AbstractBlockHandler out= "+out+" flags= "+flags+" collection.size()= "+collection.size());
+ for (Object element : collection)
+ {
+ // if(md.getName().equals("MCFastReconstructedParticles")) System.out.println(" AbstractBlockHandler ((ReconstructedParticle)element).getCharge()= "+((ReconstructedParticle)element).getCharge()+" getEnergy()= "+((ReconstructedParticle)element).getEnergy());
+ writeCollectionElement(element,out,flags);
+ }
+ out.close();
+ }
+ abstract void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException;
+}