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
PHTypedNodeIterator.h
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file PHTypedNodeIterator.h
1
#ifndef PHOOL_PHTYPEDNODEITERATOR_H
2
#define PHOOL_PHTYPEDNODEITERATOR_H
3
4
#include "
PHNodeIterator.h
"
5
6
#include <cstddef>
7
8
class
TObject;
9
template
<
typename
T>
10
class
PHIODataNode
;
11
class
PHCompositeNode
;
12
13
// A special PHOOL node iterator that simplifies finding and adding
14
// data nodes. This version is a templated class, to allow its use
15
// interactively in CINT. (CINT only allows function templates in
16
// very recent versions, which we aren't using yet.)
17
// @author Kyle Pope
18
19
template
<
class
T>
20
class
PHTypedNodeIterator
:
public
PHNodeIterator
21
{
22
public
:
24
explicit
PHTypedNodeIterator
(
PHCompositeNode
*
n
)
25
:
PHNodeIterator
(n)
26
{
27
myIODataNode
=
nullptr
;
28
}
29
30
PHTypedNodeIterator
()
31
:
PHNodeIterator
()
32
{
33
myIODataNode
=
nullptr
;
34
}
35
36
T
&
operator*
();
37
39
// virtual ~PHTypedNodeIterator(); // Need a virtual ~PHNodeIterator() !
40
~PHTypedNodeIterator
()
override
{}
46
PHIODataNode<T>
*
FindIODataNode
(
const
char
*
name
);
47
48
PHIODataNode<T>
*
find
(
const
char
*
name
);
49
56
bool
AddIODataNode
(
T
*
data
,
const
char
*
name
);
57
58
bool
insert
(
T
*
data
,
const
char
*
name
);
59
60
protected
:
61
PHIODataNode<T>
*
myIODataNode
;
62
};
63
64
template
<
class
T>
65
T
&
66
PHTypedNodeIterator<T>::operator*
()
67
{
68
return
*(myIODataNode->getData());
69
}
70
71
template
<
class
T>
72
PHIODataNode<T>
*
73
PHTypedNodeIterator<T>::FindIODataNode
(
const
char
*
name
)
74
{
75
return
find(name);
76
}
77
78
template
<
class
T>
79
PHIODataNode<T>
*
80
PHTypedNodeIterator<T>::find
(
const
char
*
name
)
81
{
82
// TODO: also check that "name" is not a null string!
83
if
(!name)
84
{
85
return
0;
86
}
87
88
// Can't do dynamic_cast here; it fails if node was created as
89
// PHIODataNode<X> instead of PHIODataNode<T>, even if T is a
90
// derived class of X! In general, T -> X does not imply A<T> ->
91
// A<X>. ("->" denotes "derives from", and "A" is any template
92
// class)
93
myIODataNode =
94
static_cast<
PHIODataNode<T>
*
>
(findFirst(
"PHIODataNode"
, name));
95
96
return
myIODataNode;
97
}
98
99
template
<
class
T>
100
bool
PHTypedNodeIterator<T>::AddIODataNode
(
T
*
data
,
const
char
*
name
)
101
{
102
return
insert(data, name);
103
}
104
105
template
<
class
T>
106
bool
PHTypedNodeIterator<T>::insert
(
T
*
data
,
const
char
*
name
)
107
{
108
// TODO: also check that "name" is not a null string!
109
if
(!name)
110
{
111
return
false
;
112
}
113
114
// For IODataNode, ought to check (if possible) that T derives from
115
// TObject. Will typeid() give us this info?
116
PHIODataNode<T>
*
n
=
new
PHIODataNode<T>
(
data
,
name
);
117
if
(!n)
118
{
119
// problem creating node?
120
return
false
;
121
}
122
123
return
addNode(n);
124
}
125
126
// Typedef to simplify notation.
127
typedef
PHTypedNodeIterator<TObject>
PHRootNodeIterator
;
128
129
#endif
coresoftware
blob
master
offline
framework
phool
PHTypedNodeIterator.h
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:05
using
1.8.2 with
sPHENIX GitHub integration