Skip to content

Commit

Permalink
add string tables to conman
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Baltzell authored and baltzell committed Sep 20, 2024
1 parent c1bdee0 commit fbdcb2f
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

private String databaseVariation = "default";
private String timeStamp = "";
Expand Down Expand Up @@ -58,7 +61,11 @@ public synchronized void init(String... tables) {
public synchronized void init(List<String> 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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -139,6 +153,15 @@ private synchronized void loadConstantsForRun(int run) {
requestStatus = -1;
}
}

if (!stringConstants.containsKey(run)) {
Map<String,StringIndexedTable> 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);

Expand Down Expand Up @@ -181,11 +204,11 @@ public static class DatabaseConstantsDescriptor {
Set<String> tableNames = new LinkedHashSet<String>();
Set<String> mapKeys = new LinkedHashSet<String>();
Map<String,IndexedTable> hashTables = new LinkedHashMap<String,IndexedTable>();

public DatabaseConstantsDescriptor(){

}

public void addTable(String table, int indices) {
if (tableNames.add(table)) {
mapKeys.add(table);
Expand Down

0 comments on commit fbdcb2f

Please sign in to comment.