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

Last change on this file since 731 was 731, checked in by rlacroix, 9 years ago

Correctly estimate the needed buffer sizes.

The attributes were not considered which could lead to incorrect estimations.

  • 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: 7.9 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
19
20namespace xios {
21
22   /// ////////////////////// Déclarations ////////////////////// ///
23
24   class CFieldGroup;
25   class CFieldAttributes;
26   class CField;
27
28   class CFile;
29   class CGrid;
30   class CContext;
31   class CGenericFilter;
32
33   class CGarbageCollector;
34   class COutputPin;
35   class CSourceFilter;
36   class CStoreFilter;
37   class CFileWriterFilter;
38
39   ///--------------------------------------------------------------
40
41   // Declare/Define CFieldAttribute
42   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
43#  include "field_attribute.conf"
44   END_DECLARE_ATTRIBUTE_MAP(CField)
45
46   ///--------------------------------------------------------------
47   class CField
48      : public CObjectTemplate<CField>
49      , public CFieldAttributes
50   {
51         /// friend ///
52         friend class CFile;
53
54         /// typedef ///
55         typedef CObjectTemplate<CField>   SuperClass;
56         typedef CFieldAttributes SuperClassAttribute;
57
58      public:
59
60         typedef CFieldAttributes RelAttributes;
61         typedef CFieldGroup      RelGroup;
62
63         enum EEventId
64         {
65           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
66           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP
67         };
68
69         /// Constructeurs ///
70         CField(void);
71         explicit CField(const StdString& id);
72         CField(const CField& field);       // Not implemented yet.
73         CField(const CField* const field); // Not implemented yet.
74
75         /// Accesseurs ///
76
77         CGrid* getRelGrid(void) const;
78         CFile* getRelFile(void) const;
79
80         func::CFunctor::ETimeType getOperationTimeType() const;
81
82      public:
83         StdSize getNStep(void) const;
84
85         template <int N> void getData(CArray<double, N>& _data) const;
86
87         boost::shared_ptr<COutputPin> getInstantDataFilter();
88
89         /// Mutateur ///
90         void setRelFile(CFile* _file);
91         void incrementNStep(void);
92         void resetNStep(StdSize nstep = 0);
93         void resetNStepMax();
94
95         std::map<int, StdSize> getGridAttributesBufferSize();
96         std::map<int, StdSize> getGridDataBufferSize();
97
98       public:
99         bool isActive(void) const;
100         bool hasOutputFile;
101
102         bool wasWritten() const;
103         void setWritten();
104
105         bool getUseCompressedOutput() const;
106         void setUseCompressedOutput();
107
108         /// Traitements ///
109         void solveGridReference(void);
110         void solveServerOperation(void);
111         void solveCheckMaskIndex(bool doSendingIndex);
112         void solveAllReferenceEnabledField(bool doSending2Sever);
113         void solveGridDomainAxisRef(bool checkAtt);
114         void solveTransformedGrid();
115         void solveGenerateGrid();
116
117         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
118         boost::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
119         boost::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
120
121//         virtual void fromBinary(StdIStream& is);
122
123         /// Destructeur ///
124         virtual ~CField(void);
125
126         /// Accesseurs statiques ///
127         static StdString GetName(void);
128         static StdString GetDefName(void);
129
130         static ENodeType GetType(void);
131
132        template <int N> void setData(const CArray<double, N>& _data);
133        static bool dispatchEvent(CEventServer& event);
134        void sendUpdateData(const CArray<double,1>& data);
135        static void recvUpdateData(CEventServer& event);
136        void recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers);
137        void writeField(void);
138        void sendReadDataRequest(void);
139        bool sendReadDataRequestIfNeeded(void);
140        static void recvReadDataRequest(CEventServer& event);
141        void recvReadDataRequest(void);
142        bool readField(void);
143        static void recvReadDataReady(CEventServer& event);
144        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
145        void outputField(CArray<double,3>& fieldOut);
146        void outputField(CArray<double,2>& fieldOut);
147        void outputField(CArray<double,1>& fieldOut);
148        void inputField(CArray<double,3>& fieldOut);
149        void inputField(CArray<double,2>& fieldOut);
150        void inputField(CArray<double,1>& fieldOut);
151        void outputCompressedField(CArray<double, 1>& fieldOut);
152        void scaleFactorAddOffset(double scaleFactor, double addOffset);
153        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
154        void parse(xml::CXMLNode& node);
155
156        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
157        void setVirtualVariableGroup(void);
158        CVariableGroup* getVirtualVariableGroup(void) const;
159        vector<CVariable*> getAllVariables(void) const;
160        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
161
162        CVariable* addVariable(const string& id = "");
163        CVariableGroup* addVariableGroup(const string& id = "");
164        void sendAddVariable(const string& id = "");
165        void sendAddVariableGroup(const string& id = "");
166        static void recvAddVariable(CEventServer& event);
167        void recvAddVariable(CBufferIn& buffer);
168        static void recvAddVariableGroup(CEventServer& event);
169        void recvAddVariableGroup(CBufferIn& buffer);
170        void sendAddAllVariables();
171
172
173        const std::pair<StdString, StdString>& getRefDomainAxisIds();
174
175      public:
176         /// Propriétés privées ///
177         CVariableGroup* vVariableGroup;
178
179         CGrid*  grid;
180         CFile*  file;
181
182         CDuration freq_operation_srv, freq_write_srv;
183
184         bool written; //<! Was the field written at least once
185         StdSize nstep, nstepMax;
186         bool isEOF;
187         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
188         CDate lastDataRequestedFromServer;
189
190         map<int,boost::shared_ptr<func::CFunctor> > foperation_srv;
191
192         map<int, CArray<double,1> > data_srv;
193         string content;
194
195         bool areAllReferenceSolved;
196         std::pair<StdString,StdString> domAxisIds_;
197         bool isReadDataRequestPending;
198         bool useCompressedOutput;
199
200         DECLARE_REF_FUNC(Field,field)
201
202      private:
203         //! The type of operation attached to the field
204         func::CFunctor::ETimeType operationTimeType;
205
206         //! The output pin of the filter providing the instant data for the field
207         boost::shared_ptr<COutputPin> instantDataFilter;
208         //! The output pin of the filters providing the result of the field's temporal operation
209         std::map<CDuration, boost::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
210         //! The source filter for data provided by the client
211         boost::shared_ptr<CSourceFilter> clientSourceFilter;
212         //! The source filter for data provided by the server
213         boost::shared_ptr<CSourceFilter> serverSourceFilter;
214         //! The terminal filter which stores the instant data
215         boost::shared_ptr<CStoreFilter> storeFilter;
216         //! The terminal filter which writes the data to file
217         boost::shared_ptr<CFileWriterFilter> fileWriterFilter;
218   }; // class CField
219
220   ///--------------------------------------------------------------
221
222   // Declare/Define CFieldGroup and CFieldDefinition
223   DECLARE_GROUP(CField);
224
225   ///-----------------------------------------------------------------
226
227   template <>
228      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
229
230   ///-----------------------------------------------------------------
231} // namespace xios
232
233
234#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.