Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
graph_test.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file graph_test.cpp
1 /* This software is distributed under the GNU Lesser General Public License */
2 //==========================================================================
3 //
4 // graph_test.cpp
5 //
6 //==========================================================================
7 // $Id: graph_test.cpp,v 1.1 2003/01/14 16:50:46 raitner Exp $
8 
9 #include <iostream>
10 
11 #include <GTL/graph.h>
12 #include <GTL/node_map.h>
13 
14 #ifdef __GTL_MSVCC
15 # ifdef _DEBUG
16 # define new DEBUG_NEW
17 # undef THIS_FILE
18  static char THIS_FILE[] = __FILE__;
19 # endif // _DEBUG
20 #endif // __GTL_MSVCC
21 
22 class vertex {
23 
24 public:
25  vertex() {};
26  vertex(int myId) {id=myId;}
27  virtual ~vertex() {cout<<" Vertex Detructor ..."<<endl;}
28  int id;
29 };
30 
31 class parton {
32 
33 public:
34 
35  parton() {};
36  parton (double mpt, double meta, double mphi, double me, bool mfinal) {pt=mpt;eta=meta;phi=mphi;e=me;final=mfinal;}
37  virtual ~parton() {cout<<" Parton Destructor ..."<<endl;}
38 
39  bool isFinal() {return final;}
40 
41  double pt, eta, phi, e;
42  bool final;
43 };
44 
45 class shower2 : public graph {
46 
47 public:
48 
49  shower2() : graph() {cout<<"Shower2 Constrcutor ..."<<endl;}
50  virtual ~shower2() {cout<<"Shower2 Detrcutor ..."<<endl;}
51 
52  node new_vertex(shared_ptr<vertex> v) {node n=graph::new_node();XX[n]=v; return n;}
53  //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;}
54  void new_parton(node s, node t, unique_ptr<parton> p) {edge e=graph::new_edge(s,t);PP[e]=std::move(p);}
55 
56  //unique_ptr<parton> GetParton(edge e) {return unique_ptr<parton> (PP[e]);}
57 
58  //int GetNodeValue(node n) const {return XX[n];}
59  void save_node_info_handler (ostream *o, node n) const { *o<<"MyID = "<<XX[n]->id<<endl;}
60  void save_edge_info_handler (ostream *o, edge n) const { *o<<"Value = "<<PP[n]->pt<<endl;}
61  double GetEdgeValue(edge n) const {return PP[n]->pt;}
62  int GetNodeValue(node n) const {return XX[n]->id;}
63  bool GetFinal(edge e) const {return PP[e]->final;}
64  //void pre_new_edge_handler(node s,node t) {};
65  //void post_new_edge_handler(edge e) {};
67  edge_iterator git3, gend3;
68  for (git3 = edges_begin(), gend3 = edges_end(); git3 != gend3; ++git3)
69  {
70  //cout<<*git3<<" "<<mS->GetEdgeValue(*git3)<<endl;
71  PP[*git3]=nullptr;
72  }
73  node_iterator git4, gend4;
74  for (git4 = nodes_begin(), gend4 = nodes_end(); git4 != gend4; ++git4)
75  {
76  XX[*git4]=nullptr;
77  }
78  }
79 
80  // vector<shared_ptr<vertex>> GetVertices() {};
81  /*
82  vector<shared_ptr<parton>> GetPartons() {
83  vector<shared_ptr<parton>> myv; list<edge> le=all_edges();
84  //int n=le.size();
85  //for (int i=0;i<n;i++)
86  int n=0;
87 
88  for (list<edge>::iterator it=le.begin(); it!=le.end(); ++it)
89  {
90  if (PP[*it]->isFinal())
91  myv.push_back(PP[*it]);
92  //cout<<PP[*it]->pt<<endl;
93  }
94  return myv;
95  }
96  */
97 
98  vector<weak_ptr<parton>> GetPartons() {
99  vector<weak_ptr<parton>> myv; list<edge> le=all_edges();
100  //int n=le.size();
101  //for (int i=0;i<n;i++)
102  int n=0;
103 
104  for (list<edge>::iterator it=le.begin(); it!=le.end(); ++it)
105  {
106  if (PP[*it]->isFinal())
107  myv.push_back(PP[*it]);
108  //cout<<PP[*it]->pt<<endl;
109  }
110  return myv;
111  }
112 
113  private:
114 
116  edge_map<shared_ptr<parton>> PP; //unique_ptr not working !???
117 
118 };
119 
120 int main (int argc, char* argv[])
121 {
122 
123  cout << "Loading graph and preserving ids" << endl;
124  shower2 G;
125  if (G.load("test.gml", true).err_num != GML_OK) {
126  cout << "Loading failed" << endl;
127  exit(1);
128  }
129 
130  cout << "Loading OK" << endl;
131 
132  if (G.number_of_ids(node()) != 20) {
133  cout << "Wrong number of ids: " << G.number_of_ids(node()) << endl;
134  exit(1);
135  }
136 
137  cout << "Number of ids OK" << endl;
138 
139  cout << "Loading graph and preserving ids" << endl;
140 
141  graph G1;
142  if (G.load("test.gml", false).err_num != GML_OK) {
143  cout << "Loading failed" << endl;
144  exit(1);
145  }
146 
147  cout << "Loading OK" << endl;
148 
149  if (G.number_of_ids(node()) != 2) {
150  cout << "Wrong number of ids: " << G.number_of_ids(node()) << endl;
151  exit(1);
152  }
153 
154  cout << "Number of ids OK" << endl;
155 }