From b1e128cf9d944056c0dc9ad52ea5fa009d4cbcf6 Mon Sep 17 00:00:00 2001 From: baltzell Date: Mon, 2 Apr 2018 08:55:30 -0400 Subject: [PATCH] eb: use ccdb based on RUN::config.run --- .../java/org/jlab/rec/eb/EBCCDBConstants.java | 22 +++++++++----- .../src/main/java/org/jlab/rec/eb/EBUtil.java | 30 +++++++++++++++++-- .../java/org/jlab/service/eb/EBEngine.java | 26 ++++++++++++---- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBCCDBConstants.java b/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBCCDBConstants.java index c09bfea408..20fbece800 100644 --- a/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBCCDBConstants.java +++ b/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBCCDBConstants.java @@ -15,7 +15,8 @@ */ public class EBCCDBConstants { - public static boolean LOADED = false; + private static int currentRun = -1; + private static boolean isLoaded = false; private static final String ebTablePrefix="/calibration/eb/"; @@ -36,6 +37,8 @@ public class EBCCDBConstants { private static final String[] otherTableNames={ "/geometry/target", + "/calibration/ftof/tres", + //"/calibration/ctof/tres" }; public static List getAllTableNames() { @@ -51,8 +54,6 @@ public static List getAllTableNames() { private static Map dbVector3Ds = new HashMap(); private static Map dbArrays = new HashMap(); - private static EBDatabaseConstantProvider DBP = new EBDatabaseConstantProvider(10,"default"); - // fill maps: private static synchronized void setDouble(EBCCDBEnum key,Double value) { dbDoubles.put(key,value); @@ -89,6 +90,11 @@ public static synchronized Double[] getArray(EBCCDBEnum key) { return dbArrays.get(key); } + public static synchronized IndexedTable getTable(String tableName) { + if (tables.containsKey(tableName)) return tables.get(tableName); + else return null; + } + // read ccdb tables: private static synchronized void loadTable( int run, @@ -236,13 +242,13 @@ public static final synchronized void load(int run,ConstantsManager manager) { //loadDouble(EBCCDBEnum.TRIGGER_ID, - LOADED = true; - setDB(DBP); + currentRun = run; + isLoaded = true; + //setDB(DBP); System.out.println("EBCCDBConstants: loaded run "+run); } - private static EBDatabaseConstantProvider DB; - public static final EBDatabaseConstantProvider getDB() { return DB; } - public static final void setDB(EBDatabaseConstantProvider db) { DB=db; } + public static synchronized boolean isLoaded() { return isLoaded; } + public static synchronized int getRunNumber() { return currentRun; } } diff --git a/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBUtil.java b/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBUtil.java index 5d437e6b8f..93062c29ce 100644 --- a/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBUtil.java +++ b/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBUtil.java @@ -2,6 +2,7 @@ import static java.lang.Math.abs; import static java.lang.Math.pow; +import org.jlab.clas.detector.ScintillatorResponse; import org.jlab.clas.detector.DetectorResponse; import org.jlab.clas.detector.DetectorParticle; import org.jlab.detector.base.DetectorType; @@ -62,9 +63,9 @@ else if (pcalEnergy < EBConstants.PCAL_ELEC_MINENERGY) } /** - * Calculate timing resolution: + * Calculate timing resolution from EventBuilder constants: */ - public static double getDetTimingResolution(DetectorParticle p, DetectorType type, int layer) { + public static double getEBTimingResolution(DetectorParticle p, DetectorType type, int layer) { Double[] pars; if (type==DetectorType.FTOF) { if (layer==1) pars=EBCCDBConstants.getArray(EBCCDBEnum.FTOF1A_TimingRes); @@ -81,6 +82,27 @@ else if (type==DetectorType.CTOF) { return res; } + /** + * Get timing resolution from detector calibration constants: + */ + public static double getDetTimingResolution(ScintillatorResponse resp,int run) { + final int sector = resp.getDescriptor().getSector(); + final int layer = resp.getDescriptor().getLayer(); + final int component = resp.getDescriptor().getComponent(); + String tableName=null; + if (resp.getDescriptor().getType()==DetectorType.FTOF) { + tableName="/calibration/ftof/tres"; + } + else { + throw new RuntimeException("not ready for non-FTOF"); + } + return EBCCDBConstants.getTable(tableName). + getDoubleValue("tres",sector,layer,component); + } + + /** + * Calculate beta for given detector type: + */ public static double getNeutralBeta(DetectorParticle p, DetectorType type, int layer,double startTime) { double beta=-1; DetectorResponse resp = p.getResponse(type,layer); @@ -91,6 +113,10 @@ public static double getNeutralBeta(DetectorParticle p, DetectorType type, int l } return beta; } + + /** + * Calculate beta for ECAL, prioritized by layer: + */ public static double getNeutralBetaECAL(DetectorParticle p, double startTime) { double beta = getNeutralBeta(p,DetectorType.ECAL,1,startTime); if (beta<0) beta = getNeutralBeta(p,DetectorType.ECAL,4,startTime); diff --git a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBEngine.java b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBEngine.java index 448566eb98..f68a29a077 100644 --- a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBEngine.java +++ b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBEngine.java @@ -43,7 +43,20 @@ public void initBankNames() { public boolean processDataEvent(DataEvent de) { - + + // check run number, get constants from CCDB: + int run=-1; + if (de.hasBank("RUN::config")) { + run=de.getBank("RUN::config").getInt("run",0); + } + if (run>0 && run!=EBCCDBConstants.getRunNumber()) { + EBCCDBConstants.load(run,this.getConstantsManager()); + } + if (!EBCCDBConstants.isLoaded()) { + System.out.println("EBEngine: found no run number, CCDB constants not loaded, skipping event."); + return false; + } + DetectorHeader head = EBio.readHeader(de); EventBuilder eb = new EventBuilder(); @@ -201,15 +214,16 @@ public void setTrackType(String trackType) { @Override public boolean init() { - - // load EB constants from CCDB: requireConstants(EBCCDBConstants.getAllTableNames()); this.getConstantsManager().setVariation("default"); - // FIXME: check run number in processDataEvent, reload from CCDB if changed. - // For now we just use hard-coded run number: - EBCCDBConstants.load(10,this.getConstantsManager()); System.out.println("[EB::] --> event builder is ready...."); return true; } + + public boolean init(int run) { + this.init(); + EBCCDBConstants.load(run,this.getConstantsManager()); + return true; + } }