source: XIOS/dev/dev_olga/src/parse_expr/filter_expr_node.cpp @ 1686

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

backup for trunk with graph

File size: 17.9 KB
Line 
1#include "filter_expr_node.hpp"
2#include "unary_arithmetic_filter.hpp"
3#include "binary_arithmetic_filter.hpp"
4#include "ternary_arithmetic_filter.hpp"
5#include "field.hpp"
6
7namespace xios
8{
9  CFilterFieldExprNode::CFilterFieldExprNode(const std::string& fieldId)
10    : fieldId(fieldId)
11  { /* Nothing to do */ }
12
13 
14  std::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
15  {
16    std::shared_ptr<COutputPin> outputPin;
17
18    if (fieldId == "this") outputPin = thisField.getSelfReference(gc);
19    else
20    {
21      string id ;
22
23      if (fieldId == "this_ref")
24      {
25        if (thisField.field_ref.isEmpty())
26        {
27          ERROR("shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
28                << "field_ref attribute is empty.");
29        }
30        else id = thisField.field_ref ;
31      }
32      else id= fieldId ;
33       
34      if (CField::has(id))
35      {
36        CField* field = CField::get(id);
37        if (field == &thisField)
38          ERROR("shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
39                << "The field " << id << " has an invalid reference to itself. "
40                << "Use the keyword \"this\" if you want to reference the input data sent to this field.");
41
42        // field->buildFilterGraph(gc, false);
43        field->buildFilterGraph(gc, false, start_graph, end_graph);
44        outputPin = field->getInstantDataFilter();
45      }
46      else ERROR("boost::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
47                  << "The field " << id << " does not exist.");
48    }
49    return outputPin;
50  }
51
52
53  CFilterTemporalFieldExprNode::CFilterTemporalFieldExprNode(const std::string& fieldId)
54    : fieldId(fieldId)
55  { /* Nothing to do */ }
56
57
58  std::shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
59  {
60    std::shared_ptr<COutputPin> outputPin;
61
62    if (fieldId == "this")
63      outputPin = thisField.getSelfTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op);
64    else
65    {
66      string id ;
67
68      if (fieldId == "this_ref")
69      {
70        if (thisField.field_ref.isEmpty())
71        {
72          ERROR("shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
73                << "field_ref attribute is empty.");
74        }
75        else id = thisField.field_ref ;
76      }
77      else id = fieldId ;
78
79      if (CField::has(id))
80      {
81        CField* field = CField::get(id);
82        if (field == &thisField)
83          ERROR("shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
84                << "The field " << fieldId << " has an invalid reference to itself. "
85                << "Use the keyword \"this\" if you want to reference the input data sent to this field.");
86
87        field->buildFilterGraph(gc, false);
88        outputPin = field->getTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op);
89      }
90      else
91        ERROR("shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const",
92              << "The field " << fieldId << " does not exist.");
93    }
94    return outputPin;
95  }
96
97
98  CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)
99    : opId(opId)
100    , child(child)
101  {
102    if (!child)
103      ERROR("CFilterUnaryOpExprNode::CFilterUnaryOpExprNode(const std::string& opId, IFilterExprNode* child)",
104            "Impossible to create the new expression node, an invalid child node was provided.");
105  }
106
107  std::shared_ptr<COutputPin> CFilterUnaryOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
108  {
109    std::shared_ptr<COutputPin> ch = child->reduce(gc, thisField, start_graph, end_graph);
110
111    std::shared_ptr<CUnaryArithmeticFilter> filter(new CUnaryArithmeticFilter(gc, opId));
112    ch->connectOutput(filter, 0);
113
114    (filter->parent_filters).resize(1);
115    (filter->parent_filters)[0] = ch;
116
117    filter->tag = ch->tag;
118    filter->start_graph = ch->start_graph;
119    filter->end_graph = ch->end_graph;
120    filter->field = &thisField;
121
122
123    return filter;
124  }
125
126  CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)
127    : child1(child1)
128    , opId(opId)
129    , child2(child2)
130  {
131    if (!child1 || !child2)
132      ERROR("CFilterScalarFieldOpExprNode::CFilterScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
133            "Impossible to create the new expression node, an invalid child node was provided.");
134  }
135
136  std::shared_ptr<COutputPin> CFilterScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
137  {
138    std::shared_ptr<COutputPin> ch2 = child2->reduce(gc, thisField, start_graph, end_graph);
139    std::shared_ptr<CScalarFieldArithmeticFilter> filter(new CScalarFieldArithmeticFilter(gc, opId, child1->reduce()));
140    ch2->connectOutput(filter, 0);
141   
142    (filter->parent_filters).resize(1);
143    (filter->parent_filters)[0] = ch2;
144
145    filter->tag = ch2->tag;
146    filter->start_graph = ch2->start_graph;
147    filter->end_graph = ch2->end_graph;
148    filter->field = &thisField;
149
150    return filter;
151  }
152
153  CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)
154    : child1(child1)
155    , opId(opId)
156    , child2(child2)
157  {
158    if (!child1 || !child2)
159      ERROR("CFilterFieldScalarOpExprNode::CFilterFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2)",
160            "Impossible to create the new expression node, an invalid child node was provided.");
161  }
162
163  std::shared_ptr<COutputPin> CFilterFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
164  {
165    std::shared_ptr<COutputPin> ch1 = child1->reduce(gc, thisField, start_graph, end_graph);
166
167    std::shared_ptr<CFieldScalarArithmeticFilter> filter(new CFieldScalarArithmeticFilter(gc, opId, child2->reduce()));
168    ch1->connectOutput(filter, 0);
169
170    (filter->parent_filters).resize(1);
171    (filter->parent_filters)[0] = ch1;
172
173    filter->tag = ch1->tag;
174    filter->start_graph = ch1->start_graph;
175    filter->end_graph = ch1->end_graph;
176    filter->field = &thisField;
177
178    return filter;
179  }
180
181  CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)
182    : child1(child1)
183    , opId(opId)
184    , child2(child2)
185  {
186    if (!child1 || !child2)
187      ERROR("CFilterFieldFieldOpExprNode::CFilterFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2)",
188            "Impossible to create the new expression node, an invalid child node was provided.");
189  }
190
191  std::shared_ptr<COutputPin> CFilterFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
192  {
193    std::shared_ptr<COutputPin> ch1 = child1->reduce(gc, thisField, start_graph, end_graph);
194    std::shared_ptr<COutputPin> ch2 = child2->reduce(gc, thisField, start_graph, end_graph);
195
196    std::shared_ptr<CFieldFieldArithmeticFilter> filter(new CFieldFieldArithmeticFilter(gc, opId));
197    ch1->connectOutput(filter, 0);
198    ch2->connectOutput(filter, 1); 
199
200    (filter->parent_filters).resize(2);
201    (filter->parent_filters)[0] = ch1;
202    (filter->parent_filters)[1] = ch2;
203
204    filter->tag = (ch1->tag || ch2->tag);
205    filter->start_graph = ch1->tag? ch1->start_graph : (ch2->tag? ch2->start_graph: -1);
206    filter->end_graph = ch1->tag? ch1->end_graph : (ch2->tag? ch2->end_graph: -1);
207
208    filter->field = &thisField;
209
210
211    return filter;
212  }
213
214
215
216
217  CFilterScalarScalarFieldOpExprNode::CFilterScalarScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)
218    : child1(child1)
219    , opId(opId)
220    , child2(child2)
221    , child3(child3)
222  {
223    if (!child1 || !child2 || !child3)
224      ERROR("  CFilterScalarScalarFieldOpExprNode::CFilterScalarScalarFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)",
225            "Impossible to create the new expression node, an invalid child node was provided.");
226  }
227
228  std::shared_ptr<COutputPin> CFilterScalarScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
229  {
230    std::shared_ptr<COutputPin> ch3 = child3->reduce(gc, thisField, start_graph, end_graph);
231
232    std::shared_ptr<CScalarScalarFieldArithmeticFilter> filter(new CScalarScalarFieldArithmeticFilter(gc, opId, child1->reduce(),child2->reduce()));
233    ch3->connectOutput(filter, 0);
234   
235    (filter->parent_filters).resize(1);
236    (filter->parent_filters)[0] = ch3;
237
238    filter->tag = ch3->tag;
239    filter->start_graph = ch3->start_graph;
240    filter->end_graph = ch3->end_graph;
241    filter->field = &thisField;
242
243    return filter;
244  }
245
246
247  CFilterScalarFieldScalarOpExprNode::CFilterScalarFieldScalarOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)
248    : child1(child1)
249    , opId(opId)
250    , child2(child2)
251    , child3(child3)
252  {
253    if (!child1 || !child2 || !child3)
254      ERROR("  CFilterScalarFieldScalarOpExprNode::CFilterScalarFieldScalarOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)",
255            "Impossible to create the new expression node, an invalid child node was provided.");
256  }
257
258  std::shared_ptr<COutputPin> CFilterScalarFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
259  {
260    std::shared_ptr<COutputPin> ch2 = child2->reduce(gc, thisField, start_graph, end_graph);
261
262    std::shared_ptr<CScalarFieldScalarArithmeticFilter> filter(new CScalarFieldScalarArithmeticFilter(gc, opId, child1->reduce(),child3->reduce()));
263    ch2->connectOutput(filter, 0);
264
265    (filter->parent_filters).resize(1);
266    (filter->parent_filters)[0] = ch2;
267
268    filter->tag = ch2->tag;
269    filter->start_graph = ch2->start_graph;
270    filter->end_graph = ch2->end_graph;
271    filter->field = &thisField;
272
273    return filter;
274  }
275
276
277  CFilterScalarFieldFieldOpExprNode::CFilterScalarFieldFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)
278    : child1(child1)
279    , opId(opId)
280    , child2(child2)
281    , child3(child3)
282  {
283    if (!child1 || !child2 || !child3)
284      ERROR("  CFilterScalarFieldFieldOpExprNode::CFilterScalarFieldFieldOpExprNode(IScalarExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)",
285            "Impossible to create the new expression node, an invalid child node was provided.");
286  }
287
288  std::shared_ptr<COutputPin> CFilterScalarFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
289  {
290    std::shared_ptr<COutputPin> ch2 = child2->reduce(gc, thisField, start_graph, end_graph);
291    std::shared_ptr<COutputPin> ch3 = child3->reduce(gc, thisField, start_graph, end_graph);
292
293    std::shared_ptr<CScalarFieldFieldArithmeticFilter> filter(new CScalarFieldFieldArithmeticFilter(gc, opId, child1->reduce()));
294    ch2->connectOutput(filter, 0);
295    ch3->connectOutput(filter, 1);
296
297    (filter->parent_filters).resize(2);
298    (filter->parent_filters)[0] = ch2;
299    (filter->parent_filters)[1] = ch3;
300
301    filter->tag = (ch3->tag || ch2->tag);
302    filter->start_graph = ch3->tag? ch3->start_graph : (ch2->tag? ch2->start_graph: -1);
303    filter->end_graph = ch3->tag? ch3->end_graph : (ch2->tag? ch2->end_graph: -1);
304    filter->field = &thisField;
305
306    return filter;
307  }
308
309
310
311  CFilterFieldScalarScalarOpExprNode::CFilterFieldScalarScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IScalarExprNode* child3)
312    : child1(child1)
313    , opId(opId)
314    , child2(child2)
315    , child3(child3)
316  {
317    if (!child1 || !child2 || !child3)
318      ERROR("  CFilterFieldScalarScalarOpExprNode::CFilterFieldScalarScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IScalarExprNode* child3)",
319            "Impossible to create the new expression node, an invalid child node was provided.");
320  }
321
322  std::shared_ptr<COutputPin> CFilterFieldScalarScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
323  {
324    std::shared_ptr<COutputPin> ch1 = child1->reduce(gc, thisField, start_graph, end_graph);
325
326    std::shared_ptr<CFieldScalarScalarArithmeticFilter> filter(new CFieldScalarScalarArithmeticFilter(gc, opId, child2->reduce(),child3->reduce()));
327    ch1->connectOutput(filter, 0);
328
329    (filter->parent_filters).resize(1);
330    (filter->parent_filters)[0] = ch1;
331
332    filter->tag = ch1->tag;
333    filter->start_graph = ch1->start_graph;
334    filter->end_graph = ch1->end_graph;
335    filter->field = &thisField;
336
337    return filter;
338  }
339
340
341
342  CFilterFieldScalarFieldOpExprNode::CFilterFieldScalarFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)
343    : child1(child1)
344    , opId(opId)
345    , child2(child2)
346    , child3(child3)
347  {
348    if (!child1 || !child2 || !child3)
349      ERROR("  CFilterFieldScalarFieldOpExprNode::CFilterFieldScalarFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IScalarExprNode* child2, IFilterExprNode* child3)",
350            "Impossible to create the new expression node, an invalid child node was provided.");
351  }
352
353  std::shared_ptr<COutputPin> CFilterFieldScalarFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
354  {
355    std::shared_ptr<COutputPin> ch1 = child1->reduce(gc, thisField, start_graph, end_graph);
356    std::shared_ptr<COutputPin> ch3 = child3->reduce(gc, thisField, start_graph, end_graph);
357
358    std::shared_ptr<CFieldScalarFieldArithmeticFilter> filter(new CFieldScalarFieldArithmeticFilter(gc, opId, child2->reduce()));
359    ch1->connectOutput(filter, 0);
360    ch3->connectOutput(filter, 1);
361
362    (filter->parent_filters).resize(2);
363    (filter->parent_filters)[0] = ch1;
364    (filter->parent_filters)[1] = ch3;
365
366    filter->tag = (ch3->tag || ch1->tag);
367    filter->start_graph = ch3->tag? ch3->start_graph : (ch1->tag? ch1->start_graph: -1);
368    filter->end_graph = ch3->tag? ch3->end_graph : (ch1->tag? ch1->end_graph: -1);
369    filter->field = &thisField;
370
371    return filter;
372  }
373
374
375
376  CFilterFieldFieldScalarOpExprNode::CFilterFieldFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)
377    : child1(child1)
378    , opId(opId)
379    , child2(child2)
380    , child3(child3)
381  {
382    if (!child1 || !child2 || !child3)
383      ERROR("  CFilterFieldFieldScalarOpExprNode::CFilterFieldFieldScalarOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IScalarExprNode* child3)",
384            "Impossible to create the new expression node, an invalid child node was provided.");
385  }
386
387  std::shared_ptr<COutputPin> CFilterFieldFieldScalarOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
388  {
389    std::shared_ptr<COutputPin> ch1 = child1->reduce(gc, thisField, start_graph, end_graph);
390    std::shared_ptr<COutputPin> ch2 = child2->reduce(gc, thisField, start_graph, end_graph);
391
392    std::shared_ptr<CFieldFieldScalarArithmeticFilter> filter(new CFieldFieldScalarArithmeticFilter(gc, opId, child3->reduce()));
393    ch1->connectOutput(filter, 0);
394    ch2->connectOutput(filter, 1);
395
396    (filter->parent_filters).resize(2);
397    (filter->parent_filters)[0] = ch1;
398    (filter->parent_filters)[1] = ch2;
399
400    filter->tag = (ch2->tag || ch1->tag);
401    filter->start_graph = ch2->tag? ch2->start_graph : (ch1->tag? ch1->start_graph: -1);
402    filter->end_graph = ch2->tag? ch2->end_graph : (ch1->tag? ch1->end_graph: -1);
403    filter->field = &thisField;
404    return filter;
405  }
406
407
408  CFilterFieldFieldFieldOpExprNode::CFilterFieldFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)
409    : child1(child1)
410    , opId(opId)
411    , child2(child2)
412    , child3(child3)
413  {
414    if (!child1 || !child2 || !child3)
415      ERROR("  CFilterFieldFieldFieldOpExprNode::CFilterFieldFieldFieldOpExprNode(IFilterExprNode* child1, const std::string& opId, IFilterExprNode* child2, IFilterExprNode* child3)",
416            "Impossible to create the new expression node, an invalid child node was provided.");
417  }
418
419  std::shared_ptr<COutputPin> CFilterFieldFieldFieldOpExprNode::reduce(CGarbageCollector& gc, CField& thisField, Time start_graph, Time end_graph) const
420  {
421    std::shared_ptr<COutputPin> ch1 = child1->reduce(gc, thisField, start_graph, end_graph);
422    std::shared_ptr<COutputPin> ch2 = child2->reduce(gc, thisField, start_graph, end_graph);
423    std::shared_ptr<COutputPin> ch3 = child3->reduce(gc, thisField, start_graph, end_graph);
424
425    std::shared_ptr<CFieldFieldFieldArithmeticFilter> filter(new CFieldFieldFieldArithmeticFilter(gc, opId));
426    std::cout<<"std::shared_ptr<CFieldFieldFieldArithmeticFilter> filter(new CFieldFieldFieldArithmeticFilter(gc, opId))" <<std::endl;
427    ch1->connectOutput(filter, 0);
428    ch2->connectOutput(filter, 1);
429    ch3->connectOutput(filter, 2);
430
431    (filter->parent_filters).resize(3);
432    (filter->parent_filters)[0] = ch1;
433    (filter->parent_filters)[1] = ch2;
434    (filter->parent_filters)[2] = ch3;
435
436
437    filter->tag = (ch1->tag || ch1->tag || ch3->tag);
438    filter->start_graph = ch1->tag? ch1->start_graph : (ch2->tag? ch2->start_graph: (ch3->tag? ch3->start_graph: -1));
439    filter->end_graph = ch1->tag? ch1->end_graph : (ch2->tag? ch2->end_graph: (ch3->tag? ch3->end_graph: -1));
440    filter->field = &thisField;
441
442
443    return filter;
444  }
445 
446}
Note: See TracBrowser for help on using the repository browser.