source: XIOS2/dev/dev_ym/XIOS_ONE_SIDED/src/filter/store_filter.cpp @ 2380

Last change on this file since 2380 was 1752, checked in by ymipsl, 5 years ago

suspend tracing when probing to avoid too big trace

YM

File size: 4.3 KB
Line 
1#include "store_filter.hpp"
2#include "context.hpp"
3#include "grid.hpp"
4#include "timer.hpp"
5#include "tracer.hpp"
6
7namespace xios
8{
9  CStoreFilter::CStoreFilter(CGarbageCollector& gc, CContext* context, CGrid* grid,
10                             bool detectMissingValues /*= false*/, double missingValue /*= 0.0*/)
11    : CInputPin(gc, 1)
12    , gc(gc)
13    , context(context)
14    , grid(grid)
15    , detectMissingValues(detectMissingValues)
16    , missingValue(missingValue)
17  {
18    if (!context)
19      ERROR("CStoreFilter::CStoreFilter(CContext* context, CGrid* grid)",
20            "Impossible to construct a store filter without providing a context.");
21    if (!grid)
22      ERROR("CStoreFilter::CStoreFilter(CContext* context, CGrid* grid)",
23            "Impossible to construct a store filter without providing a grid.");
24  }
25
26  CConstDataPacketPtr CStoreFilter::getPacket(Time timestamp)
27  {
28    CTimer timer("CStoreFilter::getPacket");
29//    timer.resume();
30    info(0)<<"ENTERING CStoreFilter::getPacket"<<std::endl ;
31    traceOff() ;
32//    timer.suspend();
33    CConstDataPacketPtr packet;
34    const double timeout = CXios::recvFieldTimeout;
35
36    do
37    {
38      if (canBeTriggered())
39        trigger(timestamp);
40
41      timer.resume();
42
43      std::map<Time, CDataPacketPtr>::const_iterator it = packets.find(timestamp);
44      if (it != packets.end())
45        packet = it->second;
46      else // if the packet is not available yet, check if it can be received
47        context->checkBuffersAndListen();
48
49      timer.suspend();
50    } while (!packet && timer.getCumulatedTime() < timeout);
51//    timer.resume();
52    traceOn() ;
53//    timer.suspend();
54
55    if (!packet)
56    {
57      std::map<Time, CDataPacketPtr>::const_iterator it ;
58      info(0)<<"Impossible to get the packet with timestamp = " << timestamp<<std::endl<<"Available timestamp are : "<<std::endl ;
59      for(it=packets.begin();it!=packets.end();++it) info(0)<<it->first<<"  ";
60      info(0)<<std::endl ;
61      ERROR("CConstDataPacketPtr CStoreFilter::getPacket(Time timestamp) const",
62            << "Impossible to get the packet with timestamp = " << timestamp);
63    }
64    return packet;
65  }
66
67  template <int N>
68  CDataPacket::StatusCode CStoreFilter::getData(Time timestamp, CArray<double, N>& data)
69  {
70    CConstDataPacketPtr packet = getPacket(timestamp);
71
72    if (packet->status == CDataPacket::NO_ERROR)
73      grid->outputField(packet->data, data);
74
75    return packet->status;
76  }
77
78  template CDataPacket::StatusCode CStoreFilter::getData<1>(Time timestamp, CArray<double, 1>& data);
79  template CDataPacket::StatusCode CStoreFilter::getData<2>(Time timestamp, CArray<double, 2>& data);
80  template CDataPacket::StatusCode CStoreFilter::getData<3>(Time timestamp, CArray<double, 3>& data);
81  template CDataPacket::StatusCode CStoreFilter::getData<4>(Time timestamp, CArray<double, 4>& data);
82  template CDataPacket::StatusCode CStoreFilter::getData<5>(Time timestamp, CArray<double, 5>& data);
83  template CDataPacket::StatusCode CStoreFilter::getData<6>(Time timestamp, CArray<double, 6>& data);
84  template CDataPacket::StatusCode CStoreFilter::getData<7>(Time timestamp, CArray<double, 7>& data);
85
86  void CStoreFilter::onInputReady(std::vector<CDataPacketPtr> data)
87  {
88
89    CDataPacketPtr packet;
90    if (detectMissingValues)
91    {
92      const size_t nbData = data[0]->data.numElements();
93
94      packet = CDataPacketPtr(new CDataPacket);
95      packet->date = data[0]->date;
96      packet->timestamp = data[0]->timestamp;
97      packet->status = data[0]->status;
98      packet->data.resize(nbData);
99      packet->data = data[0]->data;
100
101      for (size_t idx = 0; idx < nbData; ++idx)
102      {
103        if (NumTraits<double>::isNan(packet->data(idx)))
104          packet->data(idx) = missingValue;
105      }
106
107    }
108
109    else
110    {
111      packet = data[0];
112    }
113
114    packets.insert(std::make_pair(packet->timestamp, packet));
115    // The packet is always destroyed by the garbage collector
116    // so we register but never unregister
117    gc.registerObject(this, packet->timestamp);
118
119  }
120
121  bool CStoreFilter::mustAutoTrigger() const
122  {
123    return false;
124  }
125
126  bool CStoreFilter::isDataExpected(const CDate& date) const
127  {
128    return true;
129  }
130
131  void CStoreFilter::invalidate(Time timestamp)
132  {
133    CInputPin::invalidate(timestamp);
134    packets.erase(packets.begin(), packets.lower_bound(timestamp));
135  }
136} // namespace xios
Note: See TracBrowser for help on using the repository browser.