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 ;
@@ -41,6 +43,8 @@ public class EngineProcessor {
4143 private SchemaFactory banksToKeep = null ;
4244 private final List <String > schemaExempt = Arrays .asList ("RUN::config" ,"DC::tdc" );
4345
46+ private CLASDecoder decoder = new CLASDecoder ();
47+
4448 public EngineProcessor (){}
4549
4650 private ReconstructionEngine findEngine (String clazz ) {
@@ -296,7 +300,7 @@ public void processEvent(DataEvent event, HipoDataSync writer) {
296300 removeBanks (event );
297301 writer .writeEvent (event );
298302 }
299-
303+
300304 public void processFile (HipoDataSource reader , HipoDataSync writer , int skipEvents , int maxEvents ) {
301305 if (updateDictionary ==true ) updateDictionary (reader , writer );
302306 ProgressPrintout progress = new ProgressPrintout ();
@@ -313,7 +317,6 @@ public void processFile(HipoDataSource reader, HipoDataSync writer, int skipEven
313317 }
314318
315319 public void processFile (EvioSource reader , HipoDataSync writer , int skipEvents , int maxEvents ) {
316- CLASDecoder decoder = new CLASDecoder ();
317320 ProgressPrintout progress = new ProgressPrintout ();
318321 int eventsRead = 0 ;
319322 while (reader .hasEvent ()) {
@@ -322,35 +325,37 @@ public void processFile(EvioSource reader, HipoDataSync writer, int skipEvents,
322325 ByteBuffer bb = reader .getEventBuffer (eventsRead , true );
323326 EvioDataEvent evio = new EvioDataEvent (bb .array (), ByteOrder .LITTLE_ENDIAN );
324327 Event hipo = decoder .getDecodedEvent (evio , -1 , eventsRead , null , null );
325- //processEvent(hipo, writer);
328+ HipoDataEvent hipo2 = new HipoDataEvent (hipo , decoder .getSchemaFactory ());
329+ if (skipEvents <= 0 || eventsRead > skipEvents ) processEvent (hipo2 , writer );
330+ if (maxEvents > 0 && eventsRead > maxEvents +skipEvents ) break ;
326331 } catch (EvioException ex ) {
327332 System .getLogger (EngineProcessor .class .getName ()).log (System .Logger .Level .ERROR , (String ) null , ex );
328333 }
329334 progress .updateStatus ();
330335 }
336+ progress .showStatus ();
337+ writer .close ();
331338 }
332339
333340 /**}
334341 * process entire file through engine chain.
335- * @param file input file name to process
342+ * @param input input file name to process
336343 * @param output output filename
337344 * @param nskip number of events to skip
338345 * @param nevents number of events to process
339346 */
340- public void processFile (String file , String output , int nskip , int nevents ) {
341- if (file .endsWith (".hipo" ) || file .endsWith (".h5" ) || file .endsWith (".h4" )) {
347+ public void processFile (String input , String output , int nskip , int nevents ) {
348+ HipoDataSync writer = new HipoDataSync ();
349+ writer .setCompressionType (2 );
350+ if (input .endsWith (".hipo" ) || input .endsWith (".h5" ) || input .endsWith (".h4" )) {
342351 HipoDataSource reader = new HipoDataSource ();
343- reader .open (file );
344- HipoDataSync writer = new HipoDataSync ();
345- writer .setCompressionType (2 );
352+ reader .open (input );
346353 writer .open (output );
347354 processFile (reader , writer , nskip , nevents );
348355 } else {
349- LOGGER .info (() -> "No HIPO file extension found, assuming this is an EVIO file: " +file );
356+ LOGGER .info (() -> "No HIPO file extension found, assuming this is an EVIO file: " +input );
350357 EvioSource reader = new EvioSource ();
351- reader .open (file );
352- HipoDataSync writer = new HipoDataSync ();
353- writer .setCompressionType (2 );
358+ reader .open (input );
354359 writer .open (output );
355360 processFile (reader , writer , nskip , nevents );
356361 }
0 commit comments