diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorCollection.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorCollection.java index 4cbd24df65..355fe18d6e 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorCollection.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorCollection.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.detector.base; import java.util.ArrayList; @@ -10,7 +5,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.jlab.detector.base.DetectorDescriptor; import org.jlab.utils.groups.IndexedList; /** @@ -19,7 +13,7 @@ */ public class DetectorCollection { - private IndexedList collection = new IndexedList(3); + private IndexedList collection = new IndexedList<>(3); private String collectionName = "undefined"; public void setName(String name){ @@ -67,7 +61,7 @@ public T getObjectForKey(Long key){ */ public List getList(){ Collection vc = this.collection.getMap().values(); - List list = new ArrayList(); + List list = new ArrayList<>(); for(T c : vc){ list.add(c); } @@ -79,7 +73,7 @@ public List getList(){ */ public Set getSectors(){ Set list = this.collection.getMap().keySet(); - Set sectors = new HashSet(); + Set sectors = new HashSet<>(); for(Long item : list){ int sect = this.collection.getIndexGenerator().getIndex(item, 0); @@ -95,7 +89,7 @@ public Set getSectors(){ */ public Set getLayers(int sector){ Set list = this.collection.getMap().keySet(); - Set layers = new HashSet(); + Set layers = new HashSet<>(); for(Long item : list){ int sect = this.collection.getIndexGenerator().getIndex(item, 0); if(sect==sector){ @@ -113,7 +107,7 @@ public Set getLayers(int sector){ */ public Set getComponents(int sector, int layer){ Set list = this.collection.getMap().keySet(); - Set components = new HashSet(); + Set components = new HashSet<>(); for(Long item : list){ int sect = this.collection.getIndexGenerator().getIndex(item, 0); int lay = this.collection.getIndexGenerator().getIndex(item, 1); diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java index 058916d69c..6cb753f016 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java @@ -1,11 +1,5 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.detector.base; - /** * * @author gavalian @@ -158,7 +152,5 @@ public int compareTo(DetectorDescriptor o) { } else { return 1; } - //return 0; - //return 1; } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java index b08b0801ef..ff90cc4a11 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java @@ -1,5 +1,7 @@ package org.jlab.detector.base; +import java.util.HashMap; + /** * * @author gavalian @@ -37,6 +39,16 @@ public enum DetectorType { private final int detectorId; private final String detectorName; + + private static final HashMap stringLookup = new HashMap<>(); + private static final HashMap intLookup = new HashMap<>(); + + static { + for (DetectorType t : values()) { + stringLookup.put(t.getName(), t); + intLookup.put(t.getDetectorId(), t); + } + } DetectorType(){ detectorId = 0; @@ -70,11 +82,7 @@ public int getDetectorId() { * @return */ public static DetectorType getType(String name) { - name = name.trim(); - for(DetectorType id: DetectorType.values()) - if (id.getName().equalsIgnoreCase(name)) - return id; - return UNDEFINED; + return stringLookup.getOrDefault(name.trim(), UNDEFINED); } /** @@ -83,10 +91,6 @@ public static DetectorType getType(String name) { * @return */ public static DetectorType getType(Integer detId) { - - for(DetectorType id: DetectorType.values()) - if (id.getDetectorId() == detId) - return id; - return UNDEFINED; + return intLookup.getOrDefault(detId, UNDEFINED); } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/GeometryFactory.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/GeometryFactory.java index 6b3ab66f88..c723ded1ca 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/GeometryFactory.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/GeometryFactory.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.detector.base; import org.jlab.detector.calib.utils.DatabaseConstantProvider; @@ -24,12 +19,7 @@ public class GeometryFactory { public static int SYSTEM_TILTED = 2; public static int SYSTEM_CLAS = 3; - //private volatile - - public GeometryFactory(){ - - } - + public GeometryFactory(){} /** * Load constants for given detector, with RUN and VARIATION specified @@ -39,7 +29,9 @@ public GeometryFactory(){ * @return */ public static ConstantProvider getConstants(DetectorType type, int run, String variation){ + DatabaseConstantProvider provider = new DatabaseConstantProvider(run,variation); + if(type==DetectorType.DC){ provider.loadTable("/geometry/dc/dc"); provider.loadTable("/geometry/dc/region"); @@ -47,8 +39,8 @@ public static ConstantProvider getConstants(DetectorType type, int run, String v provider.loadTable("/geometry/dc/layer"); provider.loadTable("/geometry/dc/alignment"); provider.loadTable("/geometry/dc/ministagger"); - provider.loadTable("/geometry/dc/endplatesbow"); - provider.loadTable("/geometry/dc/feedthroughs"); + provider.loadTable("/geometry/dc/endplatesbow"); + provider.loadTable("/geometry/dc/feedthroughs"); } if(type==DetectorType.ECAL){