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

Last change on this file since 1417 was 1417, checked in by oabramkina, 3 years ago

Including calculations of grid distributions for fields which are disabled but, at the same time, are referenced in arithmetic filters.

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