-
Notifications
You must be signed in to change notification settings - Fork 26
Add background merging engine #310
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
530131c
add convenience method, cleanup
baltzell e3bfb66
add background merging service
baltzell 2c366e7
plug bgmerging into recon-util
baltzell 80847ea
support lazy initialization
baltzell 96c6cba
oops
baltzell d296f8f
no printing every event
baltzell e9c19f6
CLI initialize BackgroundEngine
baltzell 8c40e2d
cleanup
baltzell c3a4caa
bugfix on boolean string parsing
baltzell 50c0b84
cleanup
baltzell 47f65b3
Merge branch 'development' into bgmerger-service
baltzell 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
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
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
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
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,40 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>org.jlab.clas12.detector</groupId> | ||
| <artifactId>clas12detector-bg</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <parent> | ||
| <groupId>org.jlab.clas</groupId> | ||
| <artifactId>clas12rec</artifactId> | ||
| <relativePath>../../parent/pom.xml</relativePath> | ||
| <version>11.0.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <dependencies> | ||
|
|
||
| <dependency> | ||
| <groupId>org.jlab.clas</groupId> | ||
| <artifactId>clas-io</artifactId> | ||
| <version>11.0.0-SNAPSHOT</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.jlab.clas</groupId> | ||
| <artifactId>clas-reco</artifactId> | ||
| <version>11.0.0-SNAPSHOT</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.jlab.clas</groupId> | ||
| <artifactId>clas-analysis</artifactId> | ||
| <version>11.0.0-SNAPSHOT</version> | ||
| </dependency> | ||
|
|
||
| </dependencies> | ||
| </project> |
83 changes: 83 additions & 0 deletions
83
reconstruction/bg/src/main/java/org/jlab/service/bg/BackgroundEngine.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,83 @@ | ||
| package org.jlab.service.bg; | ||
|
|
||
| import java.io.File; | ||
| import java.util.LinkedList; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
| import org.jlab.analysis.eventmerger.EventMerger; | ||
| import org.jlab.clas.reco.ReconstructionEngine; | ||
| import org.jlab.io.base.DataEvent; | ||
| import org.jlab.io.hipo.HipoDataSource; | ||
|
|
||
| /** | ||
| * | ||
| * @author baltzell | ||
| */ | ||
| public class BackgroundEngine extends ReconstructionEngine { | ||
|
|
||
| public static final String CONF_FILENAME = "filename"; | ||
| public static final String CONF_DETECTORS = "detectors"; | ||
| public static final String CONF_ORDERS = "orders"; | ||
| public static final String CONF_SUPPRESS_DOUBLES = "suppressDoubles"; | ||
| public static final String CONF_PRESERVE_ORDER = "preserveOrder"; | ||
|
|
||
| static final Logger logger = Logger.getLogger(BackgroundEngine.class.getName()); | ||
|
|
||
| EventMerger bgmerger = null; | ||
| HipoDataSource bgreader = null; | ||
| LinkedList<String> bgfilenames = new LinkedList<>(); | ||
|
|
||
| public BackgroundEngine() { | ||
| super("BG", "baltzell", "1.0"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean init() { | ||
| if (getEngineConfigString(CONF_FILENAME) != null) | ||
| return init(getEngineConfigString(CONF_FILENAME).split(",")); | ||
| return true; | ||
| } | ||
|
|
||
| public boolean init(String... filenames) { | ||
| bgfilenames.clear(); | ||
| for (String filename : filenames) { | ||
| File f = new File(filename); | ||
| if (!f.exists() || !f.isFile() || !f.canRead()) { | ||
| logger.log(Level.SEVERE,"BackgroundEngine:: filename {0} invalid.",filename); | ||
| return false; | ||
| } | ||
| logger.log(Level.INFO,"BackgroundEngine:: reading {0}",filename); | ||
| bgfilenames.add(filename); | ||
| } | ||
| String detectors = getEngineConfigString(CONF_DETECTORS,"DC,FTOF"); | ||
| String orders = getEngineConfigString(CONF_ORDERS,"NOMINAL"); | ||
| Boolean suppressDoubles = Boolean.valueOf(getEngineConfigString(CONF_SUPPRESS_DOUBLES,"true")); | ||
| Boolean preserveOrder = Boolean.valueOf(getEngineConfigString(CONF_PRESERVE_ORDER,"true")); | ||
| bgmerger = new EventMerger(detectors.split(","), orders.split(","), suppressDoubles, preserveOrder); | ||
| openNextFile(); | ||
| return true; | ||
| } | ||
|
|
||
| private void openNextFile() { | ||
| String filename = bgfilenames.remove(); | ||
| bgfilenames.add(filename); | ||
| bgreader = new HipoDataSource(); | ||
| bgreader.open(filename); | ||
| } | ||
|
|
||
| synchronized public DataEvent getBackgroundEvent() { | ||
| if (!bgreader.hasEvent()) openNextFile(); | ||
| return bgreader.getNextEvent(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean processDataEvent(DataEvent event) { | ||
| if (!bgfilenames.isEmpty()) { | ||
| DataEvent a = getBackgroundEvent(); | ||
| DataEvent b = getBackgroundEvent(); | ||
| bgmerger.mergeEvents(event, a, b); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
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 |
|---|---|---|
|
|
@@ -34,5 +34,6 @@ | |
| <module>vtx</module> | ||
| <module>urwell</module> | ||
| <module>alert</module> | ||
| <module>bg</module> | ||
| </modules> | ||
| </project> | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice to have an option to turn it off, so to reproduce the behavior of the standalone bg-merger