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

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

dev_trunk_omp : bug fix for workflowgraph

File size: 11.9 KB
RevLine 
[642]1#include "binary_arithmetic_filter.hpp"
[1677]2#include "workflow_graph.hpp"
[1680]3#include "yacc_var.hpp"
4#include "file.hpp"
[642]5
[1679]6
[642]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)
[1677]13  { 
[1680]14    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
[1677]15  };
[642]16
[1681]17  std::tuple<int, int, int> CScalarFieldArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
[642]18  {
[1679]19    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
[1680]20    int unique_filter_id;
[1681]21    bool firstround;
[1679]22
23    if(building_graph)
[1677]24    {
[1680]25      CWorkflowGraph::allocNodeEdge();
[1677]26
[1680]27      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
[1677]28
[1680]29      // first round
30      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
31      {
[1681]32        firstround = true;
[1680]33        this->filterID = InvalidableObject::filterIdGenerator++;
34        int edgeID = InvalidableObject::edgeIdGenerator++;
[1677]35
[1680]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;
[1681]38        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
[1679]39
[1681]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();
[1680]43     
[1679]44
[1680]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;
[1679]56      }
[1680]57      // not first round
58      else 
59      {
[1681]60        firstround=false;
[1680]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      } 
[1677]70    }
71
[1681]72    return std::make_tuple(building_graph, firstround, unique_filter_id);
73  }
74
75
76  CDataPacketPtr CScalarFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
77  {
[642]78    CDataPacketPtr packet(new CDataPacket);
[643]79    packet->date = data[0]->date;
[642]80    packet->timestamp = data[0]->timestamp;
81    packet->status = data[0]->status;
[1681]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
[1679]89    packet->field = this->field;
[642]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)
[1677]101  { 
[1680]102    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
[1677]103  };
[642]104
[1681]105  std::tuple<int, int, int> CFieldScalarArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
[642]106  {
[1679]107    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
[1680]108    int unique_filter_id;
[1681]109    bool firstround;
[1679]110
111    if(building_graph)
[1677]112    {
[1680]113      CWorkflowGraph::allocNodeEdge();
[1677]114
[1680]115      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
[1677]116
[1680]117      // first round
118      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
[1679]119      {
[1681]120        firstround = true;
[1680]121        this->filterID = InvalidableObject::filterIdGenerator++;
122        int edgeID = InvalidableObject::edgeIdGenerator++;
[1679]123
[1680]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;
[1681]126        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
[1680]127
[1681]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();
[1680]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;
[1679]144      }
[1680]145      // not first round
146      else 
147      {
[1681]148        firstround=false;
[1680]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      } 
[1677]158    }
159
[1681]160    return std::make_tuple(building_graph, firstround, unique_filter_id);
161  }
162
163  CDataPacketPtr CFieldScalarArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
164  {
[642]165    CDataPacketPtr packet(new CDataPacket);
[643]166    packet->date = data[0]->date;
[642]167    packet->timestamp = data[0]->timestamp;
168    packet->status = data[0]->status;
[1681]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
[1679]176    packet->field = this->field;
[642]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)
[804]185    : CFilter(gc, 2, this)
[642]186    , op(operatorExpr.getOpFieldField(op))
[1677]187  { 
[1680]188    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
[1677]189  };
[642]190
[1681]191  std::tuple<int, int, int> CFieldFieldArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
[642]192  {
[1681]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
[1680]195    int unique_filter_id;
[1679]196
[1681]197    bool firstround;
198
[1679]199    if(building_graph)
[1680]200    { 
201      CWorkflowGraph::allocNodeEdge();
[1677]202
[1681]203      // std::cout<<"CFieldFieldArithmeticFilter::apply filter tag = "<<this->tag<<std::endl;
[1677]204
[1680]205      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
[1677]206
[1680]207      // first round
208      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
[1679]209      {
[1681]210        firstround = true;
[1680]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]);
[1681]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();
[1680]219   
220        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
221        if(CWorkflowGraph::build_begin)
222        {
[1677]223
[1680]224          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
225          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
[1679]226
[1680]227          edgeID = InvalidableObject::edgeIdGenerator++;
[1679]228
[1680]229          CWorkflowGraph::addEdge(edgeID, this->filterID, data[1]);
230          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
[1679]231
[1680]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 
[1679]240      }
[1680]241      // not first round
242      else 
243      {
[1681]244        firstround = false;
[1680]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      } 
[1677]262    }
263
[1681]264    return std::make_tuple(building_graph, firstround, unique_filter_id);
265  }
[1677]266
[1681]267  CDataPacketPtr CFieldFieldArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
268  {
[642]269    CDataPacketPtr packet(new CDataPacket);
[643]270    packet->date = data[0]->date;
[642]271    packet->timestamp = data[0]->timestamp;
[1681]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   
[1679]279    packet->field = this->field;
[1677]280   
[642]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  }
[1677]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
[642]300} // namespace xios
Note: See TracBrowser for help on using the repository browser.