Skip to content

Commit 87c12ef

Browse files
authored
feat: add decoding to recon-util (#1016)
* cleanup * breakout methods * prep for recon-util decoding * finish * fix * fix dependency analysis * cleanup
1 parent 4dd7b02 commit 87c12ef

File tree

3 files changed

+73
-80
lines changed

3 files changed

+73
-80
lines changed

common-tools/clas-reco/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<artifactId>jclara</artifactId>
3232
</dependency>
3333

34+
<dependency>
35+
<groupId>org.jlab.jnp</groupId>
36+
<artifactId>jnp-hipo</artifactId>
37+
</dependency>
38+
3439
<dependency>
3540
<groupId>org.jlab.jnp</groupId>
3641
<artifactId>jnp-hipo4</artifactId>

common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java

Lines changed: 68 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.jlab.clas.reco;
22

33
import java.io.File;
4+
import java.nio.ByteBuffer;
5+
import java.nio.ByteOrder;
46
import java.nio.file.Files;
57
import java.util.LinkedHashMap;
68
import java.util.List;
@@ -15,6 +17,12 @@
1517
import org.jlab.clara.engine.EngineData;
1618
import org.jlab.clara.engine.EngineDataType;
1719
import java.util.Arrays;
20+
import org.jlab.coda.jevio.EvioException;
21+
import org.jlab.detector.decode.CLASDecoder4;
22+
import org.jlab.io.evio.EvioDataEvent;
23+
import org.jlab.io.evio.EvioSource;
24+
import org.jlab.io.hipo.HipoDataEvent;
25+
import org.jlab.jnp.hipo4.data.Event;
1826
import org.jlab.jnp.hipo4.data.SchemaFactory;
1927
import org.json.JSONObject;
2028
import org.jlab.utils.ClaraYaml;
@@ -34,6 +42,8 @@ public class EngineProcessor {
3442
private SchemaFactory banksToKeep = null;
3543
private final List<String> schemaExempt = Arrays.asList("RUN::config","DC::tdc");
3644

45+
private CLASDecoder4 decoder = new CLASDecoder4();
46+
3747
public EngineProcessor(){}
3848

3949
private ReconstructionEngine findEngine(String clazz) {
@@ -284,57 +294,72 @@ public void processFile(String file, String output){
284294
this.processFile(file, output, -1, -1);
285295
}
286296

287-
/**
297+
public void processEvent(DataEvent event, HipoDataSync writer) {
298+
processEvent(event);
299+
removeBanks(event);
300+
writer.writeEvent(event);
301+
}
302+
303+
public void processFile(HipoDataSource reader, HipoDataSync writer, int skipEvents, int maxEvents) {
304+
if (updateDictionary==true) updateDictionary(reader, writer);
305+
ProgressPrintout progress = new ProgressPrintout();
306+
int eventsRead = 0;
307+
while (reader.hasEvent()) {
308+
DataEvent event = reader.getNextEvent();
309+
eventsRead++;
310+
if (skipEvents <= 0 || eventsRead > skipEvents) processEvent(event, writer);
311+
if (maxEvents > 0 && eventsRead > maxEvents+skipEvents) break;
312+
progress.updateStatus();
313+
}
314+
progress.showStatus();
315+
writer.close();
316+
}
317+
318+
public void processFile(EvioSource reader, HipoDataSync writer, int skipEvents, int maxEvents) {
319+
ProgressPrintout progress = new ProgressPrintout();
320+
int eventsRead = 0;
321+
while (reader.hasEvent()) {
322+
eventsRead++;
323+
try {
324+
ByteBuffer bb = reader.getEventBuffer(eventsRead, true);
325+
if (skipEvents <= 0 || eventsRead > skipEvents) {
326+
EvioDataEvent evio = new EvioDataEvent(bb.array(), ByteOrder.LITTLE_ENDIAN);
327+
Event hipo = decoder.getDecodedEvent(evio, -1, eventsRead, null, null);
328+
HipoDataEvent hipo2 = new HipoDataEvent(hipo, decoder.getSchemaFactory());
329+
processEvent(hipo2, writer);
330+
}
331+
if (maxEvents > 0 && eventsRead > maxEvents+skipEvents) break;
332+
} catch (EvioException ex) {
333+
System.getLogger(EngineProcessor.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex);
334+
}
335+
progress.updateStatus();
336+
}
337+
progress.showStatus();
338+
writer.close();
339+
}
340+
341+
/**}
288342
* process entire file through engine chain.
289-
* @param file input file name to process
343+
* @param input input file name to process
290344
* @param output output filename
291345
* @param nskip number of events to skip
292346
* @param nevents number of events to process
293347
*/
294-
public void processFile(String file, String output, int nskip, int nevents){
295-
if(file.endsWith(".hipo")==true||file.endsWith(".h5")==true
296-
||file.endsWith(".h4")==true){
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")) {
297352
HipoDataSource reader = new HipoDataSource();
298-
reader.open(file);
299-
300-
int eventCounter = 0;
301-
HipoDataSync writer = new HipoDataSync();
302-
writer.setCompressionType(2);
303-
304-
// this doesn't work (before or after "open"):
305-
//if (this.banksToKeep != null)
306-
// writer.getWriter().getSchemaFactory().reduce(banksToKeep.getSchemaKeys());
307-
353+
reader.open(input);
308354
writer.open(output);
309-
310-
if(updateDictionary==true)
311-
updateDictionary(reader, writer);
312-
313-
if(nskip>0 && nevents>0) nevents += nskip;
314-
315-
ProgressPrintout progress = new ProgressPrintout();
316-
while(reader.hasEvent()==true){
317-
DataEvent event = reader.getNextEvent();
318-
if(nskip<=0 || eventCounter>nskip) {
319-
processEvent(event);
320-
321-
// this works:
322-
removeBanks(event);
323-
324-
writer.writeEvent(event);
325-
}
326-
eventCounter++;
327-
if(nevents>0){
328-
if(eventCounter>nevents) break;
329-
}
330-
progress.updateStatus();
331-
}
332-
progress.showStatus();
333-
writer.close();
355+
processFile(reader, writer, nskip, nevents);
334356
} else {
335-
LOGGER.info("\n\n>>>> error in file extension (use .hipo,.h4 or .h5)\n>>>> how is this not simple ?\n");
357+
LOGGER.info(() -> "No HIPO file extension found, assuming this is an EVIO file: "+input);
358+
EvioSource reader = new EvioSource();
359+
reader.open(input);
360+
writer.open(output);
361+
processFile(reader, writer, nskip, nevents);
336362
}
337-
338363
}
339364

340365
/**
@@ -350,7 +375,7 @@ public void show(){
350375
public static void main(String[] args){
351376
OptionParser parser = new OptionParser("recon-util");
352377
parser.addRequired("-o","output.hipo");
353-
parser.addRequired("-i","input.hipo");
378+
parser.addRequired("-i","input.evio/hipo");
354379
parser.setRequiresInputList(false);
355380
parser.addOption("-c","0","use default configuration [0 - no, 1 - yes/default, 2 - all services] ");
356381
parser.addOption("-s","-1","number of events to skip");

common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ public EngineData execute(EngineData input) {
434434
try {
435435
this.processDataEvent(dataevent);
436436
ByteBuffer bbo = dataevent.getEventBuffer();
437-
//byte[] buffero = bbo.array();
438437
output.setData(mt, bbo);
439438
} catch (Exception e) {
440439
String msg = String.format("Error processing input event%n%n%s", ClaraUtil.reportException(e));
@@ -446,42 +445,6 @@ public EngineData execute(EngineData input) {
446445
}
447446

448447
return input;
449-
/*
450-
if (!mt.equalsIgnoreCase()) {
451-
String msg = String.format("Wrong input type: %s", mt);
452-
output.setStatus(EngineStatus.ERROR);
453-
output.setDescription(msg);
454-
return output;
455-
}*/
456-
/*
457-
EvioDataEvent dataevent = null;
458-
459-
try {
460-
ByteBuffer bb = (ByteBuffer) input.getData();
461-
byte[] buffer = bb.array();
462-
ByteOrder endianness = bb.order();
463-
dataevent = new EvioDataEvent(buffer, endianness, EvioFactory.getDictionary());
464-
} catch (Exception e) {
465-
String msg = String.format("Error reading input event%n%n%s", ClaraUtil.reportException(e));
466-
output.setStatus(EngineStatus.ERROR);
467-
output.setDescription(msg);
468-
return output;
469-
}
470-
471-
try {
472-
this.processDataEvent(dataevent);
473-
ByteBuffer bbo = dataevent.getEventBuffer();
474-
//byte[] buffero = bbo.array();
475-
output.setData(mt, bbo);
476-
} catch (Exception e) {
477-
String msg = String.format("Error processing input event%n%n%s", ClaraUtil.reportException(e));
478-
output.setStatus(EngineStatus.ERROR);
479-
output.setDescription(msg);
480-
return output;
481-
}
482-
483-
return output;
484-
*/
485448
}
486449

487450
@Override

0 commit comments

Comments
 (0)