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

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

Fix Deadlock from reading phase.
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.0 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         void sendCloseDefinition(void) ;
149     
150      public:
151         void sendFieldToCouplerOut(void) ;
152      private:
153         bool sendFieldToCouplerOut_done_=false;
154      public:
155
[1872]156         void sendFieldToInputFileServer(void) ;
[1870]157
[1278]158         /// Vérifications ///
[1405]159         void checkTimeAttributes(CDuration* freqOp=NULL);
[1278]160
[1869]161         bool buildWorkflowGraph(CGarbageCollector& gc) ;
162         bool buildWorkflowGraphDone_ = false ;
163
[1215]164         size_t getGlobalWrittenSize(void) ;
165         
166         
[1542]167         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
168         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
169         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
[640]170
[651]171//         virtual void fromBinary(StdIStream& is);
[219]172
173         /// Destructeur ///
174         virtual ~CField(void);
175
176         /// Accesseurs statiques ///
177         static StdString GetName(void);
178         static StdString GetDefName(void);
[509]179
[219]180         static ENodeType GetType(void);
[509]181
[651]182        template <int N> void setData(const CArray<double, N>& _data);
[2318]183        void checkSumLike( const double* array, int numElements, bool output ) const;
[651]184        static bool dispatchEvent(CEventServer& event);
[2230]185        static bool isCollectiveEvent(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;
[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) ;
[1871]240
[1870]241        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
242                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
243                                        bool bufferForWriting) ;
244        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
245                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
246                                                 bool bufferForWriting) ;
[1869]247      private:
[1875]248          bool isGridCompleted_ = true ;
249      public:
[2022]250          bool isGridCompleted()  ; 
[1875]251          void setGridCompleted(void) { isGridCompleted_= true; }
252          void unsetGridCompleted(void) { isGridCompleted_ = false ;}
253     
254      public:     
255          void sendGridCompleted(void) ;
256      private:   
257          static void recvGridCompleted(CEventServer& event);
258          void recvGridCompleted(CBufferIn& buffer);
259
260
261      private:
[1869]262        std::vector<CGrid*> getGridPath(void) ;
263
[707]264      public:
[219]265         /// Propriétés privées ///
[651]266         CVariableGroup* vVariableGroup;
[509]267
[1869]268         CGrid*  grid_=nullptr;
[1984]269         CGrid* getGrid(void) { return grid_; } 
270     
271      private:
272         CGrid* sentGrid_=nullptr ;
273      public:
274         CGrid* getSentGrid(void) { return sentGrid_; }   
275
276      public:
[1872]277//         CFile*  file;
[1869]278         
279         CFile* fileIn_ = nullptr ; //<! pointer to input related file
[1872]280         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
[1869]281         CFile* getFileIn(void) {return fileIn_;}
282         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
283         void unsetFileIn(void) { fileIn_ = nullptr ;}
[219]284
[1869]285         CFile* fileOut_ = nullptr ; //<! pointer to output related file
[1872]286         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
[1869]287         CFile* getFileOut(void) {return fileOut_;}
288         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
289         void unsetFileOut(void) { fileOut_ = nullptr ;}
290
291         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
[1872]292         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
[1869]293         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
294         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
295         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
296
297         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
[1872]298         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
[1869]299         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
300         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
301         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
302
303         bool modelIn_ = false ; //<! field can be received from model == true
304         bool getModelIn(void) { return modelIn_ ;}
305         void setModelIn(void) { modelIn_ = true ;}
306         void unsetModelIn(void) { modelIn_ = false ;}
307         
308         bool modelOut_ = false ; //<! field can be retrieve to model == true
309         bool getModelOut(void) { return modelOut_ ;}
310         void setModelOut(void) { modelOut_ = true ;}
311         void unsetModelOut(void) { modelOut_ = false ;}
312
[1962]313         
[707]314         bool written; //<! Was the field written at least once
[1358]315         bool mustAutoTrigger;
[509]316
[651]317         string content;
[509]318
[887]319         std::vector<StdString> domAxisScalarIds_;
[676]320         bool useCompressedOutput;
[645]321
[1021]322         // Two variables to identify the time_counter meta data written in file, which has no time_counter
323         bool hasTimeInstant;
324         bool hasTimeCentered;
325
[1129]326
[540]327         DECLARE_REF_FUNC(Field,field)
[1869]328       
[640]329      private:
[1294]330         CContextClient* client;
[1875]331      public:
332         void setContextClient(CContextClient* newContextClient);
333         CContextClient* getContextClient(void) {return client;}
[1294]334
[1875]335      private:
336
[1129]337         bool areAllReferenceSolved;
338         bool isReferenceSolved;
339         bool isReferenceSolvedAndTransformed;
[1417]340         bool isGridChecked;
[1129]341
[1869]342       private: 
343         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
344         bool workflowEnabled_ = false ;
345       public: 
346         /*! workflowEnabled_ public accessor
347          * \return Value of workflowEnabled_ */
348         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
349 
350
[1129]351      private:
[1869]352     
[645]353         //! The type of operation attached to the field
354         func::CFunctor::ETimeType operationTimeType;
355
[1869]356         //! The output pin of the input filter of the field
357         std::shared_ptr<CPassThroughFilter> inputFilter;
358
359         //! The self temporal data filter
360         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
361         
[640]362         //! The output pin of the filter providing the instant data for the field
[1542]363         std::shared_ptr<COutputPin> instantDataFilter;
[2011]364      public:
365          std::shared_ptr<COutputPin> getInstantDataFilter(void) { return instantDataFilter;}
366
367      private:
368
[643]369         //! The output pin of the filters providing the result of the field's temporal operation
[1542]370         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
[1869]371         
[737]372         //! The output pin of the filter providing the instant data for self references
[1869]373         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
374
[640]375         //! The source filter for data provided by the client
[1935]376//         std::shared_ptr<CSourceFilter> clientSourceFilter; // obsolete to remove
[1930]377 
378         //! The source filter for data provided by the model to enter the client workflow
379         std::shared_ptr<CModelToClientSourceFilter> modelToClientSourceFilter_;
380
381         //! The source filter for data provided by the model to enter the client workflow
382         std::shared_ptr<CClientToModelStoreFilter> clientToModelStoreFilter_;
383
384         //! The source filter for data provided by the client that send data to server workflow
385         std::shared_ptr<CServerFromClientSourceFilter> serverFromClientSourceFilter_;
386
387         //! The source filter for data provided by an other to enter the current client workflow (coupling mode)
388         std::shared_ptr<CClientFromClientSourceFilter> clientFromClientSourceFilter_;
389
390         //! The source filter for data provided by server to enter the current client workflow (reading mode)
391         std::shared_ptr<CClientFromServerSourceFilter> clientFromServerSourceFilter_;
[1869]392         
[1930]393         //! The source filter for data read from file on server side
394         std::shared_ptr<CFileReaderSourceFilter> fileReaderSourceFilter_;
395
[640]396         //! The source filter for data provided by the server
[1935]397//         std::shared_ptr<CSourceFilter> serverSourceFilter; // obsolete to remove
[1869]398       
[1935]399         //! The terminal filter which send data to server for writing
400         std::shared_ptr<CClientToServerStoreFilter> clientToServerStoreFilter_;
[1869]401       
[1024]402         //! The terminal filter which writes data to file
[1935]403         std::shared_ptr<CFileWriterStoreFilter> fileWriterStoreFilter_;
[1883]404
[1930]405         //! The terminal filter which send data from server to client
[1934]406         std::shared_ptr<CServerToClientStoreFilter> serverToClientStoreFilter_;
[1883]407
408
[219]409   }; // class CField
410
411   ///--------------------------------------------------------------
412
413   // Declare/Define CFieldGroup and CFieldDefinition
414   DECLARE_GROUP(CField);
415
416   ///-----------------------------------------------------------------
417
418   template <>
419      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
420
421   ///-----------------------------------------------------------------
[335]422} // namespace xios
[219]423
424
[591]425#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.