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

Last change on this file since 2325 was 2318, checked in by jderouillat, 2 years ago

Add a checksum ability in xios_send/recv_field, enabled with info_level > 100.

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