00001 #ifndef DCVERTEX_H
00002 #define DCVERTEX_H
00003
00004 #include <iostream>
00005 #include <vector>
00006 #include "TObject.h"
00007 #include "NueAna/NueAnaTools/DCEdge.h"
00008
00009 using std::vector;
00010 using std::cout;
00011 using std::endl;
00012
00013 template<class T> class DCGraph;
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 template <class T> class DCVertex : public TObject
00026 {
00027 public:
00028
00029 DCVertex(){data=0; edges=0; next=0;}
00030 DCVertex(T *idata, DCVertex<T> *nextVert) { data=new T(*idata); next=nextVert; edges=0;}
00031
00032 virtual ~DCVertex(){
00033 if(data!=0){delete data; data=0;}
00034 if(next!=0){delete next; next=0;}
00035 if(edges!=0){delete edges; edges=0;}
00036 }
00037
00038 T *GetData(){return data;}
00039 DCVertex<T> *GetNextVertex() {return next;}
00040 DCEdge<T> *GetFirstEdge() {return edges;}
00041 void ResetNextVertex(DCVertex<T> *newvert) { next=newvert;}
00042 void ResetFirstEdge(DCEdge<T> *newedge) { edges=newedge;}
00043
00044 virtual void Print(Option_t *t="") const;
00045 void PrintEdges();
00046 void PrintGraph();
00047 float ConnectTo(DCVertex<T> *);
00048 virtual void Draw(Option_t* t="");
00049 void DrawEdges(Option_t *t="");
00050 void DrawGraph(Option_t *t="");
00051 void ClearConnections();
00052
00053 private:
00054 T *data;
00055 DCEdge<T> *edges;
00056 DCVertex<T> *next;
00057 ClassDef(DCVertex<T>,1)
00058
00059 };
00060
00061
00062 ClassImpT(DCVertex,T)
00063
00064 template<class T> void DCVertex<T>::PrintEdges()
00065 {
00066 if (edges == 0){
00067 cout << "vertex ";
00068 GetData()->Print();
00069 cout<< " has no edges" << endl;
00070 }
00071 else {
00072 cout << "vertex ";
00073 GetData()->Print();
00074 cout << " has edges to: " << endl;
00075 edges->Print();
00076 }
00077 }
00078
00079
00080
00081 template<class T>void DCVertex<T>::PrintGraph()
00082 {
00083 PrintEdges();
00084 if (next != 0){
00085 next->PrintGraph();
00086 }
00087 }
00088
00089 template<class T>void DCVertex<T>::Draw(Option_t *t)
00090 {
00091
00092
00093
00094 data->Draw(t);
00095 }
00096
00097 template<class T>void DCVertex<T>::DrawEdges(Option_t *t)
00098 {
00099
00100 data->Draw(t);
00101 if(edges!=0){
00102 edges->DrawThisEdge(this,t);
00103 }
00104 }
00105
00106 template<class T> void DCVertex<T>::DrawGraph(Option_t *t)
00107 {
00108
00109 DrawEdges(t);
00110 if (next != 0){
00111
00112 next->DrawGraph(t);
00113 }
00114 }
00115
00116
00117 template<class T> void DCVertex<T>::Print(Option_t *t) const
00118 {
00119 data->Print(t);
00120 }
00121
00122
00123 template<class T> float DCVertex<T>::ConnectTo(DCVertex<T> *Vert)
00124 {
00125
00126
00127
00128 T minus = (*(Vert->GetData()))-(*data);
00129 float m=(*data-*(Vert->GetData())).abs();
00130 float xm=0.;
00131 float ym=0.;
00132 float zm=0.;
00133 minus.GetData(xm,ym,zm);
00134 float wm = m*zm;
00135 float xwm=xm*zm;
00136 float ywm=ym*zm;
00137 DCEdge<T> *newEdge = new DCEdge<T>(Vert, edges, m, xm, ym, wm, xwm, ywm);
00138
00139
00140 edges = newEdge;
00141 return newEdge->GetMetric();
00142 }
00143
00144 template<class T> void DCVertex<T>::ClearConnections()
00145 {
00146 edges=0;
00147 }
00148
00149
00150 #endif //VERTEX_H