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

Last change on this file since 2249 was 2230, checked in by ymipsl, 3 years ago

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