StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMcTofHitCollection.cc
1 /***************************************************************************
2  *
3  * $Id: StMcTofHitCollection.cc,v 2.3 2012/03/01 16:48:29 perev Exp $
4  * $Log: StMcTofHitCollection.cc,v $
5  * Revision 2.3 2012/03/01 16:48:29 perev
6  * method Browse() added
7  *
8  * Revision 2.2 2005/01/27 23:40:48 calderon
9  * Adding persistency to StMcEvent as a step for Virtual MonteCarlo.
10  *
11  * Revision 2.1 2003/08/20 18:50:21 calderon
12  * Addition of Tof classes and Pixel classes. Modified track, event, and
13  * container code to reflect this.
14  * Fix bug in StMcVertex and in clearing of some hit collections.
15  *
16  */
17 #include "TBrowser.h"
18 #include "StMcTofHitCollection.hh"
19 #include "StMcTofHit.hh"
20 
21 static const char rcsid[] = "$Id: StMcTofHitCollection.cc,v 2.3 2012/03/01 16:48:29 perev Exp $";
22 
23 ClassImp(StMcTofHitCollection);
24 //_____________________________________________________________________________
25 StMcTofHitCollection::StMcTofHitCollection()
26 {
27 }
28 
29 //_____________________________________________________________________________
30 StMcTofHitCollection::~StMcTofHitCollection()
31 {
32  // StMcTofHit provides its own new/delete operator, and
33  // mHits is a polymorphic container, so we need to do this.
34  for (unsigned int i=0; i<mHits.size(); i++) {
35  delete mHits[i];
36  mHits[i] = 0;
37  }
38 }
39 
40 //_____________________________________________________________________________
41 bool StMcTofHitCollection::addHit(StMcTofHit* hit)
42 {
43  if (!hit) return false;
44  mHits.push_back(hit);
45  return true;
46 }
47 
48 //_____________________________________________________________________________
49 unsigned long StMcTofHitCollection::numberOfHits() const
50 {
51  return mHits.size();
52 }
53 
54 //_____________________________________________________________________________
55 const StSPtrVecMcTofHit& StMcTofHitCollection::hits() const { return mHits; }
56 
57 //_____________________________________________________________________________
58 StSPtrVecMcTofHit& StMcTofHitCollection::hits() { return mHits; }
59 //_____________________________________________________________________________
60 void StMcTofHitCollection::Clear(const char*)
61 {
62  for (int i=0; i<(int)mHits.size(); i++)
63  {
64  delete mHits[i]; mHits[i] = 0;
65  }
66  mHits.clear();
67 }
68 //_____________________________________________________________________________
69 void StMcTofHitCollection::Browse(TBrowser *b)
70 {
71  // Browse this event (called by TBrowser).
72  for (int i=0; i<(int)mHits.size(); i++) {
73  TObject *obj = mHits[i]; if (!obj) continue;
74  TString ts(obj->GetName()); ts+="#"; ts+=i;
75  b->Add(obj,ts.Data());
76  }
77 }