source: XIOS/dev/dev_trunk_omp/src/filter/ternary_arithmetic_filter.cpp @ 1680

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

MARK: Dynamic workflow graph developement. Branch up to date with trunk @1676. Arithmetic filter unified

File size: 13.8 KB
Line 
1#include "ternary_arithmetic_filter.hpp"
2#include "workflow_graph.hpp"
3#include "yacc_var.hpp"
4
5namespace xios
6{
7  CScalarScalarFieldArithmeticFilter::CScalarScalarFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value1, double value2)
8    : CFilter(gc, 1, this)
9    , op(operatorExpr.getOpScalarScalarField(op))
10    , value1(value1)
11    , value2(value2)
12  { 
13    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
14    /* Nothing to do */ 
15  };
16
17  CDataPacketPtr CScalarScalarFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
18  {
19    bool building_graph=this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
20   
21    if(building_graph)
22    {
23      this->filterID = InvalidableObject::filterIdGenerator++;
24       int edgeID = InvalidableObject::edgeIdGenerator++;
25   
26      CWorkflowGraph::allocNodeEdge();
27
28      std::cout<<"CScalarScalarFieldArithmeticFilter::apply connection = "<<data[0]->src_filterID<<" <-> "<<this->filterID<<std::endl;
29
30
31
32      CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 1, data[0]);
33
34
35      if(CWorkflowGraph::build_begin)
36      {
37
38        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
39
40        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
41      }
42      else CWorkflowGraph::build_begin = true;
43    }
44
45    CDataPacketPtr packet(new CDataPacket);
46    packet->date = data[0]->date;
47    packet->timestamp = data[0]->timestamp;
48    packet->status = data[0]->status;
49    if(building_graph) packet->src_filterID = this->filterID;
50    packet->field = this->field;
51
52    if (packet->status == CDataPacket::NO_ERROR)
53      packet->data.reference(op(value1,value2, data[0]->data));
54
55    return packet;
56  }
57
58  CScalarFieldScalarArithmeticFilter::CScalarFieldScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value1, double value2)
59    : CFilter(gc, 1, this)
60    , op(operatorExpr.getOpScalarFieldScalar(op))
61    , value1(value1)
62    , value2(value2)
63  { 
64    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
65    /* Nothing to do */ 
66  };
67
68  CDataPacketPtr CScalarFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
69  {
70    bool building_graph=this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
71   
72    if(building_graph)
73    {
74      this->filterID = InvalidableObject::filterIdGenerator++;
75       int edgeID = InvalidableObject::edgeIdGenerator++;
76   
77
78      CWorkflowGraph::allocNodeEdge();
79
80      std::cout<<"CScalarFieldScalarArithmeticFilter::apply connection = "<<data[0]->src_filterID<<" <-> "<<this->filterID<<std::endl;
81
82
83
84      CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 1, data[0]);
85
86      if(CWorkflowGraph::build_begin)
87      {
88
89        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
90        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
91      }
92      else CWorkflowGraph::build_begin = true;
93    }
94
95    CDataPacketPtr packet(new CDataPacket);
96    packet->date = data[0]->date;
97    packet->timestamp = data[0]->timestamp;
98    packet->status = data[0]->status;
99    if(building_graph) packet->src_filterID = this->filterID;
100    packet->field = this->field;
101
102    if (packet->status == CDataPacket::NO_ERROR)
103      packet->data.reference(op(value1, data[0]->data,value2));
104
105    return packet;
106  }
107
108  CScalarFieldFieldArithmeticFilter::CScalarFieldFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
109    : CFilter(gc, 2, this)
110    , op(operatorExpr.getOpScalarFieldField(op))
111    , value(value)
112  { 
113    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
114    /* Nothing to do */ 
115  };
116
117  CDataPacketPtr CScalarFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
118  {
119    bool building_graph=this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
120   
121    if(building_graph)
122    {
123      this->filterID = InvalidableObject::filterIdGenerator++;
124      int edgeID = InvalidableObject::edgeIdGenerator++;
125   
126
127      CWorkflowGraph::allocNodeEdge();
128
129      std::cout<<"CScalarFieldFieldArithmeticFilter::apply connection = "<<data[0]->src_filterID<<" <-> "<<this->filterID<<std::endl;
130
131
132      CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 2, data[0]);
133
134      if(CWorkflowGraph::build_begin)
135      {
136
137        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
138
139
140        edgeID = InvalidableObject::edgeIdGenerator++;
141
142        CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
143
144        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
145        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
146      }
147      else CWorkflowGraph::build_begin = true;
148    }
149
150    CDataPacketPtr packet(new CDataPacket);
151    packet->date = data[0]->date;
152    packet->timestamp = data[0]->timestamp;
153    packet->status = data[0]->status;
154    if(building_graph) packet->src_filterID = this->filterID;
155    packet->field = this->field;
156
157    if (data[0]->status != CDataPacket::NO_ERROR)
158      packet->status = data[0]->status;
159    else if (data[1]->status != CDataPacket::NO_ERROR)
160      packet->status = data[1]->status;
161    else
162    { 
163      packet->status = CDataPacket::NO_ERROR;
164      packet->data.reference(op(value, data[0]->data, data[1]->data));
165    }
166    return packet;
167
168  }
169
170
171  CFieldScalarScalarArithmeticFilter::CFieldScalarScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value1, double value2)
172    : CFilter(gc, 1, this)
173    , op(operatorExpr.getOpFieldScalarScalar(op))
174    , value1(value1)
175    , value2(value2)
176  { 
177    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
178    /* Nothing to do */ 
179  };
180
181  CDataPacketPtr CFieldScalarScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
182  {
183    bool building_graph=this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
184   
185    if(building_graph)
186    {
187      this->filterID = InvalidableObject::filterIdGenerator++;
188      int edgeID = InvalidableObject::edgeIdGenerator++;
189   
190
191      CWorkflowGraph::allocNodeEdge();
192
193      std::cout<<"CFieldScalarScalarArithmeticFilter::apply connection = "<<data[0]->src_filterID<<" <-> "<<this->filterID<<std::endl;
194
195      CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 1, data[0]);
196
197      if(CWorkflowGraph::build_begin)
198      {
199
200        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
201
202        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
203      }
204      else CWorkflowGraph::build_begin = true;
205    }
206
207    CDataPacketPtr packet(new CDataPacket);
208    packet->date = data[0]->date;
209    packet->timestamp = data[0]->timestamp;
210    packet->status = data[0]->status;
211    if(building_graph) packet->src_filterID = this->filterID;
212    packet->field = this->field;
213
214    if (packet->status == CDataPacket::NO_ERROR)
215      packet->data.reference(op(data[0]->data, value1, value2));
216
217    return packet;
218  }
219
220
221  CFieldScalarFieldArithmeticFilter::CFieldScalarFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
222    : CFilter(gc, 2, this)
223    , op(operatorExpr.getOpFieldScalarField(op))
224    , value(value)
225  { 
226    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
227    /* Nothing to do */ 
228  };
229
230  CDataPacketPtr CFieldScalarFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
231  {
232    bool building_graph=this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
233   
234    if(building_graph)
235    {
236      this->filterID = InvalidableObject::filterIdGenerator++;
237      int edgeID = InvalidableObject::edgeIdGenerator++;
238   
239
240      CWorkflowGraph::allocNodeEdge();
241
242      std::cout<<"CFieldScalarFieldArithmeticFilter::apply connection = "<<data[0]->src_filterID<<" <-> "<<this->filterID<<std::endl;
243
244      CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 2, data[0]);
245
246      if(CWorkflowGraph::build_begin)
247      {
248
249        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
250
251        edgeID = InvalidableObject::edgeIdGenerator++;
252
253        CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
254
255        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
256        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
257      }
258      else CWorkflowGraph::build_begin = true;
259    }
260
261    CDataPacketPtr packet(new CDataPacket);
262    packet->date = data[0]->date;
263    packet->timestamp = data[0]->timestamp;
264    packet->status = data[0]->status;
265    if(building_graph) packet->src_filterID = this->filterID;
266    packet->field = this->field;
267
268    if (data[0]->status != CDataPacket::NO_ERROR)
269      packet->status = data[0]->status;
270    else if (data[1]->status != CDataPacket::NO_ERROR)
271      packet->status = data[1]->status;
272    else
273    { 
274      packet->status = CDataPacket::NO_ERROR;
275      packet->data.reference(op(data[0]->data, value, data[1]->data));
276    }
277    return packet;
278  }
279 
280   CFieldFieldScalarArithmeticFilter::CFieldFieldScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
281    : CFilter(gc, 2, this)
282    , op(operatorExpr.getOpFieldFieldScalar(op))
283    , value(value)
284  { 
285    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
286    std::cout<<"expression = "<<expression;
287    /* Nothing to do */ 
288  };
289
290  CDataPacketPtr CFieldFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
291  {
292    bool building_graph=this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
293   
294    if(building_graph)
295    {
296      this->filterID = InvalidableObject::filterIdGenerator++;
297      int edgeID = InvalidableObject::edgeIdGenerator++;
298   
299      CWorkflowGraph::allocNodeEdge();
300
301      std::cout<<"CFieldFieldScalarArithmeticFilter::apply connection = "<<data[0]->src_filterID<<" <-> "<<this->filterID<<std::endl;
302
303
304      CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 2, data[0]);
305
306      if(CWorkflowGraph::build_begin)
307      {
308
309        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
310
311        int edgeID = InvalidableObject::edgeIdGenerator++;
312
313        CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
314
315        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
316        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
317      }
318      else CWorkflowGraph::build_begin = true;
319    }
320
321    CDataPacketPtr packet(new CDataPacket);
322    packet->date = data[0]->date;
323    packet->timestamp = data[0]->timestamp;
324    packet->status = data[0]->status;
325    if(building_graph) packet->src_filterID = this->filterID;
326    packet->field = this->field;
327
328    if (data[0]->status != CDataPacket::NO_ERROR)
329      packet->status = data[0]->status;
330    else if (data[1]->status != CDataPacket::NO_ERROR)
331      packet->status = data[1]->status;
332    else
333    { 
334      packet->status = CDataPacket::NO_ERROR;
335      packet->data.reference(op(data[0]->data, data[1]->data, value));
336    }
337    return packet;
338  } 
339 
340 
341  CFieldFieldFieldArithmeticFilter::CFieldFieldFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op)
342    : CFilter(gc, 3, this)
343    , op(operatorExpr.getOpFieldFieldField(op))
344  { 
345    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
346    /* Nothing to do */ 
347  };
348
349  CDataPacketPtr CFieldFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
350  {
351    bool building_graph=this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
352   
353    if(building_graph)
354    {
355      this->filterID = InvalidableObject::filterIdGenerator++;
356      int edgeID = InvalidableObject::edgeIdGenerator++;
357   
358
359      CWorkflowGraph::allocNodeEdge();
360
361      std::cout<<"CFieldFieldFieldArithmeticFilter::apply connection = "<<data[0]->src_filterID<<" <-> "<<this->filterID<<std::endl;
362
363
364      CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 3, data[0]);
365
366      if(CWorkflowGraph::build_begin)
367      {
368
369        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
370
371
372        edgeID = InvalidableObject::edgeIdGenerator++;
373
374        CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
375
376
377        edgeID = InvalidableObject::edgeIdGenerator++;
378
379        CWorkflowGraph::addEdge(edgeID, this->filterID, data[2]);
380
381        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
382        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
383        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[2]->src_filterID].filter_filled = 0 ;
384      }
385      else CWorkflowGraph::build_begin = true;
386    }
387
388
389    CDataPacketPtr packet(new CDataPacket);
390    packet->date = data[0]->date;
391    packet->timestamp = data[0]->timestamp;
392    packet->status = data[0]->status;
393    if(building_graph) packet->src_filterID = this->filterID;
394    packet->field = this->field;
395
396    if (data[0]->status != CDataPacket::NO_ERROR)
397      packet->status = data[0]->status;
398    else if (data[1]->status != CDataPacket::NO_ERROR)
399      packet->status = data[1]->status;
400    else if (data[2]->status != CDataPacket::NO_ERROR)
401      packet->status = data[2]->status;
402    else
403    { 
404      packet->status = CDataPacket::NO_ERROR;
405      packet->data.reference(op(data[0]->data, data[1]->data, data[2]->data));
406    }
407    return packet;
408  } 
409 
410} // namespace xios
411
Note: See TracBrowser for help on using the repository browser.