Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support string-indexed ccdb tables #329

Draft
wants to merge 4 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,6 +93,14 @@ public Set<String> getEntrySet(){
}
return entries;
}

public Assignment getAssignment(String table) {
return provider.getData(table);
}

public TypeTable getTypeTable(String table) {
return provider.getTypeTable(table);
}

private String getEnvironment(){

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Integer> keyrows = new LinkedHashMap<>();
private Assignment assignment = null;

public StringIndexedTable(Assignment a) {
List<TypeTableColumn> t = a.getTypeTable().getColumns();
for (int i=0; i<a.getRowCount(); ++i)
keyrows.put(a.getColumnValuesString(t.get(0).getName()).get(i), i);
assignment = a;
}

public String getValueString(String key, String varname) {
return assignment.getColumnValuesString(varname).get(keyrows.get(key));
}

public float getValueFloat(String key, String varname) {
return Float.parseFloat(getValueString(key, varname));
}

public int getValueInt(String key, String varname) {
return Integer.parseInt(getValueString(key, varname));
}

}