Skip to content

Commit 22ad41a

Browse files
committed
add Clas12Reader
1 parent 975a9cc commit 22ad41a

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package org.jlab.io.clara;
2+
3+
import java.nio.ByteBuffer;
4+
import java.nio.ByteOrder;
5+
import java.nio.file.Path;
6+
import org.jlab.clara.engine.EngineDataType;
7+
import org.jlab.clara.std.services.AbstractEventReaderService;
8+
import org.jlab.clara.std.services.EventReaderException;
9+
import org.jlab.coda.jevio.EvioException;
10+
import org.jlab.io.evio.EvioDataEvent;
11+
import org.jlab.io.evio.EvioSource;
12+
import org.jlab.jnp.hipo4.data.Event;
13+
import org.jlab.jnp.hipo4.io.HipoReader;
14+
import org.json.JSONObject;
15+
16+
/**
17+
* Just reads EVIO or HIPO, and passes it along.
18+
*
19+
* @author baltzell
20+
*/
21+
public class Clas12Reader extends AbstractEventReaderService<Object> {
22+
23+
EngineDataType type = Clas12Types.HIPO;
24+
private long maxEvents;
25+
26+
@Override
27+
protected Object createReader(Path path, JSONObject opts) throws EventReaderException {
28+
if (path.toString().endsWith(".hipo")) {
29+
type = Clas12Types.HIPO;
30+
HipoReader r = new HipoReader();
31+
r.open(path.toString());
32+
return r;
33+
}
34+
else {
35+
type = Clas12Types.EVIO;
36+
EvioSource r = new EvioSource();
37+
r.open(path.toString());
38+
maxEvents = r.getEventCount();
39+
return r;
40+
}
41+
}
42+
43+
@Override
44+
protected void closeReader() {
45+
if (type == Clas12Types.EVIO) {
46+
((EvioSource)reader).close();
47+
}
48+
else {
49+
((HipoReader)reader).close();
50+
}
51+
}
52+
53+
@Override
54+
protected int readEventCount() throws EventReaderException {
55+
if (type == Clas12Types.EVIO) {
56+
return ((EvioSource)reader).getEventCount();
57+
}
58+
else {
59+
return ((HipoReader)reader).getEventCount();
60+
}
61+
}
62+
63+
@Override
64+
protected Object readEvent(int eventNumber) throws EventReaderException {
65+
try {
66+
if (type == Clas12Types.EVIO) {
67+
if (eventNumber++ >= maxEvents) return null;
68+
return ((EvioSource)reader).getEventBuffer(eventNumber, true);
69+
//return new EvioDataEvent(b.array(), readByteOrder());
70+
}
71+
else {
72+
return ((HipoReader)reader).getEvent(new Event(),eventNumber);
73+
}
74+
} catch (EvioException e) {
75+
throw new EventReaderException(e);
76+
}
77+
}
78+
79+
@Override
80+
public ByteOrder readByteOrder() throws EventReaderException {
81+
return ByteOrder.LITTLE_ENDIAN;
82+
}
83+
84+
@Override
85+
protected EngineDataType getDataType() {
86+
return type;
87+
}
88+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
name: Clas12Reader
3+
engine: org.jlab.io.clara.Clas12Reader
4+
type: java
5+
6+
author: Nathan Baltzell
7+
email: baltzell@jlab.org
8+
9+
version: 0.1
10+
description:
11+
Reads EVIO or HIPO events from a file and passes them along unchanged.

0 commit comments

Comments
 (0)