|
1 | 1 | package org.jlab.clas.reco; |
2 | 2 |
|
3 | 3 | import java.io.File; |
| 4 | +import java.nio.ByteBuffer; |
| 5 | +import java.nio.ByteOrder; |
4 | 6 | import java.nio.file.Files; |
5 | 7 | import java.util.LinkedHashMap; |
6 | 8 | import java.util.List; |
|
15 | 17 | import org.jlab.clara.engine.EngineData; |
16 | 18 | import org.jlab.clara.engine.EngineDataType; |
17 | 19 | import java.util.Arrays; |
| 20 | +import org.jlab.coda.jevio.EvioException; |
| 21 | +import org.jlab.detector.decode.CLASDecoder; |
| 22 | +import org.jlab.io.evio.EvioDataEvent; |
| 23 | +import org.jlab.io.evio.EvioSource; |
| 24 | +import org.jlab.jnp.hipo4.data.Event; |
18 | 25 | import org.jlab.jnp.hipo4.data.SchemaFactory; |
19 | 26 | import org.json.JSONObject; |
20 | 27 | import org.jlab.logging.SplitLogger; |
@@ -285,42 +292,68 @@ public void processFile(String file, String output){ |
285 | 292 | this.processFile(file, output, -1, -1); |
286 | 293 | } |
287 | 294 |
|
| 295 | + public void processEvent(DataEvent event, HipoDataSync writer) { |
| 296 | + processEvent(event); |
| 297 | + removeBanks(event); |
| 298 | + writer.writeEvent(event); |
| 299 | + } |
| 300 | + |
288 | 301 | public void processFile(HipoDataSource reader, HipoDataSync writer, int skipEvents, int maxEvents) { |
289 | 302 | if (updateDictionary==true) updateDictionary(reader, writer); |
290 | | - ProgressPrintout progress = new ProgressPrintout(); |
| 303 | + ProgressPrintout progress = new ProgressPrintout(); |
291 | 304 | int eventsRead = 0; |
292 | 305 | while (reader.hasEvent()) { |
293 | 306 | DataEvent event = reader.getNextEvent(); |
294 | 307 | eventsRead++; |
295 | | - if (skipEvents <= 0 || eventsRead > skipEvents) { |
296 | | - processEvent(event); |
297 | | - removeBanks(event); |
298 | | - writer.writeEvent(event); |
299 | | - } |
| 308 | + if (skipEvents <= 0 || eventsRead > skipEvents) processEvent(event, writer); |
300 | 309 | if (maxEvents > 0 && eventsRead > maxEvents+skipEvents) break; |
301 | 310 | progress.updateStatus(); |
302 | 311 | } |
303 | 312 | progress.showStatus(); |
304 | 313 | writer.close(); |
305 | 314 | } |
306 | 315 |
|
307 | | - /** |
| 316 | + public void processFile(EvioSource reader, HipoDataSync writer, int skipEvents, int maxEvents) { |
| 317 | + CLASDecoder decoder = new CLASDecoder(); |
| 318 | + ProgressPrintout progress = new ProgressPrintout(); |
| 319 | + int eventsRead = 0; |
| 320 | + while (reader.hasEvent()) { |
| 321 | + eventsRead++; |
| 322 | + try { |
| 323 | + ByteBuffer bb = reader.getEventBuffer(eventsRead, true); |
| 324 | + EvioDataEvent evio = new EvioDataEvent(bb.array(), ByteOrder.LITTLE_ENDIAN); |
| 325 | + Event hipo = decoder.getDecodedEvent(evio, -1, eventsRead, null, null); |
| 326 | + //processEvent(hipo, writer); |
| 327 | + } catch (EvioException ex) { |
| 328 | + System.getLogger(EngineProcessor.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex); |
| 329 | + } |
| 330 | + progress.updateStatus(); |
| 331 | + } |
| 332 | + } |
| 333 | + |
| 334 | + /**} |
308 | 335 | * process entire file through engine chain. |
309 | 336 | * @param file input file name to process |
310 | 337 | * @param output output filename |
311 | 338 | * @param nskip number of events to skip |
312 | 339 | * @param nevents number of events to process |
313 | 340 | */ |
314 | 341 | public void processFile(String file, String output, int nskip, int nevents) { |
315 | | - if(file.endsWith(".hipo") || file.endsWith(".h5") || file.endsWith(".h4")) { |
| 342 | + if (file.endsWith(".hipo") || file.endsWith(".h5") || file.endsWith(".h4")) { |
316 | 343 | HipoDataSource reader = new HipoDataSource(); |
317 | 344 | reader.open(file); |
318 | 345 | HipoDataSync writer = new HipoDataSync(); |
319 | 346 | writer.setCompressionType(2); |
320 | 347 | writer.open(output); |
321 | 348 | processFile(reader, writer, nskip, nevents); |
322 | 349 | } else { |
323 | | - LOGGER.info("\n\n>>>> error in file extension (use .hipo,.h4 or .h5)\n>>>> how is this not simple ?\n"); |
| 350 | + LOGGER.info(() -> "No HIPO file extension found, assuming this is an EVIO file: "+file); |
| 351 | + EvioSource reader = new EvioSource(); |
| 352 | + reader.open(file); |
| 353 | + HipoDataSync writer = new HipoDataSync(); |
| 354 | + writer.setCompressionType(2); |
| 355 | + writer.open(output); |
| 356 | + processFile(reader, writer, nskip, nevents); |
324 | 357 | } |
325 | 358 | } |
326 | 359 |
|
|
0 commit comments