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

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

Big cleaning on XIOS coupling branch
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.6 KB
RevLine 
[591]1#ifndef __XIOS_CField__
2#define __XIOS_CField__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[219]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"
[231]12#include "calendar_util.hpp"
[369]13#include "array_new.hpp"
14#include "attribute_array.hpp"
[540]15#include "declare_ref_func.hpp"
[619]16#include "transformation_enum.hpp"
[646]17#include "variable.hpp"
[1021]18#include "context_client.hpp"
[1869]19#include "pass_through_filter.hpp"
20#include "temporal_filter.hpp"
[1930]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"
[1934]25#include "server_to_client_store_filter.hpp"
[1935]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"
[219]30
[300]31
[1869]32
[509]33
[1935]34
[1930]35namespace xios
36{
37
[219]38   /// ////////////////////// Déclarations ////////////////////// ///
39
40   class CFieldGroup;
41   class CFieldAttributes;
42   class CField;
43
44   class CFile;
[1869]45   class CCouplerIn ;
46   class CCouplerOut ;
[219]47   class CGrid;
[640]48   class CContext;
[619]49   class CGenericFilter;
50
[640]51   class CGarbageCollector;
52   class COutputPin;
53   class CSourceFilter;
[1883]54   class CServerToClientFilter;
[219]55   ///--------------------------------------------------------------
56
57   // Declare/Define CFieldAttribute
58   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
59#  include "field_attribute.conf"
60   END_DECLARE_ATTRIBUTE_MAP(CField)
61
[1853]62   class CContextClient ;
[1869]63
[219]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
[1930]76      public :   
[1232]77         enum EReadField
78         {
79           RF_NODATA, RF_EOF, RF_DATA
80         };
81         
[707]82      public:
[219]83
84         typedef CFieldAttributes RelAttributes;
85         typedef CFieldGroup      RelGroup;
86
[300]87         enum EEventId
88         {
[598]89           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
[1875]90           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_GRID_COMPLETED
[651]91         };
[509]92
[219]93         /// Constructeurs ///
94         CField(void);
[651]95         explicit CField(const StdString& id);
96         CField(const CField& field);       // Not implemented yet.
97         CField(const CField* const field); // Not implemented yet.
[219]98
99         /// Accesseurs ///
100
[651]101         CGrid* getRelGrid(void) const;
102         CFile* getRelFile(void) const;
[219]103
[645]104         func::CFunctor::ETimeType getOperationTimeType() const;
105
[707]106      public:
[593]107         template <int N> void getData(CArray<double, N>& _data) const;
[219]108
[1542]109         std::shared_ptr<COutputPin> getInstantDataFilter();
[219]110
[1330]111         std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
112         // Grid data buffer size for each connection of contextclient
113         std::map<int, StdSize> getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false);
[509]114
[707]115       public:
[1875]116          void makeGridAliasForCoupling(void) ;
117       public:
[1158]118         bool isActive(bool atCurrentTimestep = false) const;
[651]119         bool hasOutputFile;
[219]120
[707]121         bool wasWritten() const;
122         void setWritten();
123
[676]124         bool getUseCompressedOutput() const;
125         void setUseCompressedOutput();
126
[219]127         /// Traitements ///
128         void solveGridReference(void);
[645]129         void solveServerOperation(void);
[509]130         void solveCheckMaskIndex(bool doSendingIndex);
[823]131         void solveAllReferenceEnabledField(bool doSending2Server);
[1784]132         void solveOnlyReferenceEnabledField(void);
[823]133         void generateNewTransformationGridDest();
134         void updateRef(CGrid* grid);
135         void buildGridTransformationGraph();
[509]136         void solveGridDomainAxisRef(bool checkAtt);
[619]137         void solveTransformedGrid();
[687]138         void solveGenerateGrid();
[775]139         void solveGridDomainAxisBaseRef();
[219]140
[1129]141         void solveAllEnabledFieldsAndTransform();
[1024]142         void checkGridOfEnabledFields();
143         void sendGridOfEnabledFields();
[1278]144         void sendGridComponentOfEnabledFields();
[1024]145
[1870]146         void sendFieldToFileServer(void) ;
[1875]147         void sendCloseDefinition(void) ;
148     
149      public:
150         void sendFieldToCouplerOut(void) ;
151      private:
152         bool sendFieldToCouplerOut_done_=false;
153      public:
154
[1872]155         void sendFieldToInputFileServer(void) ;
[1870]156
[1278]157         /// Vérifications ///
[1405]158         void checkTimeAttributes(CDuration* freqOp=NULL);
[1278]159
[640]160         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
[1869]161
162         bool buildWorkflowGraph(CGarbageCollector& gc) ;
163         bool buildWorkflowGraphDone_ = false ;
164
[1215]165         size_t getGlobalWrittenSize(void) ;
166         
167         
[1542]168         std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
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);
[640]172
[651]173//         virtual void fromBinary(StdIStream& is);
[219]174
175         /// Destructeur ///
176         virtual ~CField(void);
177
178         /// Accesseurs statiques ///
179         static StdString GetName(void);
180         static StdString GetDefName(void);
[509]181
[219]182         static ENodeType GetType(void);
[509]183
[651]184        template <int N> void setData(const CArray<double, N>& _data);
185        static bool dispatchEvent(CEventServer& event);
[1524]186        void sendAllAttributesToServer(CContextClient* client) ; 
[1962]187       
[651]188        static void recvUpdateData(CEventServer& event);
[1930]189        void receiveUpdateData(CEventServer& event); 
[1962]190
[1934]191        bool sendReadDataRequest(const CDate& tsDataRequested);
[598]192        bool sendReadDataRequestIfNeeded(void);
193        static void recvReadDataRequest(CEventServer& event);
[1930]194        void recvReadDataRequest(void);
[598]195        static void recvReadDataReady(CEventServer& event);
[1930]196        void receiveReadDataReady(CEventServer& event);
197        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); // old interface to remove
198        void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ; // old interface to remove
[1318]199        void checkForLateDataFromServer(void);
[1875]200        void checkForLateDataFromCoupler(void) ;
201
202        void checkIfMustAutoTrigger(void); // ym obsolete
203        void autoTriggerIfNeeded(void); //ym obsolete
204        void triggerLateField(void) ;
205
[651]206        void parse(xml::CXMLNode& node);
[509]207
[472]208        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
209        CVariableGroup* getVirtualVariableGroup(void) const;
210        vector<CVariable*> getAllVariables(void) const;
[651]211        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
[509]212
[651]213        CVariable* addVariable(const string& id = "");
[1144]214        CVariableGroup* addVariableGroup(const string& id = "");       
[1021]215        void sendAddVariable(const string& id, CContextClient* client);
[1144]216        void sendAddVariableGroup(const string& id, CContextClient* client);
[651]217        static void recvAddVariable(CEventServer& event);
218        void recvAddVariable(CBufferIn& buffer);
219        static void recvAddVariableGroup(CEventServer& event);
[1144]220        void recvAddVariableGroup(CBufferIn& buffer);       
[1021]221        void sendAddAllVariables(CContextClient* client);
[509]222
[887]223        const std::vector<StdString>& getRefDomainAxisIds();
[619]224
[1021]225        const string& getExpression(void);
226        bool hasExpression(void) const;
227
[1637]228        bool hasGridMask(void) const;
[1869]229        CGrid* getGrid(void) { return grid_; } 
[1637]230
[1869]231        void connectToFileServer(CGarbageCollector& gc) ;
[1875]232        void connectToCouplerOut(CGarbageCollector& gc) ;
233        void connectToCouplerIn(CGarbageCollector& gc) ;
[1870]234        void connectToModelInput(CGarbageCollector& gc) ;
[1871]235        void connectToFileWriter(CGarbageCollector& gc) ;
236        void connectToClientInput(CGarbageCollector& gc) ;
237        void connectToServerInput(CGarbageCollector& gc) ;
238        void connectToModelOutput(CGarbageCollector& gc);
[1883]239        void connectToFileReader(CGarbageCollector& gc) ;
240        void connectToServerToClient(CGarbageCollector& gc) ;
[1871]241
[1870]242        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
243                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
244                                        bool bufferForWriting) ;
245        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
246                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
247                                                 bool bufferForWriting) ;
[1869]248      private:
[1875]249          bool isGridCompleted_ = true ;
250      public:
251          bool isGridCompleted() { return isGridCompleted_ ;} 
252          void setGridCompleted(void) { isGridCompleted_= true; }
253          void unsetGridCompleted(void) { isGridCompleted_ = false ;}
254     
255      public:     
256          void sendGridCompleted(void) ;
257      private:   
258          static void recvGridCompleted(CEventServer& event);
259          void recvGridCompleted(CBufferIn& buffer);
260
261
262      private:
[1869]263        std::vector<CGrid*> getGridPath(void) ;
264
[707]265      public:
[219]266         /// Propriétés privées ///
[651]267         CVariableGroup* vVariableGroup;
[509]268
[1869]269         CGrid*  grid_=nullptr;
[1872]270//         CFile*  file;
[1869]271         
272         CFile* fileIn_ = nullptr ; //<! pointer to input related file
[1872]273         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
[1869]274         CFile* getFileIn(void) {return fileIn_;}
275         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
276         void unsetFileIn(void) { fileIn_ = nullptr ;}
[219]277
[1869]278         CFile* fileOut_ = nullptr ; //<! pointer to output related file
[1872]279         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
[1869]280         CFile* getFileOut(void) {return fileOut_;}
281         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
282         void unsetFileOut(void) { fileOut_ = nullptr ;}
283
284         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
[1872]285         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
[1869]286         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
287         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
288         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
289
290         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
[1872]291         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
[1869]292         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
293         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
294         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
295
296         bool modelIn_ = false ; //<! field can be received from model == true
297         bool getModelIn(void) { return modelIn_ ;}
298         void setModelIn(void) { modelIn_ = true ;}
299         void unsetModelIn(void) { modelIn_ = false ;}
300         
301         bool modelOut_ = false ; //<! field can be retrieve to model == true
302         bool getModelOut(void) { return modelOut_ ;}
303         void setModelOut(void) { modelOut_ = true ;}
304         void unsetModelOut(void) { modelOut_ = false ;}
305
[1962]306         
[707]307         bool written; //<! Was the field written at least once
[1358]308         bool mustAutoTrigger;
[509]309
[651]310         string content;
[509]311
[887]312         std::vector<StdString> domAxisScalarIds_;
[676]313         bool useCompressedOutput;
[645]314
[1021]315         // Two variables to identify the time_counter meta data written in file, which has no time_counter
316         bool hasTimeInstant;
317         bool hasTimeCentered;
318
[1129]319
[540]320         DECLARE_REF_FUNC(Field,field)
[1869]321       
[640]322      private:
[1294]323         CContextClient* client;
[1875]324      public:
325         void setContextClient(CContextClient* newContextClient);
326         CContextClient* getContextClient(void) {return client;}
[1294]327
[1875]328      private:
329
[1129]330         bool areAllReferenceSolved;
331         bool isReferenceSolved;
332         bool isReferenceSolvedAndTransformed;
[1417]333         bool isGridChecked;
[1129]334
[1869]335       private: 
336         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
337         bool workflowEnabled_ = false ;
338       public: 
339         /*! workflowEnabled_ public accessor
340          * \return Value of workflowEnabled_ */
341         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
342 
343
[1129]344      private:
[1869]345     
[645]346         //! The type of operation attached to the field
347         func::CFunctor::ETimeType operationTimeType;
348
[1869]349         //! The output pin of the input filter of the field
350         std::shared_ptr<CPassThroughFilter> inputFilter;
351
352         //! The self temporal data filter
353         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
354         
[640]355         //! The output pin of the filter providing the instant data for the field
[1542]356         std::shared_ptr<COutputPin> instantDataFilter;
[1869]357         
[643]358         //! The output pin of the filters providing the result of the field's temporal operation
[1542]359         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
[1869]360         
[737]361         //! The output pin of the filter providing the instant data for self references
[1869]362         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
363
[640]364         //! The source filter for data provided by the client
[1935]365//         std::shared_ptr<CSourceFilter> clientSourceFilter; // obsolete to remove
[1930]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_;
[1869]381         
[1930]382         //! The source filter for data read from file on server side
383         std::shared_ptr<CFileReaderSourceFilter> fileReaderSourceFilter_;
384
[640]385         //! The source filter for data provided by the server
[1935]386//         std::shared_ptr<CSourceFilter> serverSourceFilter; // obsolete to remove
[1869]387       
[1935]388         //! The terminal filter which send data to server for writing
389         std::shared_ptr<CClientToServerStoreFilter> clientToServerStoreFilter_;
[1869]390       
[1024]391         //! The terminal filter which writes data to file
[1935]392         std::shared_ptr<CFileWriterStoreFilter> fileWriterStoreFilter_;
[1883]393
[1930]394         //! The terminal filter which send data from server to client
[1934]395         std::shared_ptr<CServerToClientStoreFilter> serverToClientStoreFilter_;
[1883]396
397
[219]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   ///-----------------------------------------------------------------
[335]411} // namespace xios
[219]412
413
[591]414#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.