Skip to content

Commit

Permalink
add no-reuse-events option for background merging
Browse files Browse the repository at this point in the history
  • Loading branch information
baltzell committed Aug 23, 2024
1 parent e4ebfd2 commit 4d4366a
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ public class BackgroundEngine extends ReconstructionEngine {
public static final String CONF_ORDERS = "orders";
public static final String CONF_SUPPRESS_DOUBLES = "suppressDoubles";
public static final String CONF_PRESERVE_ORDER = "preserveOrder";
public static final String CONF_REUSE_EVENTS = "reuseEvents";

static final Logger logger = Logger.getLogger(BackgroundEngine.class.getName());

int filesUsed = 0;
boolean reuseEvents = true;
EventMerger bgmerger = null;
HipoDataSource bgreader = null;
LinkedList<String> bgfilenames = new LinkedList<>();
Expand All @@ -40,6 +43,11 @@ public boolean init() {

public boolean init(String... filenames) {
bgfilenames.clear();
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"));
boolean reuseEvents = Boolean.valueOf(getEngineConfigString(CONF_REUSE_EVENTS,"false"));
for (String filename : filenames) {
File f = new File(filename);
if (!f.exists() || !f.isFile() || !f.canRead()) {
Expand All @@ -49,20 +57,21 @@ public boolean init(String... filenames) {
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() {
if (filesUsed>0 && filesUsed%bgfilenames.size()==0) {
if (reuseEvents) logger.info("BackgroundEngine:: Reopening previously used file.");
else throw new RuntimeException("BackgroundEngine:: Ran out of events.");
}
String filename = bgfilenames.remove();
bgfilenames.add(filename);
bgreader = new HipoDataSource();
bgreader.open(filename);
filesUsed++;
}

synchronized public DataEvent getBackgroundEvent() {
Expand Down

0 comments on commit 4d4366a

Please sign in to comment.