[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" |
---|
[1730] | 7 | #ifdef _usingEP |
---|
[1677] | 8 | using namespace ep_lib; |
---|
[1730] | 9 | #endif |
---|
[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 | |
---|
[1681] | 21 | void CFileWriterFilter::buildGraph(std::vector<CDataPacketPtr> data) |
---|
[638] | 22 | { |
---|
[1679] | 23 | bool building_graph = this->tag ? data[0]->timestamp >= this->start_graph && data[0]->timestamp <= this->end_graph: false; |
---|
[1680] | 24 | |
---|
[1679] | 25 | if(building_graph) |
---|
[1677] | 26 | { |
---|
| 27 | this->filterID = InvalidableObject::filterIdGenerator++; |
---|
[1679] | 28 | int edgeID = InvalidableObject::edgeIdGenerator++; |
---|
[1677] | 29 | |
---|
[1680] | 30 | CWorkflowGraph::allocNodeEdge(); |
---|
[1681] | 31 | StdString namestring = to_string(this->field->name); |
---|
| 32 | namestring.erase(0, 6); |
---|
| 33 | namestring.erase(namestring.length()-1, 1); |
---|
[1677] | 34 | |
---|
[1681] | 35 | CWorkflowGraph::addNode(this->filterID, namestring + "\\n("+this->field->file->getId()+".nc)", 6, 0, 1, data[0]); |
---|
[1677] | 36 | |
---|
[1681] | 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; |
---|
[1685] | 40 | (*CWorkflowGraph::mapFilters_ptr_with_info)[this->filterID].distance = data[0]->distance+1; |
---|
[1677] | 41 | |
---|
[1679] | 42 | if(CXios::isClient && CWorkflowGraph::build_begin) |
---|
[1677] | 43 | { |
---|
[1679] | 44 | |
---|
| 45 | CWorkflowGraph::addEdge(edgeID, this->filterID, data[0]); |
---|
| 46 | |
---|
| 47 | (*CWorkflowGraph::mapFilters_ptr_with_info)[data[0]->src_filterID].filter_filled = 0 ; |
---|
[1677] | 48 | } |
---|
[1679] | 49 | else CWorkflowGraph::build_begin=true; |
---|
[1677] | 50 | } |
---|
[1681] | 51 | } |
---|
| 52 | |
---|
| 53 | void CFileWriterFilter::onInputReady(std::vector<CDataPacketPtr> data) |
---|
| 54 | { |
---|
| 55 | buildGraph(data); |
---|
[1677] | 56 | |
---|
[1646] | 57 | const bool detectMissingValue = ( !field->default_value.isEmpty() && |
---|
| 58 | ( (!field->detect_missing_value.isEmpty() || field->detect_missing_value == true) |
---|
| 59 | || field->hasGridMask()) ); |
---|
[1251] | 60 | |
---|
| 61 | CArray<double, 1> dataArray = (detectMissingValue) ? data[0]->data.copy() : data[0]->data; |
---|
| 62 | |
---|
[1201] | 63 | if (detectMissingValue) |
---|
[1158] | 64 | { |
---|
[1201] | 65 | const double missingValue = field->default_value; |
---|
[1251] | 66 | const size_t nbData = dataArray.numElements(); |
---|
[1158] | 67 | for (size_t idx = 0; idx < nbData; ++idx) |
---|
| 68 | { |
---|
[1474] | 69 | if (NumTraits<double>::isNan(dataArray(idx))) |
---|
[1251] | 70 | dataArray(idx) = missingValue; |
---|
[1158] | 71 | } |
---|
[1201] | 72 | } |
---|
[1158] | 73 | |
---|
[1251] | 74 | field->sendUpdateData(dataArray); |
---|
[638] | 75 | } |
---|
[1158] | 76 | |
---|
[1358] | 77 | bool CFileWriterFilter::mustAutoTrigger() const |
---|
| 78 | { |
---|
| 79 | return true; |
---|
| 80 | } |
---|
| 81 | |
---|
[1158] | 82 | bool CFileWriterFilter::isDataExpected(const CDate& date) const |
---|
| 83 | { |
---|
| 84 | return true; |
---|
| 85 | } |
---|
[638] | 86 | } // namespace xios |
---|