Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:16:19

0001 #ifndef PHOOL_PHDATANODE_H
0002 #define PHOOL_PHDATANODE_H
0003 
0004 //  Declaration of class PHDataNode
0005 //  Purpose: a node which can hold a data object (template)
0006 
0007 #include "PHNode.h"
0008 
0009 #include <iostream>
0010 class TObject;
0011 
0012 template <class T>
0013 class PHDataNode : public PHNode
0014 {
0015  public:
0016   PHDataNode(T*, const std::string&);
0017   PHDataNode(T*, const std::string&, const std::string&);
0018   ~PHDataNode() override;
0019 
0020  public:
0021   T* getData() { return data.data; }
0022   void setData(T* d) { data.data = d; }
0023   void prune() override {}
0024   void forgetMe(PHNode*) override {}
0025   void print(const std::string&) override;
0026   bool write(PHIOManager*, const std::string& = "") override
0027   {
0028     return true;
0029   }
0030 
0031  protected:
0032   union tobjcast
0033   {
0034     T* data;
0035     TObject* tobj;
0036   };
0037   tobjcast data;
0038   PHDataNode() = delete;
0039 };
0040 
0041 template <class T>
0042 PHDataNode<T>::PHDataNode(T* d,
0043                           const std::string& n)
0044   : PHNode(n)
0045 {
0046   type = "PHDataNode";
0047   setData(d);
0048 }
0049 
0050 template <class T>
0051 PHDataNode<T>::PHDataNode(T* d,
0052                           const std::string& n,
0053                           const std::string& objtype)
0054   : PHNode(n, objtype)
0055 {
0056   type = "PHDataNode";
0057   setData(d);
0058 }
0059 
0060 template <class T>
0061 PHDataNode<T>::~PHDataNode()
0062 {
0063   // This means that the node has complete responsibility for the
0064   // data it contains. Check for null pointer just in case some
0065   // joker adds a node with a null pointer
0066   if (data.data)
0067   {
0068     delete data.data;
0069     data.data = nullptr;
0070   }
0071 }
0072 
0073 template <class T>
0074 void PHDataNode<T>::print(const std::string& path)
0075 {
0076   std::cout << path << name << " (";
0077   if (!this->objectclass.empty())
0078   {
0079     if (type.find("IO") != std::string::npos)
0080     {
0081       std::cout << "IO";
0082     }
0083     else
0084     {
0085       std::cout << "Data";
0086     }
0087     std::cout << "," << this->objectclass;
0088   }
0089   else
0090   {
0091     std::cout << type;
0092   }
0093   std::cout << ")" << std::endl;
0094 }
0095 
0096 #endif