StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTrackNode.cxx
1 /***************************************************************************
2  *
3  * $Id: StTrackNode.cxx,v 2.17 2013/07/23 11:21:49 jeromel Exp $
4  *
5  * Author: Thomas Ullrich, Sep 1999
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StTrackNode.cxx,v $
13  * Revision 2.17 2013/07/23 11:21:49 jeromel
14  * Undo past week changes
15  *
16  * Revision 2.15 2013/04/10 19:15:53 jeromel
17  * Step back from StEvent changes - previous change recoverable [Thomas OK-ed]
18  *
19  * Revision 2.13 2003/11/25 04:10:47 perev
20  * bug in erase fixed
21  *
22  * Revision 2.12 2003/09/02 17:58:06 perev
23  * gcc 3.2 updates + WarnOff
24  *
25  * Revision 2.11 2003/04/30 20:37:06 perev
26  * Warnings cleanup. Modified lines marked VP
27  *
28  * Revision 2.10 2002/04/24 02:26:57 ullrich
29  * Replaced iterator loop by index loop in entries(StTrackType).
30  *
31  * Revision 2.9 2002/04/18 23:38:21 jeromel
32  * Implementation of the SVT 2 tables scheme ...
33  *
34  * Revision 2.8 2001/04/05 04:00:58 ullrich
35  * Replaced all (U)Long_t by (U)Int_t and all redundant ROOT typedefs.
36  *
37  * Revision 2.7 2000/08/17 00:35:27 ullrich
38  * Added hooks for handling tpt tracks.
39  *
40  * Revision 2.6 2000/03/23 13:49:31 ullrich
41  * Not implemented track type 'secondary' now handled
42  * in a more clean way; entries(secondary) returns 0.
43  *
44  * Revision 2.5 1999/12/01 20:04:58 ullrich
45  * Fixed bug in track() method.
46  *
47  * Revision 2.4 1999/11/09 15:44:17 ullrich
48  * Removed method unlink() and all calls to it.
49  *
50  * Revision 2.3 1999/11/05 15:27:10 ullrich
51  * Added non-const versions of several methods
52  *
53  * Revision 2.2 1999/10/28 22:27:44 ullrich
54  * Adapted new StArray version. First version to compile on Linux and Sun.
55  *
56  * Revision 2.1 1999/10/13 19:45:44 ullrich
57  * Initial Revision
58  *
59  **************************************************************************/
60 #include <Stiostream.h>
61 #include "StTrackNode.h"
62 #include "StGlobalTrack.h"
63 #include "StPrimaryTrack.h"
64 
65 ClassImp(StTrackNode)
66 
67 static const char rcsid[] = "$Id: StTrackNode.cxx,v 2.17 2013/07/23 11:21:49 jeromel Exp $";
68 
69 StTrackNode::StTrackNode() { /* noop */ }
70 
71 StTrackNode::~StTrackNode() { /* noop */ }
72 
73 void
74 StTrackNode::addTrack(StTrack* track)
75 {
76  if (track) {
77  switch (track->type()) {
78  case primary:
79  case estPrimary:
80  mReferencedTracks.push_back(track);
81  break;
82  case secondary: // not implemented yet
83  cerr << "StTrackNode::addTrack(): track type 'secondary' not implemented yet." << endl;
84  break;
85  case global:
86  case tpt:
87  case estGlobal:
88  mOwnedTracks.push_back(track);
89  break;
90  default:
91  cerr << "StTrackNode::addTrack(): cannot add, unknown track type." << endl;
92  return;
93  break;
94  }
95  track->setNode(this);
96  }
97 }
98 
99 void
100 StTrackNode::removeTrack(StTrack* track)
101 {
102  StPtrVecTrackIterator iter;
103  StSPtrVecTrackIterator iterS;
104  if (track) {
105  switch (track->type()) {
106  case primary:
107  case estPrimary:
108  for (iter = mReferencedTracks.begin(); iter < mReferencedTracks.end(); iter++)
109  if (*iter == track) mReferencedTracks.erase(iter);
110  break;
111  case secondary: // not implemented yet
112  cerr << "StTrackNode::removeTrack(): track type 'secondary' not implemented yet." << endl;
113  break;
114  case tpt:
115  case global:
116  case estGlobal:
117  for (iterS = mOwnedTracks.begin(); iterS < mOwnedTracks.end(); iterS++)
118  if (*iterS == track) mOwnedTracks.erase(iterS);
119  break;
120  default:
121  cerr << "StTrackNode::removeTrack(): cannot remove, unknown track type." << endl;
122  break;
123  }
124  track->setNode(0);
125  }
126 }
127 
128 unsigned int
129 StTrackNode::entries() const
130 {
131  return mReferencedTracks.size() + mOwnedTracks.size();
132 }
133 
134 const StTrack*
135 StTrackNode::track(unsigned int i) const
136 {
137  if (i < mOwnedTracks.size())
138  return mOwnedTracks[i];
139  else {
140  i -= mOwnedTracks.size();
141  if (i < mReferencedTracks.size())
142  return mReferencedTracks[i];
143  else
144  return 0;
145  }
146 }
147 
148 StTrack*
149 StTrackNode::track(unsigned int i)
150 {
151  if (i < mOwnedTracks.size())
152  return mOwnedTracks[i];
153  else {
154  i -= mOwnedTracks.size();
155  if (i < mReferencedTracks.size())
156  return mReferencedTracks[i];
157  else
158  return 0;
159  }
160 }
161 
162 unsigned int
163 StTrackNode::entries(StTrackType type) const
164 {
165  unsigned int i;
166  //VPunused StSPtrVecTrackConstIterator iterS;
167  //VPunused StPtrVecTrackConstIterator iter;
168  unsigned int counter;
169 
170  switch (type) {
171  case primary:
172  case estPrimary:
173  for (counter=0, i=0; i < mReferencedTracks.size(); i++)
174  if (mReferencedTracks[i]->type() == type) counter++;
175  return counter;
176  break;
177  case secondary: // not implemented yet
178  cerr << "StTrackNode::entries(): track type 'secondary' not implemented yet." << endl;
179  return 0;
180  break;
181  case tpt:
182  case global:
183  case estGlobal:
184  for (counter=0, i=0; i < mOwnedTracks.size(); i++)
185  if (mOwnedTracks[i]->type() == type) counter++;
186  return counter;
187  break;
188  default:
189  cerr << "StTrackNode::entries(): unknown track type." << endl;
190  return 0;
191  break;
192  }
193 }
194 
195 const StTrack*
196 StTrackNode::track(StTrackType type, unsigned int i) const
197 {
198  int j;
199  unsigned int k;
200 
201  switch (type) {
202  case primary:
203  case estPrimary:
204  for (j=-1, k=0; k < mReferencedTracks.size(); k++) {
205  if (mReferencedTracks[k]->type() == type) j++;
206  if (j == static_cast<int>(i)) return mReferencedTracks[k];
207  }
208  return 0;
209  break;
210  case secondary: // not implemented yet
211  cerr << "StTrackNode::track(): track type 'secondary' not implemented yet." << endl;
212  return 0;
213  break;
214  case tpt:
215  case global:
216  case estGlobal:
217  for (j=-1, k=0; k < mOwnedTracks.size(); k++) {
218  if (mOwnedTracks[k]->type() == type) j++;
219  if (j == static_cast<int>(i)) return mOwnedTracks[k];
220  }
221  return 0;
222  break;
223  default:
224  cerr << "StTrackNode::track(): unknown track type." << endl;
225  return 0;
226  break;
227  }
228 }
229 
230 StTrack*
231 StTrackNode::track(StTrackType type, unsigned int i)
232 {
233  int j;
234  unsigned int k;
235 
236  switch (type) {
237  case primary:
238  case estPrimary:
239  for (j=-1, k=0; k < mReferencedTracks.size(); k++) {
240  if (mReferencedTracks[k]->type() == type) j++;
241  if (j == static_cast<int>(i)) return mReferencedTracks[k];
242  }
243  return 0;
244  break;
245  case secondary: // not implemented yet
246  cerr << "StTrackNode::track(): track type 'secondary' not implemented yet." << endl;
247  return 0;
248  break;
249  case tpt:
250  case global:
251  case estGlobal:
252  for (j=-1, k=0; k < mOwnedTracks.size(); k++) {
253  if (mOwnedTracks[k]->type() == type) j++;
254  if (j == static_cast<int>(i)) return mOwnedTracks[k];
255  }
256  return 0;
257  break;
258  default:
259  cerr << "StTrackNode::track(): unknown track type." << endl;
260  return 0;
261  break;
262  }
263 }
264