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

Last change on this file since 2311 was 2311, checked in by ymipsl, 2 years ago

Add possibility to refer to a grid using the field which is attached to, using notation : "fieldId::"

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