Changeset 1158 for XIOS/dev/dev_olga/src/filter/temporal_filter.cpp
- Timestamp:
- 06/06/17 17:58:16 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_olga/src/filter/temporal_filter.cpp
r854 r1158 5 5 namespace xios 6 6 { 7 static func::CFunctor* createFunctor(const std::string& opId, bool ignoreMissingValue, double missingValue, CArray<double, 1>& tmpData); 8 7 9 CTemporalFilter::CTemporalFilter(CGarbageCollector& gc, const std::string& opId, 8 10 const CDate& initDate, const CDuration samplingFreq, const CDuration samplingOffset, const CDuration opFreq, 9 11 bool ignoreMissingValue /*= false*/, double missingValue /*= 0.0*/) 10 12 : 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) 12 19 , 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) 15 22 , isFirstOperation(true) 16 23 { 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);37 24 } 38 25 … … 43 30 if (data[0]->status != CDataPacket::END_OF_STREAM) 44 31 { 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 46 42 if (usePacket) 47 43 { 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()); 50 48 51 (*functor)(data[0]->data); 49 (*functor)(data[0]->data); 50 } 52 51 53 52 nextSamplingDate = nextSamplingDate + samplingFreq; 54 53 } 55 54 56 const bool outputResult = isOnceOperation ? isFirstOperation : (data[0]->date + samplingFreq > nextOperationDate);57 55 if (outputResult) 58 56 { 59 functor->final(); 57 if (!copyLess) 58 { 59 functor->final(); 60 60 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]; 67 70 68 71 isFirstOperation = false; … … 73 76 return packet; 74 77 } 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 } 75 111 } // namespace xios
Note: See TracChangeset
for help on using the changeset viewer.