Changeset 643


Ignore:
Timestamp:
07/17/15 13:58:13 (9 years ago)
Author:
rlacroix
Message:

Use the filter infrastructure to handle the temporal operations.

Add a temporal filter to do so.

Location:
XIOS/trunk/src
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/calendar_util.cpp

    r550 r643  
    211211    ///---------------------------------------------------------------- 
    212212 
     213    bool DurationFakeLessComparator::operator()(const CDuration& dur1, const CDuration& dur2) const 
     214    { 
     215      if (dur1.year < dur2.year) 
     216        return true; 
     217      else if (dur1.year == dur2.year) 
     218      { 
     219        if (dur1.month < dur2.month) 
     220          return true; 
     221        else if (dur1.month == dur2.month) 
     222        { 
     223          if (dur1.day < dur2.day) 
     224            return true; 
     225          else if (dur1.day == dur2.day) 
     226          { 
     227            if (dur1.hour < dur2.hour) 
     228              return true; 
     229            else if (dur1.hour == dur2.hour) 
     230            { 
     231              if (dur1.minute < dur2.minute) 
     232                return true; 
     233              else if (dur1.minute == dur2.minute) 
     234              { 
     235                if (dur1.second < dur2.second) 
     236                  return true; 
     237                else if (dur1.second == dur2.second) 
     238                  return (dur1.timestep < dur2.timestep); 
     239              } 
     240            } 
     241          } 
     242        } 
     243      } 
     244      return false; 
     245    } 
     246 
     247    ///---------------------------------------------------------------- 
     248 
    213249} // namespace xios 
    214250 
  • XIOS/trunk/src/calendar_util.hpp

    r591 r643  
    3636      ///--------------------------------------------------------------- 
    3737 
     38      //!< Provides a fake "less" comparator for durations that can be used as a comparator for maps 
     39      struct DurationFakeLessComparator { 
     40        bool operator()(const CDuration& dur1, const CDuration& dur2) const; 
     41      }; 
    3842} // namespace xios 
    3943 
  • XIOS/trunk/src/filter/binary_arithmetic_filter.cpp

    r642 r643  
    1212  { 
    1313    CDataPacketPtr packet(new CDataPacket); 
     14    packet->date = data[0]->date; 
    1415    packet->timestamp = data[0]->timestamp; 
    1516    packet->status = data[0]->status; 
     
    3031  { 
    3132    CDataPacketPtr packet(new CDataPacket); 
     33    packet->date = data[0]->date; 
    3234    packet->timestamp = data[0]->timestamp; 
    3335    packet->status = data[0]->status; 
     
    4749  { 
    4850    CDataPacketPtr packet(new CDataPacket); 
     51    packet->date = data[0]->date; 
    4952    packet->timestamp = data[0]->timestamp; 
    5053 
  • XIOS/trunk/src/filter/data_packet.hpp

    r637 r643  
    55 
    66#include "array_new.hpp" 
    7 #include "duration.hpp" 
     7#include "date.hpp" 
    88 
    99namespace xios 
     
    2323 
    2424    CArray<double, 1> data; //!< Array containing the data 
     25    CDate date;             //!< Date associated to the data 
    2526    Time timestamp;         //!< Timestamp of the data 
    2627    StatusCode status;      //!< Status of the packet 
     
    3536      p->data.resize(data.shape()); 
    3637      p->data = data; 
     38      p->date = date; 
    3739      p->timestamp = timestamp; 
    3840      p->status = status; 
  • XIOS/trunk/src/filter/source_filter.cpp

    r638 r643  
    1414 
    1515  template <int N> 
    16   void CSourceFilter::streamData(Time timestamp, const CArray<double, N>& data) 
     16  void CSourceFilter::streamData(CDate date, const CArray<double, N>& data) 
    1717  { 
    1818    CDataPacketPtr packet(new CDataPacket); 
    19     packet->timestamp = timestamp; 
     19    packet->date = date; 
     20    packet->timestamp = date; 
    2021    packet->status = CDataPacket::NO_ERROR; 
    2122 
     
    2627  } 
    2728 
    28   template void CSourceFilter::streamData<1>(Time timestamp, const CArray<double, 1>& data); 
    29   template void CSourceFilter::streamData<2>(Time timestamp, const CArray<double, 2>& data); 
    30   template void CSourceFilter::streamData<3>(Time timestamp, const CArray<double, 3>& data); 
     29  template void CSourceFilter::streamData<1>(CDate date, const CArray<double, 1>& data); 
     30  template void CSourceFilter::streamData<2>(CDate date, const CArray<double, 2>& data); 
     31  template void CSourceFilter::streamData<3>(CDate date, const CArray<double, 3>& data); 
    3132 
    32   void CSourceFilter::streamDataFromServer(Time timestamp, const std::map<int, CArray<double, 1> >& data) 
     33  void CSourceFilter::streamDataFromServer(CDate date, const std::map<int, CArray<double, 1> >& data) 
    3334  { 
    3435    CDataPacketPtr packet(new CDataPacket); 
    35     packet->timestamp = timestamp; 
     36    packet->date = date; 
     37    packet->timestamp = date; 
    3638    packet->status = CDataPacket::NO_ERROR; 
    3739 
    3840    if (data.size() != grid->storeIndex_toSrv.size()) 
    39       ERROR("CSourceFilter::streamDataFromServer(Time timestamp, const std::map<int, CArray<double, 1> >& data)", 
     41      ERROR("CSourceFilter::streamDataFromServer(CDate date, const std::map<int, CArray<double, 1> >& data)", 
    4042            << "Incoherent data received from servers," 
    4143            << " expected " << grid->storeIndex_toSrv.size() << " chunks but " << data.size() << " were given."); 
     
    5456  } 
    5557 
    56   void CSourceFilter::signalEndOfStream(Time timestamp) 
     58  void CSourceFilter::signalEndOfStream(CDate date) 
    5759  { 
    5860    CDataPacketPtr packet(new CDataPacket); 
    59     packet->timestamp = timestamp; 
     61    packet->date = date; 
     62    packet->timestamp = date; 
    6063    packet->status = CDataPacket::END_OF_STREAM; 
    6164    deliverOuput(packet); 
  • XIOS/trunk/src/filter/source_filter.hpp

    r638 r643  
    2828       * immediately after this method returns. 
    2929       * 
    30        * \param timestamp the timestamp of the data 
     30       * \param date the date associated to the data 
    3131       * \param data an array containing the data 
    3232       */ 
    3333      template <int N> 
    34       void streamData(Time timestamp, const CArray<double, N>& data); 
     34      void streamData(CDate date, const CArray<double, N>& data); 
    3535 
    3636      /*! 
     
    3939       * immediately after this method returns. 
    4040       * 
    41        * \param timestamp the timestamp of the data 
     41       * \param date the date associated to the data 
    4242       * \param data an array containing the data 
    4343       */ 
    44       void streamDataFromServer(Time timestamp, const std::map<int, CArray<double, 1> >& data); 
     44      void streamDataFromServer(CDate date, const std::map<int, CArray<double, 1> >& data); 
    4545 
    4646      /*! 
    4747       * Signals the filter graph that the end of stream was reached. 
    4848       * 
    49        * \param timestamp the timestamp at which the end of stream occurred 
     49       * \param date the date at which the end of stream occurred 
    5050       */ 
    51       void signalEndOfStream(Time timestamp); 
     51      void signalEndOfStream(CDate date); 
    5252 
    5353    private: 
  • XIOS/trunk/src/filter/unary_arithmetic_filter.cpp

    r642 r643  
    1111  { 
    1212    CDataPacketPtr packet(new CDataPacket); 
     13    packet->date = data[0]->date; 
    1314    packet->timestamp = data[0]->timestamp; 
    1415    packet->status = data[0]->status; 
  • XIOS/trunk/src/node/field.cpp

    r642 r643  
    2121#include "filter_expr_node.hpp" 
    2222#include "lex_parser.hpp" 
     23#include "temporal_filter.hpp" 
    2324 
    2425namespace xios{ 
     
    810811       { 
    811812         fileWriterFilter = boost::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this)); 
    812          instantDataFilter->connectOutput(fileWriterFilter, 0); 
     813         getTemporalDataFilter(gc, file->output_freq)->connectOutput(fileWriterFilter, 0); 
    813814       } 
    814815     } 
     
    834835 
    835836     return clientSourceFilter; 
     837   } 
     838 
     839   /*! 
     840    * Returns the temporal filter corresponding to the field's temporal operation 
     841    * for the specified operation frequency. The filter is created if it does not 
     842    * exist, otherwise it is reused. 
     843    * 
     844    * \param gc the garbage collector to use 
     845    * \param outFreq the operation frequency, i.e. the frequency at which the output data will be computed 
     846    * \return the output pin corresponding to the requested temporal filter 
     847    */ 
     848   boost::shared_ptr<COutputPin> CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq) 
     849   { 
     850     std::map<CDuration, boost::shared_ptr<COutputPin> >::iterator it = temporalDataFilters.find(outFreq); 
     851 
     852     if (it == temporalDataFilters.end()) 
     853     { 
     854       if (operation.isEmpty()) 
     855         ERROR("void CField::getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq)", 
     856               << "An operation must be defined for field \"" << getId() << "\"."); 
     857 
     858       if (freq_op.isEmpty()) 
     859         freq_op.setValue(TimeStep); 
     860       if (freq_offset.isEmpty()) 
     861         freq_offset.setValue(NoneDu); 
     862 
     863       const bool ignoreMissingValue = (!detect_missing_value.isEmpty() && !default_value.isEmpty() && detect_missing_value == true); 
     864 
     865       boost::shared_ptr<CTemporalFilter> temporalFilter(new CTemporalFilter(gc, operation, 
     866                                                                             CContext::getCurrent()->getCalendar()->getInitDate(), 
     867                                                                             freq_op, freq_offset, outFreq, 
     868                                                                             ignoreMissingValue, ignoreMissingValue ? default_value : 0.0)); 
     869       instantDataFilter->connectOutput(temporalFilter, 0); 
     870 
     871       it = temporalDataFilters.insert(std::make_pair(outFreq, temporalFilter)).first; 
     872     } 
     873 
     874     return it->second; 
    836875   } 
    837876 
  • XIOS/trunk/src/node/field.hpp

    r642 r643  
    134134         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput); 
    135135         boost::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc); 
     136         boost::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq); 
    136137 
    137138//         virtual void fromBinary(StdIStream & is); 
     
    246247         //! The output pin of the filter providing the instant data for the field 
    247248         boost::shared_ptr<COutputPin> instantDataFilter; 
     249         //! The output pin of the filters providing the result of the field's temporal operation 
     250         std::map<CDuration, boost::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters; 
    248251         //! The source filter for data provided by the client 
    249252         boost::shared_ptr<CSourceFilter> clientSourceFilter; 
  • XIOS/trunk/src/parse_expr/filter_expr_node.cpp

    r642 r643  
    3232 
    3333    return outputPin; 
     34  } 
     35 
     36  CFilterTemporalFieldExprNode::CFilterTemporalFieldExprNode(const std::string& fieldId) 
     37    : fieldId(fieldId) 
     38  { /* Nothing to do */ } 
     39 
     40  boost::shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const 
     41  { 
     42    if (!CField::has(fieldId)) 
     43      ERROR("boost::shared_ptr<COutputPin> CFilterTemporalFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", 
     44            << "The field " << fieldId << " does not exist."); 
     45 
     46    CField* field = CField::get(fieldId); 
     47    if (field == &thisField) 
     48      ERROR("boost::shared_ptr<COutputPin> CFilterFieldExprNode::reduce(CGarbageCollector& gc, CField& thisField) const", 
     49            << "The field " << fieldId << " has an invalid reference to itself."); 
     50 
     51    field->buildFilterGraph(gc, false); 
     52    return field->getTemporalDataFilter(gc, thisField.freq_op.isEmpty() ? TimeStep : thisField.freq_op); 
    3453  } 
    3554 
  • XIOS/trunk/src/parse_expr/filter_expr_node.hpp

    r642 r643  
    4242       */ 
    4343      CFilterFieldExprNode(const std::string& fieldId); 
     44 
     45      virtual boost::shared_ptr<COutputPin> reduce(CGarbageCollector& gc, CField& thisField) const; 
     46 
     47    private: 
     48      std::string fieldId; //!< The identifier of the field 
     49  }; 
     50 
     51  /*! 
     52   * Expression node corresponding to a field for which the result of 
     53   * the temporal operation is requested instead of the instant value. 
     54   */ 
     55  class CFilterTemporalFieldExprNode : public IFilterExprNode 
     56  { 
     57    public: 
     58      /*! 
     59       * Constructs an expression node corresponding 
     60       * to the field whose id is provided. 
     61       * 
     62       * \param fieldId the identifier of the field 
     63       */ 
     64      CFilterTemporalFieldExprNode(const std::string& fieldId); 
    4465 
    4566      virtual boost::shared_ptr<COutputPin> reduce(CGarbageCollector& gc, CField& thisField) const; 
  • XIOS/trunk/src/parse_expr/yacc_parser.cpp

    r642 r643  
    13731373  case 15: 
    13741374#line 78 "yacc_parser.yacc" /* yacc.c:1646  */ 
    1375     { /* TODO: Use temporal operation */ (yyval.filterNode) = new CFilterFieldExprNode(*(yyvsp[0].str)); delete (yyvsp[0].str); } 
     1375    { (yyval.filterNode) = new CFilterTemporalFieldExprNode(*(yyvsp[0].str)); delete (yyvsp[0].str); } 
    13761376#line 1377 "yacc_parser.cpp" /* yacc.c:1646  */ 
    13771377    break; 
  • XIOS/trunk/src/parse_expr/yacc_parser.yacc

    r642 r643  
    7676Field_expr: 
    7777            ID      { $$ = new CFilterFieldExprNode(*$1); delete $1; } 
    78           | AVERAGE { /* TODO: Use temporal operation */ $$ = new CFilterFieldExprNode(*$1); delete $1; } 
     78          | AVERAGE { $$ = new CFilterTemporalFieldExprNode(*$1); delete $1; } 
    7979          | Field_expr PLUS Field_expr   { $$ = new CFilterFieldFieldOpExprNode($1, "add", $3); } 
    8080          | Field_expr MINUS Field_expr  { $$ = new CFilterFieldFieldOpExprNode($1, "minus", $3); } 
Note: See TracChangeset for help on using the changeset viewer.