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

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

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.

  • 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.5 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
96         /// Mutateur ///
97         void setRelFile(CFile* _file);
98         void incrementNStep(void);
99         void resetNStep() ;
100         void resetNStepMax();
101
102         template <int N> bool updateData(const CArray<double, N>&   data);
103         template <int N> bool updateFilteredData(CArray<double, N>&   data);
104         template<int N>
105         void updateDataWithoutOperation(const CArray<double, N>& _data, CArray<double,1>& updatedData);
106         bool updateDataFromExpression(const CArray<double, 1>&   data);
107         void setDataFromExpression(const CArray<double, 1>& _data) ;
108
109         bool updateDataServer
110               (const CDate & currDate,
111                const std::deque< CArray<double, 1>* > storedClient);
112
113         std::map<int, StdSize> getGridDataSize();
114
115       public :
116         bool isActive(void) const;
117         bool active ;
118         bool hasOutputFile ;
119         bool hasFieldOut ;
120
121         /// Traitements ///
122         void processEnabledField(void) ;
123
124         void solveGridReference(void);
125         void solveOperation(void);
126         void solveCheckMaskIndex(bool doSendingIndex);
127         void solveAllReferenceEnabledField(bool doSending2Sever);
128         void buildAllExpressionEnabledField();
129         void solveGridDomainAxisRef(bool checkAtt);
130         void solveTransformedGrid();
131         CGrid* getGridRefOfBaseReference();
132
133         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
134
135//         virtual void fromBinary(StdIStream & is);
136
137         /// Destructeur ///
138         virtual ~CField(void);
139
140         /// Accesseurs statiques ///
141         static StdString GetName(void);
142         static StdString GetDefName(void);
143
144         static ENodeType GetType(void);
145
146        template <int N> void setData(const CArray<double, N>& _data) ;
147        static bool dispatchEvent(CEventServer& event) ;
148        void sendUpdateData(void) ;
149        void sendUpdateData(const CArray<double,1>& data);
150        static void recvUpdateData(CEventServer& event) ;
151        void recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) ;
152        void writeField(void) ;
153        void sendReadDataRequest(void);
154        bool sendReadDataRequestIfNeeded(void);
155        static void recvReadDataRequest(CEventServer& event);
156        void recvReadDataRequest(void);
157        bool readField(void);
158        static void recvReadDataReady(CEventServer& event);
159        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
160        void outputField(CArray<double,3>& fieldOut) ;
161        void outputField(CArray<double,2>& fieldOut) ;
162        void outputField(CArray<double,1>& fieldOut) ;
163        void inputField(CArray<double,3>& fieldOut);
164        void inputField(CArray<double,2>& fieldOut);
165        void inputField(CArray<double,1>& fieldOut);
166        void scaleFactorAddOffset(double scaleFactor, double addOffset) ;
167        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
168        void parse(xml::CXMLNode & node) ;
169        CArray<double,1>* getInstantData(void)  ;
170
171        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
172        void setVirtualVariableGroup(void);
173        CVariableGroup* getVirtualVariableGroup(void) const;
174        vector<CVariable*> getAllVariables(void) const;
175        virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
176
177        CVariable* addVariable(const string& id="") ;
178        CVariableGroup* addVariableGroup(const string& id="") ;
179        void sendAddVariable(const string& id="") ;
180        void sendAddVariableGroup(const string& id="") ;
181        static void recvAddVariable(CEventServer& event) ;
182        void recvAddVariable(CBufferIn& buffer) ;
183        static void recvAddVariableGroup(CEventServer& event) ;
184        void recvAddVariableGroup(CBufferIn& buffer) ;
185        void sendAddAllVariables();
186
187
188        const std::pair<StdString, StdString>& getRefDomainAxisIds();
189
190        const std::vector<CField*>& getFilterSources();
191        void applyFilter(const CArray<double, 1>& dataToSend, CArray<double,1>& dataToReceive);
192        void sendAndReceiveTransformedData(const std::map<int, CArray<int,1>* >& localIndexToSend,
193                                           const CArray<double, 1>& dataSrc,
194                                           const std::map<int,std::vector<std::vector<std::pair<int,double> > > >& localIndexToReceive,
195                                           CArray<double,1>& dataDest);
196      public :
197         /// Propriétés privées ///
198         CVariableGroup* vVariableGroup ;
199
200         CGrid*  grid ;
201         CFile*  file;
202         CField* fieldOut ;
203
204         CDuration freq_operation, freq_write;
205         CDuration freq_operation_srv, freq_write_srv;
206
207         StdSize nstep, nstepMax;
208         bool isEOF;
209         boost::shared_ptr<CDate>    last_Write, last_operation;
210         boost::shared_ptr<CDate>    lastlast_Write_srv,last_Write_srv, last_operation_srv;
211         CDate lastDataRequestedFromServer;
212
213         boost::shared_ptr<func::CFunctor> foperation;
214         map<int,boost::shared_ptr<func::CFunctor> > foperation_srv;
215
216         CArray<double, 1> data;
217         CArray<double, 1> instantData;
218         CArray<double, 1> filteredData;
219         bool hasInstantData ;
220         map<int, CArray<double,1>* > data_srv ;
221         bool isOnceOperation ;
222         bool isFirstOperation ;
223         string content ;
224
225         list< pair<CField *,int> > fieldDependency ;
226         void buildExpression(void) ;
227         void addDependency(CField* field, int slotId) ;
228         void resetSlots(void) ;
229         vector<bool> slots ;
230         CDate* slotUpdateDate ;
231         CFieldNode * expression ;
232         bool hasExpression ;
233         bool slotsFull(void) ;
234         void setSlot(int slotId);
235         bool processed ;
236         bool areAllReferenceSolved;
237         bool areAllExpressionBuilt;
238         std::pair<StdString,StdString> domAxisIds_;
239         bool isReadDataRequestPending;
240         std::vector<CField*> filterSources_;
241         DECLARE_REF_FUNC(Field,field)
242
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;
254   }; // class CField
255
256   ///--------------------------------------------------------------
257
258   // Declare/Define CFieldGroup and CFieldDefinition
259   DECLARE_GROUP(CField);
260
261   ///-----------------------------------------------------------------
262
263   template <>
264      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
265
266   ///-----------------------------------------------------------------
267} // namespace xios
268
269
270#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.