Class Reference for E1039 Core & Analysis Software
PHDataNode.h
Go to the documentation of this file.
1 #ifndef PHDATANODE_H__
2 #define PHDATANODE_H__
3 
4 // Declaration of class PHDataNode
5 // Purpose: a node which can hold a data object (template)
6 
7 #include "PHNode.h"
8 
9 #include <iostream>
10 class TObject;
11 
12 template <class T>
13 class PHDataNode : public PHNode
14 {
15 public:
16  PHDataNode(T*, const std::string&);
17  PHDataNode(T*, const std::string&, const std::string &);
18  virtual ~PHDataNode();
19 
20 public:
21  T* getData() {return data.data;}
22  void setData(T* d) {data.data = d;}
23  virtual void prune() {}
24  virtual void forgetMe(PHNode*) {}
25  virtual void print(const std::string&);
26  virtual bool write(PHIOManager *, const std::string& = "")
27  {
28  return true;
29  }
30 
31 protected:
32  union tobjcast
33  {
34  T* data;
35  TObject *tobj;
36  };
38  PHDataNode();
39 };
40 
41 template <class T>
43 {
44  data.data = 0;
45 }
46 
47 template <class T>
49  const std::string & name)
50  : PHNode(name)
51 {
52  type = "PHDataNode";
53  setData(d);
54 }
55 
56 template <class T>
58  const std::string &name,
59  const std::string &objtype)
60  : PHNode(name,objtype)
61 {
62  type = "PHDataNode";
63  setData(d);
64 }
65 
66 template <class T>
68 {
69  // This means that the node has complete responsibility for the
70  // data it contains. Check for null pointer just in case some
71  // joker adds a node with a null pointer
72  if (data.data)
73  {
74  delete data.data;
75  data.data = 0;
76  }
77 }
78 
79 template <class T>
80 void PHDataNode<T>::print(const std::string& path)
81 {
82  std::cout << path << name << " (";
83  if (! this->objectclass.empty())
84  {
85  if (type.find("IO") != std::string::npos)
86  {
87  std::cout << "IO";
88  }
89  else
90  {
91  std::cout << "Data";
92  }
93  std::cout << "," << this->objectclass;
94  }
95  else
96  {
97  std::cout << type;
98  }
99  std::cout << ")" << std::endl;
100 }
101 
102 #endif /* __PHDATANODE_H__ */
virtual ~PHDataNode()
Definition: PHDataNode.h:67
T * getData()
Definition: PHDataNode.h:21
virtual bool write(PHIOManager *, const std::string &="")
Definition: PHDataNode.h:26
tobjcast data
Definition: PHDataNode.h:37
void setData(T *d)
Definition: PHDataNode.h:22
virtual void print(const std::string &)
Definition: PHDataNode.h:80
virtual void prune()
Definition: PHDataNode.h:23
virtual void forgetMe(PHNode *)
Definition: PHDataNode.h:24
Definition: PHNode.h:15
std::string type
Definition: PHNode.h:55