source: XIOS/trunk/src/node/field.hpp @ 643

Last change on this file since 643 was 643, checked in by rlacroix, 9 years ago

Use the filter infrastructure to handle the temporal operations.

Add a temporal filter to do so.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:executable set to *
File size: 9.9 KB
Line 
1#ifndef __XIOS_CField__
2#define __XIOS_CField__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "group_factory.hpp"
7#include "functor.hpp"
8#include "functor_type.hpp"
9#include "duration.hpp"
10#include "date.hpp"
11#include "declare_group.hpp"
12#include "calendar_util.hpp"
13#include "array_new.hpp"
14#include "attribute_array.hpp"
15#include "expr_node.hpp"
16#include "declare_ref_func.hpp"
17#include "transformation_enum.hpp"
18
19
20namespace xios {
21
22   /// ////////////////////// Déclarations ////////////////////// ///
23
24   class CFieldGroup;
25   class CFieldAttributes;
26   class CField;
27
28   class CFile;
29   class CGrid;
30   class CContext;
31   class CGenericFilter;
32
33   class CGarbageCollector;
34   class COutputPin;
35   class CSourceFilter;
36   class CStoreFilter;
37   class CFileWriterFilter;
38
39   ///--------------------------------------------------------------
40
41   // Declare/Define CFieldAttribute
42   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
43#  include "field_attribute.conf"
44   END_DECLARE_ATTRIBUTE_MAP(CField)
45
46   ///--------------------------------------------------------------
47   class CField
48      : public CObjectTemplate<CField>
49      , public CFieldAttributes
50   {
51         /// friend ///
52         friend class CFile;
53
54         /// typedef ///
55         typedef CObjectTemplate<CField>   SuperClass;
56         typedef CFieldAttributes SuperClassAttribute;
57
58      public :
59
60         typedef CFieldAttributes RelAttributes;
61         typedef CFieldGroup      RelGroup;
62
63         enum EEventId
64         {
65           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
66           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP
67         } ;
68
69         /// Constructeurs ///
70         CField(void);
71         explicit CField(const StdString & id);
72         CField(const CField & field);       // Not implemented yet.
73         CField(const CField * const field); // Not implemented yet.
74
75         /// Accesseurs ///
76
77         CGrid* getRelGrid(void) const ;
78         CFile* getRelFile(void) const ;
79
80      public :
81
82         StdSize getNStep(void) const;
83
84         const CDuration & getFreqOperation(void) const;
85         const CDuration & getFreqWrite(void) const;
86
87         boost::shared_ptr<CDate> getLastWriteDate(void) const;
88         boost::shared_ptr<CDate> getLastOperationDate(void) const;
89
90         boost::shared_ptr<func::CFunctor> getFieldOperation(void) const;
91
92         CArray<double, 1> getData(void) const;
93         template <int N> void getData(CArray<double, N>& _data) const;
94
95         boost::shared_ptr<COutputPin> getInstantDataFilter();
96
97         /// Mutateur ///
98         void setRelFile(CFile* _file);
99         void incrementNStep(void);
100         void resetNStep() ;
101         void resetNStepMax();
102
103         template <int N> bool updateData(const CArray<double, N>&   data);
104         template <int N> bool updateFilteredData(CArray<double, N>&   data);
105         template<int N>
106         void updateDataWithoutOperation(const CArray<double, N>& _data, CArray<double,1>& updatedData);
107         bool updateDataFromExpression(const CArray<double, 1>&   data);
108         void setDataFromExpression(const CArray<double, 1>& _data) ;
109
110         bool updateDataServer
111               (const CDate & currDate,
112                const std::deque< CArray<double, 1>* > storedClient);
113
114         std::map<int, StdSize> getGridDataSize();
115
116       public :
117         bool isActive(void) const;
118         bool active ;
119         bool hasOutputFile ;
120         bool hasFieldOut ;
121
122         /// Traitements ///
123         void processEnabledField(void) ;
124
125         void solveGridReference(void);
126         void solveOperation(void);
127         void solveCheckMaskIndex(bool doSendingIndex);
128         void solveAllReferenceEnabledField(bool doSending2Sever);
129         void buildAllExpressionEnabledField();
130         void solveGridDomainAxisRef(bool checkAtt);
131         void solveTransformedGrid();
132         CGrid* getGridRefOfBaseReference();
133
134         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
135         boost::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
136         boost::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
137
138//         virtual void fromBinary(StdIStream & is);
139
140         /// Destructeur ///
141         virtual ~CField(void);
142
143         /// Accesseurs statiques ///
144         static StdString GetName(void);
145         static StdString GetDefName(void);
146
147         static ENodeType GetType(void);
148
149        template <int N> void setData(const CArray<double, N>& _data) ;
150        static bool dispatchEvent(CEventServer& event) ;
151        void sendUpdateData(void) ;
152        void sendUpdateData(const CArray<double,1>& data);
153        static void recvUpdateData(CEventServer& event) ;
154        void recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) ;
155        void writeField(void) ;
156        void sendReadDataRequest(void);
157        bool sendReadDataRequestIfNeeded(void);
158        static void recvReadDataRequest(CEventServer& event);
159        void recvReadDataRequest(void);
160        bool readField(void);
161        static void recvReadDataReady(CEventServer& event);
162        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
163        void outputField(CArray<double,3>& fieldOut) ;
164        void outputField(CArray<double,2>& fieldOut) ;
165        void outputField(CArray<double,1>& fieldOut) ;
166        void inputField(CArray<double,3>& fieldOut);
167        void inputField(CArray<double,2>& fieldOut);
168        void inputField(CArray<double,1>& fieldOut);
169        void scaleFactorAddOffset(double scaleFactor, double addOffset) ;
170        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
171        void parse(xml::CXMLNode & node) ;
172        CArray<double,1>* getInstantData(void)  ;
173
174        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
175        void setVirtualVariableGroup(void);
176        CVariableGroup* getVirtualVariableGroup(void) const;
177        vector<CVariable*> getAllVariables(void) const;
178        virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
179
180        CVariable* addVariable(const string& id="") ;
181        CVariableGroup* addVariableGroup(const string& id="") ;
182        void sendAddVariable(const string& id="") ;
183        void sendAddVariableGroup(const string& id="") ;
184        static void recvAddVariable(CEventServer& event) ;
185        void recvAddVariable(CBufferIn& buffer) ;
186        static void recvAddVariableGroup(CEventServer& event) ;
187        void recvAddVariableGroup(CBufferIn& buffer) ;
188        void sendAddAllVariables();
189
190
191        const std::pair<StdString, StdString>& getRefDomainAxisIds();
192
193        const std::vector<CField*>& getFilterSources();
194        void applyFilter(const CArray<double, 1>& dataToSend, CArray<double,1>& dataToReceive);
195        void sendAndReceiveTransformedData(const std::map<int, CArray<int,1>* >& localIndexToSend,
196                                           const CArray<double, 1>& dataSrc,
197                                           const std::map<int,std::vector<std::vector<std::pair<int,double> > > >& localIndexToReceive,
198                                           CArray<double,1>& dataDest);
199      public :
200         /// Propriétés privées ///
201         CVariableGroup* vVariableGroup ;
202
203         CGrid*  grid ;
204         CFile*  file;
205         CField* fieldOut ;
206
207         CDuration freq_operation, freq_write;
208         CDuration freq_operation_srv, freq_write_srv;
209
210         StdSize nstep, nstepMax;
211         bool isEOF;
212         boost::shared_ptr<CDate>    last_Write, last_operation;
213         boost::shared_ptr<CDate>    lastlast_Write_srv,last_Write_srv, last_operation_srv;
214         CDate lastDataRequestedFromServer;
215
216         boost::shared_ptr<func::CFunctor> foperation;
217         map<int,boost::shared_ptr<func::CFunctor> > foperation_srv;
218
219         CArray<double, 1> data;
220         CArray<double, 1> instantData;
221         CArray<double, 1> filteredData;
222         bool hasInstantData ;
223         map<int, CArray<double,1>* > data_srv ;
224         bool isOnceOperation ;
225         bool isFirstOperation ;
226         string content ;
227
228         list< pair<CField *,int> > fieldDependency ;
229         void buildExpression(void) ;
230         void addDependency(CField* field, int slotId) ;
231         void resetSlots(void) ;
232         vector<bool> slots ;
233         CDate* slotUpdateDate ;
234         CFieldNode * expression ;
235         bool hasExpression ;
236         bool slotsFull(void) ;
237         void setSlot(int slotId);
238         bool processed ;
239         bool areAllReferenceSolved;
240         bool areAllExpressionBuilt;
241         std::pair<StdString,StdString> domAxisIds_;
242         bool isReadDataRequestPending;
243         std::vector<CField*> filterSources_;
244         DECLARE_REF_FUNC(Field,field)
245
246      private:
247         //! The output pin of the filter providing the instant data for the field
248         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;
251         //! The source filter for data provided by the client
252         boost::shared_ptr<CSourceFilter> clientSourceFilter;
253         //! The source filter for data provided by the server
254         boost::shared_ptr<CSourceFilter> serverSourceFilter;
255         //! The terminal filter which stores the instant data
256         boost::shared_ptr<CStoreFilter> storeFilter;
257         //! The terminal filter which writes the data to file
258         boost::shared_ptr<CFileWriterFilter> fileWriterFilter;
259   }; // class CField
260
261   ///--------------------------------------------------------------
262
263   // Declare/Define CFieldGroup and CFieldDefinition
264   DECLARE_GROUP(CField);
265
266   ///-----------------------------------------------------------------
267
268   template <>
269      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
270
271   ///-----------------------------------------------------------------
272} // namespace xios
273
274
275#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.