1 package org.lcsim.detector.converter.compact;
2
3 import hep.graphics.heprep.HepRep;
4 import hep.graphics.heprep.HepRepFactory;
5 import hep.graphics.heprep.HepRepInstanceTree;
6 import hep.graphics.heprep.HepRepTreeID;
7 import hep.graphics.heprep.HepRepType;
8 import hep.graphics.heprep.HepRepTypeTree;
9 import hep.graphics.heprep.HepRepWriter;
10
11 import java.io.FileOutputStream;
12 import java.io.InputStream;
13
14 import junit.framework.TestCase;
15 import junit.framework.TestSuite;
16
17 import org.lcsim.detector.DetectorElementStore;
18 import org.lcsim.detector.IDetectorElement;
19 import org.lcsim.detector.converter.heprep.DetectorElementToHepRepConverter;
20 import org.lcsim.geometry.Detector;
21 import org.lcsim.geometry.GeometryReader;
22 import org.lcsim.util.test.TestUtil.TestOutputFile;
23
24
25
26
27
28
29
30
31 public class SiTrackerBarrelTest
32 extends TestCase
33 {
34 private Detector detector;
35
36 public SiTrackerBarrelTest(String name)
37 {
38 super(name);
39 }
40
41 public static junit.framework.Test suite()
42 {
43 return new TestSuite(SiTrackerBarrelTest.class);
44 }
45
46 private static final String resource =
47 "/org/lcsim/detector/converter/compact/SiTrackerBarrelTest.xml";
48
49 public void setUp()
50 {
51 InputStream in =
52 this.getClass().
53 getResourceAsStream(resource);
54
55 GeometryReader reader = new GeometryReader();
56
57 try {
58 detector = reader.read(in);
59 }
60 catch ( Throwable x )
61 {
62 throw new RuntimeException(x);
63 }
64 }
65
66 public void testHepRep()
67 {
68 try {
69 writeHepRep(new TestOutputFile("SiTrackerBarrelTest.heprep").getAbsolutePath());
70 }
71 catch ( Exception x )
72 {
73 throw new RuntimeException( x );
74 }
75 }
76
77
78 public final static String HITS_LAYER = "Hits";
79 public final static String PARTICLES_LAYER = "Particles";
80
81 private void writeHepRep(String filepath) throws Exception
82 {
83 HepRepFactory factory = HepRepFactory.create();
84 HepRep root = factory.createHepRep();
85
86
87 HepRepTreeID treeID = factory.createHepRepTreeID("DetectorType", "1.0");
88 HepRepTypeTree typeTree = factory.createHepRepTypeTree(treeID);
89 root.addTypeTree(typeTree);
90
91 HepRepInstanceTree instanceTree = factory.createHepRepInstanceTree("Detector", "1.0", typeTree);
92 root.addInstanceTree(instanceTree);
93
94 String detectorLayer = "Detector";
95 root.addLayer(detectorLayer);
96
97 HepRepType barrel = factory.createHepRepType(typeTree, "Barrel");
98 barrel.addAttValue("layer", detectorLayer);
99 HepRepType endcap = factory.createHepRepType(typeTree, "Endcap");
100 endcap.addAttValue("layer", detectorLayer);
101
102
103
104
105 for (IDetectorElement de : DetectorElementStore.getInstance())
106 {
107
108 DetectorElementToHepRepConverter.convert(de, factory, root, -1, false, null);
109 }
110
111
112 HepRepWriter writer =
113 HepRepFactory.create().createHepRepWriter(new FileOutputStream(filepath),false,false);
114 writer.write(root,"test");
115 writer.close();
116 }
117 }