source: XIOS/dev/dev_olga/src/node/field.hpp @ 1144

Last change on this file since 1144 was 1144, checked in by mhnguyen, 7 years ago

Cleaning up some redundant codes

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