Author: [log in to unmask]
Date: Mon Jan 25 11:16:13 2016
New Revision: 4134
Log:
remove hardcoded layer number assumptions
Modified:
java/branches/layer0-branch/detector-model/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerBuilder.java
Modified: java/branches/layer0-branch/detector-model/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerBuilder.java
=============================================================================
--- java/branches/layer0-branch/detector-model/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerBuilder.java (original)
+++ java/branches/layer0-branch/detector-model/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerBuilder.java Mon Jan 25 11:16:13 2016
@@ -266,51 +266,37 @@
}
public static String getHalfFromName(String name) {
- String half = "";
- if (name.contains("bottom")) {
- half = "bottom";
- }
- if (name.contains("top")) {
- // check that both sides are not found
- if (half.equals("bottom")) {
- throw new RuntimeException("found both halfs from name " + name);
- } else {
- half = "top";
- }
- }
+ boolean matchBottom = Pattern.matches(".*bottom.*", name);
+ boolean matchTop = Pattern.matches(".*bottom.*", name);
+
+ if(matchBottom && matchTop)
+ throw new RuntimeException("found both halfs from name " + name);
+
+ if(matchBottom)
+ return "bottom";
+ if(matchTop)
+ return "top";
+
// check for other signatures
- if (half.isEmpty()) {
- Pattern pattern = Pattern.compile(".*_L[1-6][1-6]?([a-z]).*");
- Matcher matcher = pattern.matcher(name);
- if(matcher.matches()) {
- if(matcher.group(1).equals("t")) {
- half = "top";
- } else if(matcher.group(1).equals("b")) {
- half = "bottom";
- }
- }
- }
- if (half.isEmpty()) {
- System.out.println("found no half from " + name);
- throw new RuntimeException("found no half from " + name);
- } else {
- return half;
-
- }
+ Pattern pattern = Pattern.compile(".*_L\\d\\d?(t|b).*");
+ Matcher matcher = pattern.matcher(name);
+ if(matcher.matches()) {
+ if(matcher.group(1).equals("t"))
+ return "top";
+ else if(matcher.group(1).equals("b"))
+ return "bottom";
+ else
+ throw new RuntimeException("I should never get here from name " + name);
+ }
+ throw new RuntimeException("Couldn't find half from " + name);
}
public static int getLayerFromVolumeName(String name) {
- int layer = -1;
- for (int i = 1; i <= 6; ++i) {
- if (name.contains(String.format("module_L%d", i))) {
- layer = i;
- }
- }
- if (layer == -1) {
- System.out.println("cannot find layer from " + name);
- System.exit(1);
- }
- return layer;
+ Matcher matcher = Pattern.compile(".*module_L(\\d+).*").matcher(name);
+ if(matcher.matches())
+ return Integer.parseInt( matcher.group(1));
+ else
+ throw new RuntimeException("cannot find layer from " + name);
}
public static boolean isBase(String name) {
@@ -330,7 +316,7 @@
}
public static boolean isModule(String name) {
- return Pattern.matches("module_L[1-6][bt]$", name);
+ return Pattern.matches("module_L\\d+[bt]$", name);
}
public static int getUChannelSupportLayer(String name) {
|