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

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

dev_trunk_omp : bug fix for workflowgraph

File size: 11.9 KB
Line 
1#include "binary_arithmetic_filter.hpp"
2#include "workflow_graph.hpp"
3#include "yacc_var.hpp"
4#include "file.hpp"
5
6
7namespace xios
8{
9  CScalarFieldArithmeticFilter::CScalarFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
10    : CFilter(gc, 1, this)
11    , op(operatorExpr.getOpScalarField(op))
12    , value(value)
13  { 
14    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
15  };
16
17  std::tuple<int, int, int> CScalarFieldArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
18  {
19    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
20    int unique_filter_id;
21    bool firstround;
22
23    if(building_graph)
24    {
25      CWorkflowGraph::allocNodeEdge();
26
27      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
28
29      // first round
30      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
31      {
32        firstround = true;
33        this->filterID = InvalidableObject::filterIdGenerator++;
34        int edgeID = InvalidableObject::edgeIdGenerator++;
35
36        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
37        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
38        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
39
40
41        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
42        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
43     
44
45        if(CWorkflowGraph::build_begin)
46        {
47          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
48          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
49
50          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
51        }
52        else CWorkflowGraph::build_begin = true;
53
54        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
55        unique_filter_id = this->filterID;
56      }
57      // not first round
58      else 
59      {
60        firstround=false;
61        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
62        if(data[0]->src_filterID != unique_filter_id)
63        {
64          int edgeID = InvalidableObject::edgeIdGenerator++;
65          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
66          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
67          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
68        }
69      } 
70    }
71
72    return std::make_tuple(building_graph, firstround, unique_filter_id);
73  }
74
75
76  CDataPacketPtr CScalarFieldArithmeticFilter::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(value, data[0]->data));
93
94    return packet;
95  }
96
97  CFieldScalarArithmeticFilter::CFieldScalarArithmeticFilter(CGarbageCollector& gc, const std::string& op, double value)
98    : CFilter(gc, 1, this)
99    , op(operatorExpr.getOpFieldScalar(op))
100    , value(value)
101  { 
102    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
103  };
104
105  std::tuple<int, int, int> CFieldScalarArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
106  {
107    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
108    int unique_filter_id;
109    bool firstround;
110
111    if(building_graph)
112    {
113      CWorkflowGraph::allocNodeEdge();
114
115      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
116
117      // first round
118      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
119      {
120        firstround = true;
121        this->filterID = InvalidableObject::filterIdGenerator++;
122        int edgeID = InvalidableObject::edgeIdGenerator++;
123
124        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
125        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
126        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
127
128
129        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
130        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
131     
132
133        if(CWorkflowGraph::build_begin)
134        {
135          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
136          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
137
138          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
139        }
140        else CWorkflowGraph::build_begin = true;
141
142        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
143        unique_filter_id = this->filterID;
144      }
145      // not first round
146      else 
147      {
148        firstround=false;
149        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
150        if(data[0]->src_filterID != unique_filter_id)
151        {
152          int edgeID = InvalidableObject::edgeIdGenerator++;
153          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
154          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
155          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
156        }
157      } 
158    }
159
160    return std::make_tuple(building_graph, firstround, unique_filter_id);
161  }
162
163  CDataPacketPtr CFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
164  {
165    CDataPacketPtr packet(new CDataPacket);
166    packet->date = data[0]->date;
167    packet->timestamp = data[0]->timestamp;
168    packet->status = data[0]->status;
169
170    std::tuple<int, int, int> graph = buildGraph(data);
171
172    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
173    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
174    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
175
176    packet->field = this->field;
177
178    if (packet->status == CDataPacket::NO_ERROR)
179      packet->data.reference(op(data[0]->data, value));
180
181    return packet;
182  }
183
184  CFieldFieldArithmeticFilter::CFieldFieldArithmeticFilter(CGarbageCollector& gc, const std::string& op)
185    : CFilter(gc, 2, this)
186    , op(operatorExpr.getOpFieldField(op))
187  { 
188    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
189  };
190
191  std::tuple<int, int, int> CFieldFieldArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
192  {
193    bool building_graph = this->tag ? ((data[0]->timestamp >= this->field->field_graph_start && data[0]->timestamp <= this->field->field_graph_end) && (data[0]->timestamp == data[1]->timestamp)) : false;
194
195    int unique_filter_id;
196
197    bool firstround;
198
199    if(building_graph)
200    { 
201      CWorkflowGraph::allocNodeEdge();
202
203      // std::cout<<"CFieldFieldArithmeticFilter::apply filter tag = "<<this->tag<<std::endl;
204
205      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
206
207      // first round
208      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
209      {
210        firstround = true;
211        this->filterID = InvalidableObject::filterIdGenerator++;
212        int edgeID = InvalidableObject::edgeIdGenerator++;
213   
214        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
215        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
216        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
217
218        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
219   
220        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
221        if(CWorkflowGraph::build_begin)
222        {
223
224          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
225          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
226
227          edgeID = InvalidableObject::edgeIdGenerator++;
228
229          CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
230          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
231
232          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
233          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
234        }
235        CWorkflowGraph::build_begin = true;
236
237        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
238        unique_filter_id = this->filterID;
239 
240      }
241      // not first round
242      else 
243      {
244        firstround = false;
245        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
246        if(data[0]->src_filterID != unique_filter_id)
247        {
248          int edgeID = InvalidableObject::edgeIdGenerator++;
249          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
250          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
251          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
252        }
253        if(data[1]->src_filterID != unique_filter_id)
254        { 
255          int edgeID = InvalidableObject::edgeIdGenerator++;
256          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[1]); 
257          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[1]->src_filterID].filter_filled = 0 ;
258          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
259        }
260       
261      } 
262    }
263
264    return std::make_tuple(building_graph, firstround, unique_filter_id);
265  }
266
267  CDataPacketPtr CFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
268  {
269    CDataPacketPtr packet(new CDataPacket);
270    packet->date = data[0]->date;
271    packet->timestamp = data[0]->timestamp;
272
273    std::tuple<int, int, int> graph = buildGraph(data);
274
275    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
276    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
277    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
278   
279    packet->field = this->field;
280   
281
282    if (data[0]->status != CDataPacket::NO_ERROR)
283      packet->status = data[0]->status;
284    else if (data[1]->status != CDataPacket::NO_ERROR)
285      packet->status = data[1]->status;
286    else
287    {
288      packet->status = CDataPacket::NO_ERROR;
289      packet->data.reference(op(data[0]->data, data[1]->data));
290    }
291
292    return packet;
293  }
294
295  StdString CScalarFieldArithmeticFilter::GetName(void)    { return StdString("CScalarFieldArithmeticFilter"); }
296  StdString CFieldScalarArithmeticFilter::GetName(void)    { return StdString("CFieldScalarArithmeticFilter"); }
297  StdString CFieldFieldArithmeticFilter::GetName(void)     { return StdString("CFieldFieldArithmeticFilter"); }
298
299
300} // namespace xios
Note: See TracBrowser for help on using the repository browser.