-
Notifications
You must be signed in to change notification settings - Fork 32
feat: add generic EVIO+HIPO reader service #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
baltzell
wants to merge
3
commits into
development
Choose a base branch
from
clas12reader
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
common-tools/clara-io/src/main/java/org/jlab/io/clara/Clas12Reader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package org.jlab.io.clara; | ||
|
|
||
| import java.nio.ByteOrder; | ||
| import java.nio.file.Path; | ||
| import org.jlab.clara.engine.EngineDataType; | ||
| import org.jlab.clara.std.services.AbstractEventReaderService; | ||
| import org.jlab.clara.std.services.EventReaderException; | ||
| import org.jlab.coda.jevio.EvioException; | ||
| import org.jlab.io.evio.EvioSource; | ||
| import org.jlab.jnp.hipo4.data.Event; | ||
| import org.jlab.jnp.hipo4.io.HipoReader; | ||
| import org.json.JSONObject; | ||
|
|
||
| /** | ||
| * Just reads EVIO or HIPO, and passes it along. | ||
| * | ||
| * @author baltzell | ||
| */ | ||
| public class Clas12Reader extends AbstractEventReaderService<Object> { | ||
|
|
||
| EngineDataType type = Clas12Types.HIPO; | ||
| private long maxEvents; | ||
|
|
||
| @Override | ||
| protected Object createReader(Path path, JSONObject opts) throws EventReaderException { | ||
| if (path.toString().endsWith(".hipo")) { | ||
| type = Clas12Types.HIPO; | ||
| HipoReader r = new HipoReader(); | ||
| try { | ||
| r.open(path.toString()); | ||
| return r; | ||
| } catch (Exception e) { | ||
| throw new EventReaderException(e); | ||
| } | ||
| } | ||
| else { | ||
| type = Clas12Types.EVIO; | ||
| EvioSource r = new EvioSource(); | ||
| r.open(path.toString()); | ||
| maxEvents = r.getEventCount(); | ||
| return r; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void closeReader() { | ||
| if (type == Clas12Types.EVIO) { | ||
| ((EvioSource)reader).close(); | ||
| } | ||
| else { | ||
| ((HipoReader)reader).close(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected int readEventCount() throws EventReaderException { | ||
| if (type == Clas12Types.EVIO) { | ||
| return ((EvioSource)reader).getEventCount(); | ||
| } | ||
| else { | ||
| return ((HipoReader)reader).getEventCount(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected Object readEvent(int eventNumber) throws EventReaderException { | ||
| try { | ||
| if (type == Clas12Types.EVIO) { | ||
| if (eventNumber++ >= maxEvents) return null; | ||
| return ((EvioSource)reader).getEventBuffer(eventNumber, true); | ||
| //return new EvioDataEvent(b.array(), readByteOrder()); | ||
| } | ||
| else { | ||
| return ((HipoReader)reader).getEvent(new Event(),eventNumber); | ||
| } | ||
| } catch (EvioException e) { | ||
| throw new EventReaderException(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public ByteOrder readByteOrder() throws EventReaderException { | ||
|
baltzell marked this conversation as resolved.
|
||
| return ByteOrder.LITTLE_ENDIAN; | ||
| } | ||
|
|
||
| @Override | ||
| protected EngineDataType getDataType() { | ||
| return type; | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
common-tools/clara-io/src/main/resources/org/jlab/io/clara/Clas12Reader.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| name: Clas12Reader | ||
| engine: org.jlab.io.clara.Clas12Reader | ||
| type: java | ||
|
|
||
| author: Nathan Baltzell | ||
| email: baltzell@jlab.org | ||
|
|
||
| version: 0.1 | ||
| description: | ||
| Reads EVIO or HIPO events from a file and passes them along unchanged. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.