Changeset 640


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

Start using the filter infrastructure to read and write fields.

Note that currently only the simple cases are working. References and all types of operations are disabled.

Location:
XIOS/trunk/src/node
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/context.cpp

    r639 r640  
    4646 
    4747   //---------------------------------------------------------------- 
     48 
    4849   /*! 
    4950   \brief Get context group (context root) 
     
    5657   } 
    5758 
    58  
    5959   //---------------------------------------------------------------- 
     60 
    6061   /*! 
    6162   \brief Get calendar of a context 
     
    6869 
    6970   //---------------------------------------------------------------- 
     71 
    7072   /*! 
    7173   \brief Set a context with a calendar 
     
    386388    if (hasClient) 
    387389    { 
     390      //this->buildAllExpressionOfEnabledFields(); 
     391      //buildAllExpressionOfFieldsWithReadAccess(); 
     392      this->buildFilterGraphOfEnabledFields(); 
     393      buildFilterGraphOfFieldsWithReadAccess(); 
    388394      this->solveAllRefOfEnabledFields(true); 
    389       this->buildAllExpressionOfEnabledFields(); 
    390       buildAllExpressionOfFieldsWithReadAccess(); 
    391395    } 
    392396 
     
    426430     { 
    427431       this->enabledFiles[i]->buildAllExpressionOfEnabledFields(); 
     432     } 
     433   } 
     434 
     435   void CContext::buildFilterGraphOfEnabledFields() 
     436   { 
     437     int size = this->enabledFiles.size(); 
     438     for (int i = 0; i < size; ++i) 
     439     { 
     440       this->enabledFiles[i]->buildFilterGraphOfEnabledFields(garbageCollector); 
    428441     } 
    429442   } 
     
    474487    for (size_t i = 0; i < fieldsWithReadAccess.size(); ++i) 
    475488      fieldsWithReadAccess[i]->buildAllExpressionEnabledField(); 
     489  } 
     490 
     491  void CContext::buildFilterGraphOfFieldsWithReadAccess() 
     492  { 
     493    for (size_t i = 0; i < fieldsWithReadAccess.size(); ++i) 
     494      fieldsWithReadAccess[i]->buildFilterGraph(garbageCollector, true); 
    476495  } 
    477496 
  • XIOS/trunk/src/node/context.hpp

    r639 r640  
    112112         void solveAllRefOfEnabledFields(bool sendToServer); 
    113113         void buildAllExpressionOfEnabledFields(); 
     114         void buildFilterGraphOfEnabledFields(); 
    114115         void startPrefetchingOfEnabledReadModeFiles(); 
    115116         void checkPrefetchingOfEnabledReadModeFiles(); 
     
    117118         void solveAllRefOfFieldsWithReadAccess(); 
    118119         void buildAllExpressionOfFieldsWithReadAccess(); 
     120         void buildFilterGraphOfFieldsWithReadAccess(); 
    119121         void postProcessing(); 
    120122 
  • XIOS/trunk/src/node/field.cpp

    r638 r640  
    1414#include "context_server.hpp" 
    1515#include <set> 
     16#include "garbage_collector.hpp" 
     17#include "source_filter.hpp" 
     18#include "store_filter.hpp" 
     19#include "file_writer_filter.hpp" 
    1620 
    1721namespace xios{ 
     
    3135      , isReadDataRequestPending(false) 
    3236      , filterSources_() 
    33       { setVirtualVariableGroup(); } 
     37   { setVirtualVariableGroup(); } 
    3438 
    3539   CField::CField(const StdString& id) 
     
    456460    CContext* context = CContext::getCurrent(); 
    457461    StdSize record; 
     462    std::map<int, CArray<double,1> > data; 
     463 
    458464    for (int i = 0; i < ranks.size(); i++) 
     465    { 
     466      int rank = ranks[i]; 
     467      *buffers[i] >> record; 
     468      isEOF = (record == size_t(-1)); 
     469 
     470      if (!isEOF) 
     471        *buffers[i] >> data[rank]; 
     472      else 
     473        break; 
     474    } 
     475 
     476    if (isEOF) 
     477      serverSourceFilter->signalEndOfStream(lastDataRequestedFromServer); 
     478    else 
     479      serverSourceFilter->streamDataFromServer(lastDataRequestedFromServer, data); 
     480 
     481    /*for (int i = 0; i < ranks.size(); i++) 
    459482    { 
    460483      int rank = ranks[i]; 
     
    487510        if (hasFieldOut) updateDataFromExpression(instantData); 
    488511      } 
    489     } 
     512    }*/ 
    490513 
    491514    isReadDataRequestPending = false; 
     
    633656      using namespace func; 
    634657 
    635       if (!hasOutputFile && !hasFieldOut) return; 
     658      CContext* context = CContext::getCurrent(); 
     659 
     660      if (!context->hasServer || !hasOutputFile) return; 
    636661 
    637662      StdString id; 
     
    639664      else if (!name.isEmpty()) id = name; 
    640665      else if (hasDirectFieldReference()) id = baseRefObject->getId(); 
    641  
    642       CContext* context = CContext::getCurrent(); 
    643666 
    644667      if (freq_op.isEmpty()) freq_op.setValue(TimeStep); 
     
    722745               << "The operation is not defined !"); 
    723746//      } 
     747   } 
     748 
     749   //---------------------------------------------------------------- 
     750 
     751   /*! 
     752    * Constructs the graph filter for the field, enabling or not the data output. 
     753    * This method should not be called more than once with enableOutput equal to true. 
     754    * 
     755    * \param gc the garbage collector to use when building the filter graph 
     756    * \param enableOutput must be true when the field data is to be 
     757    *                     read by the client or/and written to a file 
     758    */ 
     759   void CField::buildFilterGraph(CGarbageCollector& gc, bool enableOutput) 
     760   { 
     761     // Start by building a filter which can provide the field's instant data 
     762     if (!instantDataFilter) 
     763     { 
     764       // Check if the data is to be read from a file 
     765       if (file && !file->mode.isEmpty() && file->mode == CFile::mode_attr::read) 
     766         instantDataFilter = serverSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(grid)); 
     767       else // The data might be passed from the model 
     768         instantDataFilter = clientSourceFilter = boost::shared_ptr<CSourceFilter>(new CSourceFilter(grid)); 
     769     } 
     770 
     771     // If the field data is to be read by the client or/and written to a file 
     772     if (enableOutput && !storeFilter && !fileWriterFilter) 
     773     { 
     774       if (!read_access.isEmpty() && read_access.getValue()) 
     775       { 
     776         storeFilter = boost::shared_ptr<CStoreFilter>(new CStoreFilter(gc, CContext::getCurrent(), grid)); 
     777         instantDataFilter->connectOutput(storeFilter, 0); 
     778       } 
     779 
     780       if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write)) 
     781       { 
     782         fileWriterFilter = boost::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this)); 
     783         instantDataFilter->connectOutput(fileWriterFilter, 0); 
     784       } 
     785     } 
    724786   } 
    725787 
  • XIOS/trunk/src/node/field.hpp

    r638 r640  
    2828   class CFile; 
    2929   class CGrid; 
    30    class CContext ; 
     30   class CContext; 
    3131   class CGenericFilter; 
     32 
     33   class CGarbageCollector; 
     34   class COutputPin; 
     35   class CSourceFilter; 
     36   class CStoreFilter; 
     37   class CFileWriterFilter; 
    3238 
    3339   ///-------------------------------------------------------------- 
     
    124130         void solveTransformedGrid(); 
    125131         CGrid* getGridRefOfBaseReference(); 
     132 
     133         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput); 
    126134 
    127135//         virtual void fromBinary(StdIStream & is); 
     
    233241         DECLARE_REF_FUNC(Field,field) 
    234242 
     243      private: 
     244         //! The output pin of the filter providing the instant data for the field 
     245         boost::shared_ptr<COutputPin> instantDataFilter; 
     246         //! The source filter for data provided by the client 
     247         boost::shared_ptr<CSourceFilter> clientSourceFilter; 
     248         //! The source filter for data provided by the server 
     249         boost::shared_ptr<CSourceFilter> serverSourceFilter; 
     250         //! The terminal filter which stores the instant data 
     251         boost::shared_ptr<CStoreFilter> storeFilter; 
     252         //! The terminal filter which writes the data to file 
     253         boost::shared_ptr<CFileWriterFilter> fileWriterFilter; 
    235254   }; // class CField 
    236255 
  • XIOS/trunk/src/node/field_impl.hpp

    r624 r640  
    99#include "timer.hpp" 
    1010#include "array_new.hpp" 
     11#include "source_filter.hpp" 
     12#include "store_filter.hpp" 
    1113 
    1214 
     
    1618  void CField::setData(const CArray<double, N>& _data) 
    1719  { 
    18     if (hasInstantData) 
     20    if (clientSourceFilter) 
     21      clientSourceFilter->streamData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data); 
     22    else if (!field_ref.isEmpty() || !content.empty()) 
     23      ERROR("void CField::setData(const CArray<double, N>& _data)", 
     24            << "Impossible to receive data from the model for a field [ id = " << getId() << " ] with a reference or an arithmetic operation."); 
     25 
     26    /*if (hasInstantData) 
    1927    { 
    2028      grid->inputField(_data, instantData); 
     
    5260      } 
    5361      if (hasOutputFile || hasFieldOut) updateData(_data); 
    54     } 
     62    }*/ 
    5563  } 
    5664 
     
    279287  void CField::getData(CArray<double, N>& _data) const 
    280288  { 
    281     if (!read_access.isEmpty() && read_access.getValue() && hasInstantData) 
    282     { 
    283       CContext* context = CContext::getCurrent(); 
     289    if (storeFilter) 
     290    { 
     291      CDataPacket::StatusCode status = storeFilter->getData(CContext::getCurrent()->getCalendar()->getCurrentDate(), _data); 
     292 
     293      if (status == CDataPacket::END_OF_STREAM) 
     294        ERROR("void CField::getData(CArray<double, N>& _data) const", 
     295              << "Impossible to access field data, all the records of the field [ id = " << getId() << " ] have been already read."); 
     296 
     297      /*CContext* context = CContext::getCurrent(); 
    284298      const CDate& currentDate = context->getCalendar()->getCurrentDate(); 
    285299 
     
    291305              << "Impossible to access field data, all the records of the field [ id = " << getId() << " ] have been already read."); 
    292306 
    293       grid->outputField(instantData, _data); 
     307      grid->outputField(instantData, _data);*/ 
    294308    } 
    295309    else 
  • XIOS/trunk/src/node/file.cpp

    r609 r640  
    622622 
    623623   /*! 
     624    * Constructs the filter graph for each active field. 
     625    * 
     626    * \param gc the garbage collector to use when building the filter graph 
     627    */ 
     628   void CFile::buildFilterGraphOfEnabledFields(CGarbageCollector& gc) 
     629   { 
     630     int size = this->enabledFields.size(); 
     631     for (int i = 0; i < size; ++i) 
     632     { 
     633       this->enabledFields[i]->buildFilterGraph(gc, true); 
     634     } 
     635   } 
     636 
     637   /*! 
    624638     Prefetching the data for enabled fields read from file. 
    625639   */ 
  • XIOS/trunk/src/node/file.hpp

    r609 r640  
    2222   class CFileAttributes; 
    2323   class CFile; 
     24 
     25   class CGarbageCollector; 
    2426 
    2527   ///-------------------------------------------------------------- 
     
    108110         void solveAllRefOfEnabledFields(bool sendToServer); 
    109111         void buildAllExpressionOfEnabledFields(); 
     112         void buildFilterGraphOfEnabledFields(CGarbageCollector& gc); 
    110113         void prefetchEnabledReadModeFields(); 
    111114         void prefetchEnabledReadModeFieldsIfNeeded(); 
Note: See TracChangeset for help on using the changeset viewer.