Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
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
PHCompositeNode::PHCompositeNode
(
const
std::string
&
n
)
17
:
PHNode
(n,
"PHCompositeNode"
)
18
{
19
type
=
"PHCompositeNode"
;
20
}
21
22
PHCompositeNode::~PHCompositeNode
()
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;
31
subNodes
.
clearAndDestroy
();
32
}
33
34
bool
PHCompositeNode::addNode
(
PHNode
* newNode)
35
{
36
//
37
// Check all existing subNodes for name-conflict.
38
//
39
PHPointerListIterator<PHNode>
nodeIter(
subNodes
);
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
57
void
PHCompositeNode::prune
()
58
{
59
PHPointerListIterator<PHNode>
nodeIter(
subNodes
);
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
76
void
PHCompositeNode::forgetMe
(
PHNode
*
child
)
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
}
86
PHPointerListIterator<PHNode>
nodeIter(
subNodes
);
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
98
bool
PHCompositeNode::write
(
PHIOManager
* IOManager,
const
std::string
&
path
)
99
{
100
std::string
newPath =
name
;
101
if
(!path.empty())
102
{
103
newPath = path +
phooldefs::branchpathdelim
+
name
;
104
}
105
PHPointerListIterator<PHNode>
nodeIter(
subNodes
);
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
118
void
PHCompositeNode::print
(
const
std::string
&
path
)
119
{
120
std::string
newPath =
" "
+
path
;
121
std::cout << path <<
name
<<
" ("
<<
type
<<
")/"
<< std::endl;
122
PHPointerListIterator<PHNode>
nodeIter(
subNodes
);
123
PHNode
* thisNode;
124
while
((thisNode = nodeIter()))
125
{
126
thisNode->
print
(newPath);
127
}
128
}
coresoftware
blob
master
offline
framework
phool
PHCompositeNode.cc
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:05
using
1.8.2 with
sPHENIX GitHub integration