Skip to content

Commit

Permalink
Merge pull request #42 from JeffersonLab/qtl
Browse files Browse the repository at this point in the history
Add random wagon for Chris
  • Loading branch information
baltzell authored Apr 19, 2024
2 parents 1bab3e2 + 01c7410 commit 82b808f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/org/jlab/jnp/grapes/services/RandomWagon.java
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;
}

}

0 comments on commit 82b808f

Please sign in to comment.