QwAnalysis
treenode.cc
Go to the documentation of this file.
1 /*------------------------------------------------------------------------*//*!
2 
3  \file treenode.cc
4  \ingroup QwTracking
5 
6  \author Wolfgang Wander <wwc@hermes.desy.de>
7  \author Burnham Stokes <bestokes@jlab.org>
8  \author Wouter Deconinck <wdconinc@mit.edu>
9 
10  \date 2009-09-04 18:06:23
11 
12  \brief Definition of a treenode which contains the bits that make up a tree pattern
13 
14 *//*-------------------------------------------------------------------------*/
15 
16 #include "treenode.h"
17 
18 // Qweak headers
19 #include "QwLog.h"
20 #include "nodenode.h"
21 
22 namespace QwTracking {
23 
24 int treenode::fDebug = 0;
25 
26 /**
27  * Default constructor
28  * @param size Size of the bit pattern
29  */
30 treenode::treenode(unsigned int size)
31 {
32  // Set the size
33  fSize = size;
34  fBit = new int[fSize];
35  for (unsigned int i = 0; i < fSize; i++) fBit[i] = 0;
36 
37  // Initialize pointers
38  fNext = 0;
39  for (int i = 0; i < 4; i++) fSon[i] = 0;
40 }
41 
42 /**
43  * Copy-constructor from object
44  * @param node Original tree node
45  */
47 {
48  // Copy the node
49  *this = node;
50 
51  // Copy the bit pattern
52  fBit = new int[fSize];
53  for (unsigned int i = 0; i < fSize; i++) fBit[i] = node.fBit[i];
54 
55  // Set the external reference link
56  this->fRef = -1L;
57 
58  // Initialize pointers
59  fNext = 0;
60  for (int i = 0; i < 4; i++) fSon[i] = 0;
61 }
62 
63 /**
64  * Copy-constructor from pointer
65  * @param node Pointer to original tree node
66  */
68 {
69  // Copy the node
70  *this = *node;
71 
72  // Copy the bit pattern
73  fBit = new int[fSize];
74  for (unsigned int i = 0; i < fSize; i++) fBit[i] = node->fBit[i];
75 
76  // Set the external reference link
77  this->fRef = -1L;
78 
79  // Initialize pointers
80  fNext = 0;
81  for (int i = 0; i < 4; i++) fSon[i] = 0;
82 }
83 
84 /**
85  * Destructor
86  */
88 {
89  // Delete the sons
90  for (int i = 0; i < 4; i++)
91  if (fSon[i]) delete fSon[i];
92 
93  // Delete the bit pattern
94  delete[] fBit;
95 }
96 
97 /**
98  * Print the entire tree (descending all the way down)
99  * \warning This will produce a lot of screen output!
100  *
101  * @param recursive Flag to enable recursive calls
102  * @param indent Indentation level (for recursive calls)
103  */
104 void treenode::Print(bool recursive, int indent)
105 {
106  // Print this node
107  std::string indentation;
108  for (int i = 0; i < indent; i++) indentation += " ";
109  QwOut << indentation << this << ": " << *this << QwLog::endl;
110 
111  // Bail out if too deep (probably in a loop)
112  if (indent > 50) {
113  QwWarning << "Tree is too deep to print, probably a self-reference somewhere" << QwLog::endl;
114  return;
115  }
116 
117  // Descend to the sons of this node
118  for (int i = 0; recursive && i < 4; i++) {
119  nodenode* node = this->fSon[i];
120  if (node) {
121  treenode* tree = node->GetTree();
122  if (tree)
123  tree->Print(recursive,indent+1);
124  } // if (node)
125 
126  } // loop over sons
127 }
128 
129 /**
130  * Stream summary info about the tree node
131  * @param stream Stream as lhs of the operator
132  * @param tn Tree node as rhs of the operator
133  * @return Stream as result of the operator
134  */
135 std::ostream& operator<< (std::ostream& stream, const treenode& tn)
136 {
137  stream << "(" << tn.fMinLevel << "," << tn.fMaxLevel << ") ";
138  for (unsigned int i = 0; i < tn.fSize; i++)
139  stream << tn.fBit[i] << ",";
140  stream << " width = " << tn.fWidth << ",";
141  stream << " ref = " << tn.fRef;
142  return stream;
143 }
144 
145 } // namespace QwTracking
#define QwOut
Predefined log drain for explicit output.
Definition: QwLog.h:35
treenode * GetTree() const
Get the tree.
Definition: nodenode.h:66
static int fDebug
Debug level.
Definition: treenode.h:123
void Print(bool recursive=false, int indent=0)
Print some debugging information.
Definition: treenode.cc:104
int fMinLevel
Minimum level at which this node is valid.
Definition: treenode.h:79
Definition of nodenode which links treenodes to their siblings.
int fWidth
Width in bins of the hit pattern.
Definition: treenode.h:87
int fRef
Reference of this node when writing to file.
Definition: treenode.h:90
A logfile class, based on an identical class in the Hermes analyzer.
nodenode * fSon[4]
Each tree has four son nodes.
Definition: treenode.h:95
unsigned int fSize
Definition: treenode.h:114
treenode * fNext
Link to the next tree node.
Definition: treenode.h:100
Definition of a treenode which contains the bits that make up a tree pattern.
int * fBit
Hit pattern, one bin specified per detector layer.
Definition: treenode.h:84
~treenode()
Destructor.
Definition: treenode.cc:87
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
treenode(unsigned int size)
Default constructor.
Definition: treenode.cc:30
int fMaxLevel
Maximum level at which this node is valid.
Definition: treenode.h:81
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
unsigned int size() const
Get size of the bit array.
Definition: treenode.h:123
A nodenode is used as a pointer which links treenodes to their siblings.
Definition: nodenode.h:42
A treenode contains the bits that make up a tree pattern.
Definition: treenode.h:63
std::ostream & operator<<(std::ostream &stream, const shortnode &sn)
Definition: shortnode.cc:93