source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp @ 2011

Last change on this file since 2011 was 2011, checked in by ymipsl, 3 years ago
  • bug fix when createing mask on server side when overlapping grid
  • implement axis interpolation on pressure coordinate
  • big cleaning in transformation

YM

  • 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: 15.3 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 "declare_ref_func.hpp"
16#include "transformation_enum.hpp"
17#include "variable.hpp"
18#include "context_client.hpp"
19#include "pass_through_filter.hpp"
20#include "temporal_filter.hpp"
21#include "model_to_client_source_filter.hpp"
22#include "client_from_client_source_filter.hpp"
23#include "client_from_server_source_filter.hpp"
24#include "client_to_model_store_filter.hpp"
25#include "server_to_client_store_filter.hpp"
26#include "server_from_client_source_filter.hpp"
27#include "file_writer_store_filter.hpp"
28#include "client_to_server_store_filter.hpp"
29#include "file_reader_source_filter.hpp"
30
31
32
33
34
35namespace xios
36{
37
38   /// ////////////////////// Déclarations ////////////////////// ///
39
40   class CFieldGroup;
41   class CFieldAttributes;
42   class CField;
43
44   class CFile;
45   class CCouplerIn ;
46   class CCouplerOut ;
47   class CGrid;
48   class CContext;
49   class CGenericFilter;
50
51   class CGarbageCollector;
52   class COutputPin;
53   class CSourceFilter;
54   class CServerToClientFilter;
55   ///--------------------------------------------------------------
56
57   // Declare/Define CFieldAttribute
58   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
59#  include "field_attribute.conf"
60   END_DECLARE_ATTRIBUTE_MAP(CField)
61
62   class CContextClient ;
63
64   ///--------------------------------------------------------------
65   class CField
66      : public CObjectTemplate<CField>
67      , public CFieldAttributes
68   {
69         /// friend ///
70         friend class CFile;
71
72         /// typedef ///
73         typedef CObjectTemplate<CField>   SuperClass;
74         typedef CFieldAttributes SuperClassAttribute;
75
76      public :   
77         enum EReadField
78         {
79           RF_NODATA, RF_EOF, RF_DATA
80         };
81         
82      public:
83
84         typedef CFieldAttributes RelAttributes;
85         typedef CFieldGroup      RelGroup;
86
87         enum EEventId
88         {
89           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
90           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_GRID_COMPLETED
91         };
92
93         /// Constructeurs ///
94         CField(void);
95         explicit CField(const StdString& id);
96         CField(const CField& field);       // Not implemented yet.
97         CField(const CField* const field); // Not implemented yet.
98
99         /// Accesseurs ///
100
101         CGrid* getRelGrid(void) const;
102         CFile* getRelFile(void) const;
103
104         func::CFunctor::ETimeType getOperationTimeType() const;
105
106      public:
107         template <int N> void getData(CArray<double, N>& _data) const;
108
109         std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
110         // Grid data buffer size for each connection of contextclient
111         std::map<int, StdSize> getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false);
112
113       public:
114          void makeGridAliasForCoupling(void) ;
115       public:
116         bool isActive(bool atCurrentTimestep = false) const;
117         bool hasOutputFile;
118
119         bool wasWritten() const;
120         void setWritten();
121
122         bool getUseCompressedOutput() const;
123         void setUseCompressedOutput();
124
125         /// Traitements ///
126         void solveGridReference(void);
127         void solveServerOperation(void);
128         void solveCheckMaskIndex(bool doSendingIndex);
129         void updateRef(CGrid* grid);
130         void solveGridDomainAxisRef(bool checkAtt);
131         void solveGridDomainAxisBaseRef();
132
133         void checkGridOfEnabledFields();
134         void sendGridOfEnabledFields();
135         void sendGridComponentOfEnabledFields();
136
137         void sendFieldToFileServer(void) ;
138         void sendCloseDefinition(void) ;
139     
140      public:
141         void sendFieldToCouplerOut(void) ;
142      private:
143         bool sendFieldToCouplerOut_done_=false;
144      public:
145
146         void sendFieldToInputFileServer(void) ;
147
148         /// Vérifications ///
149         void checkTimeAttributes(CDuration* freqOp=NULL);
150
151         bool buildWorkflowGraph(CGarbageCollector& gc) ;
152         bool buildWorkflowGraphDone_ = false ;
153
154         size_t getGlobalWrittenSize(void) ;
155         
156         
157         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
158         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
159         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
160
161//         virtual void fromBinary(StdIStream& is);
162
163         /// Destructeur ///
164         virtual ~CField(void);
165
166         /// Accesseurs statiques ///
167         static StdString GetName(void);
168         static StdString GetDefName(void);
169
170         static ENodeType GetType(void);
171
172        template <int N> void setData(const CArray<double, N>& _data);
173        static bool dispatchEvent(CEventServer& event);
174        void sendAllAttributesToServer(CContextClient* client) ; 
175       
176        static void recvUpdateData(CEventServer& event);
177        void receiveUpdateData(CEventServer& event); 
178
179        bool sendReadDataRequest(const CDate& tsDataRequested);
180        bool sendReadDataRequestIfNeeded(void);
181        static void recvReadDataRequest(CEventServer& event);
182        void recvReadDataRequest(void);
183        static void recvReadDataReady(CEventServer& event);
184        void receiveReadDataReady(CEventServer& event);
185        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); // old interface to remove
186        void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ; // old interface to remove
187        void checkForLateDataFromServer(void);
188        void checkForLateDataFromCoupler(void) ;
189
190        void checkIfMustAutoTrigger(void); // ym obsolete
191        void autoTriggerIfNeeded(void); //ym obsolete
192        void triggerLateField(void) ;
193
194        void parse(xml::CXMLNode& node);
195
196        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
197        CVariableGroup* getVirtualVariableGroup(void) const;
198        vector<CVariable*> getAllVariables(void) const;
199        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
200
201        CVariable* addVariable(const string& id = "");
202        CVariableGroup* addVariableGroup(const string& id = "");       
203        void sendAddVariable(const string& id, CContextClient* client);
204        void sendAddVariableGroup(const string& id, CContextClient* client);
205        static void recvAddVariable(CEventServer& event);
206        void recvAddVariable(CBufferIn& buffer);
207        static void recvAddVariableGroup(CEventServer& event);
208        void recvAddVariableGroup(CBufferIn& buffer);       
209        void sendAddAllVariables(CContextClient* client);
210
211        const std::vector<StdString>& getRefDomainAxisIds();
212
213        const string& getExpression(void);
214        bool hasExpression(void) const;
215
216        bool hasGridMask(void) const;
217       
218        void connectToFileServer(CGarbageCollector& gc) ;
219        void connectToCouplerOut(CGarbageCollector& gc) ;
220        void connectToCouplerIn(CGarbageCollector& gc) ;
221        void connectToModelInput(CGarbageCollector& gc) ;
222        void connectToFileWriter(CGarbageCollector& gc) ;
223        void connectToClientInput(CGarbageCollector& gc) ;
224        void connectToServerInput(CGarbageCollector& gc) ;
225        void connectToModelOutput(CGarbageCollector& gc);
226        void connectToFileReader(CGarbageCollector& gc) ;
227        void connectToServerToClient(CGarbageCollector& gc) ;
228
229        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
230                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
231                                        bool bufferForWriting) ;
232        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
233                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
234                                                 bool bufferForWriting) ;
235      private:
236          bool isGridCompleted_ = true ;
237      public:
238          bool isGridCompleted() { return isGridCompleted_ ;} 
239          void setGridCompleted(void) { isGridCompleted_= true; }
240          void unsetGridCompleted(void) { isGridCompleted_ = false ;}
241     
242      public:     
243          void sendGridCompleted(void) ;
244      private:   
245          static void recvGridCompleted(CEventServer& event);
246          void recvGridCompleted(CBufferIn& buffer);
247
248
249      private:
250        std::vector<CGrid*> getGridPath(void) ;
251
252      public:
253         /// Propriétés privées ///
254         CVariableGroup* vVariableGroup;
255
256         CGrid*  grid_=nullptr;
257         CGrid* getGrid(void) { return grid_; } 
258     
259      private:
260         CGrid* sentGrid_=nullptr ;
261      public:
262         CGrid* getSentGrid(void) { return sentGrid_; }   
263
264      public:
265//         CFile*  file;
266         
267         CFile* fileIn_ = nullptr ; //<! pointer to input related file
268         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
269         CFile* getFileIn(void) {return fileIn_;}
270         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
271         void unsetFileIn(void) { fileIn_ = nullptr ;}
272
273         CFile* fileOut_ = nullptr ; //<! pointer to output related file
274         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
275         CFile* getFileOut(void) {return fileOut_;}
276         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
277         void unsetFileOut(void) { fileOut_ = nullptr ;}
278
279         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
280         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
281         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
282         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
283         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
284
285         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
286         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
287         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
288         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
289         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
290
291         bool modelIn_ = false ; //<! field can be received from model == true
292         bool getModelIn(void) { return modelIn_ ;}
293         void setModelIn(void) { modelIn_ = true ;}
294         void unsetModelIn(void) { modelIn_ = false ;}
295         
296         bool modelOut_ = false ; //<! field can be retrieve to model == true
297         bool getModelOut(void) { return modelOut_ ;}
298         void setModelOut(void) { modelOut_ = true ;}
299         void unsetModelOut(void) { modelOut_ = false ;}
300
301         
302         bool written; //<! Was the field written at least once
303         bool mustAutoTrigger;
304
305         string content;
306
307         std::vector<StdString> domAxisScalarIds_;
308         bool useCompressedOutput;
309
310         // Two variables to identify the time_counter meta data written in file, which has no time_counter
311         bool hasTimeInstant;
312         bool hasTimeCentered;
313
314
315         DECLARE_REF_FUNC(Field,field)
316       
317      private:
318         CContextClient* client;
319      public:
320         void setContextClient(CContextClient* newContextClient);
321         CContextClient* getContextClient(void) {return client;}
322
323      private:
324
325         bool areAllReferenceSolved;
326         bool isReferenceSolved;
327         bool isReferenceSolvedAndTransformed;
328         bool isGridChecked;
329
330       private: 
331         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
332         bool workflowEnabled_ = false ;
333       public: 
334         /*! workflowEnabled_ public accessor
335          * \return Value of workflowEnabled_ */
336         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
337 
338
339      private:
340     
341         //! The type of operation attached to the field
342         func::CFunctor::ETimeType operationTimeType;
343
344         //! The output pin of the input filter of the field
345         std::shared_ptr<CPassThroughFilter> inputFilter;
346
347         //! The self temporal data filter
348         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
349         
350         //! The output pin of the filter providing the instant data for the field
351         std::shared_ptr<COutputPin> instantDataFilter;
352      public:
353          std::shared_ptr<COutputPin> getInstantDataFilter(void) { return instantDataFilter;}
354
355      private:
356
357         //! The output pin of the filters providing the result of the field's temporal operation
358         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
359         
360         //! The output pin of the filter providing the instant data for self references
361         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
362
363         //! The source filter for data provided by the client
364//         std::shared_ptr<CSourceFilter> clientSourceFilter; // obsolete to remove
365 
366         //! The source filter for data provided by the model to enter the client workflow
367         std::shared_ptr<CModelToClientSourceFilter> modelToClientSourceFilter_;
368
369         //! The source filter for data provided by the model to enter the client workflow
370         std::shared_ptr<CClientToModelStoreFilter> clientToModelStoreFilter_;
371
372         //! The source filter for data provided by the client that send data to server workflow
373         std::shared_ptr<CServerFromClientSourceFilter> serverFromClientSourceFilter_;
374
375         //! The source filter for data provided by an other to enter the current client workflow (coupling mode)
376         std::shared_ptr<CClientFromClientSourceFilter> clientFromClientSourceFilter_;
377
378         //! The source filter for data provided by server to enter the current client workflow (reading mode)
379         std::shared_ptr<CClientFromServerSourceFilter> clientFromServerSourceFilter_;
380         
381         //! The source filter for data read from file on server side
382         std::shared_ptr<CFileReaderSourceFilter> fileReaderSourceFilter_;
383
384         //! The source filter for data provided by the server
385//         std::shared_ptr<CSourceFilter> serverSourceFilter; // obsolete to remove
386       
387         //! The terminal filter which send data to server for writing
388         std::shared_ptr<CClientToServerStoreFilter> clientToServerStoreFilter_;
389       
390         //! The terminal filter which writes data to file
391         std::shared_ptr<CFileWriterStoreFilter> fileWriterStoreFilter_;
392
393         //! The terminal filter which send data from server to client
394         std::shared_ptr<CServerToClientStoreFilter> serverToClientStoreFilter_;
395
396
397   }; // class CField
398
399   ///--------------------------------------------------------------
400
401   // Declare/Define CFieldGroup and CFieldDefinition
402   DECLARE_GROUP(CField);
403
404   ///-----------------------------------------------------------------
405
406   template <>
407      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
408
409   ///-----------------------------------------------------------------
410} // namespace xios
411
412
413#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.