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

Last change on this file since 2426 was 2406, checked in by ymipsl, 22 months ago

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