source: XIOS3/trunk/src/node/field.hpp @ 2406

Last change on this file since 2406 was 2406, checked in by ymipsl, 21 months ago

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