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

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

dev for graph. up to date with trunk at r1684

File size: 29.4 KB
Line 
1#include "ternary_arithmetic_filter.hpp"
2#include "workflow_graph.hpp"
3#include "yacc_var.hpp"
4#include "file.hpp"
5
6namespace xios
7{
8  CScalarScalarFieldArithmeticFilter::CScalarScalarFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value1, double value2)
9    : CFilter(gc, 1, this)
10    , op(operatorExpr.getOpScalarScalarField(op))
11    , value1(value1)
12    , value2(value2)
13  { 
14    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
15    /* Nothing to do */ 
16  };
17
18  std::tuple<int, int, int> CScalarScalarFieldArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
19  {
20    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
21    int unique_filter_id;
22    bool firstround;
23
24    if(building_graph)
25    {
26      CWorkflowGraph::allocNodeEdge();
27
28      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
29
30      // first round
31      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
32      {
33        firstround = true;
34        this->filterID = InvalidableObject::filterIdGenerator++;
35        int edgeID = InvalidableObject::edgeIdGenerator++;
36
37        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
38        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
39        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
40
41
42        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
43        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
44     
45
46        if(CWorkflowGraph::build_begin)
47        {
48          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
49          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
50
51          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
52        }
53        else CWorkflowGraph::build_begin = true;
54
55        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
56        unique_filter_id = this->filterID;
57      }
58      // not first round
59      else 
60      {
61        firstround=false;
62        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
63        if(data[0]->src_filterID != unique_filter_id)
64        {
65          int edgeID = InvalidableObject::edgeIdGenerator++;
66          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
67          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
68          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
69        }
70      } 
71    }
72
73    return std::make_tuple(building_graph, firstround, unique_filter_id);
74  }
75
76  CDataPacketPtr CScalarScalarFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
77  {
78    CDataPacketPtr packet(new CDataPacket);
79    packet->date = data[0]->date;
80    packet->timestamp = data[0]->timestamp;
81    packet->status = data[0]->status;
82   
83    std::tuple<int, int, int> graph = buildGraph(data);
84
85    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
86    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
87    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
88
89    packet->field = this->field;
90
91    if (packet->status == CDataPacket::NO_ERROR)
92      packet->data.reference(op(value1,value2, data[0]->data));
93
94    return packet;
95  }
96
97  CScalarFieldScalarArithmeticFilter::CScalarFieldScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value1, double value2)
98    : CFilter(gc, 1, this)
99    , op(operatorExpr.getOpScalarFieldScalar(op))
100    , value1(value1)
101    , value2(value2)
102  { 
103    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
104    /* Nothing to do */ 
105  };
106
107  std::tuple<int, int, int> CScalarFieldScalarArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
108  {
109    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
110    int unique_filter_id;
111    bool firstround;
112
113    if(building_graph)
114    {
115      CWorkflowGraph::allocNodeEdge();
116
117      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
118
119      // first round
120      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
121      {
122        firstround = true;
123        this->filterID = InvalidableObject::filterIdGenerator++;
124        int edgeID = InvalidableObject::edgeIdGenerator++;
125
126        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
127        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
128        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
129
130
131        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
132        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
133     
134
135        if(CWorkflowGraph::build_begin)
136        {
137          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
138          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
139
140          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
141        }
142        else CWorkflowGraph::build_begin = true;
143
144        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
145        unique_filter_id = this->filterID;
146      }
147      // not first round
148      else 
149      {
150        firstround=false;
151        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
152        if(data[0]->src_filterID != unique_filter_id)
153        {
154          int edgeID = InvalidableObject::edgeIdGenerator++;
155          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
156          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
157          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
158        }
159      } 
160    }
161
162    return std::make_tuple(building_graph, firstround, unique_filter_id);
163  }
164
165  CDataPacketPtr CScalarFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
166  {
167    CDataPacketPtr packet(new CDataPacket);
168    packet->date = data[0]->date;
169    packet->timestamp = data[0]->timestamp;
170    packet->status = data[0]->status;
171   
172    std::tuple<int, int, int> graph = buildGraph(data);
173
174    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
175    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
176    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
177
178    packet->field = this->field;
179
180    if (packet->status == CDataPacket::NO_ERROR)
181      packet->data.reference(op(value1, data[0]->data,value2));
182
183    return packet;
184  }
185
186  CScalarFieldFieldArithmeticFilter::CScalarFieldFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
187    : CFilter(gc, 2, this)
188    , op(operatorExpr.getOpScalarFieldField(op))
189    , value(value)
190  { 
191    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
192    /* Nothing to do */ 
193  };
194
195  std::tuple<int, int, int> CScalarFieldFieldArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
196  {
197    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
198    int unique_filter_id;
199
200    bool firstround;
201
202    if(building_graph)
203    { 
204      CWorkflowGraph::allocNodeEdge();
205
206      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
207
208      // first round
209      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
210      {
211        firstround = true;
212        this->filterID = InvalidableObject::filterIdGenerator++;
213        int edgeID = InvalidableObject::edgeIdGenerator++;
214   
215        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
216        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
217        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
218
219        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
220   
221        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
222        if(CWorkflowGraph::build_begin)
223        {
224
225          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
226          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
227
228          edgeID = InvalidableObject::edgeIdGenerator++;
229
230          CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
231          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
232
233          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
234          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
235        }
236        CWorkflowGraph::build_begin = true;
237
238        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
239        unique_filter_id = this->filterID;
240 
241      }
242      // not first round
243      else 
244      {
245        firstround = false;
246        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
247        if(data[0]->src_filterID != unique_filter_id)
248        {
249          int edgeID = InvalidableObject::edgeIdGenerator++;
250          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
251          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
252          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
253        }
254        if(data[1]->src_filterID != unique_filter_id)
255        { 
256          int edgeID = InvalidableObject::edgeIdGenerator++;
257          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[1]); 
258          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
259          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
260        }
261       
262      } 
263    }
264
265    return std::make_tuple(building_graph, firstround, unique_filter_id);
266  }
267
268  CDataPacketPtr CScalarFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
269  {
270    CDataPacketPtr packet(new CDataPacket);
271    packet->date = data[0]->date;
272    packet->timestamp = data[0]->timestamp;
273    packet->status = data[0]->status;
274   
275    std::tuple<int, int, int> graph = buildGraph(data);
276
277    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
278    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
279    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
280
281    packet->field = this->field;
282
283    if (data[0]->status != CDataPacket::NO_ERROR)
284      packet->status = data[0]->status;
285    else if (data[1]->status != CDataPacket::NO_ERROR)
286      packet->status = data[1]->status;
287    else
288    { 
289      packet->status = CDataPacket::NO_ERROR;
290      packet->data.reference(op(value, data[0]->data, data[1]->data));
291    }
292    return packet;
293
294  }
295
296
297  CFieldScalarScalarArithmeticFilter::CFieldScalarScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value1, double value2)
298    : CFilter(gc, 1, this)
299    , op(operatorExpr.getOpFieldScalarScalar(op))
300    , value1(value1)
301    , value2(value2)
302  { 
303    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
304    /* Nothing to do */ 
305  };
306
307  std::tuple<int, int, int> CFieldScalarScalarArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
308  {
309    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
310    int unique_filter_id;
311    bool firstround;
312
313    if(building_graph)
314    {
315      CWorkflowGraph::allocNodeEdge();
316
317      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
318
319      // first round
320      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
321      {
322        firstround = true;
323        this->filterID = InvalidableObject::filterIdGenerator++;
324        int edgeID = InvalidableObject::edgeIdGenerator++;
325
326        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
327        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
328        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
329
330
331        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
332        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
333     
334
335        if(CWorkflowGraph::build_begin)
336        {
337          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
338          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
339
340          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
341        }
342        else CWorkflowGraph::build_begin = true;
343
344        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
345        unique_filter_id = this->filterID;
346      }
347      // not first round
348      else 
349      {
350        firstround=false;
351        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
352        if(data[0]->src_filterID != unique_filter_id)
353        {
354          int edgeID = InvalidableObject::edgeIdGenerator++;
355          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
356          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
357          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
358        }
359      } 
360    }
361
362    return std::make_tuple(building_graph, firstround, unique_filter_id);
363  }
364
365  CDataPacketPtr CFieldScalarScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
366  {
367    CDataPacketPtr packet(new CDataPacket);
368    packet->date = data[0]->date;
369    packet->timestamp = data[0]->timestamp;
370    packet->status = data[0]->status;
371
372    std::tuple<int, int, int> graph = buildGraph(data);
373
374    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
375    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
376    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
377
378    packet->field = this->field;
379
380    if (packet->status == CDataPacket::NO_ERROR)
381      packet->data.reference(op(data[0]->data, value1, value2));
382
383    return packet;
384  }
385
386
387  CFieldScalarFieldArithmeticFilter::CFieldScalarFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
388    : CFilter(gc, 2, this)
389    , op(operatorExpr.getOpFieldScalarField(op))
390    , value(value)
391  { 
392    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
393    /* Nothing to do */ 
394  };
395
396  std::tuple<int, int, int> CFieldScalarFieldArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
397  {
398    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
399    int unique_filter_id;
400
401    bool firstround;
402
403    if(building_graph)
404    { 
405      CWorkflowGraph::allocNodeEdge();
406
407      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
408
409      // first round
410      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
411      {
412        firstround = true;
413        this->filterID = InvalidableObject::filterIdGenerator++;
414        int edgeID = InvalidableObject::edgeIdGenerator++;
415   
416        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
417        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
418        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
419
420        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
421   
422        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
423        if(CWorkflowGraph::build_begin)
424        {
425
426          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
427          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
428
429          edgeID = InvalidableObject::edgeIdGenerator++;
430
431          CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
432          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
433
434          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
435          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
436        }
437        CWorkflowGraph::build_begin = true;
438
439        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
440        unique_filter_id = this->filterID;
441 
442      }
443      // not first round
444      else 
445      {
446        firstround = false;
447        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
448        if(data[0]->src_filterID != unique_filter_id)
449        {
450          int edgeID = InvalidableObject::edgeIdGenerator++;
451          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
452          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
453          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
454        }
455        if(data[1]->src_filterID != unique_filter_id)
456        { 
457          int edgeID = InvalidableObject::edgeIdGenerator++;
458          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[1]); 
459          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
460          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
461        }
462       
463      } 
464    }
465
466    return std::make_tuple(building_graph, firstround, unique_filter_id);
467  }
468
469  CDataPacketPtr CFieldScalarFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
470  {
471    CDataPacketPtr packet(new CDataPacket);
472    packet->date = data[0]->date;
473    packet->timestamp = data[0]->timestamp;
474    packet->status = data[0]->status;
475   
476    std::tuple<int, int, int> graph = buildGraph(data);
477
478    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
479    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
480    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
481
482    packet->field = this->field;
483
484    if (data[0]->status != CDataPacket::NO_ERROR)
485      packet->status = data[0]->status;
486    else if (data[1]->status != CDataPacket::NO_ERROR)
487      packet->status = data[1]->status;
488    else
489    { 
490      packet->status = CDataPacket::NO_ERROR;
491      packet->data.reference(op(data[0]->data, value, data[1]->data));
492    }
493    return packet;
494  }
495 
496   CFieldFieldScalarArithmeticFilter::CFieldFieldScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
497    : CFilter(gc, 2, this)
498    , op(operatorExpr.getOpFieldFieldScalar(op))
499    , value(value)
500  { 
501    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
502    std::cout<<"expression = "<<expression;
503    /* Nothing to do */ 
504  };
505
506  std::tuple<int, int, int> CFieldFieldScalarArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
507  {
508    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
509    int unique_filter_id;
510
511    bool firstround;
512
513    if(building_graph)
514    { 
515      CWorkflowGraph::allocNodeEdge();
516
517      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
518
519      // first round
520      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
521      {
522        firstround = true;
523        this->filterID = InvalidableObject::filterIdGenerator++;
524        int edgeID = InvalidableObject::edgeIdGenerator++;
525   
526        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
527        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
528        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
529
530        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
531   
532        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
533        if(CWorkflowGraph::build_begin)
534        {
535
536          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
537          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
538
539          edgeID = InvalidableObject::edgeIdGenerator++;
540
541          CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
542          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
543
544          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
545          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
546        }
547        CWorkflowGraph::build_begin = true;
548
549        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
550        unique_filter_id = this->filterID;
551 
552      }
553      // not first round
554      else 
555      {
556        firstround = false;
557        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
558        if(data[0]->src_filterID != unique_filter_id)
559        {
560          int edgeID = InvalidableObject::edgeIdGenerator++;
561          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
562          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
563          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
564        }
565        if(data[1]->src_filterID != unique_filter_id)
566        { 
567          int edgeID = InvalidableObject::edgeIdGenerator++;
568          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[1]); 
569          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
570          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
571        }
572       
573      } 
574    }
575
576    return std::make_tuple(building_graph, firstround, unique_filter_id);
577  }
578
579  CDataPacketPtr CFieldFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
580  {
581    CDataPacketPtr packet(new CDataPacket);
582    packet->date = data[0]->date;
583    packet->timestamp = data[0]->timestamp;
584    packet->status = data[0]->status;
585   
586    std::tuple<int, int, int> graph = buildGraph(data);
587
588    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
589    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
590    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
591
592    packet->field = this->field;
593
594    if (data[0]->status != CDataPacket::NO_ERROR)
595      packet->status = data[0]->status;
596    else if (data[1]->status != CDataPacket::NO_ERROR)
597      packet->status = data[1]->status;
598    else
599    { 
600      packet->status = CDataPacket::NO_ERROR;
601      packet->data.reference(op(data[0]->data, data[1]->data, value));
602    }
603    return packet;
604  } 
605 
606 
607  CFieldFieldFieldArithmeticFilter::CFieldFieldFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op)
608    : CFilter(gc, 3, this)
609    , op(operatorExpr.getOpFieldFieldField(op))
610  { 
611    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
612    /* Nothing to do */ 
613  };
614
615  std::tuple<int, int, int> CFieldFieldFieldArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
616  {
617    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
618    int unique_filter_id;
619
620    bool firstround;
621
622    if(building_graph)
623    { 
624      CWorkflowGraph::allocNodeEdge();
625
626      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
627
628      // first round
629      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
630      {
631        firstround = true;
632        this->filterID = InvalidableObject::filterIdGenerator++;
633        int edgeID = InvalidableObject::edgeIdGenerator++;
634   
635        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
636        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
637        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
638
639        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
640   
641        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
642        if(CWorkflowGraph::build_begin)
643        {
644
645          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
646          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
647
648          edgeID = InvalidableObject::edgeIdGenerator++;
649
650          CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
651          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
652
653          edgeID = InvalidableObject::edgeIdGenerator++;
654
655          CWorkflowGraph::addEdge(edgeID, this->filterID, data[2]);
656          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
657
658          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
659          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
660          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[2]->src_filterID].filter_filled = 0 ;
661        }
662        CWorkflowGraph::build_begin = true;
663
664        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
665        unique_filter_id = this->filterID;
666 
667      }
668      // not first round
669      else 
670      {
671        firstround = false;
672        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
673        if(data[0]->src_filterID != unique_filter_id)
674        {
675          int edgeID = InvalidableObject::edgeIdGenerator++;
676          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
677          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
678          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
679        }
680        if(data[1]->src_filterID != unique_filter_id)
681        { 
682          int edgeID = InvalidableObject::edgeIdGenerator++;
683          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[1]); 
684          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
685          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
686        }
687        if(data[2]->src_filterID != unique_filter_id)
688        { 
689          int edgeID = InvalidableObject::edgeIdGenerator++;
690          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[2]); 
691          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[2]->src_filterID].filter_filled = 0 ;
692          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
693        }
694       
695      } 
696    }
697
698    return std::make_tuple(building_graph, firstround, unique_filter_id);
699  }
700
701  CDataPacketPtr CFieldFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
702  {
703    CDataPacketPtr packet(new CDataPacket);
704    packet->date = data[0]->date;
705    packet->timestamp = data[0]->timestamp;
706    packet->status = data[0]->status;
707   
708    std::tuple<int, int, int> graph = buildGraph(data);
709
710    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
711    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
712    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
713
714    packet->field = this->field;
715
716    if (data[0]->status != CDataPacket::NO_ERROR)
717      packet->status = data[0]->status;
718    else if (data[1]->status != CDataPacket::NO_ERROR)
719      packet->status = data[1]->status;
720    else if (data[2]->status != CDataPacket::NO_ERROR)
721      packet->status = data[2]->status;
722    else
723    { 
724      packet->status = CDataPacket::NO_ERROR;
725      packet->data.reference(op(data[0]->data, data[1]->data, data[2]->data));
726    }
727    return packet;
728  } 
729 
730} // namespace xios
731
Note: See TracBrowser for help on using the repository browser.