source: XIOS/trunk/src/node/field.hpp @ 2250

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

Merging branch dev_oa with tiling into trunk

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