Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
my_test2.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file my_test2.cc
1 #include <iostream>
2 
3 #include <GTL/graph.h>
4 #include <GTL/bellman_ford.h>
5 #include <GTL/edge_map.h>
6 #include <GTL/node_map.h>
7 #include <GTL/dfs.h>
8 #include <memory>
9 #include <list>
10 
11 class my_graph : public graph {
12 
13 public:
14 
15  my_graph() : graph () {}
16 
17  node new_vertex(int x) {node n=graph::new_node();X[n]=x; return n;}
18  void new_parton(node s, node t, int p) {edge e=graph::new_edge(s,t) ;P[e]=p;} //; return e;}
19 
20  void save_node_info_handler (ostream *o, node n) const { *o<<"Value = "<<X[n]<<endl;}
21  void save_edge_info_handler (ostream *o, edge n) const { *o<<"Value = "<<P[n]<<endl;}
22 
23  int GetNodeValue(node n) const {return X[n];}
24  int GetEdgeValue(edge n) const {return P[n];}
25 
26 private:
27 
30 
31 };
32 
33 
34 class parton {
35 
36 public:
37 
38  parton() {};
39  parton (double mpt, double meta, double mphi, double me, bool mfinal) {pt=mpt;eta=meta;phi=mphi;e=me;final=mfinal;}
40  ~parton() {cout<<" Parton Destructor ..."<<endl;}
41 
42  bool isFinal() {return final;}
43 
44  double pt, eta, phi, e;
45  bool final;
46 };
47 
48 class shower : public graph {
49 
50 public:
51 
52  shower() : graph() {cout<<"Shower Constrcutor ..."<<endl;}
53  ~shower() {cout<<"Shower Detrcutor ..."<<endl;}
54 
55  node new_vertex(int x) {node n=graph::new_node();XX[n]=x; return n;}
56  void new_parton(node s, node t, parton p) {edge e=graph::new_edge(s,t) ;PP[e]=p;} //; return e;}
57  int GetNodeValue(node n) const {return XX[n];}
58  void save_edge_info_handler (ostream *o, edge n) const { *o<<"Value = "<<PP[n].pt<<endl;}
59  double GetEdgeValue(edge n) const {return PP[n].pt;}
60 
61  private:
62 
65 
66 };
67 
68 class shower2 : public graph {
69 
70 public:
71 
72  shower2() : graph() {cout<<"Shower2 Constrcutor ..."<<endl;}
73  virtual ~shower2() {cout<<"Shower2 Detrcutor ..."<<endl;}
74 
75  node new_vertex(int x) {node n=graph::new_node();XX[n]=x; return n;}
76  //void new_parton(node s, node t, shared_ptr<parton> p) {edge e=graph::new_edge(s,t);PP[e]=p;}//std::move(p);} //; return e;}
77  void new_parton(node s, node t, unique_ptr<parton> p) {edge e=graph::new_edge(s,t);PP[e]=std::move(p);}
78 
79  //int GetNodeValue(node n) const {return XX[n];}
80  void save_edge_info_handler (ostream *o, edge n) const { *o<<"Value = "<<PP[n]->pt<<endl;}
81  double GetEdgeValue(edge n) const {return PP[n]->pt;}
82  int GetNodeValue(node n) const {return XX[n];}
83  bool GetFinal(edge e) const {return PP[e]->final;}
84  //void pre_new_edge_handler(node s,node t) {};
87  edge_iterator git3, gend3;
88  for (git3 = edges_begin(), gend3 = edges_end(); git3 != gend3; ++git3)
89  {
90  //cout<<*git3<<" "<<mS->GetEdgeValue(*git3)<<endl;
91  PP[*git3]=nullptr;
92  }
93  }
94 
95  private:
96 
98  edge_map<shared_ptr<parton>> PP; //unique_ptr not working !???
99 
100 };
101 
102 int main (int argc, char* argv[])
103 {
104  graph G;
105  G.make_directed();
106  node n1 = G.new_node();
107  node n2 = G.new_node();
108 
109  edge e1 = G.new_edge(n1,n2);
110 
111 
112  node_map<int> n(G,1);
113  edge_map<int> e(G,10);
114 
115  //edge_map<int> e1(n1,n2,10);
116 
117  //G.save();
118 
119  my_graph S;
120 
121  node n11=S.new_vertex(0);
122  node n22=S.new_vertex(1);
123  node n33=S.new_vertex(2);
124  node n44=S.new_vertex(3);
125  node n55=S.new_vertex(5);
126 
127  //edge e11=S.new_parton(n11,n22,10);
128  S.new_parton(n11,n22,10);
129  S.new_parton(n11,n33,11);
130  S.new_parton(n33,n44,20);
131  S.new_parton(n33,n55,21);
132 
133  //S.save();
134  //S.insert_reverse_edges();
135 
137 
138  for (it = S.nodes_begin(), end = S.nodes_end(); it != end; ++it)
139  {
140  cout<<*it<<" "<<S.GetNodeValue((node) *it)<<endl;
141  }
142 
143  graph::edge_iterator it2, end2;
144 
145  for (it2 = S.edges_begin(), end2 = S.edges_end(); it2 != end2; ++it2)
146  {
147  cout<<*it2<<" "<<S.GetEdgeValue((edge) *it2)<<endl;
148  }
149 
150  cout<<endl;
151 
152  shower gS;
153 
154  cout<<endl;
155 
156  node nn11=gS.new_vertex(0);
157  node nn22=gS.new_vertex(1);
158  node nn33=gS.new_vertex(1);
159  node nn44=gS.new_vertex(2);
160  node nn55=gS.new_vertex(2);
161 
162  //parton p(100,0,0,100,false);
163 
164  gS.new_parton(nn11,nn22,parton(100,0,0,100,false));
165  gS.new_parton(nn11,nn33,parton(200,0,0,200,false));
166  gS.new_parton(nn33,nn44,parton(50,0,0,50,true));
167  gS.new_parton(nn33,nn55,parton(150,0,0,150,true));
168 
170 
171  for (git = gS.nodes_begin(), gend = gS.nodes_end(); git != gend; ++git)
172  {
173  cout<<*git<<" "<<gS.GetNodeValue(*git)<<endl;
174  }
175 
176  shower::edge_iterator git2, gend2;
177 
178  for (git2 = gS.edges_begin(), gend2 = gS.edges_end(); git2 != gend2; ++git2)
179  {
180  cout<<*git2<<" "<<gS.GetEdgeValue(*git2)<<endl;
181  }
182 
183  //shower *mS=new shower();
184  cout<<endl;
185  auto mS=make_shared<shower2>();
186  mS->make_directed();
187 
188  node nnn11=mS->new_vertex(0);
189  node nnn22=mS->new_vertex(1);
190  node nnn33=mS->new_vertex(1);
191  node nnn44=mS->new_vertex(2);
192  node nnn55=mS->new_vertex(2);
193  node nnn66=mS->new_vertex(3);
194  node nnn77=mS->new_vertex(3);
195  node nnn88=mS->new_vertex(4);
196 
197  mS->new_parton(nnn11,nnn22,unique_ptr<parton>(new parton(100,0,0,100,false)));
198  mS->new_parton(nnn11,nnn33,unique_ptr<parton>(new parton(200,0,0,200,false)));
199  mS->new_parton(nnn33,nnn44,unique_ptr<parton>(new parton(50,0,0,50,true)));
200  mS->new_parton(nnn33,nnn55,unique_ptr<parton>(new parton(150,0,0,150,false)));
201  mS->new_parton(nnn55,nnn66,unique_ptr<parton>(new parton(80,0,0,80,true)));
202  mS->new_parton(nnn55,nnn77,unique_ptr<parton>(new parton(70,0,0,70,false)));
203  mS->new_parton(nnn77,nnn88,unique_ptr<parton>(new parton(60,0,0,60,true)));
204 
205  //reverse changes all counts --> new inverse graph ... ? (shared pointers ...)
206  /*
207  mS->new_parton(nnn22,nnn11,unique_ptr<parton>(new parton(100,0,0,100,false)));
208  mS->new_parton(nnn33,nnn11,unique_ptr<parton>(new parton(200,0,0,200,false)));
209  mS->new_parton(nnn44,nnn33,unique_ptr<parton>(new parton(50,0,0,50,true)));
210  mS->new_parton(nnn55,nnn33,unique_ptr<parton>(new parton(150,0,0,150,false)));
211  mS->new_parton(nnn66,nnn55,unique_ptr<parton>(new parton(80,0,0,80,true)));
212  mS->new_parton(nnn77,nnn55,unique_ptr<parton>(new parton(70,0,0,70,true)));
213  */
214 
215  //mS->new_parton(nnn11,nnn22,make_shared<parton>(100,0,0,100,false));
216  //mS->save();
217 
218  //mS->insert_reverse_edges(); //problem with new parton creation .... so post/pre handler
219  // not really doing the trick
220 
221  shower2::node_iterator git0, gend0;
222 
223  for (git0 = mS->nodes_begin(), gend0 = mS->nodes_end(); git0 != gend0; ++git0)
224  {
225  cout<<*git0<<" "<<mS->GetNodeValue(*git0)<<" "<<git0->indeg()<<" "<<git0->outdeg()<<endl;
226  }
227 
228  shower2::edge_iterator git3, gend3;
229 
230  for (git3 = mS->edges_begin(), gend3 = mS->edges_end(); git3 != gend3; ++git3)
231  {
232  cout<<*git3<<" "<<mS->GetEdgeValue(*git3)<<endl;
233  }
234 
235  list<node> ln=mS->all_nodes();
236  cout<<ln.size()<<endl;
237 
238  list<edge> le=mS->all_edges();
239  cout<<le.size()<<endl;
240  //le.remove_if( // hmmm, not with parton in graph (inheritence !??) Check ..
241 
242  dfs search;
243  search.start_node(nnn11);
244  search.run(*mS);
245  cout<< search.number_of_reached_nodes () <<endl;
246 
247  dfs::dfs_iterator itt2, endt2;
248  for (itt2 = search.begin(), endt2=search.end(); itt2 !=endt2; ++itt2)
249  {
250  cout<<*itt2<<endl;
251  }
252 
253  dfs::tree_edges_iterator itt, endt;
254  for (itt = search.tree_edges_begin(), endt=search.tree_edges_end(); itt !=endt; ++itt)
255  {
256  cout<<*itt<<endl;
257  }
258 
259  mS->clear(); //does not call parton destructor but with handler it does ...
260  cout<<" mS->clear()"<<endl;
261  //mS->save();
262 
263  mS=0;
264  cout<<"Done .."<<endl;
265 }