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

Last change on this file since 2507 was 2507, checked in by ymipsl, 13 months ago

Merging XIOS3_ATTACHED branch into XIOS3 trunk.

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