Search in sources :

Example 1 with Property

use of dr.util.Property in project beast-mcmc by beast-dev.

the class LoggerParser method parseXMLObject.

/**
     * @return an object based on the XML element it was passed.
     */
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    // You must say how often you want to log
    final int logEvery = xo.getIntegerAttribute(LOG_EVERY);
    final PrintWriter pw = getLogFile(xo, getParserName());
    final LogFormatter formatter = new TabDelimitedFormatter(pw);
    boolean performanceReport = false;
    if (!xo.hasAttribute(FILE_NAME)) {
        // is a screen log
        performanceReport = true;
    }
    // added a performance measurement delay to avoid the full evaluation period.
    final MCLogger logger = new MCLogger(formatter, logEvery, performanceReport, 10000);
    String title = null;
    if (xo.hasAttribute(TITLE)) {
        title = xo.getStringAttribute(TITLE);
    }
    String header = null;
    if (xo.hasAttribute(HEADER)) {
        header = xo.getStringAttribute(HEADER);
    }
    if (title == null) {
        final BeastVersion version = new BeastVersion();
        title = "BEAST " + version.getVersionString() + "\n" + (header != null ? header + "\n" : "") + "Generated " + (new Date()).toString() + " [seed=" + MathUtils.getSeed() + "]\n" + System.getProperty("command_line", "");
    } else {
        if (header != null) {
            title += "\n" + header;
        }
    }
    logger.setTitle(title);
    for (int i = 0; i < xo.getChildCount(); i++) {
        final Object child = xo.getChild(i);
        if (child instanceof Columns) {
            logger.addColumns(((Columns) child).getColumns());
        } else if (child instanceof Loggable) {
            logger.add((Loggable) child);
        } else if (child instanceof Identifiable) {
            logger.addColumn(new LogColumn.Default(((Identifiable) child).getId(), child));
        } else if (child instanceof Property) {
            logger.addColumn(new LogColumn.Default(((Property) child).getAttributeName(), child));
        } else {
            logger.addColumn(new LogColumn.Default(child.getClass().toString(), child));
        }
    }
    return logger;
}
Also used : Date(java.util.Date) Identifiable(dr.util.Identifiable) BeastVersion(dr.app.beast.BeastVersion) Property(dr.util.Property) PrintWriter(java.io.PrintWriter)

Example 2 with Property

use of dr.util.Property in project beast-mcmc by beast-dev.

the class PropertyParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Object object = xo.getChild(0);
    String name = xo.getStringAttribute("name");
    Property property;
    if (xo.hasAttribute("index")) {
        int index = xo.getIntegerAttribute("index");
        property = new Property(object, name, index);
    } else if (xo.hasAttribute("label")) {
        String label = xo.getStringAttribute("label");
        property = new Property(object, name, label);
    } else {
        property = new Property(object, name);
    }
    if (property.getGetter() == null)
        throw new XMLParseException("unknown property, " + name + ", for object, " + object + ", in property element");
    return property;
}
Also used : Property(dr.util.Property)

Aggregations

Property (dr.util.Property)2 BeastVersion (dr.app.beast.BeastVersion)1 Identifiable (dr.util.Identifiable)1 PrintWriter (java.io.PrintWriter)1 Date (java.util.Date)1