lcsim/src/org/lcsim/util/lcio
diff -u -r1.5 -r1.6
--- LCIOWriter.java 3 May 2005 02:04:41 -0000 1.5
+++ LCIOWriter.java 17 Aug 2006 19:11:40 -0000 1.6
@@ -5,9 +5,12 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.logging.Logger;
import org.lcsim.event.EventHeader;
import org.lcsim.event.EventHeader.LCMetaData;
@@ -19,20 +22,65 @@
*/
public class LCIOWriter
{
- private Logger log = Logger.getLogger(LCIOWriter.class.getName());
+ private final static Logger log = Logger.getLogger(LCIOWriter.class.getName());
private SIOWriter writer;
- private HandlerManager manager = HandlerManager.instance();
+ private final HandlerManager manager = HandlerManager.instance();
private int lastRunNumber = -1;
private String lastDetectorName = "";
+ private Set<String> ignore = new HashSet<String>();
+ /**
+ * Create a writer for writing LCIO files
+ * @param file The file to write
+ */
public LCIOWriter(File file) throws IOException
{
writer = new SIOWriter(new FileOutputStream(file));
}
+ /**
+ * Create a writer for writing LCIO files
+ * @param file The name of the file to write
+ */
public LCIOWriter(String file) throws IOException
{
writer = new SIOWriter(new FileOutputStream(file));
}
+ /**
+ * Create a writer for writing LCIO files
+ * @param file The file to write
+ * @param ignoreCollections The collections that should not be written out.
+ */
+ public LCIOWriter(File file, Collection<String> ignoreCollections) throws IOException
+ {
+ this(file);
+ this.ignore = new HashSet(ignoreCollections);
+ }
+ /**
+ * Create a writer for writing LCIO files
+ * @param file The name of the file to write
+ * @param ignoreCollections The collections that should not be written out.
+ */
+ public LCIOWriter(String file, Collection<String> ignoreCollections) throws IOException
+ {
+ this(file);
+ this.ignore = new HashSet(ignoreCollections);
+ }
+ /**
+ * Add an entry to the list of collections to ignore (not write out)
+ * @param collection The collection to tadd
+ */
+ public void addIgnore(String collection)
+ {
+ ignore.add(collection);
+ }
+ /**
+ * Remove an entry to the list of collections to ignore (not write out)
+ * @param collection The collection to remove
+ */
+ public void removeIgnore(String collection)
+ {
+ ignore.add(collection);
+ }
public void close() throws IOException
{
writer.close();
@@ -56,14 +104,17 @@
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 blocks.put(md.getName(),bh.getType());
+ else if(!ignore.contains(md.getName())) blocks.put(md.getName(),bh.getType());
}
out.writeInt(blocks.size());
for (Map.Entry<String,String> entry : blocks.entrySet() )
{
- out.writeString(entry.getKey());
- out.writeString(entry.getValue());
+ if(!ignore.contains(entry.getKey()))
+ {
+ out.writeString(entry.getKey());
+ out.writeString(entry.getValue());
+ }
}
out.writeInt(0);
out.writeInt(0);
@@ -77,8 +128,11 @@
{
LCMetaData md = event.getMetaData(collection);
Class type = md.getType();
- LCIOBlockHandler bh = manager.handlerForClass(type);
- if (bh != null) bh.writeBlock(writer,collection,md);
+ if(!ignore.contains(md.getName()))
+ {
+ LCIOBlockHandler bh = manager.handlerForClass(type);
+ if (bh != null) bh.writeBlock(writer,collection,md);
+ }
}
}
}
@@ -117,8 +171,8 @@
}
private static class DefaultRunHeader implements LCIORunHeader
{
- private int run;
- private String name;
+ private final int run;
+ private final String name;
private final static String[] noDetectors = new String[0];
DefaultRunHeader(int run, String name)
{