[638] | 1 | #include "file_writer_filter.hpp" |
---|
| 2 | #include "exception.hpp" |
---|
| 3 | #include "field.hpp" |
---|
[1158] | 4 | #include "utils.hpp" |
---|
[1668] | 5 | #include "workflow_graph.hpp" |
---|
[1677] | 6 | #include "graphviz.hpp" |
---|
[638] | 7 | |
---|
[1677] | 8 | using namespace ep_lib; |
---|
| 9 | |
---|
[638] | 10 | namespace xios |
---|
| 11 | { |
---|
[1679] | 12 | CFileWriterFilter::CFileWriterFilter(CGarbageCollector& gc, CField* field) |
---|
[639] | 13 | : CInputPin(gc, 1) |
---|
[638] | 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 | { |
---|
[1679] | 23 | bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph: false; |
---|
| 24 | if(building_graph) |
---|
[1677] | 25 | { |
---|
| 26 | this->filterID = InvalidableObject::filterIdGenerator++; |
---|
[1679] | 27 | int edgeID = InvalidableObject::edgeIdGenerator++; |
---|
[1677] | 28 | |
---|
[1679] | 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>; |
---|
[1677] | 31 | |
---|
[1679] | 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; |
---|
[1677] | 38 | |
---|
[1679] | 39 | if(CXios::isClient) std::cout<<"CFileWriterFilter::apply filter tag = "<<this->tag<<" start = "<<start_graph<<" end = "<<end_graph<<std::endl; |
---|
[1677] | 40 | |
---|
[1679] | 41 | if(CXios::isClient && CWorkflowGraph::build_begin) |
---|
[1677] | 42 | { |
---|
[1679] | 43 | |
---|
| 44 | CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]); |
---|
| 45 | |
---|
| 46 | (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; |
---|
[1677] | 47 | } |
---|
[1679] | 48 | else CWorkflowGraph::build_begin=true; |
---|
[1677] | 49 | } |
---|
| 50 | |
---|
[1646] | 51 | const bool detectMissingValue = ( !field->default_value.isEmpty() && |
---|
| 52 | ( (!field->detect_missing_value.isEmpty() || field->detect_missing_value == true) |
---|
| 53 | || field->hasGridMask()) ); |
---|
[1251] | 54 | |
---|
| 55 | CArray<double, 1> dataArray = (detectMissingValue) ? data[0]->data.copy() : data[0]->data; |
---|
| 56 | |
---|
[1201] | 57 | if (detectMissingValue) |
---|
[1158] | 58 | { |
---|
[1201] | 59 | const double missingValue = field->default_value; |
---|
[1251] | 60 | const size_t nbData = dataArray.numElements(); |
---|
[1158] | 61 | for (size_t idx = 0; idx < nbData; ++idx) |
---|
| 62 | { |
---|
[1474] | 63 | if (NumTraits<double>::isNan(dataArray(idx))) |
---|
[1251] | 64 | dataArray(idx) = missingValue; |
---|
[1158] | 65 | } |
---|
[1201] | 66 | } |
---|
[1158] | 67 | |
---|
[1251] | 68 | field->sendUpdateData(dataArray); |
---|
[1677] | 69 | |
---|
| 70 | |
---|
| 71 | |
---|
[638] | 72 | } |
---|
[1158] | 73 | |
---|
[1358] | 74 | bool CFileWriterFilter::mustAutoTrigger() const |
---|
| 75 | { |
---|
| 76 | return true; |
---|
| 77 | } |
---|
| 78 | |
---|
[1158] | 79 | bool CFileWriterFilter::isDataExpected(const CDate& date) const |
---|
| 80 | { |
---|
| 81 | return true; |
---|
| 82 | } |
---|
[1668] | 83 | |
---|
| 84 | |
---|
[1677] | 85 | |
---|
[638] | 86 | } // namespace xios |
---|