File indexing completed on 2025-08-03 08:16:54
0001 #ifndef PHOOL_GETCLASS_H
0002 #define PHOOL_GETCLASS_H
0003
0004 #include "PHDataNode.h"
0005 #include "PHIODataNode.h"
0006 #include "PHNode.h"
0007 #include "PHNodeIterator.h"
0008
0009 #include <TObject.h>
0010
0011 #include <string>
0012
0013 class PHCompositeNode;
0014
0015 namespace findNode
0016 {
0017 template <class T> T *getClass(PHCompositeNode *top, const std::string &name)
0018 {
0019 PHNodeIterator iter(top);
0020 PHNode *FoundNode = iter.findFirst(name);
0021 if (!FoundNode)
0022 {
0023 return nullptr;
0024 }
0025
0026 PHDataNode<T> *DNode = dynamic_cast<PHDataNode<T> *>(FoundNode);
0027 if (DNode)
0028 {
0029 T *object = dynamic_cast<T *>(DNode->getData());
0030 if (object)
0031 {
0032 return object;
0033 }
0034 }
0035
0036
0037
0038
0039
0040
0041 PHIODataNode<TObject> *IONode = static_cast<PHIODataNode<TObject> *>(FoundNode);
0042 if (IONode)
0043 {
0044 T *object = dynamic_cast<T *>(IONode->getData());
0045 if (!object)
0046 {
0047 return nullptr;
0048 }
0049 else
0050 {
0051 return object;
0052 }
0053 }
0054
0055 return nullptr;
0056 }
0057
0058 template <class T> T *getClass(PHCompositeNode *top, const int packetid)
0059 {
0060 std::string name = std::to_string(packetid);
0061 return findNode::getClass<T>(top,name);
0062 }
0063
0064 }
0065
0066 #endif