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

Last change on this file since 1872 was 1872, checked in by ymipsl, 4 years ago

Some update on XIOS_COUPLING branch...

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: 14.4 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"
[219]21
[300]22
[1869]23
[335]24namespace xios {
[509]25
[219]26   /// ////////////////////// Déclarations ////////////////////// ///
27
28   class CFieldGroup;
29   class CFieldAttributes;
30   class CField;
31
32   class CFile;
[1869]33   class CCouplerIn ;
34   class CCouplerOut ;
[219]35   class CGrid;
[640]36   class CContext;
[619]37   class CGenericFilter;
38
[640]39   class CGarbageCollector;
40   class COutputPin;
41   class CSourceFilter;
42   class CStoreFilter;
43   class CFileWriterFilter;
[1024]44   class CFileServerWriterFilter;
[640]45
[219]46   ///--------------------------------------------------------------
47
48   // Declare/Define CFieldAttribute
49   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
50#  include "field_attribute.conf"
51   END_DECLARE_ATTRIBUTE_MAP(CField)
52
[1853]53   class CContextClient ;
[1869]54
[219]55   ///--------------------------------------------------------------
56   class CField
57      : public CObjectTemplate<CField>
58      , public CFieldAttributes
59   {
60         /// friend ///
61         friend class CFile;
62
63         /// typedef ///
64         typedef CObjectTemplate<CField>   SuperClass;
65         typedef CFieldAttributes SuperClassAttribute;
66
[1232]67         enum EReadField
68         {
69           RF_NODATA, RF_EOF, RF_DATA
70         };
71         
[707]72      public:
[219]73
74         typedef CFieldAttributes RelAttributes;
75         typedef CFieldGroup      RelGroup;
76
[300]77         enum EEventId
78         {
[598]79           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
80           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP
[651]81         };
[509]82
[219]83         /// Constructeurs ///
84         CField(void);
[651]85         explicit CField(const StdString& id);
86         CField(const CField& field);       // Not implemented yet.
87         CField(const CField* const field); // Not implemented yet.
[219]88
89         /// Accesseurs ///
90
[651]91         CGrid* getRelGrid(void) const;
92         CFile* getRelFile(void) const;
[219]93
[645]94         func::CFunctor::ETimeType getOperationTimeType() const;
95
[707]96      public:
[952]97         int getNStep(void) const;
[266]98
[593]99         template <int N> void getData(CArray<double, N>& _data) const;
[219]100
[1542]101         std::shared_ptr<COutputPin> getInstantDataFilter();
[219]102
103         /// Mutateur ///
[347]104         void setRelFile(CFile* _file);
[266]105         void incrementNStep(void);
[952]106         void resetNStep(int nstep = 0);
[599]107         void resetNStepMax();
[219]108
[1330]109         std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
110         // Grid data buffer size for each connection of contextclient
111         std::map<int, StdSize> getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false);
[509]112
[1294]113         void setContextClient(CContextClient* newContextClient);
114         CContextClient* getContextClient();
115
[707]116       public:
[1158]117         bool isActive(bool atCurrentTimestep = false) const;
[651]118         bool hasOutputFile;
[219]119
[707]120         bool wasWritten() const;
121         void setWritten();
122
[676]123         bool getUseCompressedOutput() const;
124         void setUseCompressedOutput();
125
[219]126         /// Traitements ///
127         void solveGridReference(void);
[645]128         void solveServerOperation(void);
[509]129         void solveCheckMaskIndex(bool doSendingIndex);
[823]130         void solveAllReferenceEnabledField(bool doSending2Server);
[1784]131         void solveOnlyReferenceEnabledField(void);
[823]132         void generateNewTransformationGridDest();
133         void updateRef(CGrid* grid);
134         void buildGridTransformationGraph();
[509]135         void solveGridDomainAxisRef(bool checkAtt);
[619]136         void solveTransformedGrid();
[687]137         void solveGenerateGrid();
[775]138         void solveGridDomainAxisBaseRef();
[219]139
[1129]140         void solveAllEnabledFieldsAndTransform();
[1024]141         void checkGridOfEnabledFields();
142         void sendGridOfEnabledFields();
[1278]143         void sendGridComponentOfEnabledFields();
[1024]144
[1870]145         void sendFieldToFileServer(void) ;
[1872]146         void sendFieldToInputFileServer(void) ;
[1870]147
[1278]148         /// Vérifications ///
[1405]149         void checkTimeAttributes(CDuration* freqOp=NULL);
[1278]150
[640]151         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
[1869]152
153         bool buildWorkflowGraph(CGarbageCollector& gc) ;
154         bool buildWorkflowGraphDone_ = false ;
155
[1215]156         size_t getGlobalWrittenSize(void) ;
157         
158         
[1542]159         std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
160         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
161         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
162         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
[640]163
[651]164//         virtual void fromBinary(StdIStream& is);
[219]165
166         /// Destructeur ///
167         virtual ~CField(void);
168
169         /// Accesseurs statiques ///
170         static StdString GetName(void);
171         static StdString GetDefName(void);
[509]172
[219]173         static ENodeType GetType(void);
[509]174
[651]175        template <int N> void setData(const CArray<double, N>& _data);
176        static bool dispatchEvent(CEventServer& event);
[1524]177        void sendAllAttributesToServer(CContextClient* client) ; 
[638]178        void sendUpdateData(const CArray<double,1>& data);
[1099]179        void sendUpdateData(const CArray<double,1>& data, CContextClient* client);
[651]180        static void recvUpdateData(CEventServer& event);
[1024]181        void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
[651]182        void writeField(void);
[1853]183        bool sendReadDataRequest(const CDate& tsDataRequested, CContextClient* client);
[598]184        bool sendReadDataRequestIfNeeded(void);
185        static void recvReadDataRequest(CEventServer& event);
[1853]186        void recvReadDataRequest(CContextServer* server);
[1232]187        EReadField readField(void);
[598]188        static void recvReadDataReady(CEventServer& event);
189        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
[1318]190        void checkForLateDataFromServer(void);
[1358]191        void checkIfMustAutoTrigger(void);
192        void autoTriggerIfNeeded(void);
[1158]193        void outputField(CArray<double,3>& fieldOut);
194        void outputField(CArray<double,2>& fieldOut);
[651]195        void outputField(CArray<double,1>& fieldOut);
[1158]196        void inputField(CArray<double,3>& fieldOut);
197        void inputField(CArray<double,2>& fieldOut);
[599]198        void inputField(CArray<double,1>& fieldOut);
[676]199        void outputCompressedField(CArray<double, 1>& fieldOut);
[651]200        void scaleFactorAddOffset(double scaleFactor, double addOffset);
[599]201        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
[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);
[1024]218        void writeUpdateData(const CArray<double,1>& data);
[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;
[1869]226        CGrid* getGrid(void) { return grid_; } 
[1637]227
[1869]228        void connectToFileServer(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);
234
[1869]235        void computeGridIndexToFileServer(void) ;
[1870]236
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:
244        std::vector<CGrid*> getGridPath(void) ;
245
[707]246      public:
[219]247         /// Propriétés privées ///
[651]248         CVariableGroup* vVariableGroup;
[509]249
[1869]250         CGrid*  grid_=nullptr;
[1872]251//         CFile*  file;
[1869]252         
253         CFile* fileIn_ = nullptr ; //<! pointer to input related file
[1872]254         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
[1869]255         CFile* getFileIn(void) {return fileIn_;}
256         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
257         void unsetFileIn(void) { fileIn_ = nullptr ;}
[219]258
[1869]259         CFile* fileOut_ = nullptr ; //<! pointer to output related file
[1872]260         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
[1869]261         CFile* getFileOut(void) {return fileOut_;}
262         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
263         void unsetFileOut(void) { fileOut_ = nullptr ;}
264
265         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
[1872]266         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
[1869]267         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
268         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
269         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
270
271         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
[1872]272         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
[1869]273         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
274         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
275         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
276
277         bool modelIn_ = false ; //<! field can be received from model == true
278         bool getModelIn(void) { return modelIn_ ;}
279         void setModelIn(void) { modelIn_ = true ;}
280         void unsetModelIn(void) { modelIn_ = false ;}
281         
282         bool modelOut_ = false ; //<! field can be retrieve to model == true
283         bool getModelOut(void) { return modelOut_ ;}
284         void setModelOut(void) { modelOut_ = true ;}
285         void unsetModelOut(void) { modelOut_ = false ;}
286
[343]287         CDuration freq_operation_srv, freq_write_srv;
[219]288
[707]289         bool written; //<! Was the field written at least once
[952]290         int nstep, nstepMax;
[599]291         bool isEOF;
[651]292         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
[1318]293         CDate lastDataRequestedFromServer, lastDataReceivedFromServer, dateEOF;
294         bool wasDataRequestedFromServer, wasDataAlreadyReceivedFromServer;
[1358]295         bool mustAutoTrigger;
[509]296
[1542]297         map<int,std::shared_ptr<func::CFunctor> > foperation_srv;
[509]298
[1144]299         // map<int, CArray<double,1> > data_srv;
[1024]300         CArray<double,1> recvDataSrv;
301         
[1542]302         std::shared_ptr<func::CFunctor> recvFoperationSrv;
[651]303         string content;
[509]304
[887]305         std::vector<StdString> domAxisScalarIds_;
[676]306         bool useCompressedOutput;
[645]307
[1021]308         // Two variables to identify the time_counter meta data written in file, which has no time_counter
309         bool hasTimeInstant;
310         bool hasTimeCentered;
311
[1129]312
[540]313         DECLARE_REF_FUNC(Field,field)
[1869]314       
[640]315      private:
[1294]316         CContextClient* client;
317
[1129]318         bool areAllReferenceSolved;
319         bool isReferenceSolved;
320         bool isReferenceSolvedAndTransformed;
[1417]321         bool isGridChecked;
[1232]322         bool nstepMaxRead;
[1129]323
[1869]324       private: 
325         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
326         bool workflowEnabled_ = false ;
327       public: 
328         /*! workflowEnabled_ public accessor
329          * \return Value of workflowEnabled_ */
330         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
331 
332
[1129]333      private:
[1869]334     
[645]335         //! The type of operation attached to the field
336         func::CFunctor::ETimeType operationTimeType;
337
[1869]338         //! The output pin of the input filter of the field
339         std::shared_ptr<CPassThroughFilter> inputFilter;
340
341         //! The self temporal data filter
342         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
343         
[640]344         //! The output pin of the filter providing the instant data for the field
[1542]345         std::shared_ptr<COutputPin> instantDataFilter;
[1869]346         
[643]347         //! The output pin of the filters providing the result of the field's temporal operation
[1542]348         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
[1869]349         
[737]350         //! The output pin of the filter providing the instant data for self references
[1869]351         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
352
[640]353         //! The source filter for data provided by the client
[1542]354         std::shared_ptr<CSourceFilter> clientSourceFilter;
[1869]355         
[640]356         //! The source filter for data provided by the server
[1542]357         std::shared_ptr<CSourceFilter> serverSourceFilter;
[1869]358         
[640]359         //! The terminal filter which stores the instant data
[1542]360         std::shared_ptr<CStoreFilter> storeFilter;
[1869]361       
[1158]362         //! The terminal filter which writes the data to file
[1542]363         std::shared_ptr<CFileWriterFilter> fileWriterFilter;
[1869]364       
[1024]365         //! The terminal filter which writes data to file
[1542]366         std::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter;
[219]367   }; // class CField
368
369   ///--------------------------------------------------------------
370
371   // Declare/Define CFieldGroup and CFieldDefinition
372   DECLARE_GROUP(CField);
373
374   ///-----------------------------------------------------------------
375
376   template <>
377      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
378
379   ///-----------------------------------------------------------------
[335]380} // namespace xios
[219]381
382
[591]383#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.