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

Last change on this file since 2182 was 2182, checked in by ymipsl, 3 years ago

remove unused method.
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.4 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         // evaluation the size of the buffer for the field
114         bool evaluateBufferSize(map<CContextClient*,map<int,size_t>>& evaluateBuffer, bool isOptPerformance) ;
115       public:
116          void makeGridAliasForCoupling(void) ;
117       public:
118         bool isActive(bool atCurrentTimestep = false) const;
119         bool hasOutputFile;
120
121         bool wasWritten() const;
122         void setWritten();
123
124         bool getUseCompressedOutput() const;
125         void setUseCompressedOutput();
126
127         /// Traitements ///
128         void solveGridReference(void);
129         void solveServerOperation(void);
130         void solveCheckMaskIndex(bool doSendingIndex);
131         void solveGridDomainAxisRef(bool checkAtt);
132         void solveGridDomainAxisBaseRef();
133
134         void checkGridOfEnabledFields();
135         void sendGridOfEnabledFields();
136         void sendGridComponentOfEnabledFields();
137
138         void sendFieldToFileServer(void) ;
139         void sendCloseDefinition(void) ;
140     
141      public:
142         void sendFieldToCouplerOut(void) ;
143      private:
144         bool sendFieldToCouplerOut_done_=false;
145      public:
146
147         void sendFieldToInputFileServer(void) ;
148
149         /// Vérifications ///
150         void checkTimeAttributes(CDuration* freqOp=NULL);
151
152         bool buildWorkflowGraph(CGarbageCollector& gc) ;
153         bool buildWorkflowGraphDone_ = false ;
154
155         size_t getGlobalWrittenSize(void) ;
156         
157         
158         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
159         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
160         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
161
162//         virtual void fromBinary(StdIStream& is);
163
164         /// Destructeur ///
165         virtual ~CField(void);
166
167         /// Accesseurs statiques ///
168         static StdString GetName(void);
169         static StdString GetDefName(void);
170
171         static ENodeType GetType(void);
172
173        template <int N> void setData(const CArray<double, N>& _data);
174        static bool dispatchEvent(CEventServer& event);
175        void sendAllAttributesToServer(CContextClient* client) ; 
176       
177        static void recvUpdateData(CEventServer& event);
178        void receiveUpdateData(CEventServer& event); 
179
180        bool sendReadDataRequest(const CDate& tsDataRequested);
181        bool sendReadDataRequestIfNeeded(void);
182        static void recvReadDataRequest(CEventServer& event);
183        void recvReadDataRequest(void);
184        static void recvReadDataReady(CEventServer& event);
185        void receiveReadDataReady(CEventServer& event);
186        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); // old interface to remove
187        void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ; // old interface to remove
188        void checkForLateDataFromServer(void);
189        void checkForLateDataFromCoupler(void) ;
190
191        void checkIfMustAutoTrigger(void); // ym obsolete
192        void autoTriggerIfNeeded(void); //ym obsolete
193        void triggerLateField(void) ;
194
195        void parse(xml::CXMLNode& node);
196
197        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
198        CVariableGroup* getVirtualVariableGroup(void) const;
199        vector<CVariable*> getAllVariables(void) const;
200        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
201
202        CVariable* addVariable(const string& id = "");
203        CVariableGroup* addVariableGroup(const string& id = "");       
204        void sendAddVariable(const string& id, CContextClient* client);
205        void sendAddVariableGroup(const string& id, CContextClient* client);
206        static void recvAddVariable(CEventServer& event);
207        void recvAddVariable(CBufferIn& buffer);
208        static void recvAddVariableGroup(CEventServer& event);
209        void recvAddVariableGroup(CBufferIn& buffer);       
210        void sendAddAllVariables(CContextClient* client);
211
212        const std::vector<StdString>& getRefDomainAxisIds();
213
214        const string& getExpression(void);
215        bool hasExpression(void) const;
216
217        bool hasGridMask(void) const;
218       
219        void connectToFileServer(CGarbageCollector& gc) ;
220        void connectToCouplerOut(CGarbageCollector& gc) ;
221        void connectToCouplerIn(CGarbageCollector& gc) ;
222        void connectToModelInput(CGarbageCollector& gc) ;
223        void connectToFileWriter(CGarbageCollector& gc) ;
224        void connectToClientInput(CGarbageCollector& gc) ;
225        void connectToServerInput(CGarbageCollector& gc) ;
226        void connectToModelOutput(CGarbageCollector& gc);
227        void connectToFileReader(CGarbageCollector& gc) ;
228        void connectToServerToClient(CGarbageCollector& gc) ;
229
230        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
231                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
232                                        bool bufferForWriting) ;
233        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
234                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
235                                                 bool bufferForWriting) ;
236      private:
237          bool isGridCompleted_ = true ;
238      public:
239          bool isGridCompleted()  ; 
240          void setGridCompleted(void) { isGridCompleted_= true; }
241          void unsetGridCompleted(void) { isGridCompleted_ = false ;}
242     
243      public:     
244          void sendGridCompleted(void) ;
245      private:   
246          static void recvGridCompleted(CEventServer& event);
247          void recvGridCompleted(CBufferIn& buffer);
248
249
250      private:
251        std::vector<CGrid*> getGridPath(void) ;
252
253      public:
254         /// Propriétés privées ///
255         CVariableGroup* vVariableGroup;
256
257         CGrid*  grid_=nullptr;
258         CGrid* getGrid(void) { return grid_; } 
259     
260      private:
261         CGrid* sentGrid_=nullptr ;
262      public:
263         CGrid* getSentGrid(void) { return sentGrid_; }   
264
265      public:
266//         CFile*  file;
267         
268         CFile* fileIn_ = nullptr ; //<! pointer to input related file
269         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
270         CFile* getFileIn(void) {return fileIn_;}
271         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
272         void unsetFileIn(void) { fileIn_ = nullptr ;}
273
274         CFile* fileOut_ = nullptr ; //<! pointer to output related file
275         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
276         CFile* getFileOut(void) {return fileOut_;}
277         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
278         void unsetFileOut(void) { fileOut_ = nullptr ;}
279
280         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
281         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
282         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
283         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
284         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
285
286         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
287         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
288         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
289         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
290         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
291
292         bool modelIn_ = false ; //<! field can be received from model == true
293         bool getModelIn(void) { return modelIn_ ;}
294         void setModelIn(void) { modelIn_ = true ;}
295         void unsetModelIn(void) { modelIn_ = false ;}
296         
297         bool modelOut_ = false ; //<! field can be retrieve to model == true
298         bool getModelOut(void) { return modelOut_ ;}
299         void setModelOut(void) { modelOut_ = true ;}
300         void unsetModelOut(void) { modelOut_ = false ;}
301
302         
303         bool written; //<! Was the field written at least once
304         bool mustAutoTrigger;
305
306         string content;
307
308         std::vector<StdString> domAxisScalarIds_;
309         bool useCompressedOutput;
310
311         // Two variables to identify the time_counter meta data written in file, which has no time_counter
312         bool hasTimeInstant;
313         bool hasTimeCentered;
314
315
316         DECLARE_REF_FUNC(Field,field)
317       
318      private:
319         CContextClient* client;
320      public:
321         void setContextClient(CContextClient* newContextClient);
322         CContextClient* getContextClient(void) {return client;}
323
324      private:
325
326         bool areAllReferenceSolved;
327         bool isReferenceSolved;
328         bool isReferenceSolvedAndTransformed;
329         bool isGridChecked;
330
331       private: 
332         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
333         bool workflowEnabled_ = false ;
334       public: 
335         /*! workflowEnabled_ public accessor
336          * \return Value of workflowEnabled_ */
337         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
338 
339
340      private:
341     
342         //! The type of operation attached to the field
343         func::CFunctor::ETimeType operationTimeType;
344
345         //! The output pin of the input filter of the field
346         std::shared_ptr<CPassThroughFilter> inputFilter;
347
348         //! The self temporal data filter
349         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
350         
351         //! The output pin of the filter providing the instant data for the field
352         std::shared_ptr<COutputPin> instantDataFilter;
353      public:
354          std::shared_ptr<COutputPin> getInstantDataFilter(void) { return instantDataFilter;}
355
356      private:
357
358         //! The output pin of the filters providing the result of the field's temporal operation
359         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
360         
361         //! The output pin of the filter providing the instant data for self references
362         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
363
364         //! The source filter for data provided by the client
365//         std::shared_ptr<CSourceFilter> clientSourceFilter; // obsolete to remove
366 
367         //! The source filter for data provided by the model to enter the client workflow
368         std::shared_ptr<CModelToClientSourceFilter> modelToClientSourceFilter_;
369
370         //! The source filter for data provided by the model to enter the client workflow
371         std::shared_ptr<CClientToModelStoreFilter> clientToModelStoreFilter_;
372
373         //! The source filter for data provided by the client that send data to server workflow
374         std::shared_ptr<CServerFromClientSourceFilter> serverFromClientSourceFilter_;
375
376         //! The source filter for data provided by an other to enter the current client workflow (coupling mode)
377         std::shared_ptr<CClientFromClientSourceFilter> clientFromClientSourceFilter_;
378
379         //! The source filter for data provided by server to enter the current client workflow (reading mode)
380         std::shared_ptr<CClientFromServerSourceFilter> clientFromServerSourceFilter_;
381         
382         //! The source filter for data read from file on server side
383         std::shared_ptr<CFileReaderSourceFilter> fileReaderSourceFilter_;
384
385         //! The source filter for data provided by the server
386//         std::shared_ptr<CSourceFilter> serverSourceFilter; // obsolete to remove
387       
388         //! The terminal filter which send data to server for writing
389         std::shared_ptr<CClientToServerStoreFilter> clientToServerStoreFilter_;
390       
391         //! The terminal filter which writes data to file
392         std::shared_ptr<CFileWriterStoreFilter> fileWriterStoreFilter_;
393
394         //! The terminal filter which send data from server to client
395         std::shared_ptr<CServerToClientStoreFilter> serverToClientStoreFilter_;
396
397
398   }; // class CField
399
400   ///--------------------------------------------------------------
401
402   // Declare/Define CFieldGroup and CFieldDefinition
403   DECLARE_GROUP(CField);
404
405   ///-----------------------------------------------------------------
406
407   template <>
408      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
409
410   ///-----------------------------------------------------------------
411} // namespace xios
412
413
414#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.