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

Last change on this file since 2507 was 2507, checked in by ymipsl, 13 months ago

Merging XIOS3_ATTACHED branch into XIOS3 trunk.

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.3 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"
[2507]30#include "client_online_reader_filter.hpp"
31#include "client_online_writer_filter.hpp"
[219]32
[300]33
[1869]34
[509]35
[1935]36
[1930]37namespace xios
38{
39
[219]40   /// ////////////////////// Déclarations ////////////////////// ///
41
42   class CFieldGroup;
43   class CFieldAttributes;
44   class CField;
45
46   class CFile;
[1869]47   class CCouplerIn ;
48   class CCouplerOut ;
[219]49   class CGrid;
[640]50   class CContext;
[619]51   class CGenericFilter;
[2203]52   class CDomain ;
53   class CAxis ;
54   class CScalar ;
[619]55
[640]56   class CGarbageCollector;
57   class COutputPin;
58   class CSourceFilter;
[1883]59   class CServerToClientFilter;
[2507]60   class CGridRedistributeFilter;
[219]61   ///--------------------------------------------------------------
62
63   // Declare/Define CFieldAttribute
64   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
65#  include "field_attribute.conf"
66   END_DECLARE_ATTRIBUTE_MAP(CField)
67
[1853]68   class CContextClient ;
[1869]69
[219]70   ///--------------------------------------------------------------
71   class CField
72      : public CObjectTemplate<CField>
73      , public CFieldAttributes
74   {
75         /// friend ///
76         friend class CFile;
77
78         /// typedef ///
79         typedef CObjectTemplate<CField>   SuperClass;
80         typedef CFieldAttributes SuperClassAttribute;
81
[1930]82      public :   
[1232]83         enum EReadField
84         {
85           RF_NODATA, RF_EOF, RF_DATA
86         };
87         
[707]88      public:
[219]89
90         typedef CFieldAttributes RelAttributes;
91         typedef CFieldGroup      RelGroup;
92
[300]93         enum EEventId
94         {
[2326]95           EVENT_ID_COLLECTIVE=100,
[598]96           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
[2326]97           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_GRID_COMPLETED,
98           EVENT_ID_NO_COLLECTIVE=1000,
[651]99         };
[509]100
[219]101         /// Constructeurs ///
102         CField(void);
[651]103         explicit CField(const StdString& id);
104         CField(const CField& field);       // Not implemented yet.
105         CField(const CField* const field); // Not implemented yet.
[219]106
107         /// Accesseurs ///
108
[651]109         CGrid* getRelGrid(void) const;
110         CFile* getRelFile(void) const;
[2311]111         CGrid* getAssociatedGrid(void) const ;
[2206]112         CDomain* getAssociatedDomain(const std::string& domainId, bool noError=false) const;
113         CAxis*   getAssociatedAxis(const std::string& axisId, bool noError=false) const;
114         CScalar* getAssociatedScalar(const std::string& scalarId, bool noError=false) const;
[219]115
[645]116         func::CFunctor::ETimeType getOperationTimeType() const;
117
[707]118      public:
[593]119         template <int N> void getData(CArray<double, N>& _data) const;
[219]120
[1330]121         std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
122         // Grid data buffer size for each connection of contextclient
123         std::map<int, StdSize> getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false);
[2130]124         
125         // evaluation the size of the buffer for the field
126         bool evaluateBufferSize(map<CContextClient*,map<int,size_t>>& evaluateBuffer, bool isOptPerformance) ;
[707]127       public:
[1875]128          void makeGridAliasForCoupling(void) ;
129       public:
[1158]130         bool isActive(bool atCurrentTimestep = false) const;
[651]131         bool hasOutputFile;
[219]132
[707]133         bool wasWritten() const;
134         void setWritten();
135
[676]136         bool getUseCompressedOutput() const;
137         void setUseCompressedOutput();
138
[219]139         /// Traitements ///
140         void solveGridReference(void);
[645]141         void solveServerOperation(void);
[509]142         void solveCheckMaskIndex(bool doSendingIndex);
143         void solveGridDomainAxisRef(bool checkAtt);
[775]144         void solveGridDomainAxisBaseRef();
[219]145
[1024]146         void checkGridOfEnabledFields();
147         void sendGridOfEnabledFields();
[1278]148         void sendGridComponentOfEnabledFields();
[1024]149
[1870]150         void sendFieldToFileServer(void) ;
[1875]151     
152      public:
153         void sendFieldToCouplerOut(void) ;
154      private:
155         bool sendFieldToCouplerOut_done_=false;
156      public:
157
[1872]158         void sendFieldToInputFileServer(void) ;
[1870]159
[1278]160         /// Vérifications ///
[1405]161         void checkTimeAttributes(CDuration* freqOp=NULL);
[1278]162
[1869]163         bool buildWorkflowGraph(CGarbageCollector& gc) ;
164         bool buildWorkflowGraphDone_ = false ;
165
[1215]166         size_t getGlobalWrittenSize(void) ;
167         
168         
[1542]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);
[2318]185        void checkSumLike( const double* array, int numElements, bool output ) const;
[651]186        static bool dispatchEvent(CEventServer& event);
[2230]187        static bool isCollectiveEvent(CEventServer& event);
[1524]188        void sendAllAttributesToServer(CContextClient* client) ; 
[1962]189       
[651]190        static void recvUpdateData(CEventServer& event);
[1930]191        void receiveUpdateData(CEventServer& event); 
[1962]192
[1934]193        bool sendReadDataRequest(const CDate& tsDataRequested);
[598]194        bool sendReadDataRequestIfNeeded(void);
195        static void recvReadDataRequest(CEventServer& event);
[1930]196        void recvReadDataRequest(void);
[598]197        static void recvReadDataReady(CEventServer& event);
[1930]198        void receiveReadDataReady(CEventServer& event);
199        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); // old interface to remove
200        void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ; // old interface to remove
[1318]201        void checkForLateDataFromServer(void);
[1875]202        void checkForLateDataFromCoupler(void) ;
203
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;
[1984]229       
[1869]230        void connectToFileServer(CGarbageCollector& gc) ;
[1875]231        void connectToCouplerOut(CGarbageCollector& gc) ;
232        void connectToCouplerIn(CGarbageCollector& gc) ;
[1870]233        void connectToModelInput(CGarbageCollector& gc) ;
[1871]234        void connectToFileWriter(CGarbageCollector& gc) ;
235        void connectToClientInput(CGarbageCollector& gc) ;
236        void connectToServerInput(CGarbageCollector& gc) ;
237        void connectToModelOutput(CGarbageCollector& gc);
[1883]238        void connectToFileReader(CGarbageCollector& gc) ;
239        void connectToServerToClient(CGarbageCollector& gc) ;
[2507]240        void connectToOnlineWriter(CGarbageCollector& gc) ;
241        void connectToOnlineReader(CGarbageCollector& gc) ;
[1871]242
[1870]243        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
244                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
245                                        bool bufferForWriting) ;
246        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
247                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
248                                                 bool bufferForWriting) ;
[1869]249      private:
[1875]250          bool isGridCompleted_ = true ;
251      public:
[2022]252          bool isGridCompleted()  ; 
[1875]253          void setGridCompleted(void) { isGridCompleted_= true; }
254          void unsetGridCompleted(void) { isGridCompleted_ = false ;}
255     
256      public:     
257          void sendGridCompleted(void) ;
258      private:   
259          static void recvGridCompleted(CEventServer& event);
260          void recvGridCompleted(CBufferIn& buffer);
261
262
263      private:
[1869]264        std::vector<CGrid*> getGridPath(void) ;
265
[707]266      public:
[219]267         /// Propriétés privées ///
[651]268         CVariableGroup* vVariableGroup;
[509]269
[1869]270         CGrid*  grid_=nullptr;
[1984]271         CGrid* getGrid(void) { return grid_; } 
[2507]272         void setGrid(CGrid* grid) { grid_=grid; } 
[1984]273     
274      private:
275         CGrid* sentGrid_=nullptr ;
276      public:
277         CGrid* getSentGrid(void) { return sentGrid_; }   
278
279      public:
[1872]280//         CFile*  file;
[1869]281         
282         CFile* fileIn_ = nullptr ; //<! pointer to input related file
[1872]283         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
[1869]284         CFile* getFileIn(void) {return fileIn_;}
285         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
286         void unsetFileIn(void) { fileIn_ = nullptr ;}
[219]287
[1869]288         CFile* fileOut_ = nullptr ; //<! pointer to output related file
[1872]289         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
[1869]290         CFile* getFileOut(void) {return fileOut_;}
291         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
292         void unsetFileOut(void) { fileOut_ = nullptr ;}
293
294         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
[1872]295         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
[1869]296         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
297         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
298         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
299
300         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
[1872]301         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
[1869]302         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
303         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
304         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
305
306         bool modelIn_ = false ; //<! field can be received from model == true
307         bool getModelIn(void) { return modelIn_ ;}
308         void setModelIn(void) { modelIn_ = true ;}
309         void unsetModelIn(void) { modelIn_ = false ;}
310         
311         bool modelOut_ = false ; //<! field can be retrieve to model == true
312         bool getModelOut(void) { return modelOut_ ;}
313         void setModelOut(void) { modelOut_ = true ;}
314         void unsetModelOut(void) { modelOut_ = false ;}
315
[1962]316         
[707]317         bool written; //<! Was the field written at least once
[1358]318         bool mustAutoTrigger;
[509]319
[651]320         string content;
[509]321
[887]322         std::vector<StdString> domAxisScalarIds_;
[676]323         bool useCompressedOutput;
[645]324
[1021]325         // Two variables to identify the time_counter meta data written in file, which has no time_counter
326         bool hasTimeInstant;
327         bool hasTimeCentered;
328
[1129]329
[540]330         DECLARE_REF_FUNC(Field,field)
[1869]331       
[640]332      private:
[2507]333         CContextClient* client_;
[1875]334      public:
335         void setContextClient(CContextClient* newContextClient);
[2507]336         CContextClient* getContextClient(void) {return client_;}
[1294]337
[1875]338      private:
339
[1129]340         bool areAllReferenceSolved;
341         bool isReferenceSolved;
342         bool isReferenceSolvedAndTransformed;
[1417]343         bool isGridChecked;
[1129]344
[1869]345       private: 
346         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
347         bool workflowEnabled_ = false ;
348       public: 
349         /*! workflowEnabled_ public accessor
350          * \return Value of workflowEnabled_ */
351         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
352 
353
[1129]354      private:
[1869]355     
[645]356         //! The type of operation attached to the field
357         func::CFunctor::ETimeType operationTimeType;
358
[1869]359         //! The output pin of the input filter of the field
360         std::shared_ptr<CPassThroughFilter> inputFilter;
361
362         //! The self temporal data filter
363         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
364         
[640]365         //! The output pin of the filter providing the instant data for the field
[1542]366         std::shared_ptr<COutputPin> instantDataFilter;
[2011]367      public:
368          std::shared_ptr<COutputPin> getInstantDataFilter(void) { return instantDataFilter;}
369
370      private:
371
[643]372         //! The output pin of the filters providing the result of the field's temporal operation
[1542]373         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
[1869]374         
[737]375         //! The output pin of the filter providing the instant data for self references
[1869]376         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
377
[1930]378 
379         //! The source filter for data provided by the model to enter the client workflow
380         std::shared_ptr<CModelToClientSourceFilter> modelToClientSourceFilter_;
381
382         //! The source filter for data provided by the model to enter the client workflow
383         std::shared_ptr<CClientToModelStoreFilter> clientToModelStoreFilter_;
384
385         //! The source filter for data provided by the client that send data to server workflow
386         std::shared_ptr<CServerFromClientSourceFilter> serverFromClientSourceFilter_;
387
388         //! The source filter for data provided by an other to enter the current client workflow (coupling mode)
389         std::shared_ptr<CClientFromClientSourceFilter> clientFromClientSourceFilter_;
390
391         //! The source filter for data provided by server to enter the current client workflow (reading mode)
392         std::shared_ptr<CClientFromServerSourceFilter> clientFromServerSourceFilter_;
[1869]393         
[1930]394         //! The source filter for data read from file on server side
395         std::shared_ptr<CFileReaderSourceFilter> fileReaderSourceFilter_;
396
[1935]397         //! The terminal filter which send data to server for writing
398         std::shared_ptr<CClientToServerStoreFilter> clientToServerStoreFilter_;
[1869]399       
[1024]400         //! The terminal filter which writes data to file
[1935]401         std::shared_ptr<CFileWriterStoreFilter> fileWriterStoreFilter_;
[1883]402
[1930]403         //! The terminal filter which send data from server to client
[1934]404         std::shared_ptr<CServerToClientStoreFilter> serverToClientStoreFilter_;
[1883]405
[2507]406         //! the filter to redistribute data before to call the fileWriterStoreFilter ==> to remove
407         std::shared_ptr<CGridRedistributeFilter>  redistributeFilter_ ;
[1883]408
[2507]409          //! the filter to connect to online reader
410         std::shared_ptr<CClientOnlineReaderFilter>  clientOnlineReaderFilter_ ;
411
412          //! the filter to connect to online writer
413         std::shared_ptr<CClientOnlineWriterFilter>  clientOnlineWriterFilter_ ;
414
415
[219]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   ///-----------------------------------------------------------------
[335]429} // namespace xios
[219]430
431
[591]432#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.