1 package org.lcsim.geometry.compact.converter.lcdd;
2
3 import org.jdom.Element;
4 import org.jdom.JDOMException;
5 import org.lcsim.geometry.compact.Subdetector;
6 import org.lcsim.geometry.compact.converter.lcdd.util.LCDD;
7 import org.lcsim.geometry.compact.converter.lcdd.util.LimitSet;
8 import org.lcsim.geometry.compact.converter.lcdd.util.Region;
9 import org.lcsim.geometry.compact.converter.lcdd.util.SensitiveDetector;
10 import org.lcsim.geometry.compact.converter.lcdd.util.Tracker;
11 import org.lcsim.geometry.compact.converter.lcdd.util.VisAttributes;
12 import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
13 import org.lcsim.geometry.layer.Layering;
14
15
16
17
18
19 public abstract class LCDDSubdetector extends Subdetector
20 {
21 protected Element node;
22 protected Layering layers;
23
24 LCDDSubdetector(Element c) throws JDOMException
25 {
26 super(c);
27 node = c;
28
29
30 if (layers == null)
31 {
32 try {
33 layers = org.lcsim.geometry.layer.Layering.makeLayering(c);
34 }
35 catch (JDOMException x)
36 {
37 System.err.println("WARNING: " + x.getMessage());
38 }
39 }
40 }
41
42 abstract void addToLCDD(LCDD lcdd, SensitiveDetector sens)
43 throws JDOMException;
44
45 public Element getElement()
46 {
47 return node;
48 }
49
50
51
52
53
54
55
56
57
58
59
60 public final static void setLimitSet(LCDD lcdd, Element node, Volume volume)
61 {
62 if (node.getAttribute("limits") != null)
63 {
64 String limitref = node.getAttributeValue("limits");
65 LimitSet limitset = lcdd.getLimitSet(limitref);
66 if (limitset != null)
67 {
68 volume.setLimitSet(limitset);
69 }
70 else
71 {
72 throw new RuntimeException("limitset " + limitref
73 + " does not exist");
74 }
75 }
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90 public final static void setRegion(LCDD lcdd, Element node, Volume volume)
91 {
92 if (node.getAttribute("region") != null)
93 {
94 String regionref = node.getAttributeValue("region");
95 Region region = lcdd.getRegion(regionref);
96 if (region != null)
97 {
98 volume.setRegion(region);
99 }
100 else
101 {
102 throw new RuntimeException("Region " + regionref
103 + " does not exist");
104 }
105 }
106 }
107
108
109
110
111
112
113
114
115
116
117 public final static void setCombineHits(Element node, SensitiveDetector sens)
118 {
119 if (node.getAttribute("combineHits") != null)
120 {
121
122 try
123 {
124 if (sens instanceof Tracker)
125 {
126 if (node.getAttribute("combineHits").getBooleanValue() == true)
127 {
128 sens.setAttribute("combine_hits", "true");
129 }
130 else
131 {
132 sens.setAttribute("combine_hits", "false");
133 }
134 }
135 }
136 catch (Exception e)
137 {
138 throw new RuntimeException(e);
139 }
140 }
141 }
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 public final static void setVisAttributes(LCDD lcdd, Element node, Volume volume)
161 {
162 if (lcdd == null)
163 throw new IllegalArgumentException("The lcdd object points to null.");
164
165 if (node == null)
166 throw new IllegalArgumentException("The node object points to null.");
167
168 if (volume == null)
169 throw new IllegalArgumentException("The volume object points to null.");
170
171 if (node.getAttribute("vis") != null)
172 {
173 String visref = node.getAttributeValue("vis");
174 VisAttributes vis = lcdd.getVisAttributes(visref);
175 if (vis != null)
176 {
177 volume.setVisAttributes(vis);
178 }
179 else
180 {
181 throw new RuntimeException("The vis reference " + visref + " does not exist.");
182 }
183 }
184 else
185 {
186
187 if (node.getName().equals("slice"))
188 volume.setVisAttributes(lcdd.getVisAttributes("InvisibleNoDaughters"));
189
190 else if (node.getName().equals("layer"))
191 volume.setVisAttributes(lcdd.getVisAttributes("InvisibleWithDaughters"));
192
193 else if (node.getName().equals("module"))
194 volume.setVisAttributes(lcdd.getVisAttributes("InvisibleWithDaughters"));
195
196 else if (node.getName().equals("module_component"))
197 volume.setVisAttributes(lcdd.getVisAttributes("InvisibleNoDaughters"));
198 }
199 }
200
201 public void setAttributes(LCDD lcdd, Element node, Volume volume)
202 {
203 setRegion(lcdd, node, volume);
204 setLimitSet(lcdd, node, volume);
205 setVisAttributes(lcdd, node, volume);
206 }
207 }