source: XIOS/trunk/src/filter/source_filter.cpp @ 988

Last change on this file since 988 was 988, checked in by mhnguyen, 6 years ago

Correcting a bug on reading non-distributed data in server mode.

+) Non distributed data read by all servers then transfered back to ALL clients

Test
+) On Curie
+) Work

File size: 2.9 KB
Line 
1#include "source_filter.hpp"
2#include "grid.hpp"
3#include "exception.hpp"
4#include "calendar_util.hpp"
5
6namespace xios
7{
8  CSourceFilter::CSourceFilter(CGrid* grid, const CDuration offset /*= NoneDu*/)
9    : grid(grid)
10    , offset(offset)
11  {
12    if (!grid)
13      ERROR("CSourceFilter::CSourceFilter(CGrid* grid)",
14            "Impossible to construct a source filter without providing a grid.");
15  }
16
17  template <int N>
18  void CSourceFilter::streamData(CDate date, const CArray<double, N>& data)
19  {
20    date = date + offset; // this is a temporary solution, it should be part of a proper temporal filter
21
22    CDataPacketPtr packet(new CDataPacket);
23    packet->date = date;
24    packet->timestamp = date;
25    packet->status = CDataPacket::NO_ERROR;
26
27    packet->data.resize(grid->storeIndex_client.numElements());
28    grid->inputField(data, packet->data);
29
30    deliverOuput(packet);
31  }
32
33  template void CSourceFilter::streamData<1>(CDate date, const CArray<double, 1>& data);
34  template void CSourceFilter::streamData<2>(CDate date, const CArray<double, 2>& data);
35  template void CSourceFilter::streamData<3>(CDate date, const CArray<double, 3>& data);
36  template void CSourceFilter::streamData<4>(CDate date, const CArray<double, 4>& data);
37  template void CSourceFilter::streamData<5>(CDate date, const CArray<double, 5>& data);
38  template void CSourceFilter::streamData<6>(CDate date, const CArray<double, 6>& data);
39  template void CSourceFilter::streamData<7>(CDate date, const CArray<double, 7>& data);
40
41  void CSourceFilter::streamDataFromServer(CDate date, const std::map<int, CArray<double, 1> >& data)
42  {
43    date = date + offset; // this is a temporary solution, it should be part of a proper temporal filter
44
45    CDataPacketPtr packet(new CDataPacket);
46    packet->date = date;
47    packet->timestamp = date;
48    packet->status = CDataPacket::NO_ERROR;
49
50    // if (data.size() != grid->storeIndex_toSrv.size())
51    if (data.size() != grid->storeIndex_fromSrv.size())
52      ERROR("CSourceFilter::streamDataFromServer(CDate date, const std::map<int, CArray<double, 1> >& data)",
53            << "Incoherent data received from servers,"
54            << " expected " << grid->storeIndex_fromSrv.size() << " chunks but " << data.size() << " were given.");
55
56    packet->data.resize(grid->storeIndex_client.numElements());
57    std::map<int, CArray<double, 1> >::const_iterator it, itEnd = data.end();
58    for (it = data.begin(); it != itEnd; it++)
59    {
60      // CArray<int,1>& index = grid->storeIndex_toSrv[it->first];
61      CArray<int,1>& index = grid->storeIndex_fromSrv[it->first];
62      for (int n = 0; n < index.numElements(); n++)
63        packet->data(index(n)) = it->second(n);
64    }
65
66    deliverOuput(packet);
67  }
68
69  void CSourceFilter::signalEndOfStream(CDate date)
70  {
71    CDataPacketPtr packet(new CDataPacket);
72    packet->date = date;
73    packet->timestamp = date;
74    packet->status = CDataPacket::END_OF_STREAM;
75    deliverOuput(packet);
76  }
77} // namespace xios
Note: See TracBrowser for help on using the repository browser.