Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private void printOrders() {
public void mergeEvents(DataEvent event, DataEvent bg1, DataEvent bg2) {

if(!event.hasBank("RUN::config") || !bg1.hasBank("RUN::config") || !bg2.hasBank("RUN::config")) {
System.out.println("Missing RUN::config bank");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.jlab.clara.engine.EngineDataType;
import java.util.Arrays;
import org.jlab.jnp.hipo4.data.SchemaFactory;
import org.jlab.utils.JsonUtils;
import org.json.JSONObject;
import org.jlab.logging.DefaultLogger;
import org.jlab.utils.ClaraYaml;
Expand All @@ -27,6 +26,8 @@
*/
public class EngineProcessor {

public static final String ENGINE_CLASS_BG = "org.jlab.service.bg.BackgroundEngine";

private final Map<String,ReconstructionEngine> processorEngines = new LinkedHashMap<>();
private static final Logger LOGGER = Logger.getLogger(EngineProcessor.class.getPackage().getName());
private boolean updateDictionary = true;
Expand All @@ -35,6 +36,24 @@ public class EngineProcessor {

public EngineProcessor(){}

private ReconstructionEngine findEngine(String clazz) {
for (String k : processorEngines.keySet()) {
if (processorEngines.get(k).getClass().getName().equals(clazz)) {
return processorEngines.get(k);
}
}
return null;
}

public void setBackgroundFiles(String filenames) {
if (findEngine(ENGINE_CLASS_BG) == null) {
LOGGER.info("Adding BackgroundEngine for -B option.");
addEngine("BG",ENGINE_CLASS_BG);
}
findEngine(ENGINE_CLASS_BG).engineConfigMap.put("filename", filenames);
findEngine(ENGINE_CLASS_BG).init();
}

private void updateDictionary(HipoDataSource source, HipoDataSync sync){
SchemaFactory fsync = sync.getWriter().getSchemaFactory();
SchemaFactory fsrc = source.getReader().getSchemaFactory();
Expand Down Expand Up @@ -121,7 +140,6 @@ public void initAll(){
"org.jlab.service.raster.RasterEngine",
"org.jlab.rec.cvt.services.CVTEngine",
"org.jlab.service.ctof.CTOFEngine",
//"org.jlab.service.cnd.CNDEngine",
"org.jlab.service.cnd.CNDCalibrationEngine",
"org.jlab.service.band.BANDEngine",
"org.jlab.service.htcc.HTCCReconstructionService",
Expand Down Expand Up @@ -324,7 +342,7 @@ public static void main(String[] args){
parser.addOption("-u","true","update dictionary from writer ? ");
parser.addOption("-d","1","Debug level [0 - OFF, 1 - ON/default]");
parser.addOption("-S",null,"schema directory");
parser.setDescription("previously known as notsouseful-util");
parser.addOption("-B",null,"background file");

parser.parse(args);

Expand Down Expand Up @@ -380,6 +398,11 @@ else if (config>0){
if (parser.getOption("-S").stringValue() != null)
proc.setBanksToKeep(parser.getOption("-S").stringValue());

// command-line filename for background merging overrides YAML:
if (parser.getOption("-B").stringValue() != null)
proc.setBackgroundFiles(parser.getOption("-B").stringValue());

proc.processFile(inputFile,outputFile,nskip,nevents);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ public ConstantsManager getConstantsManager(){
return constManagerMap.get(this.getClass().getName());
}

public String getEngineConfigString(String key, String def) {
return engineConfigMap.containsKey(key) ? engineConfigMap.get(key) : def;
}

public String getEngineConfigString(String key) {
String val=null;
if (this.engineConfigMap.containsKey(key)) {
val=this.engineConfigMap.get(key);
}
return val;
return getEngineConfigString(key, null);
}

/**
Expand Down
40 changes: 40 additions & 0 deletions reconstruction/bg/pom.xml
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>
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);
Copy link
Collaborator

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

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;
}

}
1 change: 1 addition & 0 deletions reconstruction/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
<module>vtx</module>
<module>urwell</module>
<module>alert</module>
<module>bg</module>
</modules>
</project>