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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.