View Javadoc

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   * This class maintains a list of LayerStat objects, a pointer to
13   * the current such object and a pointer to the cluster status.
14   * The cluster status is the one holding the relevant cluster list
15   * and miss.
16   *<p>
17   * These chains are constructed and modified by class LTrack.
18   *<p>
19   * Class LTrack is a friend so it can manipulate the chain and
20   * iterators though private accessor methods.
21   *<p>
22   * The only public methods are the destructor and methods to return
23   * the cluster list and miss.
24   *
25   *@author Norman A. Graf
26   *@version 1.0
27   *
28   **/
29  
30  public class LayerStatChain
31  {
32      
33      // package (not private) attributes so LTrack can access them
34      // chain
35      LinkedList _stats; // List of LayerStat objects
36      
37      // current stats
38      ListIterator _istat_current;
39      
40      // cluster status
41      ListIterator _istat_cluster;
42      
43      // package (private) methods
44      
45      private boolean debug;
46      
47      // constructor from a layer status
48      // current status is set, cluster status is left unset
49      LayerStatChain( LayerStat lstat)
50      {
51          _stats = new LinkedList();
52          _stats.add(lstat);
53          _istat_current = _stats.listIterator(); //should be first iterator
54          _istat_cluster = _stats.listIterator(_stats.size()); //should be last iterator, needs work
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      // return if the current status is set
63      boolean currentStatusIsValid()
64      {
65          return _istat_current.hasNext();
66      }
67      
68      // return the cluster status
69      LayerStat clusterStatus()
70      {
71          Assert.assertTrue( clusterStatusIsValid() );
72          return (LayerStat) _stats.get(_istat_cluster.nextIndex());
73      }
74      
75      // methods
76      
77      //
78      
79      /**
80       *default constructor
81       *
82       */
83      public LayerStatChain()
84      {
85          _stats = new LinkedList();
86          _istat_current = _stats.listIterator();              // at beginning
87          _istat_cluster = _stats.listIterator(_stats.size()); // at end
88      }
89      
90      //
91      
92      /**
93       *copy constructor
94       *
95       * @param   lsc LayerStatChain to replicate
96       */
97      public LayerStatChain( LayerStatChain lsc)
98      {
99          
100         // copy the iterators
101                 /*
102                   _istat_current = _stats.end();
103                   _istat_cluster = _stats.end();
104                   StatList::const_iterator istat_rhs = rhs._stats.begin();
105                   StatList::iterator istat_lhs = _stats.begin();
106                   while ( istat_rhs != rhs._stats.end() ) {
107                     if ( istat_rhs == rhs._istat_current ) _istat_current = istat_lhs;
108                     if ( istat_rhs == rhs._istat_cluster ) _istat_cluster = istat_lhs;
109                     ++istat_rhs;
110                     ++istat_lhs;
111                   }
112                  
113                  */
114         
115         // copy the list
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     // Is the cluster status set?
149     boolean clusterStatusIsValid()
150     {
151         return _istat_current.hasNext();
152     }
153     
154     // Is the cluster status at the first element of the list?
155     boolean clusterStatusAtFirst()
156     {
157         return _istat_cluster == _stats.listIterator(0);
158     }
159     
160     // Is the cluster status at the last element of the list?
161     // (Last real entry -- not stl end().)
162     boolean clusterStatusAtLast()
163     {
164         if ( ! currentStatusIsValid() ) return false;
165         return _istat_cluster == _stats.listIterator(_stats.size()-1);
166     }
167     
168     // return the current status
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     // Are there clusters associated with this chain?
178     boolean hasClusters()
179     {
180         if ( ! clusterStatusIsValid() ) return false;
181         return _istat_cluster.hasNext(); //need to check
182     }
183     
184     // return the list of clusters
185     List clusters()
186     {
187         if ( ! clusterStatusIsValid() ) return new LinkedList();
188         return ( (LayerStat) _stats.get(_istat_cluster.nextIndex())).clusters();
189         
190     }
191     
192     // return the list of clusters near a track
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     // Is there a miss associated with this chain?
200     boolean hasMiss()
201     {
202         //return (get_miss() != null); //need to improve this
203         return (clusterStatusIsValid() ); //need to check
204     }
205     
206     // Return the miss.
207     // Use get_miss()->new_copy() to get a mutable copy of the miss.
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      * output stream
217      *
218      * @return String representation of this class
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 }