Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #107 from JeffersonLab/ebdev-run
Browse files Browse the repository at this point in the history
eb:  use RUN::config.run for ccdb
  • Loading branch information
raffaelladevita authored Apr 3, 2018
2 parents 0c642bb + b1e128c commit d33a198
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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/";

Expand All @@ -36,6 +37,8 @@ public class EBCCDBConstants {

private static final String[] otherTableNames={
"/geometry/target",
"/calibration/ftof/tres",
//"/calibration/ctof/tres"
};

public static List <String> getAllTableNames() {
Expand All @@ -51,8 +54,6 @@ public static List <String> getAllTableNames() {
private static Map <EBCCDBEnum,Vector3D> dbVector3Ds = new HashMap<EBCCDBEnum,Vector3D>();
private static Map <EBCCDBEnum,Double[]> dbArrays = new HashMap<EBCCDBEnum,Double[]>();

private static EBDatabaseConstantProvider DBP = new EBDatabaseConstantProvider(10,"default");

// fill maps:
private static synchronized void setDouble(EBCCDBEnum key,Double value) {
dbDoubles.put(key,value);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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; }
}
30 changes: 28 additions & 2 deletions reconstruction/eb/src/main/java/org/jlab/rec/eb/EBUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
26 changes: 20 additions & 6 deletions reconstruction/eb/src/main/java/org/jlab/service/eb/EBEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

}

0 comments on commit d33a198

Please sign in to comment.