1919import java .util .Arrays ;
2020import org .jlab .coda .jevio .EvioException ;
2121import org .jlab .detector .decode .CLASDecoder ;
22+ import org .jlab .io .base .DataBank ;
2223import org .jlab .io .evio .EvioDataEvent ;
2324import org .jlab .io .evio .EvioSource ;
25+ import org .jlab .io .hipo .HipoDataEvent ;
2426import org .jlab .jnp .hipo4 .data .Event ;
2527import org .jlab .jnp .hipo4 .data .SchemaFactory ;
2628import org .json .JSONObject ;
@@ -42,6 +44,8 @@ public class EngineProcessor {
4244 private SchemaFactory banksToKeep = null ;
4345 private final List <String > schemaExempt = Arrays .asList ("RUN::config" ,"DC::tdc" );
4446
47+ private CLASDecoder decoder = new CLASDecoder ();
48+
4549 public EngineProcessor (){}
4650
4751 private ReconstructionEngine findEngine (String clazz ) {
@@ -297,7 +301,7 @@ public void processEvent(DataEvent event, HipoDataSync writer) {
297301 removeBanks (event );
298302 writer .writeEvent (event );
299303 }
300-
304+
301305 public void processFile (HipoDataSource reader , HipoDataSync writer , int skipEvents , int maxEvents ) {
302306 if (updateDictionary ==true ) updateDictionary (reader , writer );
303307 ProgressPrintout progress = new ProgressPrintout ();
@@ -314,7 +318,6 @@ public void processFile(HipoDataSource reader, HipoDataSync writer, int skipEven
314318 }
315319
316320 public void processFile (EvioSource reader , HipoDataSync writer , int skipEvents , int maxEvents ) {
317- CLASDecoder decoder = new CLASDecoder ();
318321 ProgressPrintout progress = new ProgressPrintout ();
319322 int eventsRead = 0 ;
320323 while (reader .hasEvent ()) {
@@ -323,35 +326,37 @@ public void processFile(EvioSource reader, HipoDataSync writer, int skipEvents,
323326 ByteBuffer bb = reader .getEventBuffer (eventsRead , true );
324327 EvioDataEvent evio = new EvioDataEvent (bb .array (), ByteOrder .LITTLE_ENDIAN );
325328 Event hipo = decoder .getDecodedEvent (evio , -1 , eventsRead , null , null );
326- //processEvent(hipo, writer);
329+ HipoDataEvent hipo2 = new HipoDataEvent (hipo , decoder .getSchemaFactory ());
330+ if (skipEvents <= 0 || eventsRead > skipEvents ) processEvent (hipo2 , writer );
331+ if (maxEvents > 0 && eventsRead > maxEvents +skipEvents ) break ;
327332 } catch (EvioException ex ) {
328333 System .getLogger (EngineProcessor .class .getName ()).log (System .Logger .Level .ERROR , (String ) null , ex );
329334 }
330335 progress .updateStatus ();
331336 }
337+ progress .showStatus ();
338+ writer .close ();
332339 }
333340
334341 /**}
335342 * process entire file through engine chain.
336- * @param file input file name to process
343+ * @param input input file name to process
337344 * @param output output filename
338345 * @param nskip number of events to skip
339346 * @param nevents number of events to process
340347 */
341- public void processFile (String file , String output , int nskip , int nevents ) {
342- if (file .endsWith (".hipo" ) || file .endsWith (".h5" ) || file .endsWith (".h4" )) {
348+ public void processFile (String input , String output , int nskip , int nevents ) {
349+ HipoDataSync writer = new HipoDataSync ();
350+ writer .setCompressionType (2 );
351+ if (input .endsWith (".hipo" ) || input .endsWith (".h5" ) || input .endsWith (".h4" )) {
343352 HipoDataSource reader = new HipoDataSource ();
344- reader .open (file );
345- HipoDataSync writer = new HipoDataSync ();
346- writer .setCompressionType (2 );
353+ reader .open (input );
347354 writer .open (output );
348355 processFile (reader , writer , nskip , nevents );
349356 } else {
350- LOGGER .info (() -> "No HIPO file extension found, assuming this is an EVIO file: " +file );
357+ LOGGER .info (() -> "No HIPO file extension found, assuming this is an EVIO file: " +input );
351358 EvioSource reader = new EvioSource ();
352- reader .open (file );
353- HipoDataSync writer = new HipoDataSync ();
354- writer .setCompressionType (2 );
359+ reader .open (input );
355360 writer .open (output );
356361 processFile (reader , writer , nskip , nevents );
357362 }
0 commit comments