source: XIOS/dev/dev_trunk_omp/src/filter/binary_arithmetic_filter.cpp @ 1679

Last change on this file since 1679 was 1679, checked in by yushan, 5 years ago

MARK: Dynamic workflow graph developement. Branch up to date with trunk @1676. Using vis.js

File size: 9.7 KB
Line 
1#include "binary_arithmetic_filter.hpp"
2#include "workflow_graph.hpp"
3
4
5namespace xios
6{
7  CScalarFieldArithmeticFilter::CScalarFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
8    : CFilter(gc, 1, this)
9    , op(operatorExpr.getOpScalarField(op))
10    , value(value)
11  { 
12    StdString input_op_expression=op;
13    if(input_op_expression == "add")
14      op_expression = "+";
15    else if(input_op_expression == "minus")
16      op_expression = "-";
17    else if(input_op_expression == "mult")
18      op_expression = "x";
19    else if(input_op_expression == "div")
20      op_expression = "/";
21    else if(input_op_expression == "eq")
22      op_expression = "=";
23    else if(input_op_expression == "lt")
24      op_expression = "<";
25    else if(input_op_expression == "gt")
26      op_expression = ">";
27    else if(input_op_expression == "le")
28      op_expression = "<=";
29    else if(input_op_expression == "ge")
30      op_expression = ">=";
31    else if(input_op_expression == "ne")
32      op_expression = "!=";
33    else
34      op_expression = " ";
35  };
36
37  CDataPacketPtr CScalarFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
38  {
39    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
40
41    if(building_graph)
42    {
43      this->filterID = InvalidableObject::filterIdGenerator++;   
44      int edgeID = InvalidableObject::edgeIdGenerator++; 
45
46      if(CWorkflowGraph::mapFieldToFilters_ptr_with_info==0) CWorkflowGraph::mapFieldToFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_edge >;
47      if(CWorkflowGraph::mapFilters_ptr_with_info==0) CWorkflowGraph::mapFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_node>;
48
49      std::cout<<"CScalarFieldArithmeticFilter::apply filter tag = "<<this->tag<<std::endl;
50
51      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_name = "S "+op_expression +" F Filter" ;
52      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_class = 2 ;
53      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_filled = 1 ;
54      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb = 1 ;
55      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].date = data[0]->date ;
56      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].timestamp = data[0]->timestamp ;
57
58      if(CWorkflowGraph::build_begin)
59      {
60        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
61
62        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
63      }
64      else CWorkflowGraph::build_begin = true;
65    }
66
67    CDataPacketPtr packet(new CDataPacket);
68    packet->date = data[0]->date;
69    packet->timestamp = data[0]->timestamp;
70    packet->status = data[0]->status;
71    if(building_graph) packet->src_filterID = this->filterID;
72    packet->field = this->field;
73
74    if (packet->status == CDataPacket::NO_ERROR)
75      packet->data.reference(op(value, data[0]->data));
76
77    return packet;
78  }
79
80  CFieldScalarArithmeticFilter::CFieldScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
81    : CFilter(gc, 1, this)
82    , op(operatorExpr.getOpFieldScalar(op))
83    , value(value)
84  { 
85    StdString input_op_expression=op;
86    if(input_op_expression == "add")
87      op_expression = "+";
88    else if(input_op_expression == "minus")
89      op_expression = "-";
90    else if(input_op_expression == "mult")
91      op_expression = "x";
92    else if(input_op_expression == "div")
93      op_expression = "/";
94    else if(input_op_expression == "pow")
95      op_expression = "^";
96    else if(input_op_expression == "eq")
97      op_expression = "=";
98    else if(input_op_expression == "lt")
99      op_expression = "<";
100    else if(input_op_expression == "gt")
101      op_expression = ">";
102    else if(input_op_expression == "le")
103      op_expression = "<=";
104    else if(input_op_expression == "ge")
105      op_expression = ">=";
106    else if(input_op_expression == "ne")
107      op_expression = "!=";
108    else
109      op_expression = " ";
110  };
111
112  CDataPacketPtr CFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
113  {
114    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
115
116    if(building_graph)
117    {
118      this->filterID = InvalidableObject::filterIdGenerator++;
119      int edgeID = InvalidableObject::edgeIdGenerator++;
120 
121      if(CWorkflowGraph::mapFieldToFilters_ptr_with_info==0) CWorkflowGraph::mapFieldToFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_edge >;
122      if(CWorkflowGraph::mapFilters_ptr_with_info==0) CWorkflowGraph::mapFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_node>;
123
124      std::cout<<"CFieldScalarArithmeticFilter::apply filter tag = "<<this->tag<<std::endl;
125
126      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_name = "F "+op_expression +" S Filter" ;
127      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_class = 2 ;
128      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_filled = 1 ;
129      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb = 1 ;
130      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].date = data[0]->date ;
131      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].timestamp = data[0]->timestamp ;
132
133      if(CWorkflowGraph::build_begin)
134      {
135        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
136
137        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
138      }
139      else CWorkflowGraph::build_begin = true;
140    }
141
142    CDataPacketPtr packet(new CDataPacket);
143    packet->date = data[0]->date;
144    packet->timestamp = data[0]->timestamp;
145    packet->status = data[0]->status;
146    if(building_graph) packet->src_filterID = this->filterID;
147    packet->field = this->field;
148   
149
150    if (packet->status == CDataPacket::NO_ERROR)
151      packet->data.reference(op(data[0]->data, value));
152
153    return packet;
154  }
155
156  CFieldFieldArithmeticFilter::CFieldFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op)
157    : CFilter(gc, 2, this)
158    , op(operatorExpr.getOpFieldField(op))
159  { 
160    StdString input_op_expression=op;
161    if(input_op_expression == "add")
162      op_expression = "+";
163    else if(input_op_expression == "minus")
164      op_expression = "-";
165    else if(input_op_expression == "mult")
166      op_expression = "x";
167    else if(input_op_expression == "div")
168      op_expression = "/";
169    else if(input_op_expression == "pow")
170      op_expression = "^";
171    else if(input_op_expression == "eq")
172      op_expression = "=";
173    else if(input_op_expression == "lt")
174      op_expression = "<";
175    else if(input_op_expression == "gt")
176      op_expression = ">";
177    else if(input_op_expression == "le")
178      op_expression = "<=";
179    else if(input_op_expression == "ge")
180      op_expression = ">=";
181    else if(input_op_expression == "ne")
182      op_expression = "!=";
183    else
184      op_expression = " ";
185  };
186
187  CDataPacketPtr CFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
188  {
189    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
190
191    if(building_graph)
192    {
193
194      this->filterID = InvalidableObject::filterIdGenerator++;
195      int edgeID = InvalidableObject::edgeIdGenerator++;
196   
197      if(CWorkflowGraph::mapFieldToFilters_ptr_with_info==0) CWorkflowGraph::mapFieldToFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_edge >;
198      if(CWorkflowGraph::mapFilters_ptr_with_info==0) CWorkflowGraph::mapFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_node>;
199
200      std::cout<<"CFieldFieldArithmeticFilter::apply filter tag = "<<this->tag<<std::endl;
201
202      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_name = "F "+op_expression +" F Filter" ;
203      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_class = 2 ;
204      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_filled = 1 ;
205      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb = 2 ;
206      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].date = data[0]->date ;
207      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].timestamp = data[0]->timestamp ;
208
209      if(CWorkflowGraph::build_begin)
210      {
211
212        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
213
214        edgeID = InvalidableObject::edgeIdGenerator++;
215
216        CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
217
218        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
219        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
220      }
221      CWorkflowGraph::build_begin = true;
222    }
223
224
225    CDataPacketPtr packet(new CDataPacket);
226    packet->date = data[0]->date;
227    packet->timestamp = data[0]->timestamp;
228    if(building_graph) packet->src_filterID = this->filterID;
229    packet->field = this->field;
230   
231
232    if (data[0]->status != CDataPacket::NO_ERROR)
233      packet->status = data[0]->status;
234    else if (data[1]->status != CDataPacket::NO_ERROR)
235      packet->status = data[1]->status;
236    else
237    {
238      packet->status = CDataPacket::NO_ERROR;
239      packet->data.reference(op(data[0]->data, data[1]->data));
240    }
241
242    return packet;
243  }
244
245  StdString CScalarFieldArithmeticFilter::GetName(void)    { return StdString("CScalarFieldArithmeticFilter"); }
246  StdString CFieldScalarArithmeticFilter::GetName(void)    { return StdString("CFieldScalarArithmeticFilter"); }
247  StdString CFieldFieldArithmeticFilter::GetName(void)     { return StdString("CFieldFieldArithmeticFilter"); }
248
249
250} // namespace xios
Note: See TracBrowser for help on using the repository browser.