Analysis Software
Documentation for sPHENIX simulation 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 
17  : PHNode(n, "PHCompositeNode")
18 {
19  type = "PHCompositeNode";
20 }
21 
23 {
24  // we need to mark this node to be to deleted
25  // The recursive taking out of deleted subnodes via
26  // forgetMe interferes with the way the PHPointerList::clearAndDestroy()
27  // works but it has to be executed in case the PHCompositeNode is
28  // a parent and supposed to stay. Then the deleted node has to take itself
29  // out of the node list
30  deleteMe = 1;
32 }
33 
35 {
36  //
37  // Check all existing subNodes for name-conflict.
38  //
40  PHNode* thisNode;
41  while ((thisNode = nodeIter()))
42  {
43  if (thisNode->getName() == newNode->getName())
44  {
45  std::cout << PHWHERE << "Node " << newNode->getName()
46  << " already exists" << std::endl;
47  return false;
48  }
49  }
50  //
51  // No conflict, so we can append the new node.
52  //
53  newNode->setParent(this);
54  return (subNodes.append(newNode));
55 }
56 
58 {
60  PHNode* thisNode;
61  while ((thisNode = nodeIter()))
62  {
63  if (!thisNode->isPersistent())
64  {
65  subNodes.removeAt(nodeIter.pos());
66  --nodeIter;
67  delete thisNode;
68  }
69  else
70  {
71  thisNode->prune();
72  }
73  }
74 }
75 
77 {
78  // if this PHCompositeNode is supposed to be deleted,
79  // do not remove the child from the list,
80  // otherwise the clearanddestroy() bookkeeping gets
81  // confused and deletes only every other node
82  if (deleteMe)
83  {
84  return;
85  }
87  PHNode* thisNode;
88  while (child && (thisNode = nodeIter()))
89  {
90  if (thisNode == child)
91  {
92  subNodes.removeAt(nodeIter.pos());
93  child = nullptr;
94  }
95  }
96 }
97 
99 {
100  std::string newPath = name;
101  if (!path.empty())
102  {
103  newPath = path + phooldefs::branchpathdelim + name;
104  }
106  PHNode* thisNode;
107  bool success = true;
108  while ((thisNode = nodeIter()))
109  {
110  if (!(thisNode->write(IOManager, newPath)))
111  {
112  success = false;
113  }
114  }
115  return success;
116 }
117 
119 {
120  std::string newPath = " " + path;
121  std::cout << path << name << " (" << type << ")/" << std::endl;
123  PHNode* thisNode;
124  while ((thisNode = nodeIter()))
125  {
126  thisNode->print(newPath);
127  }
128 }