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

Last change on this file since 1883 was 1883, checked in by ymipsl, 4 years ago

XIOS coupling branch
Adopt infrastructure based on filter for reading data on server side and sending it to the client, in a similar way on what is done for other case.

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