1 package org.lcsim.geometry.util;
2
3 import hep.physics.vec.Hep3Vector;
4 import hep.physics.vec.BasicHep3Vector;
5
6 import org.lcsim.geometry.Subdetector;
7 import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
8
9
10
11
12
13
14
15
16
17 public class BaseIDDecoder
18 implements org.lcsim.geometry.IDDecoder
19 {
20 protected org.lcsim.geometry.util.IDDecoder decoder;
21 protected IDDescriptor descriptor;
22 protected int[] values;
23 protected boolean valid = false;
24 protected Subdetector detector;
25 protected int layerIndex = -1;
26
27 public BaseIDDecoder()
28 {}
29
30 public BaseIDDecoder(IDDescriptor id)
31 {
32 setIDDescription(id);
33 }
34
35 public org.lcsim.geometry.util.IDDecoder getDecoder()
36 {
37 return decoder;
38 }
39
40 public double getX()
41 {
42 return 0;
43 }
44
45 public double getY()
46 {
47 return 0;
48 }
49
50 public double getZ()
51 {
52 return 0;
53 }
54
55 public double getPhi()
56 {
57 return 0;
58 }
59
60 public double getTheta()
61 {
62 return 0;
63 }
64
65 public double[] getPosition()
66 {
67 return new double[] { getX(), getY(), getZ() };
68 }
69
70 public void setID(long id)
71 {
72 decoder.setID(id);
73 decoder.getValues(values);
74 valid = true;
75 }
76
77
78 public int getValue(String field)
79 {
80 return decoder.getValue(field);
81 }
82
83
84 public int getValue(int index)
85 {
86 return decoder.getValue(index);
87 }
88
89 public int[] getValues(int[] buffer)
90 {
91 return decoder.getValues(buffer);
92 }
93
94
95 public String getFieldName(int index)
96 {
97 return decoder.getFieldName(index);
98 }
99
100
101 public int getFieldIndex(String name)
102 {
103 return decoder.getFieldIndex(name);
104 }
105
106
107 public int getFieldCount()
108 {
109 return values.length;
110 }
111
112 public void setIDDescription(IDDescriptor id)
113 {
114 descriptor = id;
115 decoder = new org.lcsim.geometry.util.IDDecoder(id);
116 values = new int[id.fieldCount()];
117
118
119 setLayerIndex(id);
120 }
121
122 public IDDescriptor getIDDescription()
123 {
124 return descriptor;
125 }
126
127
128 public String toString()
129 {
130 return decoder == null ? "NoDecoder" : decoder.toString();
131 }
132
133 public boolean isValid()
134 {
135 return valid;
136 }
137
138 public BarrelEndcapFlag getBarrelEndcapFlag()
139 {
140 return BarrelEndcapFlag.createBarrelEndcapFlag(decoder.getValue("barrel"));
141 }
142
143 public void setSubdetector(Subdetector d)
144 {
145 detector = d;
146 }
147
148 public Subdetector getSubdetector()
149 {
150 return detector;
151 }
152
153 private void setLayerIndex(IDDescriptor id)
154 {
155 try {
156 layerIndex = id.indexOf("layer");
157 }
158 catch (IllegalArgumentException x)
159 {
160 System.err.println("WARNING: The layer field does not exist in this IDDecoder!");
161 }
162 }
163
164 public int getLayer()
165 {
166 return values[layerIndex];
167 }
168
169 public int getVLayer()
170 {
171 return getLayer();
172 }
173
174 public int getSystemID()
175 {
176 int sysid = -1;
177 if ( getSubdetector() != null )
178 {
179 sysid = getSubdetector().getSystemID();
180 }
181 else
182 {
183 sysid = decoder.getValue("system");
184 }
185 return sysid;
186 }
187
188 public int getSystemNumber()
189 {
190 return getSystemID();
191 }
192
193 public long[] getNeighbourIDs(int deltaLayer, int deltaTheta, int deltaPhi)
194 {
195 long[] dummyNeighbours = {0, 0, 0};
196 return dummyNeighbours;
197 }
198
199 public boolean supportsNeighbours()
200 {
201 return false;
202 }
203
204 public long[] getNeighbourIDs()
205 {
206 return getNeighbourIDs(1,1,1);
207 }
208
209 public long findCellContainingXYZ(Hep3Vector pos)
210 {
211 return 0;
212 }
213
214 public long findCellContainingXYZ(double[] pos)
215 {
216 return 0;
217 }
218
219
220
221
222
223
224 public final Hep3Vector getPositionVector()
225 {
226 return new BasicHep3Vector(getPosition());
227 }
228 }