source: XIOS/trunk/src/workflow_graph.cpp @ 1704

Last change on this file since 1704 was 1704, checked in by yushan, 2 years ago

Introducing the new graph functionality. Attribute build_workflow_graph=.TRUE. is used in the field definition section in the xml file to enable the workflow graph of the field and other fields referecing to it. A more detailed document will be available soon on the graph fuctionality.

File size: 6.3 KB
Line 
1#include "workflow_graph.hpp"
2
3namespace xios
4{
5
6  std::unordered_map <int, graph_info_box_node> *CWorkflowGraph::mapFilters_ptr_with_info = 0;
7
8  std::unordered_map <int, graph_info_box_edge > *CWorkflowGraph::mapFieldToFilters_ptr_with_info = 0;
9
10  std::unordered_map <size_t, int> *CWorkflowGraph::mapHashFilterID_ptr = 0;
11
12
13  vector <StdString> CWorkflowGraph::filters;
14  vector <StdString> CWorkflowGraph::fields;
15  vector <pair<int, int> > CWorkflowGraph::fieldsToFilters;
16
17  bool CWorkflowGraph::build_begin = false;
18
19  CWorkflowGraph::CWorkflowGraph()
20  { }
21
22  /*!
23   * Reorganize information collected by XIOS for visualization.
24   */
25  void CWorkflowGraph::buildStaticWorkflow()
26  TRY
27  {
28   
29    if(mapFilters_ptr_with_info==0 || mapFieldToFilters_ptr_with_info==0) 
30      std::cout<<"No graph information provided"<<std::endl;
31
32    else // Create a list of filters (graph nodes)
33    {
34      size_t filterIdx = 0;
35      filters.resize(mapFilters_ptr_with_info->size());
36      fieldsToFilters.clear();
37      fields.clear();
38      for (auto it=mapFilters_ptr_with_info->begin(); it != mapFilters_ptr_with_info->end(); it++)
39      {
40        filters[it->first]=it->second.filter_name;
41      }
42
43      // Create a list of fields and their filter connectivity (graph edges and edge-to-node connectivity)
44      for (auto it=mapFieldToFilters_ptr_with_info->begin(); it != mapFieldToFilters_ptr_with_info->end(); it++)
45      {
46        fieldsToFilters.push_back(make_pair(it->second.from,it->second.to));
47        fields.push_back(it->second.field_id + " "+it->second.date.toString());
48      }
49    }
50  }
51  CATCH
52
53
54
55
56/*!
57   * Reorganize information collected by XIOS for visualization.
58   */
59  void CWorkflowGraph::buildStaticWorkflow_with_info()
60  TRY
61  {
62    // showStaticWorkflow();
63   
64    if(mapFilters_ptr_with_info==0 || mapFieldToFilters_ptr_with_info==0) 
65      std::cout<<"No graph information provided"<<std::endl;
66
67    else // Create a list of filters (graph nodes)
68    {
69      size_t filterIdx = 0;
70      filters.resize(mapFilters_ptr_with_info->size());
71      fieldsToFilters.clear();
72      fields.clear();
73      for (auto it=mapFilters_ptr_with_info->begin(); it != mapFilters_ptr_with_info->end(); it++)
74      {
75        // std::cout<<"it->first = "<<it->first<<std::endl;
76        filters[it->first]=it->second.filter_name;
77      }
78
79      // Create a list of fields and their filter connectivity (graph edges and edge-to-node connectivity)
80      for (auto it=mapFieldToFilters_ptr_with_info->begin(); it != mapFieldToFilters_ptr_with_info->end(); it++)
81      {
82        fieldsToFilters.push_back(make_pair(it->second.from,it->second.to));
83        fields.push_back(it->second.field_id + " "+it->second.date.toString());
84      }
85    }
86  }
87  CATCH
88
89
90
91  void CWorkflowGraph::showStaticWorkflow()
92  TRY
93  {
94    if(mapFilters_ptr_with_info!=0 && !mapFilters_ptr_with_info->empty())
95    for (auto it=mapFilters_ptr_with_info->begin(); it != mapFilters_ptr_with_info->end(); it++)
96    {
97      std::cout<<"mapFilters_ptr_with_info["<<it->first<<"].filter_name="<<it->second.filter_name<<std::endl;
98      std::cout<<"mapFilters_ptr_with_info["<<it->first<<"].filter_class="<<it->second.filter_class<<std::endl;
99      std::cout<<"mapFilters_ptr_with_info["<<it->first<<"].filter_fillled="<<it->second.filter_filled<<std::endl;
100      std::cout<<"mapFilters_ptr_with_info["<<it->first<<"].expected_entry_nb="<<it->second.expected_entry_nb<<std::endl;
101      std::cout<<"mapFilters_ptr_with_info["<<it->first<<"].date="<<it->second.date<<std::endl;
102      std::cout<<"mapFilters_ptr_with_info["<<it->first<<"].timestamp="<<it->second.timestamp<<std::endl;
103      std::cout<<"mapFilters_ptr_with_info["<<it->first<<"].transform_type="<<it->second.transform_type<<std::endl;
104    }
105    else std::cout<<"mapFilters_ptr_with_info empty"<<std::endl;
106
107    if(mapFieldToFilters_ptr_with_info!=0 && !mapFieldToFilters_ptr_with_info->empty())
108    for (auto it=mapFieldToFilters_ptr_with_info->begin(); it != mapFieldToFilters_ptr_with_info->end(); it++)
109    {
110      std::cout<<"mapFieldToFilters_ptr_with_info["<<it->first<<"].from = "<<it->second.from<<std::endl;
111      std::cout<<"mapFieldToFilters_ptr_with_info["<<it->first<<"].to = "<<it->second.to<<std::endl;
112      std::cout<<"mapFieldToFilters_ptr_with_info["<<it->first<<"].field_id = "<<it->second.field_id<<std::endl;
113      std::cout<<"mapFieldToFilters_ptr_with_info["<<it->first<<"].field_name = "<<it->second.field_name<<std::endl;
114      std::cout<<"mapFieldToFilters_ptr_with_info["<<it->first<<"].date = "<<it->second.date<<std::endl;
115     
116    }
117    else std::cout<<"mapFieldToFilters_ptr_with_info empty"<<std::endl;
118
119
120  }
121  CATCH
122
123
124  void CWorkflowGraph::addNode(int nodeID, StdString filterName, int filterClass, bool filterFilled, int entry_nb, CDataPacketPtr packet)
125  TRY
126  {
127    (*mapFilters_ptr_with_info)[nodeID].filter_name = filterName;
128    (*mapFilters_ptr_with_info)[nodeID].filter_class = filterClass;
129    (*mapFilters_ptr_with_info)[nodeID].filter_filled = filterFilled;
130    (*mapFilters_ptr_with_info)[nodeID].expected_entry_nb = entry_nb;
131    (*mapFilters_ptr_with_info)[nodeID].date = packet->date;
132    (*mapFilters_ptr_with_info)[nodeID].timestamp = packet->timestamp;
133  }
134  CATCH
135
136
137
138  void CWorkflowGraph::addEdge(int edgeID, int toID, CDataPacketPtr packet)
139  TRY
140  {
141    (*mapFieldToFilters_ptr_with_info)[edgeID].from = packet->src_filterID;
142    (*mapFieldToFilters_ptr_with_info)[edgeID].to = toID;
143    (*mapFieldToFilters_ptr_with_info)[edgeID].field_id = packet->field->getId();
144    (*mapFieldToFilters_ptr_with_info)[edgeID].field_name = packet->field->name;
145    (*mapFieldToFilters_ptr_with_info)[edgeID].grid_id = packet->field->grid->getId();
146    (*mapFieldToFilters_ptr_with_info)[edgeID].date = packet->date;
147    (*mapFieldToFilters_ptr_with_info)[edgeID].timestamp = packet->timestamp;
148    (*mapFieldToFilters_ptr_with_info)[edgeID].field = packet->field;
149    (*mapFieldToFilters_ptr_with_info)[edgeID].attributes = packet->field->record4graphXiosAttributes();
150  }
151  CATCH
152
153
154  void CWorkflowGraph::allocNodeEdge()
155  TRY
156  {
157    if(mapFilters_ptr_with_info==0) mapFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_node>;
158    if(mapFieldToFilters_ptr_with_info==0) mapFieldToFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_edge >;
159    if(mapHashFilterID_ptr==0) mapHashFilterID_ptr = new std::unordered_map <size_t, int >;
160  }
161  CATCH
162
163}
Note: See TracBrowser for help on using the repository browser.