Changeset 1158 for XIOS/dev/dev_olga/src/filter
- Timestamp:
- 06/06/17 17:58:16 (7 years ago)
- 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 18 18 field->writeUpdateData(data[0]->data); 19 19 } 20 21 bool CFileServerWriterFilter::isDataExpected(const CDate& date) const 22 { 23 return true; 24 } 20 25 } // namespace xios -
XIOS/dev/dev_olga/src/filter/file_server_writer_filter.hpp
r1026 r1158 23 23 CFileServerWriterFilter(CGarbageCollector& gc, CField* field); 24 24 25 bool virtual isDataExpected(const CDate& date) const; 25 26 protected: 26 27 /*! -
XIOS/dev/dev_olga/src/filter/file_writer_filter.cpp
r639 r1158 2 2 #include "exception.hpp" 3 3 #include "field.hpp" 4 #include "utils.hpp" 4 5 5 6 namespace xios … … 16 17 void CFileWriterFilter::onInputReady(std::vector<CDataPacketPtr> data) 17 18 { 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 18 33 field->sendUpdateData(data[0]->data); 19 34 } 35 36 bool CFileWriterFilter::isDataExpected(const CDate& date) const 37 { 38 return true; 39 } 20 40 } // namespace xios -
XIOS/dev/dev_olga/src/filter/file_writer_filter.hpp
r639 r1158 23 23 CFileWriterFilter(CGarbageCollector& gc, CField* field); 24 24 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 25 32 protected: 26 33 /*! -
XIOS/dev/dev_olga/src/filter/filter.cpp
r1021 r1158 40 40 return (CInputPin::canBeTriggered() || COutputPin::canBeTriggered()); 41 41 } 42 43 bool CFilter::isDataExpected(const CDate& date) const 44 { 45 return COutputPin::isDataExpected(date); 46 } 42 47 } // namespace xios -
XIOS/dev/dev_olga/src/filter/filter.hpp
r1021 r1158 48 48 bool virtual canBeTriggered() const; 49 49 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 50 57 protected: 51 58 IFilterEngine* engine; //!< The filter engine, might be the filter itself -
XIOS/dev/dev_olga/src/filter/input_pin.hpp
r1021 r1158 60 60 61 61 /*! 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 /*! 62 69 * Removes all pending packets which are older than the specified timestamp. 63 70 * -
XIOS/dev/dev_olga/src/filter/output_pin.cpp
r1021 r1158 73 73 } 74 74 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 75 87 void COutputPin::invalidate(Time timestamp) 76 88 { -
XIOS/dev/dev_olga/src/filter/output_pin.hpp
r1021 r1158 46 46 47 47 /*! 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 /*! 48 55 * Removes all pending packets which are older than the specified timestamp. 49 56 * -
XIOS/dev/dev_olga/src/filter/source_filter.cpp
r1021 r1158 3 3 #include "exception.hpp" 4 4 #include "calendar_util.hpp" 5 #include <limits> 5 6 6 7 namespace xios 7 8 { 8 9 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*/) 10 13 : COutputPin(gc, manualTrigger) 11 14 , grid(grid) 12 15 , offset(offset) 16 , hasMissingValue(hasMissingValue), defaultValue(defaultValue) 13 17 { 14 18 if (!grid) … … 29 33 packet->data.resize(grid->storeIndex_client.numElements()); 30 34 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 } 31 47 32 48 onOutputReady(packet); -
XIOS/dev/dev_olga/src/filter/source_filter.hpp
r1021 r1158 23 23 * \param offset the offset applied to the timestamp of all packets 24 24 * \param manualTrigger whether the output should be triggered manually 25 * \param hasMissingValue whether data has missing value 26 * \param defaultValue missing value to detect 25 27 */ 26 28 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); 28 32 29 33 /*! … … 58 62 CGrid* grid; //!< The grid attached to the data the filter can accept 59 63 const CDuration offset; //!< The offset applied to the timestamp of all packets 64 bool hasMissingValue; 65 double defaultValue; 60 66 }; // class CSourceFilter 61 67 } // namespace xios -
XIOS/dev/dev_olga/src/filter/spatial_transform_filter.cpp
r1021 r1158 11 11 12 12 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) 14 14 { 15 15 if (!srcGrid || !destGrid) … … 26 26 const std::vector<StdString>& auxInputs = gridTransformation->getAuxInputs(); 27 27 size_t inputCount = 1 + (auxInputs.empty() ? 0 : auxInputs.size()); 28 double defaultValue = (hasMissingValue) ? std::numeric_limits<double>::quiet_NaN() : 0.0; 28 29 boost::shared_ptr<CSpatialTransformFilter> filter(new CSpatialTransformFilter(gc, engine, defaultValue, inputCount)); 29 30 … … 103 104 } 104 105 packet->data.resize(gridTransformation->getGridDestination()->storeIndex_client.numElements()); 105 packet->data = defaultValue; 106 if (0 != packet->data.numElements()) 107 (packet->data)(0) = defaultValue; 106 108 apply(data[0]->data, packet->data); 107 109 } … … 115 117 116 118 // 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)); 119 122 120 123 const std::list<CGridTransformation::SendingIndexGridSourceMap>& listLocalIndexSend = gridTransformation->getLocalIndexToSendFromGridSource(); … … 191 194 else dataCurrentDest(i) = defaultValue; 192 195 193 std::vector<bool> localInitFlag(dataCurrentDest. size(), true);196 std::vector<bool> localInitFlag(dataCurrentDest.numElements(), true); 194 197 currentBuff = 0; 195 198 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) … … 201 204 dataCurrentDest, 202 205 localInitFlag, 203 defaultValue);206 ignoreMissingValue); 204 207 205 208 currentBuff += countSize; -
XIOS/dev/dev_olga/src/filter/spatial_transform_filter.hpp
r873 r1158 32 32 * \param srcGrid the source grid 33 33 * \param destGrid the destination grid 34 * \param hasMissingValue whether field source has missing value 35 * \param defaultValue default value 34 36 * \return the first and the last filters of the filter graph 35 37 */ 36 38 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); 38 40 39 41 protected: -
XIOS/dev/dev_olga/src/filter/store_filter.cpp
r1021 r1158 24 24 CTimer timer("CStoreFilter::getPacket"); 25 25 CConstDataPacketPtr packet; 26 const double timeout = 10 ; // 10 seconds timeout26 const double timeout = CXios::recvFieldTimeout; 27 27 28 28 do … … 81 81 } 82 82 83 bool CStoreFilter::isDataExpected(const CDate& date) const 84 { 85 return true; 86 } 87 83 88 void CStoreFilter::invalidate(Time timestamp) 84 89 { -
XIOS/dev/dev_olga/src/filter/store_filter.hpp
r1021 r1158 50 50 51 51 /*! 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 /*! 52 59 * Removes all pending packets which are older than the specified timestamp. 53 60 * -
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 -
XIOS/dev/dev_olga/src/filter/temporal_filter.hpp
r643 r1158 40 40 CDataPacketPtr virtual apply(std::vector<CDataPacketPtr> data); 41 41 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 42 49 private: 43 boost::scoped_ptr<func::CFunctor> functor; //!< The functor corresponding to the temporal operation50 const boost::scoped_ptr<func::CFunctor> functor; //!< The functor corresponding to the temporal operation 44 51 CArray<double, 1> tmpData; //!< The array of data used for temporary storage 45 52 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 46 54 const CDuration opFreq; //!< The operation frequency, i.e. the frequency at which the output data will be computed 47 55 CDate nextSamplingDate; //!< The date of the next sampling 48 56 CDate nextOperationDate; //!< The date of the next operation 49 57 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 51 60 }; // class CTemporalFilter 52 61 } // namespace xios
Note: See TracChangeset
for help on using the changeset viewer.