source: XIOS/dev/dev_trunk_omp/src/filter/file_writer_filter.cpp @ 1679

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

MARK: Dynamic workflow graph developement. Branch up to date with trunk @1676. Using vis.js

File size: 2.9 KB
Line 
1#include "file_writer_filter.hpp"
2#include "exception.hpp"
3#include "field.hpp"
4#include "utils.hpp"
5#include "workflow_graph.hpp"
6#include "graphviz.hpp"
7
8using namespace ep_lib;
9
10namespace xios
11{
12  CFileWriterFilter::CFileWriterFilter(CGarbageCollector& gc, CField* field)
13    : CInputPin(gc, 1)
14    , field(field)
15  {
16    if (!field)
17      ERROR("CFileWriterFilter::CFileWriterFilter(CField* field)",
18            "The field cannot be null.");
19  }
20
21  void CFileWriterFilter::onInputReady(std::vector<CDataPacketPtr> data)
22  {
23    bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph: false;
24    if(building_graph)
25    {
26      this->filterID = InvalidableObject::filterIdGenerator++;
27      int edgeID = InvalidableObject::edgeIdGenerator++;
28
29      if(CWorkflowGraph::mapFieldToFilters_ptr_with_info==0) CWorkflowGraph::mapFieldToFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_edge >;
30      if(CWorkflowGraph::mapFilters_ptr_with_info==0) CWorkflowGraph::mapFilters_ptr_with_info = new std::unordered_map <int, graph_info_box_node>;
31
32      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_name = "File Writer Filter";
33      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_class = 4;
34      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].filter_filled = 0;
35      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].expected_entry_nb = 1;
36      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].date = data[0]->date;
37      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].timestamp = data[0]->timestamp;
38
39      if(CXios::isClient) std::cout<<"CFileWriterFilter::apply filter tag = "<<this->tag<<" start = "<<start_graph<<" end = "<<end_graph<<std::endl;
40
41      if(CXios::isClient && CWorkflowGraph::build_begin) 
42      {
43
44        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
45
46        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
47      }
48      else CWorkflowGraph::build_begin=true;
49    }
50   
51    const bool detectMissingValue = ( !field->default_value.isEmpty() &&
52                               ( (!field->detect_missing_value.isEmpty() || field->detect_missing_value == true)
53                                 || field->hasGridMask()) );
54
55    CArray<double, 1> dataArray = (detectMissingValue) ? data[0]->data.copy() : data[0]->data;
56
57    if (detectMissingValue)
58    {
59      const double missingValue = field->default_value;
60      const size_t nbData = dataArray.numElements();
61      for (size_t idx = 0; idx < nbData; ++idx)
62      {
63        if (NumTraits<double>::isNan(dataArray(idx)))
64          dataArray(idx) = missingValue;
65      }
66    }
67
68    field->sendUpdateData(dataArray);
69   
70   
71   
72  }
73
74  bool CFileWriterFilter::mustAutoTrigger() const
75  {
76    return true;
77  }
78
79  bool CFileWriterFilter::isDataExpected(const CDate& date) const
80  {
81    return true;
82  }
83
84
85
86} // namespace xios
Note: See TracBrowser for help on using the repository browser.