diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/swaps/SwapManager.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/swaps/SwapManager.java index b5a9f4f2c..3eb35eb0d 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/swaps/SwapManager.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/swaps/SwapManager.java @@ -46,7 +46,8 @@ public class SwapManager { "RTPC" }; - private final HashMap> swaps = new HashMap<>(); + private volatile HashMap> swaps = new HashMap<>(); + private final Map banksToTables = new HashMap<>(); private final Map> detsToBanks = new HashMap<>(); private final Map detsToTables = new HashMap<>(); @@ -189,12 +190,15 @@ public int[] get(DataEvent event, String bankName, int row) { * Initialize the swaps for a given run number. * @param run */ - private void add(int run) { - this.swaps.put(run,new HashMap<>()); - for (String tableName : this.banksToTables.values()) { - IndexedTable prev = prevConman.getConstants(run, tableName); - IndexedTable curr = currConman.getConstants(run, tableName); - this.swaps.get(run).put(tableName,new SwapTable(prev,curr)); + synchronized private void add(int run) { + if (!this.swaps.containsKey(run)) { + HashMap x = new HashMap<>(); + for (String tableName : this.banksToTables.values()) { + IndexedTable prev = prevConman.getConstants(run, tableName); + IndexedTable curr = currConman.getConstants(run, tableName); + x.put(tableName,new SwapTable(prev,curr)); + } + this.swaps.put(run, x); } }