Ignore:
Timestamp:
06/06/17 17:58:16 (7 years ago)
Author:
oabramkina
Message:

Two server levels: merging with trunk r1137.
There are bugs.

Location:
XIOS/dev/dev_olga/src/filter
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_olga/src/filter/file_server_writer_filter.cpp

    r1026 r1158  
    1818    field->writeUpdateData(data[0]->data); 
    1919  } 
     20 
     21  bool CFileServerWriterFilter::isDataExpected(const CDate& date) const 
     22  { 
     23    return true; 
     24  } 
    2025} // namespace xios 
  • XIOS/dev/dev_olga/src/filter/file_server_writer_filter.hpp

    r1026 r1158  
    2323      CFileServerWriterFilter(CGarbageCollector& gc, CField* field); 
    2424 
     25      bool virtual isDataExpected(const CDate& date) const; 
    2526    protected: 
    2627      /*! 
  • XIOS/dev/dev_olga/src/filter/file_writer_filter.cpp

    r639 r1158  
    22#include "exception.hpp" 
    33#include "field.hpp" 
     4#include "utils.hpp" 
    45 
    56namespace xios 
     
    1617  void CFileWriterFilter::onInputReady(std::vector<CDataPacketPtr> data) 
    1718  { 
     19    bool ignoreMissingValue = (!field->detect_missing_value.isEmpty() &&  
     20                               !field->default_value.isEmpty() &&  
     21                               field->detect_missing_value == true); 
     22    if (ignoreMissingValue) 
     23    { 
     24      double missingValue = field->default_value; 
     25      size_t nbData = data[0]->data.numElements(); 
     26      for (size_t idx = 0; idx < nbData; ++idx) 
     27      { 
     28        if (NumTraits<double>::isnan(data[0]->data(idx))) 
     29          data[0]->data(idx) = missingValue; 
     30      } 
     31    }     
     32 
    1833    field->sendUpdateData(data[0]->data); 
    1934  } 
     35 
     36  bool CFileWriterFilter::isDataExpected(const CDate& date) const 
     37  { 
     38    return true; 
     39  } 
    2040} // namespace xios 
  • XIOS/dev/dev_olga/src/filter/file_writer_filter.hpp

    r639 r1158  
    2323      CFileWriterFilter(CGarbageCollector& gc, CField* field); 
    2424 
     25      /*! 
     26       * Tests whether data is expected for the specified date. 
     27       * 
     28       * \param date the date associated to the data 
     29       */ 
     30      bool virtual isDataExpected(const CDate& date) const; 
     31 
    2532    protected: 
    2633      /*! 
  • XIOS/dev/dev_olga/src/filter/filter.cpp

    r1021 r1158  
    4040    return (CInputPin::canBeTriggered() || COutputPin::canBeTriggered()); 
    4141  } 
     42 
     43  bool CFilter::isDataExpected(const CDate& date) const 
     44  { 
     45    return COutputPin::isDataExpected(date); 
     46  } 
    4247} // namespace xios 
  • XIOS/dev/dev_olga/src/filter/filter.hpp

    r1021 r1158  
    4848      bool virtual canBeTriggered() const; 
    4949 
     50      /*! 
     51       * Tests whether data is expected for the specified date. 
     52       * 
     53       * \param date the date associated to the data 
     54       */ 
     55      bool virtual isDataExpected(const CDate& date) const; 
     56 
    5057    protected: 
    5158      IFilterEngine* engine; //!< The filter engine, might be the filter itself 
  • XIOS/dev/dev_olga/src/filter/input_pin.hpp

    r1021 r1158  
    6060 
    6161      /*! 
     62       * Tests whether data is expected for the specified date. 
     63       * 
     64       * \param date the date associated to the data 
     65       */ 
     66      bool virtual isDataExpected(const CDate& date) const = 0; 
     67 
     68      /*! 
    6269       * Removes all pending packets which are older than the specified timestamp. 
    6370       * 
  • XIOS/dev/dev_olga/src/filter/output_pin.cpp

    r1021 r1158  
    7373  } 
    7474 
     75  bool COutputPin::isDataExpected(const CDate& date) const 
     76  { 
     77    std::vector<std::pair<boost::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd; 
     78    for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) 
     79    { 
     80      if (it->first->isDataExpected(date)) 
     81        return true; 
     82    } 
     83 
     84    return false; 
     85  } 
     86 
    7587  void COutputPin::invalidate(Time timestamp) 
    7688  { 
  • XIOS/dev/dev_olga/src/filter/output_pin.hpp

    r1021 r1158  
    4646 
    4747      /*! 
     48       * Tests whether data is expected for the specified date. 
     49       * 
     50       * \param date the date associated to the data 
     51       */ 
     52      bool virtual isDataExpected(const CDate& date) const; 
     53 
     54      /*! 
    4855       * Removes all pending packets which are older than the specified timestamp. 
    4956       * 
  • XIOS/dev/dev_olga/src/filter/source_filter.cpp

    r1021 r1158  
    33#include "exception.hpp" 
    44#include "calendar_util.hpp" 
     5#include <limits>  
    56 
    67namespace xios 
    78{ 
    89  CSourceFilter::CSourceFilter(CGarbageCollector& gc, CGrid* grid, 
    9                                const CDuration offset /*= NoneDu*/, bool manualTrigger /*= false*/) 
     10                               const CDuration offset /*= NoneDu*/, bool manualTrigger /*= false*/, 
     11                               bool hasMissingValue /*= false*/, 
     12                               double defaultValue /*= 0.0*/) 
    1013    : COutputPin(gc, manualTrigger) 
    1114    , grid(grid) 
    1215    , offset(offset) 
     16    , hasMissingValue(hasMissingValue), defaultValue(defaultValue) 
    1317  { 
    1418    if (!grid) 
     
    2933    packet->data.resize(grid->storeIndex_client.numElements()); 
    3034    grid->inputField(data, packet->data); 
     35 
     36    // Convert missing values to NaN 
     37    if (hasMissingValue) 
     38    { 
     39      double nanValue = std::numeric_limits<double>::quiet_NaN(); 
     40      size_t nbData = packet->data.numElements(); 
     41      for (size_t idx = 0; idx < nbData; ++idx) 
     42      { 
     43        if (defaultValue == packet->data(idx)) 
     44          packet->data(idx) = nanValue; 
     45      } 
     46    } 
    3147 
    3248    onOutputReady(packet); 
  • XIOS/dev/dev_olga/src/filter/source_filter.hpp

    r1021 r1158  
    2323       * \param offset the offset applied to the timestamp of all packets 
    2424       * \param manualTrigger whether the output should be triggered manually 
     25       * \param hasMissingValue whether data has missing value 
     26       * \param defaultValue missing value to detect 
    2527       */ 
    2628      CSourceFilter(CGarbageCollector& gc, CGrid* grid, 
    27                     const CDuration offset = NoneDu, bool manualTrigger = false); 
     29                    const CDuration offset = NoneDu, bool manualTrigger = false, 
     30                    bool hasMissingValue = false, 
     31                    double defaultValue = 0.0); 
    2832 
    2933      /*! 
     
    5862      CGrid* grid; //!< The grid attached to the data the filter can accept 
    5963      const CDuration offset; //!< The offset applied to the timestamp of all packets 
     64      bool hasMissingValue; 
     65      double defaultValue; 
    6066  }; // class CSourceFilter 
    6167} // namespace xios 
  • XIOS/dev/dev_olga/src/filter/spatial_transform_filter.cpp

    r1021 r1158  
    1111 
    1212  std::pair<boost::shared_ptr<CSpatialTransformFilter>, boost::shared_ptr<CSpatialTransformFilter> > 
    13   CSpatialTransformFilter::buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, double defaultValue) 
     13  CSpatialTransformFilter::buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, bool hasMissingValue, double missingValue) 
    1414  { 
    1515    if (!srcGrid || !destGrid) 
     
    2626      const std::vector<StdString>& auxInputs = gridTransformation->getAuxInputs(); 
    2727      size_t inputCount = 1 + (auxInputs.empty() ? 0 : auxInputs.size()); 
     28      double defaultValue  = (hasMissingValue) ? std::numeric_limits<double>::quiet_NaN() : 0.0; 
    2829      boost::shared_ptr<CSpatialTransformFilter> filter(new CSpatialTransformFilter(gc, engine, defaultValue, inputCount)); 
    2930 
     
    103104      } 
    104105      packet->data.resize(gridTransformation->getGridDestination()->storeIndex_client.numElements()); 
    105       packet->data = defaultValue; 
     106      if (0 != packet->data.numElements()) 
     107        (packet->data)(0) = defaultValue; 
    106108      apply(data[0]->data, packet->data); 
    107109    } 
     
    115117 
    116118    // Get default value for output data 
    117     double defaultValue = 0.0; 
    118     if (0 != dataDest.numElements()) defaultValue = dataDest(0); 
     119    bool ignoreMissingValue = false;  
     120    double defaultValue = std::numeric_limits<double>::quiet_NaN(); 
     121    if (0 != dataDest.numElements()) ignoreMissingValue = NumTraits<double>::isnan(dataDest(0)); 
    119122 
    120123    const std::list<CGridTransformation::SendingIndexGridSourceMap>& listLocalIndexSend = gridTransformation->getLocalIndexToSendFromGridSource(); 
     
    191194        else dataCurrentDest(i) = defaultValue; 
    192195 
    193       std::vector<bool> localInitFlag(dataCurrentDest.size(), true); 
     196      std::vector<bool> localInitFlag(dataCurrentDest.numElements(), true); 
    194197      currentBuff = 0; 
    195198      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
     
    201204                         dataCurrentDest, 
    202205                         localInitFlag, 
    203                          defaultValue); 
     206                         ignoreMissingValue); 
    204207 
    205208        currentBuff += countSize; 
  • XIOS/dev/dev_olga/src/filter/spatial_transform_filter.hpp

    r873 r1158  
    3232       * \param srcGrid the source grid 
    3333       * \param destGrid the destination grid 
     34       * \param hasMissingValue whether field source has missing value 
     35       * \param defaultValue default value 
    3436       * \return the first and the last filters of the filter graph 
    3537       */ 
    3638      static std::pair<boost::shared_ptr<CSpatialTransformFilter>, boost::shared_ptr<CSpatialTransformFilter> > 
    37       buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, double defaultValue); 
     39      buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, bool hasMissingValue, double defaultValue); 
    3840 
    3941    protected: 
  • XIOS/dev/dev_olga/src/filter/store_filter.cpp

    r1021 r1158  
    2424    CTimer timer("CStoreFilter::getPacket"); 
    2525    CConstDataPacketPtr packet; 
    26     const double timeout = 10 ; // 10 seconds timeout 
     26    const double timeout = CXios::recvFieldTimeout; 
    2727 
    2828    do 
     
    8181  } 
    8282 
     83  bool CStoreFilter::isDataExpected(const CDate& date) const 
     84  { 
     85    return true; 
     86  } 
     87 
    8388  void CStoreFilter::invalidate(Time timestamp) 
    8489  { 
  • XIOS/dev/dev_olga/src/filter/store_filter.hpp

    r1021 r1158  
    5050 
    5151      /*! 
     52       * Tests whether data is expected for the specified date. 
     53       * 
     54       * \param date the date associated to the data 
     55       */ 
     56      bool virtual isDataExpected(const CDate& date) const; 
     57 
     58      /*! 
    5259       * Removes all pending packets which are older than the specified timestamp. 
    5360       * 
  • XIOS/dev/dev_olga/src/filter/temporal_filter.cpp

    r854 r1158  
    55namespace xios 
    66{ 
     7  static func::CFunctor* createFunctor(const std::string& opId, bool ignoreMissingValue, double missingValue, CArray<double, 1>& tmpData); 
     8 
    79  CTemporalFilter::CTemporalFilter(CGarbageCollector& gc, const std::string& opId, 
    810                                   const CDate& initDate, const CDuration samplingFreq, const CDuration samplingOffset, const CDuration opFreq, 
    911                                   bool ignoreMissingValue /*= false*/, double missingValue /*= 0.0*/) 
    1012    : CFilter(gc, 1, this) 
    11     , samplingFreq(samplingFreq) 
     13    , functor(createFunctor(opId, ignoreMissingValue, missingValue, tmpData)) 
     14    , isOnceOperation(functor->timeType() == func::CFunctor::once) 
     15    , isInstantOperation(functor->timeType() == func::CFunctor::instant) 
     16    // If we can optimize the sampling when dealing with an instant functor we do it 
     17    , samplingFreq((isInstantOperation && samplingFreq == TimeStep && samplingOffset == NoneDu) ? opFreq : samplingFreq) 
     18    , samplingOffset((isInstantOperation && samplingFreq == TimeStep && samplingOffset == NoneDu) ? opFreq - initDate.getRelCalendar().getTimeStep() : samplingOffset) 
    1219    , opFreq(opFreq) 
    13     , nextSamplingDate(initDate + samplingOffset + initDate.getRelCalendar().getTimeStep()) 
    14     , nextOperationDate(initDate + opFreq) 
     20    , nextSamplingDate(initDate + this->samplingOffset + initDate.getRelCalendar().getTimeStep()) 
     21    , nextOperationDate(initDate + this->samplingOffset + opFreq) 
    1522    , isFirstOperation(true) 
    1623  { 
    17 #define DECLARE_FUNCTOR(MType, mtype) \ 
    18     if (opId.compare(#mtype) == 0) \ 
    19     { \ 
    20       if (ignoreMissingValue) \ 
    21       { \ 
    22         functor.reset(new func::C##MType(tmpData, missingValue)); \ 
    23       } \ 
    24       else \ 
    25       { \ 
    26         functor.reset(new func::C##MType(tmpData)); \ 
    27       } \ 
    28     } 
    29  
    30 #include "functor_type.conf" 
    31  
    32     if (!functor) 
    33       ERROR("CTemporalFilter::CTemporalFilter(CGarbageCollector& gc, const std::string& opId, ...)", 
    34             << "\"" << opId << "\" is not a valid operation."); 
    35  
    36     isOnceOperation = (functor->timeType() == func::CFunctor::once); 
    3724  } 
    3825 
     
    4330    if (data[0]->status != CDataPacket::END_OF_STREAM) 
    4431    { 
    45       const bool usePacket = isOnceOperation ? isFirstOperation : (data[0]->date >= nextSamplingDate); 
     32      bool usePacket, outputResult, copyLess; 
     33      if (isOnceOperation) 
     34        usePacket = outputResult = copyLess = isFirstOperation; 
     35      else 
     36      { 
     37        usePacket = (data[0]->date >= nextSamplingDate); 
     38        outputResult = (data[0]->date + samplingFreq > nextOperationDate); 
     39        copyLess = (isInstantOperation && usePacket && outputResult); 
     40      } 
     41 
    4642      if (usePacket) 
    4743      { 
    48         if (!tmpData.numElements()) 
    49           tmpData.resize(data[0]->data.numElements()); 
     44        if (!copyLess) 
     45        { 
     46          if (!tmpData.numElements()) 
     47            tmpData.resize(data[0]->data.numElements()); 
    5048 
    51         (*functor)(data[0]->data); 
     49          (*functor)(data[0]->data); 
     50        } 
    5251 
    5352        nextSamplingDate = nextSamplingDate + samplingFreq; 
    5453      } 
    5554 
    56       const bool outputResult = isOnceOperation ? isFirstOperation : (data[0]->date + samplingFreq > nextOperationDate); 
    5755      if (outputResult) 
    5856      { 
    59         functor->final(); 
     57        if (!copyLess) 
     58        { 
     59          functor->final(); 
    6060 
    61         packet = CDataPacketPtr(new CDataPacket); 
    62         packet->date = data[0]->date; 
    63         packet->timestamp = data[0]->timestamp; 
    64         packet->status = data[0]->status; 
    65         packet->data.resize(tmpData.numElements()); 
    66         packet->data = tmpData; 
     61          packet = CDataPacketPtr(new CDataPacket); 
     62          packet->date = data[0]->date; 
     63          packet->timestamp = data[0]->timestamp; 
     64          packet->status = data[0]->status; 
     65          packet->data.resize(tmpData.numElements()); 
     66          packet->data = tmpData; 
     67        } 
     68        else 
     69          packet = data[0]; 
    6770 
    6871        isFirstOperation = false; 
     
    7376    return packet; 
    7477  } 
     78 
     79  bool CTemporalFilter::isDataExpected(const CDate& date) const 
     80  { 
     81    return isOnceOperation ? isFirstOperation : (date >= nextSamplingDate || date + samplingFreq > nextOperationDate); 
     82  } 
     83 
     84  static func::CFunctor* createFunctor(const std::string& opId, bool ignoreMissingValue, double missingValue, CArray<double, 1>& tmpData) 
     85  { 
     86    func::CFunctor* functor = NULL; 
     87 
     88    double defaultValue = ignoreMissingValue ? std::numeric_limits<double>::quiet_NaN() : missingValue; 
     89 
     90#define DECLARE_FUNCTOR(MType, mtype) \ 
     91    if (opId.compare(#mtype) == 0) \ 
     92    { \ 
     93      if (ignoreMissingValue) \ 
     94      { \ 
     95        functor = new func::C##MType(tmpData, defaultValue); \ 
     96      } \ 
     97      else \ 
     98      { \ 
     99        functor = new func::C##MType(tmpData); \ 
     100      } \ 
     101    } 
     102 
     103#include "functor_type.conf" 
     104 
     105    if (!functor) 
     106      ERROR("createFunctor(const std::string& opId, ...)", 
     107            << "\"" << opId << "\" is not a valid operation."); 
     108 
     109    return functor; 
     110  } 
    75111} // namespace xios 
  • XIOS/dev/dev_olga/src/filter/temporal_filter.hpp

    r643 r1158  
    4040      CDataPacketPtr virtual apply(std::vector<CDataPacketPtr> data); 
    4141 
     42      /*! 
     43       * Tests whether data is expected for the specified date. 
     44       * 
     45       * \param date the date associated to the data 
     46       */ 
     47      bool virtual isDataExpected(const CDate& date) const; 
     48 
    4249    private: 
    43       boost::scoped_ptr<func::CFunctor> functor; //!< The functor corresponding to the temporal operation 
     50      const boost::scoped_ptr<func::CFunctor> functor; //!< The functor corresponding to the temporal operation 
    4451      CArray<double, 1> tmpData; //!< The array of data used for temporary storage 
    4552      const CDuration samplingFreq; //!< The sampling frequency, i.e. the frequency at which the input data will be used 
     53      const CDuration samplingOffset; //!< The sampling offset, i.e. the offset after which the input data will be used 
    4654      const CDuration opFreq; //!< The operation frequency, i.e. the frequency at which the output data will be computed 
    4755      CDate nextSamplingDate; //!< The date of the next sampling 
    4856      CDate nextOperationDate; //!< The date of the next operation 
    4957      bool isFirstOperation; //!< True before the first operation was been computed 
    50       bool isOnceOperation; //!< True if the operation should be computed just once 
     58      const bool isOnceOperation; //!< True if the operation should be computed just once 
     59      const bool isInstantOperation; //!< True if the operation is instant 
    5160  }; // class CTemporalFilter 
    5261} // namespace xios 
Note: See TracChangeset for help on using the changeset viewer.