source: XIOS/trunk/src/filter/unary_arithmetic_filter.cpp @ 1704

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

Introducing the new graph functionality. Attribute build_workflow_graph=.TRUE. is used in the field definition section in the xml file to enable the workflow graph of the field and other fields referecing to it. A more detailed document will be available soon on the graph fuctionality.

File size: 3.5 KB
Line 
1#include "unary_arithmetic_filter.hpp"
2#include "workflow_graph.hpp"
3#include "yacc_var.hpp"
4#include "file.hpp"
5
6namespace xios
7{
8  CUnaryArithmeticFilter::CUnaryArithmeticFilter(CGarbageCollector& gc, const std::string& op)
9    : CFilter(gc, 1, this)
10    , op(operatorExpr.getOpField(op))
11  { 
12    expression.assign(*yacc_globalInputText_ptr, 0, yacc_globalInputText_ptr->size()-1);
13  };
14
15  std::tuple<int, int, int> CUnaryArithmeticFilter::buildGraph(std::vector<CDataPacketPtr> data)
16  {
17    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph : false;
18    int unique_filter_id;
19    bool firstround;
20   
21    if(building_graph)
22    {
23      CWorkflowGraph::allocNodeEdge();
24      size_t filterhash = std::hash<StdString>{}(expression+to_string(data[0]->timestamp)+this->field->getId());
25
26      // first round
27      if(CWorkflowGraph::mapHashFilterID_ptr->find(filterhash) == CWorkflowGraph::mapHashFilterID_ptr->end())
28      {
29        firstround=true;
30        this->filterID = InvalidableObject::filterIdGenerator++;
31        int edgeID = InvalidableObject::edgeIdGenerator++;
32
33        CWorkflowGraph::addNode(this->filterID, "Arithmetic Filter\\n("+expression+")", 3, 1, 0, data[0]);
34        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_tag = this->tag;
35        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
36
37        (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
38        if(this->field->file) (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
39     
40        if(CWorkflowGraph::build_begin)
41        {
42
43          CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
44          (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb ++;
45
46          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
47        }
48        else CWorkflowGraph::build_begin = true;
49
50        (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash] = this->filterID; 
51        unique_filter_id = this->filterID;
52      }
53      else 
54      {
55        firstround=false;
56        unique_filter_id = (*CWorkflowGraph::mapHashFilterID_ptr)[filterhash];
57        if(data[0]->src_filterID != unique_filter_id)
58        {
59          int edgeID = InvalidableObject::edgeIdGenerator++;
60          CWorkflowGraph::addEdge(edgeID, unique_filter_id, data[0]); 
61          (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; 
62          (*CWorkflowGraph::mapFilters_ptr_with_info)[unique_filter_id].expected_entry_nb ++;
63        }   
64      } 
65 
66    }
67
68    return std::make_tuple(building_graph, firstround, unique_filter_id);
69  }
70
71  CDataPacketPtr CUnaryArithmeticFilter::apply(std::vector<CDataPacketPtr> data)
72  {
73    CDataPacketPtr packet(new CDataPacket);
74    packet->date = data[0]->date;
75    packet->timestamp = data[0]->timestamp;
76    packet->status = data[0]->status;
77
78    std::tuple<int, int, int> graph = buildGraph(data);
79
80    if(std::get<0>(graph)) packet->src_filterID = std::get<2>(graph);
81    if(std::get<0>(graph) && std::get<1>(graph)) packet->distance = data[0]->distance+1;
82    if(std::get<0>(graph) && !std::get<1>(graph)) packet->distance = data[0]->distance;
83
84    packet->field = this->field;
85
86    if (packet->status == CDataPacket::NO_ERROR)
87      packet->data.reference(op(data[0]->data));
88
89    return packet;
90  }
91} // namespace xios
Note: See TracBrowser for help on using the repository browser.