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

Last change on this file since 1870 was 1870, 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.1 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) ;
146
[1278]147         /// Vérifications ///
[1405]148         void checkTimeAttributes(CDuration* freqOp=NULL);
[1278]149
[640]150         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
[1869]151
152         bool buildWorkflowGraph(CGarbageCollector& gc) ;
153         bool buildWorkflowGraphDone_ = false ;
154
[1215]155         size_t getGlobalWrittenSize(void) ;
156         
157         
[1542]158         std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
159         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
160         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
161         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
[640]162
[651]163//         virtual void fromBinary(StdIStream& is);
[219]164
165         /// Destructeur ///
166         virtual ~CField(void);
167
168         /// Accesseurs statiques ///
169         static StdString GetName(void);
170         static StdString GetDefName(void);
[509]171
[219]172         static ENodeType GetType(void);
[509]173
[651]174        template <int N> void setData(const CArray<double, N>& _data);
175        static bool dispatchEvent(CEventServer& event);
[1524]176        void sendAllAttributesToServer(CContextClient* client) ; 
[638]177        void sendUpdateData(const CArray<double,1>& data);
[1099]178        void sendUpdateData(const CArray<double,1>& data, CContextClient* client);
[651]179        static void recvUpdateData(CEventServer& event);
[1024]180        void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
[651]181        void writeField(void);
[1853]182        bool sendReadDataRequest(const CDate& tsDataRequested, CContextClient* client);
[598]183        bool sendReadDataRequestIfNeeded(void);
184        static void recvReadDataRequest(CEventServer& event);
[1853]185        void recvReadDataRequest(CContextServer* server);
[1232]186        EReadField readField(void);
[598]187        static void recvReadDataReady(CEventServer& event);
188        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
[1318]189        void checkForLateDataFromServer(void);
[1358]190        void checkIfMustAutoTrigger(void);
191        void autoTriggerIfNeeded(void);
[1158]192        void outputField(CArray<double,3>& fieldOut);
193        void outputField(CArray<double,2>& fieldOut);
[651]194        void outputField(CArray<double,1>& fieldOut);
[1158]195        void inputField(CArray<double,3>& fieldOut);
196        void inputField(CArray<double,2>& fieldOut);
[599]197        void inputField(CArray<double,1>& fieldOut);
[676]198        void outputCompressedField(CArray<double, 1>& fieldOut);
[651]199        void scaleFactorAddOffset(double scaleFactor, double addOffset);
[599]200        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
[651]201        void parse(xml::CXMLNode& node);
[509]202
[472]203        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
204        CVariableGroup* getVirtualVariableGroup(void) const;
205        vector<CVariable*> getAllVariables(void) const;
[651]206        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
[509]207
[651]208        CVariable* addVariable(const string& id = "");
[1144]209        CVariableGroup* addVariableGroup(const string& id = "");       
[1021]210        void sendAddVariable(const string& id, CContextClient* client);
[1144]211        void sendAddVariableGroup(const string& id, CContextClient* client);
[651]212        static void recvAddVariable(CEventServer& event);
213        void recvAddVariable(CBufferIn& buffer);
214        static void recvAddVariableGroup(CEventServer& event);
[1144]215        void recvAddVariableGroup(CBufferIn& buffer);       
[1021]216        void sendAddAllVariables(CContextClient* client);
[1024]217        void writeUpdateData(const CArray<double,1>& data);
[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;
[1869]225        CGrid* getGrid(void) { return grid_; } 
[1637]226
[1869]227        void connectToFileServer(CGarbageCollector& gc) ;
[1870]228        void connectToModelInput(CGarbageCollector& gc) ;
[1869]229        void computeGridIndexToFileServer(void) ;
[1870]230
231        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
232                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
233                                        bool bufferForWriting) ;
234        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
235                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
236                                                 bool bufferForWriting) ;
[1869]237      private:
238        std::vector<CGrid*> getGridPath(void) ;
239
[707]240      public:
[219]241         /// Propriétés privées ///
[651]242         CVariableGroup* vVariableGroup;
[509]243
[1869]244         CGrid*  grid_=nullptr;
[347]245         CFile*  file;
[1869]246         
247         CFile* fileIn_ = nullptr ; //<! pointer to input related file
248         bool hasFileIn(void) { fileIn_==nullptr ? false : true ;}
249         CFile* getFileIn(void) {return fileIn_;}
250         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
251         void unsetFileIn(void) { fileIn_ = nullptr ;}
[219]252
[1869]253         CFile* fileOut_ = nullptr ; //<! pointer to output related file
254         bool hasFileOut(void) { fileOut_==nullptr ? false : true ;}
255         CFile* getFileOut(void) {return fileOut_;}
256         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
257         void unsetFileOut(void) { fileOut_ = nullptr ;}
258
259         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
260         bool hasCouplerIn(void) { couplerIn_==nullptr ? false : true ;}
261         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
262         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
263         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
264
265         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
266         bool hasCouplerOut(void) { couplerOut_==nullptr ? false : true ;}
267         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
268         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
269         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
270
271         bool modelIn_ = false ; //<! field can be received from model == true
272         bool getModelIn(void) { return modelIn_ ;}
273         void setModelIn(void) { modelIn_ = true ;}
274         void unsetModelIn(void) { modelIn_ = false ;}
275         
276         bool modelOut_ = false ; //<! field can be retrieve to model == true
277         bool getModelOut(void) { return modelOut_ ;}
278         void setModelOut(void) { modelOut_ = true ;}
279         void unsetModelOut(void) { modelOut_ = false ;}
280
[343]281         CDuration freq_operation_srv, freq_write_srv;
[219]282
[707]283         bool written; //<! Was the field written at least once
[952]284         int nstep, nstepMax;
[599]285         bool isEOF;
[651]286         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
[1318]287         CDate lastDataRequestedFromServer, lastDataReceivedFromServer, dateEOF;
288         bool wasDataRequestedFromServer, wasDataAlreadyReceivedFromServer;
[1358]289         bool mustAutoTrigger;
[509]290
[1542]291         map<int,std::shared_ptr<func::CFunctor> > foperation_srv;
[509]292
[1144]293         // map<int, CArray<double,1> > data_srv;
[1024]294         CArray<double,1> recvDataSrv;
295         
[1542]296         std::shared_ptr<func::CFunctor> recvFoperationSrv;
[651]297         string content;
[509]298
[887]299         std::vector<StdString> domAxisScalarIds_;
[676]300         bool useCompressedOutput;
[645]301
[1021]302         // Two variables to identify the time_counter meta data written in file, which has no time_counter
303         bool hasTimeInstant;
304         bool hasTimeCentered;
305
[1129]306
[540]307         DECLARE_REF_FUNC(Field,field)
[1869]308       
[640]309      private:
[1294]310         CContextClient* client;
311
[1129]312         bool areAllReferenceSolved;
313         bool isReferenceSolved;
314         bool isReferenceSolvedAndTransformed;
[1417]315         bool isGridChecked;
[1232]316         bool nstepMaxRead;
[1129]317
[1869]318       private: 
319         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
320         bool workflowEnabled_ = false ;
321       public: 
322         /*! workflowEnabled_ public accessor
323          * \return Value of workflowEnabled_ */
324         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
325 
326
[1129]327      private:
[1869]328     
[645]329         //! The type of operation attached to the field
330         func::CFunctor::ETimeType operationTimeType;
331
[1869]332         //! The output pin of the input filter of the field
333         std::shared_ptr<CPassThroughFilter> inputFilter;
334
335         //! The self temporal data filter
336         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
337         
[640]338         //! The output pin of the filter providing the instant data for the field
[1542]339         std::shared_ptr<COutputPin> instantDataFilter;
[1869]340         
[643]341         //! The output pin of the filters providing the result of the field's temporal operation
[1542]342         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
[1869]343         
[737]344         //! The output pin of the filter providing the instant data for self references
[1869]345         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
346
[640]347         //! The source filter for data provided by the client
[1542]348         std::shared_ptr<CSourceFilter> clientSourceFilter;
[1869]349         
[640]350         //! The source filter for data provided by the server
[1542]351         std::shared_ptr<CSourceFilter> serverSourceFilter;
[1869]352         
[640]353         //! The terminal filter which stores the instant data
[1542]354         std::shared_ptr<CStoreFilter> storeFilter;
[1869]355       
[1158]356         //! The terminal filter which writes the data to file
[1542]357         std::shared_ptr<CFileWriterFilter> fileWriterFilter;
[1869]358       
[1024]359         //! The terminal filter which writes data to file
[1542]360         std::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter;
[219]361   }; // class CField
362
363   ///--------------------------------------------------------------
364
365   // Declare/Define CFieldGroup and CFieldDefinition
366   DECLARE_GROUP(CField);
367
368   ///-----------------------------------------------------------------
369
370   template <>
371      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
372
373   ///-----------------------------------------------------------------
[335]374} // namespace xios
[219]375
376
[591]377#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.