Author: [log in to unmask] Date: Wed Feb 10 15:45:22 2016 New Revision: 4197 Log: Hack to continue past bad EVIO records (will fix this properly in loop at some point). Modified: java/branches/jeremy-dev/record-util/src/main/java/org/hps/record/evio/EvioFileSource.java java/branches/jeremy-dev/run-database/src/main/java/org/hps/run/database/RunDatabaseBuilder.java Modified: java/branches/jeremy-dev/record-util/src/main/java/org/hps/record/evio/EvioFileSource.java ============================================================================= --- java/branches/jeremy-dev/record-util/src/main/java/org/hps/record/evio/EvioFileSource.java (original) +++ java/branches/jeremy-dev/record-util/src/main/java/org/hps/record/evio/EvioFileSource.java Wed Feb 10 15:45:22 2016 @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; import org.freehep.record.source.NoSuchRecordException; @@ -41,7 +42,12 @@ * The reader to use for reading and parsing the EVIO data. */ private EvioReader reader; - + + /** + * Whether to continue on parse errors or not. + */ + private boolean continueOnErrors = false; + /** * Constructor taking a single EVIO file. * @@ -61,7 +67,15 @@ this.files.addAll(files); this.openReader(); } - + + /** + * Set whether to continue on errors or not. + * @param continueOnErrors <code>true</code> to continue on errors + */ + public void setContinueOnErrors(boolean continueOnErrors) { + this.continueOnErrors = continueOnErrors; + } + /** * Close the current reader. */ @@ -136,20 +150,26 @@ for (;;) { try { this.currentEvent = this.reader.parseNextEvent(); - } catch (final EvioException e) { - throw new IOException(e); + if (this.reader.getNumEventsRemaining() == 0 && this.currentEvent == null) { + this.closeReader(); + this.fileIndex++; + if (!this.endOfFiles()) { + this.openReader(); + } else { + throw new NoSuchRecordException("End of data."); + } + } else { + LOGGER.finest("Read EVIO event " + this.currentEvent.getEventNumber() + " okay."); + break; + } + } catch (EvioException | NegativeArraySizeException e) { + LOGGER.log(Level.SEVERE, "Error parsing next EVIO event.", e); + if (!continueOnErrors) { + throw new IOException("Fatal error parsing next EVIO event.", e); + } + } catch (Exception e) { + throw new IOException("Error parsing EVIO event.", e); } - if (this.currentEvent == null) { - this.closeReader(); - this.fileIndex++; - if (!this.endOfFiles()) { - this.openReader(); - continue; - } else { - throw new NoSuchRecordException(); - } - } - return; } } Modified: java/branches/jeremy-dev/run-database/src/main/java/org/hps/run/database/RunDatabaseBuilder.java ============================================================================= --- java/branches/jeremy-dev/run-database/src/main/java/org/hps/run/database/RunDatabaseBuilder.java (original) +++ java/branches/jeremy-dev/run-database/src/main/java/org/hps/run/database/RunDatabaseBuilder.java Wed Feb 10 15:45:22 2016 @@ -382,6 +382,7 @@ EvioLoop loop = new EvioLoop(); loop.addProcessors(processors); EvioFileSource source = new EvioFileSource(this.evioFiles); + source.setContinueOnErrors(true); // FIXME: errors should be handled by the loop instead loop.setEvioFileSource(source); loop.loop(-1);