diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/ConstantsManager.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/ConstantsManager.java index abf3d20e30..e8e55a5031 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/ConstantsManager.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/ConstantsManager.java @@ -10,6 +10,7 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import org.jlab.ccdb.Assignment; import org.jlab.utils.groups.IndexedTable; @@ -25,6 +26,8 @@ public class ConstantsManager { private volatile Map runConstants = new LinkedHashMap(); private volatile Map runConstantRequestHistory = new LinkedHashMap(); private static volatile Map rcdbConstants = new LinkedHashMap(); + private static volatile List stringTables = new ArrayList(); + private static volatile Map> stringConstants = new LinkedHashMap(); private String databaseVariation = "default"; private String timeStamp = ""; @@ -58,7 +61,11 @@ public synchronized void init(String... tables) { public synchronized void init(List tables) { this.defaultDescriptor.addTables(tables); } - + + public synchronized void addStringTable(String... tables) { + for (String s : tables) stringTables.add(s); + } + /** * use a map just to avoid name clash * @param tables map of table_name to #indices @@ -97,6 +104,13 @@ public RCDBConstants getRcdbConstants(int run) { return this.rcdbConstants.get(run); } + public StringIndexedTable getStringConstants(int run, String table) { + if (!stringConstants.containsKey(run)) { + this.loadConstantsForRun(run); + } + return stringConstants.get(run).get(table); + } + public RCDBConstants.RCDBConstant getRcdbConstant(int run, String name) { return getRcdbConstants(run).get(name); } @@ -139,6 +153,15 @@ private synchronized void loadConstantsForRun(int run) { requestStatus = -1; } } + + if (!stringConstants.containsKey(run)) { + Map s = new HashMap(); + for (String table : stringTables) + s.put(table, new StringIndexedTable(provider.getAssignment(table))); + stringConstants.put(run,s); + //System.out.println(stringConstants.get(run).get("/runcontrol/beam").getValueFloat("beam_energy","value")); + } + provider.disconnect(); this.runConstants.put(run, desc); @@ -181,11 +204,11 @@ public static class DatabaseConstantsDescriptor { Set tableNames = new LinkedHashSet(); Set mapKeys = new LinkedHashSet(); Map hashTables = new LinkedHashMap(); - + public DatabaseConstantsDescriptor(){ } - + public void addTable(String table, int indices) { if (tableNames.add(table)) { mapKeys.add(table); diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/DatabaseConstantProvider.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/DatabaseConstantProvider.java index d61aeb78e5..d6062009a0 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/DatabaseConstantProvider.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/DatabaseConstantProvider.java @@ -15,6 +15,7 @@ import org.jlab.ccdb.CCDB; import javax.swing.JFrame; import org.jlab.ccdb.Assignment; +import org.jlab.ccdb.TypeTable; import org.jlab.ccdb.TypeTableColumn; import org.rcdb.RCDB; @@ -92,6 +93,14 @@ public Set getEntrySet(){ } return entries; } + + public Assignment getAssignment(String table) { + return provider.getData(table); + } + + public TypeTable getTypeTable(String table) { + return provider.getTypeTable(table); + } private String getEnvironment(){ diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/StringIndexedTable.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/StringIndexedTable.java new file mode 100644 index 0000000000..dad844aa1b --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/StringIndexedTable.java @@ -0,0 +1,40 @@ +package org.jlab.detector.calib.utils; + +import java.util.Map; +import java.util.List; +import java.util.LinkedHashMap; +import org.jlab.ccdb.Assignment; +import org.jlab.ccdb.TypeTableColumn; +import javax.swing.table.DefaultTableModel; + +public class StringIndexedTable extends DefaultTableModel { + + private final Map keyrows = new LinkedHashMap<>(); + private Assignment assignment = null; + + public StringIndexedTable(Assignment a) { + List t = a.getTypeTable().getColumns(); + for (int i=0; i