File indexing completed on 2025-08-03 08:19:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <iostream>
0010
0011 #include <GTL/graph.h>
0012 #include <GTL/node_map.h>
0013
0014 #ifdef __GTL_MSVCC
0015 # ifdef _DEBUG
0016 # define new DEBUG_NEW
0017 # undef THIS_FILE
0018 static char THIS_FILE[] = __FILE__;
0019 # endif
0020 #endif
0021
0022 class vertex {
0023
0024 public:
0025 vertex() {};
0026 vertex(int myId) {id=myId;}
0027 virtual ~vertex() {cout<<" Vertex Detructor ..."<<endl;}
0028 int id;
0029 };
0030
0031 class parton {
0032
0033 public:
0034
0035 parton() {};
0036 parton (double mpt, double meta, double mphi, double me, bool mfinal) {pt=mpt;eta=meta;phi=mphi;e=me;final=mfinal;}
0037 virtual ~parton() {cout<<" Parton Destructor ..."<<endl;}
0038
0039 bool isFinal() {return final;}
0040
0041 double pt, eta, phi, e;
0042 bool final;
0043 };
0044
0045 class shower2 : public graph {
0046
0047 public:
0048
0049 shower2() : graph() {cout<<"Shower2 Constrcutor ..."<<endl;}
0050 virtual ~shower2() {cout<<"Shower2 Detrcutor ..."<<endl;}
0051
0052 node new_vertex(shared_ptr<vertex> v) {node n=graph::new_node();XX[n]=v; return n;}
0053
0054 void new_parton(node s, node t, unique_ptr<parton> p) {edge e=graph::new_edge(s,t);PP[e]=std::move(p);}
0055
0056
0057
0058
0059 void save_node_info_handler (ostream *o, node n) const { *o<<"MyID = "<<XX[n]->id<<endl;}
0060 void save_edge_info_handler (ostream *o, edge n) const { *o<<"Value = "<<PP[n]->pt<<endl;}
0061 double GetEdgeValue(edge n) const {return PP[n]->pt;}
0062 int GetNodeValue(node n) const {return XX[n]->id;}
0063 bool GetFinal(edge e) const {return PP[e]->final;}
0064
0065
0066 void pre_clear_handler() {
0067 edge_iterator git3, gend3;
0068 for (git3 = edges_begin(), gend3 = edges_end(); git3 != gend3; ++git3)
0069 {
0070
0071 PP[*git3]=nullptr;
0072 }
0073 node_iterator git4, gend4;
0074 for (git4 = nodes_begin(), gend4 = nodes_end(); git4 != gend4; ++git4)
0075 {
0076 XX[*git4]=nullptr;
0077 }
0078 }
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098 vector<weak_ptr<parton>> GetPartons() {
0099 vector<weak_ptr<parton>> myv; list<edge> le=all_edges();
0100
0101
0102 int n=0;
0103
0104 for (list<edge>::iterator it=le.begin(); it!=le.end(); ++it)
0105 {
0106 if (PP[*it]->isFinal())
0107 myv.push_back(PP[*it]);
0108
0109 }
0110 return myv;
0111 }
0112
0113 private:
0114
0115 node_map<shared_ptr<vertex>> XX;
0116 edge_map<shared_ptr<parton>> PP;
0117
0118 };
0119
0120 int main (int argc, char* argv[])
0121 {
0122
0123 cout << "Loading graph and preserving ids" << endl;
0124 shower2 G;
0125 if (G.load("test.gml", true).err_num != GML_OK) {
0126 cout << "Loading failed" << endl;
0127 exit(1);
0128 }
0129
0130 cout << "Loading OK" << endl;
0131
0132 if (G.number_of_ids(node()) != 20) {
0133 cout << "Wrong number of ids: " << G.number_of_ids(node()) << endl;
0134 exit(1);
0135 }
0136
0137 cout << "Number of ids OK" << endl;
0138
0139 cout << "Loading graph and preserving ids" << endl;
0140
0141 graph G1;
0142 if (G.load("test.gml", false).err_num != GML_OK) {
0143 cout << "Loading failed" << endl;
0144 exit(1);
0145 }
0146
0147 cout << "Loading OK" << endl;
0148
0149 if (G.number_of_ids(node()) != 2) {
0150 cout << "Wrong number of ids: " << G.number_of_ids(node()) << endl;
0151 exit(1);
0152 }
0153
0154 cout << "Number of ids OK" << endl;
0155 }