-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from JeffersonLab/qtl
Add random wagon for Chris
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/org/jlab/jnp/grapes/services/RandomWagon.java
This file contains 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,37 @@ | ||
package org.jlab.jnp.grapes.services; | ||
|
||
import java.util.Random; | ||
import org.jlab.jnp.hipo4.data.Event; | ||
import org.jlab.jnp.hipo4.data.SchemaFactory; | ||
import org.jlab.jnp.utils.json.Json; | ||
import org.jlab.jnp.utils.json.JsonObject; | ||
|
||
/** | ||
* | ||
* @author baltzell | ||
*/ | ||
public class RandomWagon extends Wagon { | ||
|
||
boolean includeTags = true; | ||
double prescale = 100.0f; | ||
Random random = new Random(); | ||
|
||
public RandomWagon() { | ||
super("RandomWagon", "baltzell", "1.0"); | ||
} | ||
|
||
@Override | ||
public boolean processDataEvent(Event event, SchemaFactory factory) { | ||
if (includeTags && event.getEventTag() != 0) return true; | ||
return random.nextFloat(1.0f) < 1./prescale; | ||
} | ||
|
||
@Override | ||
public boolean init(String jsonString) { | ||
JsonObject jsonObj = Json.parse(jsonString).asObject(); | ||
prescale = jsonObj.getDouble("prescale",prescale); | ||
includeTags = jsonObj.getBoolean("includeTags",includeTags); | ||
return true; | ||
} | ||
|
||
} |