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

Last change on this file since 1294 was 1294, checked in by oabramkina, 7 years ago

Improvements for the secondary server: each grid is only sent to secondary-server pools that need it.

  • 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: 10.0 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         void setContextClient(CContextClient* newContextClient);
106         CContextClient* getContextClient();
107
108       public:
109         bool isActive(bool atCurrentTimestep = false) const;
110         bool hasOutputFile;
111
112         bool wasWritten() const;
113         void setWritten();
114
115         bool getUseCompressedOutput() const;
116         void setUseCompressedOutput();
117
118         /// Traitements ///
119         void solveGridReference(void);
120         void solveServerOperation(void);
121         void solveCheckMaskIndex(bool doSendingIndex);
122         void solveAllReferenceEnabledField(bool doSending2Server);
123         void solveOnlyReferenceEnabledField(bool doSending2Server);
124         void generateNewTransformationGridDest();
125         void updateRef(CGrid* grid);
126         void buildGridTransformationGraph();
127         void solveGridDomainAxisRef(bool checkAtt);
128         void solveTransformedGrid();
129         void solveGenerateGrid();
130         void solveGridDomainAxisBaseRef();
131
132         void solveAllEnabledFieldsAndTransform();
133         void checkGridOfEnabledFields();
134         void sendGridOfEnabledFields();
135         void sendGridComponentOfEnabledFields();
136
137         /// Vérifications ///
138         void checkAttributes(void);
139
140         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
141         size_t getGlobalWrittenSize(void) ;
142         
143         
144         boost::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
145         boost::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
146         boost::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
147         boost::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
148
149//         virtual void fromBinary(StdIStream& is);
150
151         /// Destructeur ///
152         virtual ~CField(void);
153
154         /// Accesseurs statiques ///
155         static StdString GetName(void);
156         static StdString GetDefName(void);
157
158         static ENodeType GetType(void);
159
160        template <int N> void setData(const CArray<double, N>& _data);
161        static bool dispatchEvent(CEventServer& event);
162        void sendUpdateData(const CArray<double,1>& data);
163        void sendUpdateData(const CArray<double,1>& data, CContextClient* client);
164        static void recvUpdateData(CEventServer& event);
165        void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
166        void writeField(void);
167        bool sendReadDataRequest(const CDate& tsDataRequested);
168        bool sendReadDataRequestIfNeeded(void);
169        static void recvReadDataRequest(CEventServer& event);
170        void recvReadDataRequest(void);
171        EReadField readField(void);
172        static void recvReadDataReady(CEventServer& event);
173        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
174        void outputField(CArray<double,3>& fieldOut);
175        void outputField(CArray<double,2>& fieldOut);
176        void outputField(CArray<double,1>& fieldOut);
177        void inputField(CArray<double,3>& fieldOut);
178        void inputField(CArray<double,2>& fieldOut);
179        void inputField(CArray<double,1>& fieldOut);
180        void outputCompressedField(CArray<double, 1>& fieldOut);
181        void scaleFactorAddOffset(double scaleFactor, double addOffset);
182        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
183        void parse(xml::CXMLNode& node);
184
185        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
186        CVariableGroup* getVirtualVariableGroup(void) const;
187        vector<CVariable*> getAllVariables(void) const;
188        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
189
190        CVariable* addVariable(const string& id = "");
191        CVariableGroup* addVariableGroup(const string& id = "");       
192        void sendAddVariable(const string& id, CContextClient* client);
193        void sendAddVariableGroup(const string& id, CContextClient* client);
194        static void recvAddVariable(CEventServer& event);
195        void recvAddVariable(CBufferIn& buffer);
196        static void recvAddVariableGroup(CEventServer& event);
197        void recvAddVariableGroup(CBufferIn& buffer);       
198        void sendAddAllVariables(CContextClient* client);
199        void writeUpdateData(const CArray<double,1>& data);
200
201        const std::vector<StdString>& getRefDomainAxisIds();
202
203        const string& getExpression(void);
204        bool hasExpression(void) const;
205
206      public:
207         /// Propriétés privées ///
208         CVariableGroup* vVariableGroup;
209
210         CGrid*  grid;
211         CFile*  file;
212
213         CDuration freq_operation_srv, freq_write_srv;
214
215         bool written; //<! Was the field written at least once
216         int nstep, nstepMax;
217         bool isEOF;
218         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
219         CDate lastDataRequestedFromServer, lastDataReceivedFromServer;
220         bool wasDataAlreadyReceivedFromServer;
221
222         map<int,boost::shared_ptr<func::CFunctor> > foperation_srv;
223
224         // map<int, CArray<double,1> > data_srv;
225         CArray<double,1> recvDataSrv;
226         
227         boost::shared_ptr<func::CFunctor> recvFoperationSrv;
228         string content;
229
230         std::vector<StdString> domAxisScalarIds_;
231         bool useCompressedOutput;
232
233         // Two variables to identify the time_counter meta data written in file, which has no time_counter
234         bool hasTimeInstant;
235         bool hasTimeCentered;
236
237
238         DECLARE_REF_FUNC(Field,field)
239
240      private:
241         CContextClient* client;
242
243         bool areAllReferenceSolved;
244         bool isReferenceSolved;
245         bool isReferenceSolvedAndTransformed;
246         bool nstepMaxRead;
247
248      private:
249         //! The type of operation attached to the field
250         func::CFunctor::ETimeType operationTimeType;
251
252         //! The output pin of the filter providing the instant data for the field
253         boost::shared_ptr<COutputPin> instantDataFilter;
254         //! The output pin of the filters providing the result of the field's temporal operation
255         std::map<CDuration, boost::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
256         //! The output pin of the filter providing the instant data for self references
257         boost::shared_ptr<COutputPin> selfReferenceFilter;
258         //! The source filter for data provided by the client
259         boost::shared_ptr<CSourceFilter> clientSourceFilter;
260         //! The source filter for data provided by the server
261         boost::shared_ptr<CSourceFilter> serverSourceFilter;
262         //! The terminal filter which stores the instant data
263         boost::shared_ptr<CStoreFilter> storeFilter;
264         //! The terminal filter which writes the data to file
265         boost::shared_ptr<CFileWriterFilter> fileWriterFilter;
266         //! The terminal filter which writes data to file
267         boost::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter;
268   }; // class CField
269
270   ///--------------------------------------------------------------
271
272   // Declare/Define CFieldGroup and CFieldDefinition
273   DECLARE_GROUP(CField);
274
275   ///-----------------------------------------------------------------
276
277   template <>
278      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
279
280   ///-----------------------------------------------------------------
281} // namespace xios
282
283
284#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.