source: XIOS3/trunk/src/filter/model_to_client_source_filter.cpp @ 2628

Last change on this file since 2628 was 2628, checked in by jderouillat, 7 weeks ago

New timers integration/reporting

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