1 package org.lcsim.geometry;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5
6 import org.jdom.JDOMException;
7 import org.lcsim.detector.converter.compact.DetectorConverter;
8 import org.lcsim.geometry.compact.CompactElementFactory;
9 import org.lcsim.geometry.compact.CompactReader;
10 import org.lcsim.geometry.compact.Field;
11 import org.lcsim.geometry.compact.Segmentation;
12 import org.lcsim.geometry.compact.Subdetector;
13 import org.lcsim.util.xml.ElementFactory.ElementCreationException;
14 import org.lcsim.detector.DetectorStore;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public class GeometryReader extends CompactReader {
30
31 boolean buildDetailed = true;
32
33 public GeometryReader() {
34 super(new GeometryFactory());
35 }
36
37 public Detector read(InputStream in) throws IOException, JDOMException, ElementCreationException {
38
39
40 Detector detector = (Detector) super.read(in);
41
42
43 DetectorStore.getInstance().clear();
44
45
46 if (buildDetailed) {
47 DetectorConverter cnv = new DetectorConverter();
48 cnv.registerSubdetectorConverters();
49 cnv.convert(detector, getDocument());
50 }
51
52
53 resetDocument();
54
55 return detector;
56 }
57
58 public boolean buildDetailed() {
59 return buildDetailed;
60 }
61
62 public void setBuildDetailed(boolean buildDetailed) {
63 this.buildDetailed = buildDetailed;
64 }
65
66 static class GeometryFactory extends CompactElementFactory {
67 GeometryFactory() {
68 super();
69 register(Detector.class);
70 register(Subdetector.class, "org.lcsim.geometry.subdetector");
71 register(Segmentation.class, "org.lcsim.geometry.segmentation");
72 register(Field.class, "org.lcsim.geometry.field");
73 }
74 }
75 }