[638] | 1 | #include "file_writer_filter.hpp" |
---|
| 2 | #include "exception.hpp" |
---|
| 3 | #include "field.hpp" |
---|
[1158] | 4 | #include "utils.hpp" |
---|
[1704] | 5 | #include "workflow_graph.hpp" |
---|
| 6 | #include "graphviz.hpp" |
---|
[638] | 7 | |
---|
| 8 | namespace xios |
---|
| 9 | { |
---|
[639] | 10 | CFileWriterFilter::CFileWriterFilter(CGarbageCollector& gc, CField* field) |
---|
| 11 | : CInputPin(gc, 1) |
---|
[638] | 12 | , field(field) |
---|
| 13 | { |
---|
| 14 | if (!field) |
---|
| 15 | ERROR("CFileWriterFilter::CFileWriterFilter(CField* field)", |
---|
| 16 | "The field cannot be null."); |
---|
| 17 | } |
---|
| 18 | |
---|
[1704] | 19 | void CFileWriterFilter::buildGraph(std::vector<CDataPacketPtr> data) |
---|
| 20 | { |
---|
| 21 | bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph: false; |
---|
| 22 | |
---|
| 23 | if(building_graph) |
---|
| 24 | { |
---|
| 25 | this->filterID = InvalidableObject::filterIdGenerator++; |
---|
| 26 | int edgeID = InvalidableObject::edgeIdGenerator++; |
---|
| 27 | |
---|
| 28 | CWorkflowGraph::allocNodeEdge(); |
---|
| 29 | StdString namestring = to_string(this->field->name); |
---|
| 30 | namestring.erase(0, 6); |
---|
| 31 | namestring.erase(namestring.length()-1, 1); |
---|
[1877] | 32 | |
---|
| 33 | CWorkflowGraph::addNode(this->filterID, namestring + "\\n(file ID : "+this->field->file->getId()+")", 6, 0, 1, data[0]); |
---|
[1704] | 34 | |
---|
| 35 | (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes = this->field->record4graphXiosAttributes(); |
---|
| 36 | (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].attributes += "</br>file attributes : </br>" +this->field->file->record4graphXiosAttributes(); |
---|
| 37 | (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].clusterID =1; |
---|
| 38 | (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1; |
---|
| 39 | |
---|
| 40 | if(CXios::isClient && CWorkflowGraph::build_begin) |
---|
| 41 | { |
---|
| 42 | |
---|
| 43 | CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]); |
---|
| 44 | |
---|
| 45 | (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; |
---|
| 46 | } |
---|
| 47 | else CWorkflowGraph::build_begin=true; |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
[638] | 51 | void CFileWriterFilter::onInputReady(std::vector<CDataPacketPtr> data) |
---|
| 52 | { |
---|
[1704] | 53 | buildGraph(data); |
---|
| 54 | |
---|
[1637] | 55 | const bool detectMissingValue = ( !field->default_value.isEmpty() && |
---|
| 56 | ( (!field->detect_missing_value.isEmpty() || field->detect_missing_value == true) |
---|
| 57 | || field->hasGridMask()) ); |
---|
[1251] | 58 | |
---|
| 59 | CArray<double, 1> dataArray = (detectMissingValue) ? data[0]->data.copy() : data[0]->data; |
---|
| 60 | |
---|
[1201] | 61 | if (detectMissingValue) |
---|
[1158] | 62 | { |
---|
[1201] | 63 | const double missingValue = field->default_value; |
---|
[1251] | 64 | const size_t nbData = dataArray.numElements(); |
---|
[1158] | 65 | for (size_t idx = 0; idx < nbData; ++idx) |
---|
| 66 | { |
---|
[1474] | 67 | if (NumTraits<double>::isNan(dataArray(idx))) |
---|
[1251] | 68 | dataArray(idx) = missingValue; |
---|
[1158] | 69 | } |
---|
[1201] | 70 | } |
---|
[1158] | 71 | |
---|
[1251] | 72 | field->sendUpdateData(dataArray); |
---|
[638] | 73 | } |
---|
[1158] | 74 | |
---|
[1358] | 75 | bool CFileWriterFilter::mustAutoTrigger() const |
---|
| 76 | { |
---|
| 77 | return true; |
---|
| 78 | } |
---|
| 79 | |
---|
[1158] | 80 | bool CFileWriterFilter::isDataExpected(const CDate& date) const |
---|
| 81 | { |
---|
| 82 | return true; |
---|
| 83 | } |
---|
[638] | 84 | } // namespace xios |
---|