QwAnalysis
shortnode.cc
Go to the documentation of this file.
1 /*------------------------------------------------------------------------*//*!
2 
3  \file shortnode.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 shortnode, the short version of a nodenode
13 
14 *//*-------------------------------------------------------------------------*/
15 
16 #include "shortnode.h"
17 
18 // Qweak headers
19 #include "QwLog.h"
20 
21 // Qweak tree headers
22 #include "shorttree.h"
23 
24 namespace QwTracking {
25 
26 int shortnode::fDebug = 0;
27 
28 /**
29  * Constructor sets the debug level to zero
30  */
32 {
33  // Initialize pointers
34  fNext = 0;
35  fTree = 0;
36  // No tree pointed at yet
37  fNTrees = 0;
38 }
39 
40 /**
41  * Destructor deletes the memory occupied by the next nodes and daughter tree
42  */
44 {
45  // Delete the next node in the linked list (recursion)
46  if (fNext) delete fNext;
47 }
48 
49 /**
50  * Get the tree, or an indexed tree if this is an array of trees.
51  * @param i The index of the tree (default is zero)
52  * @return Pointer to the tree
53  */
55 {
56  if (fNTrees > 1 && i < fNTrees)
57  return &(fTree[i]);
58  else
59  return fTree;
60 }
61 
62 /**
63  * Print some debugging information
64  * @param recursive Flag to enable recursive calls
65  * @param indent Indentation level (for recursive calls)
66  */
67 void shortnode::Print(bool recursive, int indent)
68 {
69  // Print this node
70  std::string indentation;
71  for (int i = 0; i < indent; i++) indentation += " ";
72  QwOut << this << ": " << *this << QwLog::endl;
73 
74  // Print tree
75  if (recursive && fTree) {
76  QwOut << indentation << "tree: ";
77  fTree->Print(recursive,indent+1);
78  }
79 
80  // Print next node
81  if (recursive && fNext) {
82  QwOut << indentation << "next: ";
83  fNext->Print(recursive,indent);
84  }
85 }
86 
87 /**
88  * Stream some info about the short node
89  * @param stream Stream as lhs of the operator
90  * @param sn Short node as rhs of the operator
91  * @return Stream as result of the operator
92  */
93 std::ostream& operator<< (std::ostream& stream, const shortnode& sn)
94 {
95  stream << *(sn.GetTree());
96  return stream;
97 }
98 
99 } // namespace QwTracking
~shortnode()
Destructor.
Definition: shortnode.cc:43
int fNTrees
Number of trees pointed at by the pointer above.
Definition: shortnode.h:57
#define QwOut
Predefined log drain for explicit output.
Definition: QwLog.h:35
shortnode * fNext
Link to the next node.
Definition: shortnode.h:50
shorttree * fTree
Definition: shortnode.h:54
void Print(bool recursive=false, int indent=0)
Print some debugging information.
Definition: shorttree.cc:61
shortnode()
Default constructor.
Definition: shortnode.cc:31
A logfile class, based on an identical class in the Hermes analyzer.
Similar to a treenode.
Definition: shorttree.h:44
static int fDebug
Debug level.
Definition: shortnode.h:81
shorttree * GetTree(int i=0) const
Get the tree.
Definition: shortnode.cc:54
Definition of a shortnode, the short version of a nodenode.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Similar to a nodenode.
Definition: shortnode.h:38
std::ostream & operator<<(std::ostream &stream, const shortnode &sn)
Definition: shortnode.cc:93
void Print(bool recursive=false, int indent=0)
Print some debugging information.
Definition: shortnode.cc:67