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

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

MARK: Dynamic workflow graph developement. Branch up to date with trunk @1676. Bug fixed

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