EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHCompositeNode.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHCompositeNode.cc
1 //-----------------------------------------------------------------------------
2 //
3 // The PHOOL's Software
4 // Copyright (C) PHENIX collaboration, 1999
5 //
6 // Implementation of class PHCompositeNode
7 //
8 //-----------------------------------------------------------------------------
9 #include "PHCompositeNode.h"
10 #include "PHPointerListIterator.h"
11 #include "phool.h"
12 #include "phooldefs.h"
13 
14 #include <iostream>
15 
16 using namespace std;
17 
19  : PHNode(name, "PHCompositeNode")
20  , deleteMe(0)
21 {
22  type = "PHCompositeNode";
23 }
24 
26 {
27  // we need to mark this node to be to deleted
28  // The recursive taking out of deleted subnodes via
29  // forgetMe interferes with the way the PHPointerList::clearAndDestroy()
30  // works but it has to be executed in case the PHCompositeNode is
31  // a parent and supposed to stay. Then the deleted node has to take itself
32  // out of the node list
33  deleteMe = 1;
35 }
36 
38 {
39  //
40  // Check all existing subNodes for name-conflict.
41  //
43  PHNode* thisNode;
44  while ((thisNode = nodeIter()))
45  {
46  if (thisNode->getName() == newNode->getName())
47  {
48  cout << PHWHERE << "Node " << newNode->getName()
49  << " already exists" << endl;
50  return false;
51  }
52  }
53  //
54  // No conflict, so we can append the new node.
55  //
56  newNode->setParent(this);
57  return (subNodes.append(newNode));
58 }
59 
61 {
63  PHNode* thisNode;
64  while ((thisNode = nodeIter()))
65  {
66  if (!thisNode->isPersistent())
67  {
68  subNodes.removeAt(nodeIter.pos());
69  --nodeIter;
70  delete thisNode;
71  }
72  else
73  {
74  thisNode->prune();
75  }
76  }
77 }
78 
80 {
81  // if this PHCompositeNode is supposed to be deleted,
82  // do not remove the child from the list,
83  // otherwise the clearanddestroy() bookkeeping gets
84  // confused and deletes only every other node
85  if (deleteMe)
86  {
87  return;
88  }
90  PHNode* thisNode;
91  while (child && (thisNode = nodeIter()))
92  {
93  if (thisNode == child)
94  {
95  subNodes.removeAt(nodeIter.pos());
96  child = 0;
97  }
98  }
99 }
100 
101 bool PHCompositeNode::write(PHIOManager* IOManager, const std::string& path)
102 {
103  string newPath = name;
104  if (!path.empty())
105  {
106  newPath = path + phooldefs::branchpathdelim + name;
107  }
109  PHNode* thisNode;
110  bool success = true;
111  while ((thisNode = nodeIter()))
112  {
113  if (!(thisNode->write(IOManager, newPath)))
114  {
115  success = false;
116  }
117  }
118  return success;
119 }
120 
121 void PHCompositeNode::print(const string& path)
122 {
123  string newPath = " " + path;
124  cout << path << name << " (" << type << ")/" << endl;
126  PHNode* thisNode;
127  while ((thisNode = nodeIter()))
128  {
129  thisNode->print(newPath);
130  }
131 }