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

Last change on this file since 1877 was 1877, checked in by yushan, 18 months ago

trunk : each context has its own graph file

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