From 5f62bc5b9fb07b3309c7ec635aefad6f9a08febc Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Thu, 5 Sep 2024 18:58:28 -0400 Subject: [PATCH 1/4] allow more direct access --- .../detector/calib/utils/DatabaseConstantProvider.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 d61aeb78e..d6062009a 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(){ From c1bdee07fa5ca138328222e7b5b2ebf9b26c0c44 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Thu, 5 Sep 2024 18:58:49 -0400 Subject: [PATCH 2/4] add class for string-indexed tables --- .../calib/utils/StringIndexedTable.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/StringIndexedTable.java 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 000000000..1d8fcd50e --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/StringIndexedTable.java @@ -0,0 +1,34 @@ +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 Date: Thu, 5 Sep 2024 18:59:15 -0400 Subject: [PATCH 3/4] add string tables to conman --- .../calib/utils/ConstantsManager.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) 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 abf3d20e3..a9ce356a2 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); From 88a672d6b3c7c37f6e9d15ae077758ab898a0cd8 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Fri, 6 Sep 2024 11:14:55 -0400 Subject: [PATCH 4/4] remove debug printout --- .../java/org/jlab/detector/calib/utils/ConstantsManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a9ce356a2..e8e55a503 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 @@ -159,7 +159,7 @@ private synchronized void loadConstantsForRun(int run) { 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")); + //System.out.println(stringConstants.get(run).get("/runcontrol/beam").getValueFloat("beam_energy","value")); } provider.disconnect();