Skip to content

Commit df3e953

Browse files
committed
add string tables to conman
1 parent c567318 commit df3e953

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/ConstantsManager.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Set;
1111
import java.util.logging.Level;
1212
import java.util.logging.Logger;
13+
import org.jlab.ccdb.Assignment;
1314

1415
import org.jlab.utils.groups.IndexedTable;
1516

@@ -25,6 +26,8 @@ public class ConstantsManager {
2526
private volatile Map<Integer, DatabaseConstantsDescriptor> runConstants = new LinkedHashMap<Integer, DatabaseConstantsDescriptor>();
2627
private volatile Map<Integer, Integer> runConstantRequestHistory = new LinkedHashMap<Integer, Integer>();
2728
private static volatile Map<Integer, RCDBConstants> rcdbConstants = new LinkedHashMap<Integer, RCDBConstants>();
29+
private static volatile List<String> stringTables = new ArrayList();
30+
private static volatile Map<Integer, Map<String,StringIndexedTable>> stringConstants = new LinkedHashMap();
2831

2932
private String databaseVariation = "default";
3033
private String timeStamp = "";
@@ -58,7 +61,11 @@ public synchronized void init(String... tables) {
5861
public synchronized void init(List<String> tables) {
5962
this.defaultDescriptor.addTables(tables);
6063
}
61-
64+
65+
public synchronized void addStringTable(String... tables) {
66+
for (String s : tables) stringTables.add(s);
67+
}
68+
6269
/**
6370
* use a map just to avoid name clash
6471
* @param tables map of table_name to #indices
@@ -97,6 +104,13 @@ public RCDBConstants getRcdbConstants(int run) {
97104
return this.rcdbConstants.get(run);
98105
}
99106

107+
public StringIndexedTable getStringConstants(int run, String table) {
108+
if (!stringConstants.containsKey(run)) {
109+
this.loadConstantsForRun(run);
110+
}
111+
return stringConstants.get(run).get(table);
112+
}
113+
100114
public RCDBConstants.RCDBConstant getRcdbConstant(int run, String name) {
101115
return getRcdbConstants(run).get(name);
102116
}
@@ -139,6 +153,15 @@ private synchronized void loadConstantsForRun(int run) {
139153
requestStatus = -1;
140154
}
141155
}
156+
157+
if (!stringConstants.containsKey(run)) {
158+
Map<String,StringIndexedTable> s = new HashMap();
159+
for (String table : stringTables)
160+
s.put(table, new StringIndexedTable(provider.getAssignment(table)));
161+
stringConstants.put(run,s);
162+
System.out.println(stringConstants.get(run).get("/runcontrol/beam").getValueFloat("beam_energy","value"));
163+
}
164+
142165
provider.disconnect();
143166
this.runConstants.put(run, desc);
144167

@@ -181,11 +204,11 @@ public static class DatabaseConstantsDescriptor {
181204
Set<String> tableNames = new LinkedHashSet<String>();
182205
Set<String> mapKeys = new LinkedHashSet<String>();
183206
Map<String,IndexedTable> hashTables = new LinkedHashMap<String,IndexedTable>();
184-
207+
185208
public DatabaseConstantsDescriptor(){
186209

187210
}
188-
211+
189212
public void addTable(String table, int indices) {
190213
if (tableNames.add(table)) {
191214
mapKeys.add(table);

0 commit comments

Comments
 (0)