source: XIOS/dev/XIOS_DEV_CMIP6/src/node/field.hpp @ 1239

Last change on this file since 1239 was 1239, checked in by mhnguyen, 5 years ago

Correcting a minor bug on detecting server reading level

+) Reading server level should be 1 (for now). In the future, maybe level-2 server can be used
+) Correct nbReadSenders with the right ContextClient?

Test
+) On Curie
+) Work with toy

  • 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: 9.8 KB
Line 
1#ifndef __XIOS_CField__
2#define __XIOS_CField__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
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"
12#include "calendar_util.hpp"
13#include "array_new.hpp"
14#include "attribute_array.hpp"
15#include "declare_ref_func.hpp"
16#include "transformation_enum.hpp"
17#include "variable.hpp"
18#include "context_client.hpp"
19
20
21namespace xios {
22
23   /// ////////////////////// Déclarations ////////////////////// ///
24
25   class CFieldGroup;
26   class CFieldAttributes;
27   class CField;
28
29   class CFile;
30   class CGrid;
31   class CContext;
32   class CGenericFilter;
33
34   class CGarbageCollector;
35   class COutputPin;
36   class CSourceFilter;
37   class CStoreFilter;
38   class CFileWriterFilter;
39   class CFileServerWriterFilter;
40
41   ///--------------------------------------------------------------
42
43   // Declare/Define CFieldAttribute
44   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
45#  include "field_attribute.conf"
46   END_DECLARE_ATTRIBUTE_MAP(CField)
47
48   ///--------------------------------------------------------------
49   class CField
50      : public CObjectTemplate<CField>
51      , public CFieldAttributes
52   {
53         /// friend ///
54         friend class CFile;
55
56         /// typedef ///
57         typedef CObjectTemplate<CField>   SuperClass;
58         typedef CFieldAttributes SuperClassAttribute;
59
60         enum EReadField
61         {
62           RF_NODATA, RF_EOF, RF_DATA
63         };
64         
65      public:
66
67         typedef CFieldAttributes RelAttributes;
68         typedef CFieldGroup      RelGroup;
69
70         enum EEventId
71         {
72           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
73           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP
74         };
75
76         /// Constructeurs ///
77         CField(void);
78         explicit CField(const StdString& id);
79         CField(const CField& field);       // Not implemented yet.
80         CField(const CField* const field); // Not implemented yet.
81
82         /// Accesseurs ///
83
84         CGrid* getRelGrid(void) const;
85         CFile* getRelFile(void) const;
86
87         func::CFunctor::ETimeType getOperationTimeType() const;
88
89      public:
90         int getNStep(void) const;
91
92         template <int N> void getData(CArray<double, N>& _data) const;
93
94         boost::shared_ptr<COutputPin> getInstantDataFilter();
95
96         /// Mutateur ///
97         void setRelFile(CFile* _file);
98         void incrementNStep(void);
99         void resetNStep(int nstep = 0);
100         void resetNStepMax();
101
102         std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client);
103         std::map<int, StdSize> getGridDataBufferSize(CContextClient* client); // Grid data buffer size for each connection of contextclient
104
105       public:
106         bool isActive(bool atCurrentTimestep = false) const;
107         bool hasOutputFile;
108
109         bool wasWritten() const;
110         void setWritten();
111
112         bool getUseCompressedOutput() const;
113         void setUseCompressedOutput();
114
115         /// Traitements ///
116         void solveGridReference(void);
117         void solveServerOperation(void);
118         void solveCheckMaskIndex(bool doSendingIndex);
119         void solveAllReferenceEnabledField(bool doSending2Server);
120         void solveOnlyReferenceEnabledField(bool doSending2Server);
121         void generateNewTransformationGridDest();
122         void updateRef(CGrid* grid);
123         void buildGridTransformationGraph();
124         void solveGridDomainAxisRef(bool checkAtt);
125         void solveTransformedGrid();
126         void solveGenerateGrid();
127         void solveGridDomainAxisBaseRef();
128
129         void solveAllEnabledFieldsAndTransform();
130         void checkGridOfEnabledFields();
131         void sendGridOfEnabledFields();
132         void sendGridComponentOfEnabledFields();   
133
134         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
135         size_t getGlobalWrittenSize(void) ;
136         
137         
138         boost::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
139         boost::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
140         boost::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
141         boost::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
142
143//         virtual void fromBinary(StdIStream& is);
144
145         /// Destructeur ///
146         virtual ~CField(void);
147
148         /// Accesseurs statiques ///
149         static StdString GetName(void);
150         static StdString GetDefName(void);
151
152         static ENodeType GetType(void);
153
154        template <int N> void setData(const CArray<double, N>& _data);
155        static bool dispatchEvent(CEventServer& event);
156        void sendUpdateData(const CArray<double,1>& data);
157        void sendUpdateData(const CArray<double,1>& data, CContextClient* client);
158        static void recvUpdateData(CEventServer& event);
159        void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
160        void writeField(void);
161        bool sendReadDataRequest(const CDate& tsDataRequested);
162        bool sendReadDataRequestIfNeeded(void);
163        static void recvReadDataRequest(CEventServer& event);
164        void recvReadDataRequest(void);
165        EReadField readField(void);
166        static void recvReadDataReady(CEventServer& event);
167        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
168        void outputField(CArray<double,3>& fieldOut);
169        void outputField(CArray<double,2>& fieldOut);
170        void outputField(CArray<double,1>& fieldOut);
171        void inputField(CArray<double,3>& fieldOut);
172        void inputField(CArray<double,2>& fieldOut);
173        void inputField(CArray<double,1>& fieldOut);
174        void outputCompressedField(CArray<double, 1>& fieldOut);
175        void scaleFactorAddOffset(double scaleFactor, double addOffset);
176        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
177        void parse(xml::CXMLNode& node);
178
179        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
180        CVariableGroup* getVirtualVariableGroup(void) const;
181        vector<CVariable*> getAllVariables(void) const;
182        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
183
184        CVariable* addVariable(const string& id = "");
185        CVariableGroup* addVariableGroup(const string& id = "");       
186        void sendAddVariable(const string& id, CContextClient* client);
187        void sendAddVariableGroup(const string& id, CContextClient* client);
188        static void recvAddVariable(CEventServer& event);
189        void recvAddVariable(CBufferIn& buffer);
190        static void recvAddVariableGroup(CEventServer& event);
191        void recvAddVariableGroup(CBufferIn& buffer);       
192        void sendAddAllVariables(CContextClient* client);
193        void writeUpdateData(const CArray<double,1>& data);
194
195        const std::vector<StdString>& getRefDomainAxisIds();
196
197        const string& getExpression(void);
198        bool hasExpression(void) const;
199
200      public:
201         /// Propriétés privées ///
202         CVariableGroup* vVariableGroup;
203
204         CGrid*  grid;
205         CFile*  file;
206
207         CDuration freq_operation_srv, freq_write_srv;
208
209         bool written; //<! Was the field written at least once
210         int nstep, nstepMax;
211         bool isEOF;
212         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
213         CDate lastDataRequestedFromServer, lastDataReceivedFromServer;
214         bool wasDataAlreadyReceivedFromServer;
215
216         map<int,boost::shared_ptr<func::CFunctor> > foperation_srv;
217
218         // map<int, CArray<double,1> > data_srv;
219         CArray<double,1> recvDataSrv;
220         
221         boost::shared_ptr<func::CFunctor> recvFoperationSrv;
222         string content;
223
224         std::vector<StdString> domAxisScalarIds_;
225         bool useCompressedOutput;
226
227         // Two variables to identify the time_counter meta data written in file, which has no time_counter
228         bool hasTimeInstant;
229         bool hasTimeCentered;
230
231
232         DECLARE_REF_FUNC(Field,field)
233
234      private:
235         bool areAllReferenceSolved;
236         bool isReferenceSolved;
237         bool isReferenceSolvedAndTransformed;
238         bool nstepMaxRead;
239
240      private:
241         //! The type of operation attached to the field
242         func::CFunctor::ETimeType operationTimeType;
243
244         //! The output pin of the filter providing the instant data for the field
245         boost::shared_ptr<COutputPin> instantDataFilter;
246         //! The output pin of the filters providing the result of the field's temporal operation
247         std::map<CDuration, boost::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
248         //! The output pin of the filter providing the instant data for self references
249         boost::shared_ptr<COutputPin> selfReferenceFilter;
250         //! The source filter for data provided by the client
251         boost::shared_ptr<CSourceFilter> clientSourceFilter;
252         //! The source filter for data provided by the server
253         boost::shared_ptr<CSourceFilter> serverSourceFilter;
254         //! The terminal filter which stores the instant data
255         boost::shared_ptr<CStoreFilter> storeFilter;
256         //! The terminal filter which writes the data to file
257         boost::shared_ptr<CFileWriterFilter> fileWriterFilter;
258         //! The terminal filter which writes data to file
259         boost::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter;
260   }; // class CField
261
262   ///--------------------------------------------------------------
263
264   // Declare/Define CFieldGroup and CFieldDefinition
265   DECLARE_GROUP(CField);
266
267   ///-----------------------------------------------------------------
268
269   template <>
270      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
271
272   ///-----------------------------------------------------------------
273} // namespace xios
274
275
276#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.