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

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

dev for graph. up to date with trunk at r1684

File size: 2.8 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::buildGraph(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   
25    if(building_graph)
26    {
27      this->filterID = InvalidableObject::filterIdGenerator++;
28      int edgeID = InvalidableObject::edgeIdGenerator++;
29
30      CWorkflowGraph::allocNodeEdge();
31      StdString namestring = to_string(this->field->name);
32      namestring.erase(0, 6);
33      namestring.erase(namestring.length()-1, 1);
34
35      CWorkflowGraph::addNode(this->filterID, namestring + "\\n("+this->field->file->getId()+".nc)", 6, 0, 1, data[0]);
36
37      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes();
38      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes();
39      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].clusterID =1;
40      (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1;
41
42      if(CXios::isClient && CWorkflowGraph::build_begin) 
43      {
44
45        CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]);
46
47        (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ;
48      }
49      else CWorkflowGraph::build_begin=true;
50    }
51  }
52
53  void CFileWriterFilter::onInputReady(std::vector<CDataPacketPtr> data)
54  {
55    buildGraph(data);
56   
57    const bool detectMissingValue = ( !field->default_value.isEmpty() &&
58                               ( (!field->detect_missing_value.isEmpty() || field->detect_missing_value == true)
59                                 || field->hasGridMask()) );
60
61    CArray<double, 1> dataArray = (detectMissingValue) ? data[0]->data.copy() : data[0]->data;
62
63    if (detectMissingValue)
64    {
65      const double missingValue = field->default_value;
66      const size_t nbData = dataArray.numElements();
67      for (size_t idx = 0; idx < nbData; ++idx)
68      {
69        if (NumTraits<double>::isNan(dataArray(idx)))
70          dataArray(idx) = missingValue;
71      }
72    }
73
74    field->sendUpdateData(dataArray);
75  }
76
77  bool CFileWriterFilter::mustAutoTrigger() const
78  {
79    return true;
80  }
81
82  bool CFileWriterFilter::isDataExpected(const CDate& date) const
83  {
84    return true;
85  }
86} // namespace xios
Note: See TracBrowser for help on using the repository browser.