1 package org.lcsim.recon.tracking.trflayer;
2
3 import java.util.*;
4
5 import org.lcsim.recon.tracking.trfutil.Assert;
6
7 import org.lcsim.recon.tracking.trfbase.ETrack;
8 import org.lcsim.recon.tracking.trfbase.Hit;
9 import org.lcsim.recon.tracking.trfbase.Miss;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class LayerStatChain
31 {
32
33
34
35 LinkedList _stats;
36
37
38 ListIterator _istat_current;
39
40
41 ListIterator _istat_cluster;
42
43
44
45 private boolean debug;
46
47
48
49 LayerStatChain( LayerStat lstat)
50 {
51 _stats = new LinkedList();
52 _stats.add(lstat);
53 _istat_current = _stats.listIterator();
54 _istat_cluster = _stats.listIterator(_stats.size());
55 if(debug) System.out.println("_istat_current.hasNext()= "+_istat_current.hasNext());
56 if(debug) System.out.println("_istat_current= "+_istat_current);
57 if(debug) System.out.println("_istat_cluster.hasNext()= "+_istat_cluster.hasNext());
58 if(debug) System.out.println("_istat_cluster= "+_istat_cluster);
59
60 }
61
62
63 boolean currentStatusIsValid()
64 {
65 return _istat_current.hasNext();
66 }
67
68
69 LayerStat clusterStatus()
70 {
71 Assert.assertTrue( clusterStatusIsValid() );
72 return (LayerStat) _stats.get(_istat_cluster.nextIndex());
73 }
74
75
76
77
78
79
80
81
82
83 public LayerStatChain()
84 {
85 _stats = new LinkedList();
86 _istat_current = _stats.listIterator();
87 _istat_cluster = _stats.listIterator(_stats.size());
88 }
89
90
91
92
93
94
95
96
97 public LayerStatChain( LayerStatChain lsc)
98 {
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 _stats = new LinkedList();
118 for(Iterator it = lsc._stats.iterator(); it.hasNext(); )
119 {
120 _stats.add( new LayerStat((LayerStat) it.next()) );
121 }
122 _istat_current = _stats.listIterator(_stats.size());
123 _istat_cluster = _stats.listIterator(_stats.size());
124 if(debug) System.out.println("_stats.size()= "+_stats.size());
125 for(int i = 0; i< _stats.size(); ++i)
126 {
127 ListIterator cur = lsc._stats.listIterator(i);
128 if(debug) System.out.println("cur= "+cur);
129 ListIterator clu = lsc._stats.listIterator(i);
130 if(debug) System.out.println("clu= "+clu);
131 if (cur.equals(lsc._istat_current) ) _istat_current = _stats.listIterator(i);
132 {
133 _istat_current = _stats.listIterator(i);
134 if(debug) System.out.println("found current match, i= "+i);
135 }
136 if (clu == lsc._istat_cluster) _istat_cluster = _stats.listIterator(i);
137 {
138 _istat_cluster = _stats.listIterator(i);
139 if(debug) System.out.println("found cluster match, i= "+i);
140 }
141
142 }
143
144 if(debug) System.out.println("copy _istat_current.hasNext()= "+_istat_current.hasNext());
145 if(debug) System.out.println("copy _istat_cluster.hasNext()= "+_istat_cluster.hasNext());
146 }
147
148
149 boolean clusterStatusIsValid()
150 {
151 return _istat_current.hasNext();
152 }
153
154
155 boolean clusterStatusAtFirst()
156 {
157 return _istat_cluster == _stats.listIterator(0);
158 }
159
160
161
162 boolean clusterStatusAtLast()
163 {
164 if ( ! currentStatusIsValid() ) return false;
165 return _istat_cluster == _stats.listIterator(_stats.size()-1);
166 }
167
168
169 LayerStat currentStatus()
170 {
171 Assert.assertTrue( currentStatusIsValid() );
172 if(debug) System.out.println("get_current_status= "+_istat_current.hasNext());
173 if(debug) System.out.println("_istat_current nextIndex= "+ _istat_current.nextIndex());
174 return (LayerStat) _stats.get(_istat_current.nextIndex());
175 }
176
177
178 boolean hasClusters()
179 {
180 if ( ! clusterStatusIsValid() ) return false;
181 return _istat_cluster.hasNext();
182 }
183
184
185 List clusters()
186 {
187 if ( ! clusterStatusIsValid() ) return new LinkedList();
188 return ( (LayerStat) _stats.get(_istat_cluster.nextIndex())).clusters();
189
190 }
191
192
193 List clusters(ETrack tre)
194 {
195 if ( ! clusterStatusIsValid() ) return new LinkedList();
196 return ( (LayerStat) _stats.get(_istat_cluster.nextIndex())).clusters(tre);
197 }
198
199
200 boolean hasMiss()
201 {
202
203 return (clusterStatusIsValid() );
204 }
205
206
207
208 Miss miss()
209 {
210 if ( ! clusterStatusIsValid() ) throw new IllegalArgumentException("LayerStatChain: check status before calling get_miss()!");
211 else return ( (LayerStat) _stats.get(_istat_cluster.nextIndex())).miss();
212 }
213
214
215
216
217
218
219
220 public String toString()
221 {
222 int size = _stats.size();
223 StringBuffer sb = new StringBuffer(getClass().getName()+" Layer status chain has " + size + " entr");
224
225 if ( size == 0 )
226 {
227 sb.append( "ies.");
228 return sb.toString();
229 }
230 if ( size == 1 ) sb.append( "y:");
231 if ( size > 1 ) sb.append( "ies:");
232 for ( Iterator istat=_stats.iterator(); istat.hasNext(); )
233 {
234 sb.append( "\n"+ istat.next() );
235 if ( istat == _istat_current ) sb.append( " (current layer)");
236 if ( istat == _istat_cluster ) sb.append( " (cluster layer)");
237 }
238 return sb.toString();
239 }
240
241 }