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