source: XIOS/trunk/src/filter/ternary_arithmetic_filter.cpp @ 1768

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

trunk : bug fix for workflowgraph

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    /* Nothing to do */ 
503  };
504
505  std::tuple<int, int, int> CFieldFieldScalarArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
506  {
507    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
508    int unique_filter_id;
509
510    bool firstround;
511
512    if(building_graph)
513    { 
514      CWorkflowGraph::allocNodeEdge();
515
516      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
517
518      // first round
519      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
520      {
521        firstround = true;
522        this->filterID = InvalidableObject::filterIdGenerator++;
523        int edgeID = InvalidableObject::edgeIdGenerator++;
524   
525        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
526        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
527        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
528
529        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
530   
531        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
532        if(CWorkflowGraph::build_begin)
533        {
534
535          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
536          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
537
538          edgeID = InvalidableObject::edgeIdGenerator++;
539
540          CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
541          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
542
543          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
544          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
545        }
546        CWorkflowGraph::build_begin = true;
547
548        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
549        unique_filter_id = this->filterID;
550 
551      }
552      // not first round
553      else 
554      {
555        firstround = false;
556        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
557        if(data[0]->src_filterID != unique_filter_id)
558        {
559          int edgeID = InvalidableObject::edgeIdGenerator++;
560          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
561          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
562          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
563        }
564        if(data[1]->src_filterID != unique_filter_id)
565        { 
566          int edgeID = InvalidableObject::edgeIdGenerator++;
567          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[1]); 
568          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
569          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
570        }
571       
572      } 
573    }
574
575    return std::make_tuple(building_graph, firstround, unique_filter_id);
576  }
577
578  CDataPacketPtr CFieldFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
579  {
580    CDataPacketPtr packet(new CDataPacket);
581    packet->date = data[0]->date;
582    packet->timestamp = data[0]->timestamp;
583    packet->status = data[0]->status;
584   
585    std::tuple<int, int, int> graph = buildGraph(data);
586
587    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
588    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
589    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
590
591    packet->field = this->field;
592
593    if (data[0]->status != CDataPacket::NO_ERROR)
594      packet->status = data[0]->status;
595    else if (data[1]->status != CDataPacket::NO_ERROR)
596      packet->status = data[1]->status;
597    else
598    { 
599      packet->status = CDataPacket::NO_ERROR;
600      packet->data.reference(op(data[0]->data, data[1]->data, value));
601    }
602    return packet;
603  } 
604 
605 
606  CFieldFieldFieldArithmeticFilter::CFieldFieldFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op)
607    : CFilter(gc, 3, this)
608    , op(operatorExpr.getOpFieldFieldField(op))
609  { 
610    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
611    /* Nothing to do */ 
612  };
613
614  std::tuple<int, int, int> CFieldFieldFieldArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
615  {
616    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
617    int unique_filter_id;
618
619    bool firstround;
620
621    if(building_graph)
622    { 
623      CWorkflowGraph::allocNodeEdge();
624
625      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
626
627      // first round
628      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
629      {
630        firstround = true;
631        this->filterID = InvalidableObject::filterIdGenerator++;
632        int edgeID = InvalidableObject::edgeIdGenerator++;
633   
634        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
635        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
636        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
637
638        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
639   
640        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
641        if(CWorkflowGraph::build_begin)
642        {
643
644          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
645          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
646
647          edgeID = InvalidableObject::edgeIdGenerator++;
648
649          CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
650          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
651
652          edgeID = InvalidableObject::edgeIdGenerator++;
653
654          CWorkflowGraph::addEdge(edgeID, this->filterID, data[2]);
655          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
656
657          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
658          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
659          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[2]->src_filterID].filter_filled = 0 ;
660        }
661        CWorkflowGraph::build_begin = true;
662
663        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
664        unique_filter_id = this->filterID;
665 
666      }
667      // not first round
668      else 
669      {
670        firstround = false;
671        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
672        if(data[0]->src_filterID != unique_filter_id)
673        {
674          int edgeID = InvalidableObject::edgeIdGenerator++;
675          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
676          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
677          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
678        }
679        if(data[1]->src_filterID != unique_filter_id)
680        { 
681          int edgeID = InvalidableObject::edgeIdGenerator++;
682          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[1]); 
683          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
684          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
685        }
686        if(data[2]->src_filterID != unique_filter_id)
687        { 
688          int edgeID = InvalidableObject::edgeIdGenerator++;
689          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[2]); 
690          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[2]->src_filterID].filter_filled = 0 ;
691          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
692        }
693       
694      } 
695    }
696
697    return std::make_tuple(building_graph, firstround, unique_filter_id);
698  }
699
700  CDataPacketPtr CFieldFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
701  {
702    CDataPacketPtr packet(new CDataPacket);
703    packet->date = data[0]->date;
704    packet->timestamp = data[0]->timestamp;
705    packet->status = data[0]->status;
706   
707    std::tuple<int, int, int> graph = buildGraph(data);
708
709    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
710    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
711    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
712
713    packet->field = this->field;
714
715    if (data[0]->status != CDataPacket::NO_ERROR)
716      packet->status = data[0]->status;
717    else if (data[1]->status != CDataPacket::NO_ERROR)
718      packet->status = data[1]->status;
719    else if (data[2]->status != CDataPacket::NO_ERROR)
720      packet->status = data[2]->status;
721    else
722    { 
723      packet->status = CDataPacket::NO_ERROR;
724      packet->data.reference(op(data[0]->data, data[1]->data, data[2]->data));
725    }
726    return packet;
727  } 
728 
729} // namespace xios
730
Note: See TracBrowser for help on using the repository browser.