StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTpcHitCollection.cxx
1 /***************************************************************************
2  *
3  * $Id: StTpcHitCollection.cxx,v 2.7 2019/04/02 15:32:49 smirnovd Exp $
4  *
5  * Author: Thomas Ullrich, July 1999
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StTpcHitCollection.cxx,v $
13  * Revision 2.7 2019/04/02 15:32:49 smirnovd
14  * Add iterator to loop over StTpcHits in StTpcHitContainer
15  *
16  * Revision 2.6 2019/04/02 15:32:42 smirnovd
17  * Add accessors to StTpcHitContainer
18  *
19  * Revision 2.5 2009/11/23 16:34:07 fisyak
20  * Cleanup, remove dependence on dst tables, clean up software monitors
21  *
22  * Revision 2.4 2001/04/05 04:00:57 ullrich
23  * Replaced all (U)Long_t by (U)Int_t and all redundant ROOT typedefs.
24  *
25  * Revision 2.3 1999/12/13 20:16:29 ullrich
26  * Changed numbering scheme for hw_position unpack methods (STAR conventions).
27  *
28  * Revision 2.2 1999/10/28 22:27:13 ullrich
29  * Adapted new StArray version. First version to compile on Linux and Sun.
30  *
31  * Revision 2.1 1999/10/13 19:45:27 ullrich
32  * Initial Revision
33  *
34  **************************************************************************/
35 #include "StTpcHitCollection.h"
36 #include "StTpcPadrowHitCollection.h"
37 #include "StTpcHit.h"
38 
39 static const char rcsid[] = "$Id: StTpcHitCollection.cxx,v 2.7 2019/04/02 15:32:49 smirnovd Exp $";
40 
41 ClassImp(StTpcHitCollection)
42 
43 StTpcHitCollection::StTpcHitCollection() { /* noop */ }
44 
45 StTpcHitCollection::~StTpcHitCollection() { /* noop */ }
46 
47 bool
48 StTpcHitCollection::addHit(StTpcHit* hit)
49 {
50  unsigned int s, r;
51  if (hit &&
52  (s = hit->sector()-1) < mNumberOfSectors &&
53  (r = hit->padrow()-1) < mSectors[s].numberOfPadrows()) {
54  mSectors[s].padrow(r)->hits().push_back(hit);
55  return kTRUE;
56  }
57  else
58  return kFALSE;
59 }
60 unsigned int
61 StTpcHitCollection::numberOfHits() const
62 {
63  unsigned int sum = 0;
64  for (int i=0; i<mNumberOfSectors; i++) {
65  for (unsigned int j=0; j<mSectors[i].numberOfPadrows(); j++) {
66  sum += mSectors[i].padrow(j)->hits().size();
67  }
68  }
69  return sum;
70 }
71 
73 StTpcHitCollection::sector(unsigned int i)
74 {
75  if (i < mNumberOfSectors)
76  return &(mSectors[i]);
77  else
78  return 0;
79 }
80 
82 StTpcHitCollection::sector(unsigned int i) const
83 {
84  if (i < mNumberOfSectors)
85  return &(mSectors[i]);
86  else
87  return 0;
88 }
89 
90 const StSPtrVecTpcHit*
91 StTpcHitCollection::hits(int sectorId, int padrowId) const
92 {
93  const StTpcSectorHitCollection* sc = (sectorId < mNumberOfSectors ? sector(sectorId) : nullptr);
94  const StTpcPadrowHitCollection* pc = (sc && padrowId < sc->numberOfPadrows() ? sc->padrow(padrowId) : nullptr);
95  return pc ? &pc->hits() : nullptr;
96 }
97 
99 StTpcHitCollection::StTpcHitIter::begin(StTpcHitCollection& c)
100 {
101  // Skip to first non-empty vector
102  for (int l1 = 0; l1 < c.numberOfSectors(); ++l1)
103  for (int l2 = 0; l2 < c.numberOfPadrows(l1); ++l2)
104  if ( !(*c.hits(l1, l2)).empty() ) return StTpcHitCollection::StTpcHitIter(c, l1, l2);
105  return end(c);
106 }
107 
109 StTpcHitCollection::StTpcHitIter::end(StTpcHitCollection& c)
110 {
111  return StTpcHitCollection::StTpcHitIter(c, c.numberOfSectors());
112 }
113 
115 StTpcHitCollection::StTpcHitIter::operator++()
116 {
117  ++iHit;
118 
119  // Reset counters when this level maximum reached
120  const StSPtrVecTpcHit& currVector = *coll.hits(iSector, iPadrow);
121  if (iHit >= currVector.size()) {
122  ++iPadrow;
123  iHit = 0;
124  }
125 
126  // Reset counters when this level maximum reached
127  if (iPadrow >= coll.numberOfPadrows(iSector)) {
128  ++iSector;
129  iPadrow = 0;
130  iHit = 0;
131  }
132 
133  if (*this != end(coll)) {
134  // Skip next vector if empty and increase indices
135  const StSPtrVecTpcHit& nextVector = *coll.hits(iSector, iPadrow);
136  if (nextVector.empty()) {
137  iHit = 0;
138  (*this).operator++();
139  }
140  }
141 
142  return *this;
143 }
144 
145 bool
146 StTpcHitCollection::StTpcHitIter::operator==(const StTpcHitCollection::StTpcHitIter &other) const
147 {
148  return &other.coll == &coll && other.iSector == iSector && other.iPadrow == iPadrow && other.iHit == iHit;
149 }
150 
151 bool
152 StTpcHitCollection::StTpcHitIter::operator!=(const StTpcHitCollection::StTpcHitIter &other) const
153 {
154  return !(*this == other);
155 }
156 
157 const StTpcHit*
158 StTpcHitCollection::StTpcHitIter::operator*() const
159 {
160  return (*coll.hits(iSector, iPadrow))[iHit];
161 }
An iterator over StTpcHits in a StTpcHitCollection.