source: XIOS3/dev/XIOS_ATTACHED/src/filter/file_writer_store_filter.cpp

Last change on this file was 2482, checked in by ymipsl, 15 months ago

First guess in supression of attached mode replaced by online reader and write filters

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.7 KB
Line 
1#include "file_writer_store_filter.hpp"
2#include "exception.hpp"
3#include "field.hpp"
4#include "file.hpp"
5#include "context.hpp"
6#include "workflow_graph.hpp"
7
8namespace xios
9{
10  CFileWriterStoreFilter::CFileWriterStoreFilter(CGarbageCollector& gc, CField* field)
11    : CInputPin(gc, 1)
12    , field_(field), graphEnabled(false)
13
14  {
15    CContext* context = CContext::getCurrent();
16
17    if (!field) ERROR("CFileWriterStoreFilter::CFileWriterStoreFilter(CField* field)", "The field cannot be null.");
18    file_ = field->getFileOut() ;
19    grid_= field->getGrid() ;
20    freqWrite_ = file_->output_freq ;
21    lastWrite_ = context->getCalendar()->getInitDate();
22    if (!file_->isEmptyZone() && (field->getGrid()->doGridHaveDataToWrite() || file_->type == CFile::type_attr::one_file))
23         needToWrite_=true ;
24    else needToWrite_=false;
25    lastFileSplit_ = file_->getLastSplit() ;
26    nstep_ = file_->record_offset.isEmpty() ? 0 : file_->record_offset; // record_offset < 0 ==> no output (debugging)
27    if (!field->scale_factor.isEmpty()) { scaleFactor_ = field->scale_factor ; hasScaleFactor_ = true ; }
28    if (!field->add_offset.isEmpty()) { addOffset_ = field->add_offset ; hasAddOffset_ = true ; }
29    if (!field->prec.isEmpty() && field->prec == 2) hasRounding_ = true ;
30    if (!field->default_value.isEmpty()) {hasDefaultValue_=true ; defaultValue_ = field->default_value ;}
31    context->registerFileToWrite(file_) ;
32  }
33
34  void CFileWriterStoreFilter::onInputReady(std::vector<CDataPacketPtr> data)
35  {
36    const CDate currentWrite = lastWrite_ + freqWrite_;
37    if (needToWrite_)
38    {
39      file_->checkWriteFile();
40      if (file_->getLastSplit() != lastFileSplit_)
41      {
42        nstep_ = 0 ;
43        lastFileSplit_ = file_->getLastSplit() ;
44      }
45      nstep_ = nstep_+1;
46     
47      CArray<double,1> dataIn = data[0]->data ;
48      CArray<double,1> fieldData ;
49
50      if (hasAddOffset_ || hasScaleFactor_ || hasRounding_) dataIn = data[0]->data ;
51      else dataIn.reference(data[0]->data) ;
52
53      if (hasAddOffset_)   dataIn = dataIn - addOffset_ ;
54      if (hasScaleFactor_) dataIn = dataIn / scaleFactor_;
55      if (hasRounding_)    dataIn = round(dataIn);
56
57      if (hasDefaultValue_)
58      {
59        size_t nbData=dataIn.numElements() ;
60        for (size_t idx = 0; idx < nbData; ++idx) if ( NumTraits<double>::isNan(dataIn(idx)) ) dataIn(idx)=defaultValue_ ;
61      }
62
63      if (field_->getUseCompressedOutput()) fieldData.reference(dataIn) ;
64      else
65      {
66        fieldData.resize(grid_->getWorkflowToFullConnector()->getDstSize());
67        if (hasDefaultValue_) grid_->getWorkflowToFullConnector()->transfer(dataIn, fieldData, defaultValue_ ) ;
68        else grid_->getWorkflowToFullConnector()->transfer(dataIn, fieldData ) ;
69      } 
70      nstep_ = file_->getDataOutput()->writeFieldData(field_, fieldData, lastWrite_,currentWrite, nstep_);
71      if(this->graphEnabled)
72      {
73       
74        this->graphPackage->filterId = CWorkflowGraph::getNodeSize();
75        if(!data[0]->graphPackage) data[0]->graphPackage = new CGraphDataPackage;
76        data[0]->graphPackage->currentField = this->graphPackage->inFields[0];
77        std::rotate(this->graphPackage->inFields.begin(), this->graphPackage->inFields.begin() + 1, this->graphPackage->inFields.end());
78     
79        CWorkflowGraph::addNode("File Writer Store filter", 5, true, 1, data[0]);
80     
81        CWorkflowGraph::addEdge(data[0]->graphPackage->fromFilter, this->graphPackage->filterId, data[0]);
82        data[0]->graphPackage->fromFilter = this->graphPackage->filterId;
83
84
85      }
86    }
87
88    lastWrite_ = currentWrite ;
89
90  }
91
92  bool CFileWriterStoreFilter::mustAutoTrigger() const
93  {
94    return true;
95  }
96
97  bool CFileWriterStoreFilter::isDataExpected(const CDate& date) const
98  {
99    return true;
100  }
101} // namespace xios
Note: See TracBrowser for help on using the repository browser.