source: XIOS3/branches/xios-3.0-beta/src/filter/model_to_client_source_filter.cpp @ 2427

Last change on this file since 2427 was 2427, checked in by jderouillat, 17 months ago

Backport the system to log the memory consumption (commit ID [2418-2420,2425-2426])

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#include "model_to_client_source_filter.hpp"
2#include "grid.hpp"
3#include "exception.hpp"
4#include "calendar_util.hpp"
5#include <limits>
6#include "workflow_graph.hpp"
7#include "mem_checker.hpp"
8
9namespace xios
10{
11  CModelToClientSourceFilter::CModelToClientSourceFilter(CGarbageCollector& gc, CGrid* grid, bool hasMissingValue, double defaultValue)
12    : COutputPin(gc)
13    , grid_(grid)
14    , hasMissingValue_(hasMissingValue), defaultValue_(defaultValue)
15  {
16    if (!grid)
17      ERROR("CSourceFilter::CSourceFilter(CGrid* grid)",
18            "Impossible to construct a source filter without providing a grid.");
19  }
20
21  template <int N>
22  void CModelToClientSourceFilter::streamData(CDate date, const CArray<double, N>& data)
23  {
24    CDataPacketPtr packet(new CDataPacket);
25    packet->date = date;
26    packet->timestamp = date;
27    packet->status = CDataPacket::NO_ERROR;
28   
29    auto connector = grid_->getModelToWorkflowConnector() ;
30
31    if (connector->getSrcSize() != data.numElements())
32      ERROR("void CModelToClientSourceFilter::streamData(CDate date, const CArray<double, N>& data)",
33            << "[ Awaiting data of size = " <<connector->getSrcSize() << ", "
34            << "Received data size = "      << data.numElements() << " ] "
35            << "The data array does not have the right size! "
36            << "grid = " << grid_->getId())
37    const double nanValue = std::numeric_limits<double>::quiet_NaN();
38    packet->data.resize(connector->getDstSize()) ;
39    connector->transfer(data, packet->data, nanValue) ;
40
41    CMemChecker::logMem( "CModelToClientSourceFilter::streamData" );
42
43    if (hasMissingValue_)
44    {
45        const double nanValue = std::numeric_limits<double>::quiet_NaN();
46        const size_t nbData = packet->data.numElements();
47        for (size_t idx = 0; idx < nbData; ++idx)
48          if (defaultValue_ == packet->data(idx))   packet->data(idx) = nanValue;
49    }
50   
51    buildWorkflowGraph(packet);
52    onOutputReady(packet);
53  }
54 
55  void CModelToClientSourceFilter::buildWorkflowGraph(CDataPacketPtr packet)
56  {
57    if(this->graphEnabled)
58    {
59      this->graphPackage->filterId = CWorkflowGraph::getNodeSize();
60      if(!packet->graphPackage)
61      {
62        packet->graphPackage = new CGraphDataPackage;
63      }
64      packet->graphPackage->fromFilter = this->graphPackage->filterId;
65      packet->graphPackage->currentField = this->graphPackage->inFields[0];
66      CWorkflowGraph::addNode("Model to Client Source filter", 1, false, 0, packet);
67    }
68  }
69
70
71
72
73  template void CModelToClientSourceFilter::streamData<1>(CDate date, const CArray<double, 1>& data);
74  template void CModelToClientSourceFilter::streamData<2>(CDate date, const CArray<double, 2>& data);
75  template void CModelToClientSourceFilter::streamData<3>(CDate date, const CArray<double, 3>& data);
76  template void CModelToClientSourceFilter::streamData<4>(CDate date, const CArray<double, 4>& data);
77  template void CModelToClientSourceFilter::streamData<5>(CDate date, const CArray<double, 5>& data);
78  template void CModelToClientSourceFilter::streamData<6>(CDate date, const CArray<double, 6>& data);
79  template void CModelToClientSourceFilter::streamData<7>(CDate date, const CArray<double, 7>& data);
80
81} // namespace xios
Note: See TracBrowser for help on using the repository browser.