1 added + 8 modified, total 9 files
lcio/config
diff -u -r1.53 -r1.54
--- lcio.properties 24 May 2006 15:17:08 -0000 1.53
+++ lcio.properties 2 Jun 2006 00:22:56 -0000 1.54
@@ -1,7 +1,7 @@
# ANT property file for LCIO
#
# Author: Mark Donszelmann
-# Version: $Id: lcio.properties,v 1.53 2006/05/24 15:17:08 gaede Exp $
+# Version: $Id: lcio.properties,v 1.54 2006/06/02 00:22:56 jeremy Exp $
#
debug=true
@@ -93,7 +93,10 @@
war.dir=lib
jar.signed.jars=
jar.signed.dir=slib
-jar.includes=hadnietgehoeve
+#jar.includes=hadnietgehoeve
+# Include the lcio XML definition for SIODump.
+# --Jeremy McCormick, 6/1/2006
+jar.includes=doc/lcio.xml
jar.excludes=
#
lcio/src/java/hep/lcio/util
diff -N SIODumpCommandHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SIODumpCommandHandler.java 2 Jun 2006 00:22:57 -0000 1.1
@@ -0,0 +1,166 @@
+package hep.lcio.util;
+
+import hep.lcd.io.sio.SIOReader;
+import hep.lcd.io.sio.SIORecord;
+import hep.lcio.event.LCIO;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+
+/**
+ * Command-line handling for Tony's SIODump utility.
+ *
+ * @author jeremym
+ * @version $Id: SIODumpCommandHandler.java,v 1.1 2006/06/02 00:22:57 jeremy Exp $
+ */
+public class SIODumpCommandHandler extends CommandHandler
+{
+ File inputfile;
+ int verbosity = 4;
+ int ntoskip = 0;
+ int ntodump = 1;
+
+ public SIODumpCommandHandler()
+ {
+ super("siodump", "Dump low-level SIO information from an LCIO file.");
+
+ options = createSIODumpOptions();
+ }
+
+ /**
+ * Create options for the siodump command.
+ * @return An apache CLI Options object with siodump options.
+ */
+ private static Options createSIODumpOptions()
+ {
+ Options options = new Options();
+
+ Option opt = new Option("f", false, "Set the input LCIO file.");
+ opt.setArgs(1);
+ options.addOption(opt);
+
+ opt = new Option("s", true, "Set number of events to skip. (Must be >= 0) .");
+ opt.setArgs(1);
+ options.addOption(opt);
+
+ opt = new Option("v", true, "Set verbosity level. (Must be between 1 and 4) .");
+ opt.setArgs(1);
+ options.addOption(opt);
+
+ opt = new Option("n", true, "Set number of events to dump. (Must be > 0) .");
+ opt.setArgs(1);
+ options.addOption(opt);
+
+ return options;
+ }
+
+ /**
+ * Execute the siodump command with current options.
+ */
+ public void execute() throws Exception
+ {
+ // Create the SIO reader.
+ SIOReader reader = new SIOReader(new BufferedInputStream(new FileInputStream(inputfile)));
+
+ // Skip some records if selected.
+ if (ntoskip > 0)
+ {
+ int nread = 0;
+
+ for (;;)
+ {
+ SIORecord rec = reader.readRecord();
+
+ String recname = rec.getRecordName();
+ if (recname.compareTo(LCIO.LCEVENT) == 0)
+ {
+ // Increment number of events.
+ ++nread;
+ }
+
+ if (nread >= ntoskip)
+ break;
+ }
+ }
+
+ // Create the dumper.
+ SIODump dumper = new SIODump();
+
+ // Get the root of lcio.xml.
+ Element lcioxml = getLCIOXML();
+
+ // Dump the file.
+ dumper.dump(lcioxml, reader);
+ }
+
+ /**
+ * Parse the arguments for siodump options.
+ * @param argv The raw command-line options.
+ */
+ public void parse(String[] argv) throws Exception
+ {
+ CommandLine cl = parser.parse(options, argv);
+
+ if (cl.hasOption("f"))
+ {
+ inputfile = new File(cl.getOptionValue("f"));
+ }
+ else
+ {
+ printUsage(true);
+ }
+
+ if (cl.hasOption("n"))
+ {
+ ntodump = Integer.parseInt(cl.getOptionValue("n"));
+
+ if (ntodump > 0) {
+ SIODump.setMaxEvents(ntodump);
+ }
+ else {
+ printUsage(true);
+ }
+ }
+
+ if (cl.hasOption("s"))
+ {
+ ntoskip = Integer.parseInt(cl.getOptionValue("s"));
+
+ if (ntoskip < 0) {
+ printUsage(true);
+ }
+ }
+
+ if (cl.hasOption("v"))
+ {
+ verbosity = Integer.parseInt(cl.getOptionValue("v"));
+ SIODump.setVerbosity(verbosity);
+
+ if (verbosity < 0 || verbosity > 4) {
+ printUsage(true);
+ }
+ }
+ }
+
+ /**
+ * Get an @org.jdom.Element for the lcio.xml root.
+ * @return The Element representing the lcio.xml root node.
+ * @throws Exception
+ */
+ public static Element getLCIOXML() throws Exception
+ {
+ InputStream in = SIODumpCommandHandler.class.getResourceAsStream("/doc/lcio.xml");
+ SAXBuilder builder = new SAXBuilder();
+ Document doc = builder.build(in);
+ return doc.getRootElement();
+ }
+}
\ No newline at end of file
lcio/src/java/hep/lcio/util
diff -u -r1.3 -r1.4
--- CommandHandler.java 28 Apr 2006 23:38:48 -0000 1.3
+++ CommandHandler.java 2 Jun 2006 00:22:57 -0000 1.4
@@ -2,6 +2,8 @@
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
+import org.apache.commons.cli.Parser;
+import org.apache.commons.cli.PosixParser;
/**
*
@@ -9,7 +11,7 @@
* single command in the CommandLineTool.
*
* @author jeremym
- * @version $Id: CommandHandler.java,v 1.3 2006/04/28 23:38:48 jeremy Exp $
+ * @version $Id: CommandHandler.java,v 1.4 2006/06/02 00:22:57 jeremy Exp $
*/
public abstract class CommandHandler
@@ -17,6 +19,7 @@
String name;
String description;
Options options;
+ protected static Parser parser = new PosixParser();
/**
* CommandHandler ctor.
lcio/src/java/hep/lcio/util
diff -u -r1.5 -r1.6
--- CommandLineTool.java 28 Apr 2006 23:38:48 -0000 1.5
+++ CommandLineTool.java 2 Jun 2006 00:22:57 -0000 1.6
@@ -18,18 +18,26 @@
*
* lcio [global_options] [command] [command_options]
*
- * @see hep.lcio.util.Compare compare
- * @see hep.lcio.util.Concat concat
+ *
+ *
+ * @see hep.lcio.util.Concat concat [X]
+ *
+ * @see hep.lcio.util.MergeCommandHandler merge [X]
+ *
+ * @see hep.lcio.util.Split split [X]
+ *
+ * @see hep.lcio.util.SioDump siodump [X]
+ *
* @see hep.lcio.util.Headers head
- * @see hep.lcio.util.MergeCommandHandler merge
+ *
+ * @see hep.lcio.util.Compare compare
+ *
* @see hep.lcio.util.PrintEvent print
- * @see hep.lcio.util.SioDump siodump
- * @see hep.lcio.util.Split split
*
* FIXME: Implement all of the above commands.
*
* @author jeremym
- * @version $Id: CommandLineTool.java,v 1.5 2006/04/28 23:38:48 jeremy Exp $
+ * @version $Id: CommandLineTool.java,v 1.6 2006/06/02 00:22:57 jeremy Exp $
*/
public class CommandLineTool
{
@@ -87,12 +95,12 @@
addCommandHandler(new MergeCommandHandler());
addCommandHandler(new SplitCommandHandler());
addCommandHandler(new ConcatenateCommandHandler());
+ addCommandHandler(new SIODumpCommandHandler());
- // addCommandHandler("compare", Compare)
- // addCommandHandler("print", PrintEvent);
- // addCommandHandler("header", HeaderScan);
- // addCommandHandler("siodump", SioDump);
- // addCommandHandler("random", RandomEvent);
+ // addCommandHandler("compare", CompareCommandHandler())
+ // addCommandHandler("print", PrintEventCommandHandler());
+ // addCommandHandler("header", HeaderScanCommandHandler());
+ // addCommandHandler("random", RandomEventCommandHandler());
}
/**
lcio/src/java/hep/lcio/util
diff -u -r1.1 -r1.2
--- ConcatenateCommandHandler.java 28 Apr 2006 23:38:49 -0000 1.1
+++ ConcatenateCommandHandler.java 2 Jun 2006 00:22:57 -0000 1.2
@@ -15,7 +15,7 @@
* Command-line handling for concat command.
*
* @author jeremym
- * @version $Id: ConcatenateCommandHandler.java,v 1.1 2006/04/28 23:38:49 jeremy Exp $
+ * @version $Id: ConcatenateCommandHandler.java,v 1.2 2006/06/02 00:22:57 jeremy Exp $
*/
public class ConcatenateCommandHandler extends CommandHandler
{
@@ -69,7 +69,6 @@
*/
public void parse(String[] argv) throws Exception
{
- Parser parser = new PosixParser();
CommandLine cl = parser.parse(options, argv);
// One of '-i' or '-f' is required.
lcio/src/java/hep/lcio/util
diff -u -r1.5 -r1.6
--- MergeCommandHandler.java 28 Apr 2006 23:38:48 -0000 1.5
+++ MergeCommandHandler.java 2 Jun 2006 00:22:57 -0000 1.6
@@ -20,11 +20,10 @@
* passes the results to a method from MergeUtil.
*
* @author jeremym
- * @version $Id: MergeCommandHandler.java,v 1.5 2006/04/28 23:38:48 jeremy Exp $
+ * @version $Id: MergeCommandHandler.java,v 1.6 2006/06/02 00:22:57 jeremy Exp $
*/
public class MergeCommandHandler extends CommandHandler
{
- Parser parser = new PosixParser();
File outfile;
File[] infiles;
int maxevents = Integer.MAX_VALUE;
lcio/src/java/hep/lcio/util
diff -u -r1.5 -r1.6
--- SIODump.java 10 May 2005 01:52:10 -0000 1.5
+++ SIODump.java 2 Jun 2006 00:22:57 -0000 1.6
@@ -2,6 +2,8 @@
import gnu.jel.*;
import hep.lcd.io.sio.*;
+import hep.lcio.event.LCIO;
+
import java.io.BufferedInputStream;
import java.io.EOFException;
import java.io.FileInputStream;
@@ -37,411 +39,502 @@
*/
public class SIODump
{
- private static final Pattern pattern1 = Pattern.compile("(\\w+)(?:\\[(.*)\\])?");
- private String recordName;
- private String blockName;
- private Map blockMap = new HashMap();
- private Map compilers = new HashMap();
- private Map dimensions = new HashMap();
- private static int verbosity = 1;
- private int nWarnings = 0;
- private List output = new LinkedList();
- private int global = 0;
- private Set versionAlreadyWarned = new HashSet();
- private Map subroutines = new HashMap();
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException, JDOMException
- {
- String[] params = new String[2];
- int nParams = 0;
- for (int i=0; i<args.length; i++)
- {
- if (args[i].equals("-v")) verbosity = Integer.parseInt(args[++i]);
- else
- {
- if (nParams >= 2) help();
- params[nParams++] = args[i];
- }
- }
-
- if (nParams < 2) help();
-
- SAXBuilder builder = new SAXBuilder();
- Document doc = builder.build(params[0]);
- Element root = doc.getRootElement();
-
- SIOReader reader = new SIOReader(new BufferedInputStream(new FileInputStream(params[1])));
- SIODump dumper = new SIODump();
- dumper.dump(root,reader);
- }
- private SIODump()
- {
- }
- private void dump(Element root,SIOReader reader) throws IOException, JDOMException
- {
- try
- {
- // Build subroutine list
- for (Iterator i = root.getChildren("subroutine").iterator(); i.hasNext();)
- {
- Element node = (Element) i.next();
- subroutines.put(node.getAttributeValue("name"), node);
- }
- int n=0;
- for (;;n++)
- {
- SIORecord record;
- try
- {
- record = reader.readRecord();
- }
- catch (EOFException x)
- {
- break;
- }
- String recName = record.getRecordName();
- Element recordElement = (Element) XPath.selectSingleNode(root,"record[@name=\""+recName+"\"]");
- if (recordElement == null)
- {
- warn("Skipping unrecognized record: "+recName);
- }
- else
- {
- global = 0;
- dumpRecord(record,recordElement);
- flush();
- }
- }
- dump(0,"Read "+n+" records with "+nWarnings+" warnings");
- }
- finally
- {
- reader.close();
- flush();
- }
- }
- private void dumpRecord(SIORecord record, Element root) throws IOException, JDOMException
- {
- recordName = record.getRecordName();
- dump(1,"Record: "+recordName);
- for (;;)
- {
- SIOBlock block = record.getBlock();
- if (block == null) return;
- String blockName = block.getBlockName();
- // LCIO Special
- Object blockType = blockMap.get(blockName);
- if (blockType == null) blockType = blockName;
- //fg -- allow one generic bloc for references
- if( blockType.toString().endsWith("_References") )
- blockType = "References" ;
-
-
- Element blockElement = (Element) XPath.selectSingleNode(root,"block[@name=\""+blockType+"\"]");
- if (blockElement == null)
- {
- warn("Skipping unrecognized block type: "+blockType);
- }
- else
- {
- dumpBlock(block,blockElement);
- }
- }
- }
- private void dumpBlock(SIOBlock block, Element root) throws IOException, JDOMException
- {
- blockName = block.getBlockName();
- String version = block.getMajorVersion()+"."+block.getMinorVersion();
- dump(2," Block: "+blockName+" (v"+version+")");
- String expectedVersion = root.getAttributeValue("major")+"."+root.getAttributeValue("minor");
- String key = blockName+":"+version;
- if (!version.equals(expectedVersion) && !versionAlreadyWarned.contains(key))
- {
- warn("For block "+blockName+" expected v"+expectedVersion+" got v"+version);
- versionAlreadyWarned.add(key);
- }
- Map values = new HashMap();
- values.put("major", new Integer(block.getMajorVersion()));
- values.put("minor", new Integer(block.getMinorVersion()));
- SIOInputStream data = block.getData();
- dumpValues(data,root," ",values);
- if (data.available() != 0) warn(data.available()+" unread bytes in block "+blockName);
- }
- private void dumpValues(SIOInputStream data, Element root, String indent, Map values) throws IOException, JDOMException
- {
- dumpValues(data,root,indent, values,false);
- }
- private void dumpValues(SIOInputStream data, Element root, String indent, Map values, boolean skip) throws IOException, JDOMException
- {
- Iterator it = root.getChildren().iterator();
- while (it.hasNext())
- {
- Element node = (Element) it.next();
- String nodeName = node.getName();
- if (nodeName.equals("else"))
- {
- skip = !skip;
- }
- else if (skip) { }
- else if (nodeName.equals("data"))
- {
- String type = node.getAttributeValue("type");
- String name = node.getAttributeValue("name");
- Object value = readValue(data,type,values);
- dump(3,indent+name+": ",value);
- values.put(name,value);
- }
- else if (nodeName.equals("include"))
- {
- String subroutine = node.getAttributeValue("subroutine");
- Element subNode = (Element) subroutines.get(subroutine);
- if (subNode == null) throw new JDOMException("Unknown subroutine "+subroutine+" included");
- dumpValues(data,subNode,indent,values);
- }
- else if (nodeName.equals("repeat"))
- {
- String countName = node.getAttributeValue("count");
- int icount = evaluateInteger(countName,values,node);
- for (int i=0; i<icount; i++)
- {
- dumpValues(data,node,indent+"["+i+"]",values);
- // LCIO Special
- if (recordName.equals("LCEventHeader") && blockName.equals("EventHeader"))
- {
- blockMap.put(values.get("blockName"),values.get("blockType"));
- }
- }
- }
- else if (nodeName.equals("if"))
- {
- String condition = node.getAttributeValue("condition");
- boolean booleanCondition = evaluateBoolean(condition,values,node);
- dumpValues(data,node,indent,values,!booleanCondition);
- }
- else warn("Ignoring element: "+node.getName());
- }
- }
- private Object readValue(SIOInputStream data, String declaration, Map values) throws IOException, JDOMException
- {
- String[] dims = (String[]) dimensions.get(declaration);
- if (dims == null)
- {
- //TODO: Currently only support a single dimension
- Matcher matcher = pattern1.matcher(declaration);
- if (!matcher.matches()) throw new JDOMException("Invalid type: "+declaration);
- dims = new String[2];
- dims[0] = matcher.group(1).intern();
- dims[1] = matcher.group(2);
- dimensions.put(declaration,dims);
- }
- String type = dims[0];
- if (dims[1] != null)
- {
- int iDim = evaluateInteger(dims[1],values,declaration);
- StringBuffer result = new StringBuffer("[");
- for (int i=0;;)
- {
- result.append(readValue(data,type,values));
- if (++i == iDim) break;
- result.append(",");
- }
- result.append("]");
- return result.toString();
- }
- else
- {
- if (type == "int") return new Integer(data.readInt());
- else if (type == "long") return new Long(data.readLong());
- else if (type == "short") return new Short(data.readShort());
- else if (type == "byte") return new Byte(data.readByte());
- else if (type == "double") return new Double(data.readDouble());
- else if (type == "float") return new Float(data.readFloat());
- else if (type == "boolean") return data.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
- else if (type == "string") return data.readString();
- else if (type == "ptag")
- {
- String objectName = "Object["+(global++)+"]";
- data.readPTag(objectName); return objectName;
- }
- else if (type == "pntr") return data.readPntr();
- else throw new JDOMException("Unrecognized type: "+type);
- }
- }
- private int evaluateInteger(String expression, Map values, Object key) throws IOException, JDOMException
- {
- try
- {
- Resolver resolver = new Resolver(values);
- CompiledExpression expr_c = (CompiledExpression) compilers.get(key);
- if (expr_c == null)
- {
- expr_c = Evaluator.compile(expression,createJELLibrary(resolver),Integer.TYPE);
- compilers.put(key,expr_c);
- }
- return expr_c.evaluate_int(new Object[]{resolver});
- }
- catch (CompilationException x)
- {
- JDOMException xx = new JDOMException("Invalid expression: "+expression);
- xx.initCause(x);
- throw xx;
- }
- catch (Throwable x)
- {
- JDOMException xx = new JDOMException("Error evaluating expression: "+expression);
- xx.initCause(x);
- throw xx;
- }
- }
- private boolean evaluateBoolean(String expression, Map values, Object key) throws IOException, JDOMException
- {
- try
- {
- Resolver resolver = new Resolver(values);
- CompiledExpression expr_c = (CompiledExpression) compilers.get(key);
- if (expr_c == null)
- {
- expr_c = Evaluator.compile(expression,createJELLibrary(resolver),Boolean.TYPE);
- compilers.put(key,expr_c);
- }
- return expr_c.evaluate_boolean(new Object[]{resolver});
- }
- catch (CompilationException x)
- {
- JDOMException xx = new JDOMException("Invalid expression: "+expression);
- xx.initCause(x);
- throw xx;
- }
- catch (Throwable x)
- {
- JDOMException xx = new JDOMException("Error evaluating expression: "+expression);
- xx.initCause(x);
- throw xx;
- }
- }
- private Library createJELLibrary(Resolver resolver)
- {
- Class[] dynamicLib = { Resolver.class };
- Class[] staticLib=new Class[1];
- try
- {
- staticLib[0]=Class.forName("java.lang.Math");
- }
- catch(ClassNotFoundException e)
- {
- // Can't be ;)) ...... in java ... ;)
- };
- return new Library(staticLib,dynamicLib,null,resolver,null);
- }
- public class Resolver implements DVResolver
- {
- private Map values;
- Resolver(Map values)
- {
- this.values = values;
- }
-
- public String getTypeName(String str)
- {
- Object value = values.get(str);
- if (value == null) return null;
- else
- {
- if (value instanceof String) return "String";
- else if (value instanceof Integer) return "Integer";
- else if (value instanceof Long) return "Long";
- else if (value instanceof Short) return "Short";
- else if (value instanceof Byte) return "Byte";
- else if (value instanceof Float) return "Float";
- else if (value instanceof Double) return "Double";
- else if (value instanceof Boolean) return "Boolean";
- else return "Object";
- }
- }
- public double getDoubleProperty(String name)
- {
- return ((Number) values.get(name)).doubleValue();
- }
- public int getIntegerProperty(String name)
- {
- return ((Number) values.get(name)).intValue();
- }
- public long getLongProperty(String name)
- {
- return ((Number) values.get(name)).longValue();
- }
- public short getShortProperty(String name)
- {
- return ((Number) values.get(name)).shortValue();
- }
- public byte getByteProperty(String name)
- {
- return ((Number) values.get(name)).byteValue();
- }
- public float getFloatProperty(String name)
- {
- return ((Number) values.get(name)).floatValue();
- }
- public boolean getBooleanProperty(String name)
- {
- return ((Boolean) values.get(name)).booleanValue();
- }
- public String getStringProperty(String name)
- {
- return values.get(name).toString();
- }
- public Object getObjectProperty(String name)
- {
- return values.get(name);
- }
- }
- private void warn(String message)
- {
- nWarnings++;
- System.out.println("Warning: "+message);
- }
- private void dump(int level, String message)
- {
- if (verbosity >= level) output.add(message);
- }
- private void dump(int level, String message, Object value)
- {
- if (verbosity >= level)
- {
- if (value instanceof SIORef)
- {
- output.add(value);
- output.add(message);
- }
- else
- {
- output.add(message+value);
- }
- }
- }
- private void flush()
- {
- Iterator i = output.iterator();
- while (i.hasNext())
- {
- Object line = i.next();
- if (line instanceof SIORef)
- {
- SIORef ref = (SIORef) line;
- line = i.next();
- Object obj = ref.getObject();
- System.out.println(line.toString()+obj);
- }
- else System.out.println(line);
- }
- output.clear();
- }
- private static void help()
- {
- System.out.println("java "+SIODump.class.getName()+" [options] <xml-file> <input-file>");
- System.out.println(" options: -v n sets the verbosity (default 1)");
- System.exit(1);
- }
+ private static final Pattern pattern1 = Pattern.compile("(\\w+)(?:\\[(.*)\\])?");
+ private String recordName;
+ private String blockName;
+ private Map blockMap = new HashMap();
+ private Map compilers = new HashMap();
+ private Map dimensions = new HashMap();
+ private static int verbosity = 1;
+ private static int nevttoread = -1;
+ private int nWarnings = 0;
+ private List output = new LinkedList();
+ private int global = 0;
+ private Set versionAlreadyWarned = new HashSet();
+ private Map subroutines = new HashMap();
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) throws IOException, JDOMException
+ {
+ String[] params = new String[2];
+ int nParams = 0;
+ for (int i = 0; i < args.length; i++)
+ {
+ if (args[i].equals("-v"))
+ verbosity = Integer.parseInt(args[++i]);
+ else
+ {
+ if (nParams >= 2)
+ help();
+ params[nParams++] = args[i];
+ }
+ }
+
+ if (nParams < 2)
+ help();
+
+ SAXBuilder builder = new SAXBuilder();
+ Document doc = builder.build(params[0]);
+ Element root = doc.getRootElement();
+
+ SIOReader reader = new SIOReader(new BufferedInputStream(new FileInputStream(params[1])));
+ SIODump dumper = new SIODump();
+ dumper.dump(root, reader);
+ }
+
+ public SIODump()
+ {
+ }
+
+ public static void setVerbosity(int v)
+ {
+ verbosity = v;
+ }
+
+ public static void setMaxEvents(int e)
+ {
+ nevttoread = e;
+ }
+
+ public void dump(Element root, SIOReader reader) throws IOException, JDOMException
+ {
+ try
+ {
+ // Build subroutine list
+ for (Iterator i = root.getChildren("subroutine").iterator(); i.hasNext();)
+ {
+ Element node = (Element) i.next();
+ subroutines.put(node.getAttributeValue("name"), node);
+ }
+ int n = 0;
+ int nevt = 0;
+ for (;;)
+ {
+ SIORecord record;
+ try
+ {
+ record = reader.readRecord();
+ }
+ catch (EOFException x)
+ {
+ break;
+ }
+ String recName = record.getRecordName();
+
+ if (recName.compareTo(LCIO.LCEVENT) == 0)
+ {
+ ++nevt;
+ }
+ Element recordElement = (Element) XPath.selectSingleNode(root, "record[@name=\"" + recName + "\"]");
+ if (recordElement == null)
+ {
+ warn("Skipping unrecognized record: " + recName);
+ }
+ else
+ {
+ global = 0;
+ dumpRecord(record, recordElement);
+ flush();
+ }
+
+ n++;
+
+ if (nevttoread > 0)
+ {
+ if (nevt >= nevttoread)
+ {
+ break;
+ }
+ }
+ }
+ dump(0, "Read " + n + " records with " + nWarnings + " warnings");
+ }
+ finally
+ {
+ reader.close();
+ flush();
+ }
+ }
+
+ private void dumpRecord(SIORecord record, Element root) throws IOException, JDOMException
+ {
+ recordName = record.getRecordName();
+ dump(1, "Record: " + recordName);
+ for (;;)
+ {
+ SIOBlock block = record.getBlock();
+ if (block == null)
+ return;
+ String blockName = block.getBlockName();
+ // LCIO Special
+ Object blockType = blockMap.get(blockName);
+ if (blockType == null)
+ blockType = blockName;
+ //fg -- allow one generic bloc for references
+ if (blockType.toString().endsWith("_References"))
+ blockType = "References";
+
+ Element blockElement = (Element) XPath.selectSingleNode(root, "block[@name=\"" + blockType + "\"]");
+ if (blockElement == null)
+ {
+ warn("Skipping unrecognized block type: " + blockType);
+ }
+ else
+ {
+ dumpBlock(block, blockElement);
+ }
+ }
+ }
+
+ private void dumpBlock(SIOBlock block, Element root) throws IOException, JDOMException
+ {
+ blockName = block.getBlockName();
+ String version = block.getMajorVersion() + "." + block.getMinorVersion();
+ dump(2, " Block: " + blockName + " (v" + version + ")");
+ String expectedVersion = root.getAttributeValue("major") + "." + root.getAttributeValue("minor");
+ String key = blockName + ":" + version;
+ if (!version.equals(expectedVersion) && !versionAlreadyWarned.contains(key))
+ {
+ warn("For block " + blockName + " expected v" + expectedVersion + " got v" + version);
+ versionAlreadyWarned.add(key);
+ }
+ Map values = new HashMap();
+ values.put("major", new Integer(block.getMajorVersion()));
+ values.put("minor", new Integer(block.getMinorVersion()));
+ SIOInputStream data = block.getData();
+ dumpValues(data, root, " ", values);
+ if (data.available() != 0)
+ warn(data.available() + " unread bytes in block " + blockName);
+ }
+
+ private void dumpValues(SIOInputStream data, Element root, String indent, Map values) throws IOException, JDOMException
+ {
+ dumpValues(data, root, indent, values, false);
+ }
+
+ private void dumpValues(SIOInputStream data, Element root, String indent, Map values, boolean skip) throws IOException, JDOMException
+ {
+ Iterator it = root.getChildren().iterator();
+ while (it.hasNext())
+ {
+ Element node = (Element) it.next();
+ String nodeName = node.getName();
+ if (nodeName.equals("else"))
+ {
+ skip = !skip;
+ }
+ else if (skip)
+ {
+ }
+ else if (nodeName.equals("data"))
+ {
+ String type = node.getAttributeValue("type");
+ String name = node.getAttributeValue("name");
+ Object value = readValue(data, type, values);
+ dump(3, indent + name + ": ", value);
+ values.put(name, value);
+ }
+ else if (nodeName.equals("include"))
+ {
+ String subroutine = node.getAttributeValue("subroutine");
+ Element subNode = (Element) subroutines.get(subroutine);
+ if (subNode == null)
+ throw new JDOMException("Unknown subroutine " + subroutine + " included");
+ dumpValues(data, subNode, indent, values);
+ }
+ else if (nodeName.equals("repeat"))
+ {
+ String countName = node.getAttributeValue("count");
+ int icount = evaluateInteger(countName, values, node);
+ for (int i = 0; i < icount; i++)
+ {
+ dumpValues(data, node, indent + "[" + i + "]", values);
+ // LCIO Special
+ if (recordName.equals("LCEventHeader") && blockName.equals("EventHeader"))
+ {
+ blockMap.put(values.get("blockName"), values.get("blockType"));
+ }
+ }
+ }
+ else if (nodeName.equals("if"))
+ {
+ String condition = node.getAttributeValue("condition");
+ boolean booleanCondition = evaluateBoolean(condition, values, node);
+ dumpValues(data, node, indent, values, !booleanCondition);
+ }
+ else
+ warn("Ignoring element: " + node.getName());
+ }
+ }
+
+ private Object readValue(SIOInputStream data, String declaration, Map values) throws IOException, JDOMException
+ {
+ String[] dims = (String[]) dimensions.get(declaration);
+ if (dims == null)
+ {
+ //TODO: Currently only support a single dimension
+ Matcher matcher = pattern1.matcher(declaration);
+ if (!matcher.matches())
+ throw new JDOMException("Invalid type: " + declaration);
+ dims = new String[2];
+ dims[0] = matcher.group(1).intern();
+ dims[1] = matcher.group(2);
+ dimensions.put(declaration, dims);
+ }
+ String type = dims[0];
+ if (dims[1] != null)
+ {
+ int iDim = evaluateInteger(dims[1], values, declaration);
+ StringBuffer result = new StringBuffer("[");
+ for (int i = 0;;)
+ {
+ result.append(readValue(data, type, values));
+ if (++i == iDim)
+ break;
+ result.append(",");
+ }
+ result.append("]");
+ return result.toString();
+ }
+ else
+ {
+ if (type == "int")
+ return new Integer(data.readInt());
+ else if (type == "long")
+ return new Long(data.readLong());
+ else if (type == "short")
+ return new Short(data.readShort());
+ else if (type == "byte")
+ return new Byte(data.readByte());
+ else if (type == "double")
+ return new Double(data.readDouble());
+ else if (type == "float")
+ return new Float(data.readFloat());
+ else if (type == "boolean")
+ return data.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
+ else if (type == "string")
+ return data.readString();
+ else if (type == "ptag")
+ {
+ String objectName = "Object[" + (global++) + "]";
+ data.readPTag(objectName);
+ return objectName;
+ }
+ else if (type == "pntr")
+ return data.readPntr();
+ else
+ throw new JDOMException("Unrecognized type: " + type);
+ }
+ }
+
+ private int evaluateInteger(String expression, Map values, Object key) throws IOException, JDOMException
+ {
+ try
+ {
+ Resolver resolver = new Resolver(values);
+ CompiledExpression expr_c = (CompiledExpression) compilers.get(key);
+ if (expr_c == null)
+ {
+ expr_c = Evaluator.compile(expression, createJELLibrary(resolver), Integer.TYPE);
+ compilers.put(key, expr_c);
+ }
+ return expr_c.evaluate_int(new Object[]
+ { resolver });
+ }
+ catch (CompilationException x)
+ {
+ JDOMException xx = new JDOMException("Invalid expression: " + expression);
+ xx.initCause(x);
+ throw xx;
+ }
+ catch (Throwable x)
+ {
+ JDOMException xx = new JDOMException("Error evaluating expression: " + expression);
+ xx.initCause(x);
+ throw xx;
+ }
+ }
+
+ private boolean evaluateBoolean(String expression, Map values, Object key) throws IOException, JDOMException
+ {
+ try
+ {
+ Resolver resolver = new Resolver(values);
+ CompiledExpression expr_c = (CompiledExpression) compilers.get(key);
+ if (expr_c == null)
+ {
+ expr_c = Evaluator.compile(expression, createJELLibrary(resolver), Boolean.TYPE);
+ compilers.put(key, expr_c);
+ }
+ return expr_c.evaluate_boolean(new Object[]
+ { resolver });
+ }
+ catch (CompilationException x)
+ {
+ JDOMException xx = new JDOMException("Invalid expression: " + expression);
+ xx.initCause(x);
+ throw xx;
+ }
+ catch (Throwable x)
+ {
+ JDOMException xx = new JDOMException("Error evaluating expression: " + expression);
+ xx.initCause(x);
+ throw xx;
+ }
+ }
+
+ private Library createJELLibrary(Resolver resolver)
+ {
+ Class[] dynamicLib =
+ { Resolver.class };
+ Class[] staticLib = new Class[1];
+ try
+ {
+ staticLib[0] = Class.forName("java.lang.Math");
+ }
+ catch (ClassNotFoundException e)
+ {
+ // Can't be ;)) ...... in java ... ;)
+ }
+ ;
+ return new Library(staticLib, dynamicLib, null, resolver, null);
+ }
+ public class Resolver implements DVResolver
+ {
+ private Map values;
+
+ Resolver(Map values)
+ {
+ this.values = values;
+ }
+
+ public String getTypeName(String str)
+ {
+ Object value = values.get(str);
+ if (value == null)
+ return null;
+ else
+ {
+ if (value instanceof String)
+ return "String";
+ else if (value instanceof Integer)
+ return "Integer";
+ else if (value instanceof Long)
+ return "Long";
+ else if (value instanceof Short)
+ return "Short";
+ else if (value instanceof Byte)
+ return "Byte";
+ else if (value instanceof Float)
+ return "Float";
+ else if (value instanceof Double)
+ return "Double";
+ else if (value instanceof Boolean)
+ return "Boolean";
+ else
+ return "Object";
+ }
+ }
+
+ public double getDoubleProperty(String name)
+ {
+ return ((Number) values.get(name)).doubleValue();
+ }
+
+ public int getIntegerProperty(String name)
+ {
+ return ((Number) values.get(name)).intValue();
+ }
+
+ public long getLongProperty(String name)
+ {
+ return ((Number) values.get(name)).longValue();
+ }
+
+ public short getShortProperty(String name)
+ {
+ return ((Number) values.get(name)).shortValue();
+ }
+
+ public byte getByteProperty(String name)
+ {
+ return ((Number) values.get(name)).byteValue();
+ }
+
+ public float getFloatProperty(String name)
+ {
+ return ((Number) values.get(name)).floatValue();
+ }
+
+ public boolean getBooleanProperty(String name)
+ {
+ return ((Boolean) values.get(name)).booleanValue();
+ }
+
+ public String getStringProperty(String name)
+ {
+ return values.get(name).toString();
+ }
+
+ public Object getObjectProperty(String name)
+ {
+ return values.get(name);
+ }
+ }
+
+ private void warn(String message)
+ {
+ nWarnings++;
+ System.out.println("Warning: " + message);
+ }
+
+ private void dump(int level, String message)
+ {
+ if (verbosity >= level)
+ output.add(message);
+ }
+
+ private void dump(int level, String message, Object value)
+ {
+ if (verbosity >= level)
+ {
+ if (value instanceof SIORef)
+ {
+ output.add(value);
+ output.add(message);
+ }
+ else
+ {
+ output.add(message + value);
+ }
+ }
+ }
+
+ private void flush()
+ {
+ Iterator i = output.iterator();
+ while (i.hasNext())
+ {
+ Object line = i.next();
+ if (line instanceof SIORef)
+ {
+ SIORef ref = (SIORef) line;
+ line = i.next();
+ Object obj = ref.getObject();
+ System.out.println(line.toString() + obj);
+ }
+ else
+ System.out.println(line);
+ }
+ output.clear();
+ }
+
+ private static void help()
+ {
+ System.out.println("java " + SIODump.class.getName() + " [options] <xml-file> <input-file>");
+ System.out.println(" options: -v n sets the verbosity (default 1)");
+ System.exit(1);
+ }
}
lcio/src/java/hep/lcio/util
diff -u -r1.2 -r1.3
--- SplitCommandHandler.java 28 Apr 2006 23:38:49 -0000 1.2
+++ SplitCommandHandler.java 2 Jun 2006 00:22:57 -0000 1.3
@@ -13,11 +13,10 @@
* Command-line handler for the split utility.
*
* @author Jeremy McCormick
- * @version $Id: SplitCommandHandler.java,v 1.2 2006/04/28 23:38:49 jeremy Exp $
+ * @version $Id: SplitCommandHandler.java,v 1.3 2006/06/02 00:22:57 jeremy Exp $
*/
public class SplitCommandHandler extends CommandHandler
{
- Parser parser = new PosixParser();
File infile;
int nevents;
lcio/tools
diff -u -r1.1 -r1.2
--- lcio 26 Apr 2006 00:57:43 -0000 1.1
+++ lcio 2 Jun 2006 00:22:58 -0000 1.2
@@ -1,11 +1,39 @@
#!/bin/sh
-if [ ! $LCIO ]; then
- echo "ERROR: set LCIO"
- exit 1
+# If LCIO is not set, then figure it out
+# based on the path to this script.
+if [ -z "$LCIO" ]
+then
+
+ # Name of script.
+ PRG="$0"
+
+ # Directory of script.
+ progname=`basename "$0"`
+
+ # Resolve relative symlinks.
+ while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+ done
+
+ # LCIO up one.
+ LCIO=`dirname "$PRG"`/..
+
+ # Make the path fully qualified.
+ LCIO=`cd "$LCIO" && pwd`
fi
-LOCALCLASSPATH=$LCIO/lib/lcio.jar:$LCIO/tools/sio.jar:$LCIO/tools/commons-cli-1.0.jar:$LCIO/tools/commons-lang-2.1.jar
+#echo "LCIO=$LCIO"
+
+LOCALCLASSPATH=$LCIO/lib/lcio.jar:$LCIO/tools/sio.jar:$LCIO/tools/jdom.jar:$LCIO/tools/saxpath.jar
+LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/jaxen-jdom.jar:$LCIO/tools/jaxen-core.jar:$LCIO/tools/jel.jar
+LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/commons-cli-1.0.jar:$LCIO/tools/commons-lang-2.1.jar
# OS specific support for Cygwin
cygwin=false;
@@ -14,9 +42,11 @@
esac
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
+# echo "cygwin"
+# echo "classpath before -> "$LOCALCLASSPATH
LOCALCLASSPATH=`cygpath --path --windows "$LOCALCLASSPATH"`
+# echo "classpath after -> "$LOCALCLASSPATH
java -cp "$LOCALCLASSPATH" hep.lcio.util.CommandLineTool $*
else
java -cp $LOCALCLASSPATH hep.lcio.util.CommandLineTool $*
-fi
-
+fi
\ No newline at end of file
CVSspam 0.2.8