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 "expr_node.hpp" |
---|
16 | #include "declare_ref_func.hpp" |
---|
17 | #include "generic_filter.hpp" |
---|
18 | #include "transformation_enum.hpp" |
---|
19 | |
---|
20 | |
---|
21 | namespace 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 | ///-------------------------------------------------------------- |
---|
35 | |
---|
36 | // Declare/Define CFieldAttribute |
---|
37 | BEGIN_DECLARE_ATTRIBUTE_MAP(CField) |
---|
38 | # include "field_attribute.conf" |
---|
39 | END_DECLARE_ATTRIBUTE_MAP(CField) |
---|
40 | |
---|
41 | ///-------------------------------------------------------------- |
---|
42 | class CField |
---|
43 | : public CObjectTemplate<CField> |
---|
44 | , public CFieldAttributes |
---|
45 | { |
---|
46 | /// friend /// |
---|
47 | friend class CFile; |
---|
48 | |
---|
49 | /// typedef /// |
---|
50 | typedef CObjectTemplate<CField> SuperClass; |
---|
51 | typedef CFieldAttributes SuperClassAttribute; |
---|
52 | |
---|
53 | public : |
---|
54 | |
---|
55 | typedef CFieldAttributes RelAttributes; |
---|
56 | typedef CFieldGroup RelGroup; |
---|
57 | |
---|
58 | enum EEventId |
---|
59 | { |
---|
60 | EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY, |
---|
61 | EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP |
---|
62 | } ; |
---|
63 | |
---|
64 | /// Constructeurs /// |
---|
65 | CField(void); |
---|
66 | explicit CField(const StdString & id); |
---|
67 | CField(const CField & field); // Not implemented yet. |
---|
68 | CField(const CField * const field); // Not implemented yet. |
---|
69 | |
---|
70 | /// Accesseurs /// |
---|
71 | |
---|
72 | CGrid* getRelGrid(void) const ; |
---|
73 | CFile* getRelFile(void) const ; |
---|
74 | |
---|
75 | public : |
---|
76 | |
---|
77 | StdSize getNStep(void) const; |
---|
78 | |
---|
79 | const CDuration & getFreqOperation(void) const; |
---|
80 | const CDuration & getFreqWrite(void) const; |
---|
81 | |
---|
82 | boost::shared_ptr<CDate> getLastWriteDate(void) const; |
---|
83 | boost::shared_ptr<CDate> getLastOperationDate(void) const; |
---|
84 | |
---|
85 | boost::shared_ptr<func::CFunctor> getFieldOperation(void) const; |
---|
86 | |
---|
87 | CArray<double, 1> getData(void) const; |
---|
88 | template <int N> void getData(CArray<double, N>& _data) const; |
---|
89 | |
---|
90 | |
---|
91 | /// Mutateur /// |
---|
92 | void setRelFile(CFile* _file); |
---|
93 | void incrementNStep(void); |
---|
94 | void resetNStep() ; |
---|
95 | void resetNStepMax(); |
---|
96 | |
---|
97 | template <int N> bool updateData(const CArray<double, N>& data); |
---|
98 | template <int N> bool updateFilteredData(CArray<double, N>& data); |
---|
99 | template<int N> |
---|
100 | void updateDataWithoutOperation(const CArray<double, N>& data); |
---|
101 | bool updateDataFromExpression(const CArray<double, 1>& data); |
---|
102 | void setDataFromExpression(const CArray<double, 1>& _data) ; |
---|
103 | |
---|
104 | bool updateDataServer |
---|
105 | (const CDate & currDate, |
---|
106 | const std::deque< CArray<double, 1>* > storedClient); |
---|
107 | |
---|
108 | std::map<int, StdSize> getGridDataSize(); |
---|
109 | |
---|
110 | public : |
---|
111 | bool isActive(void) const; |
---|
112 | bool active ; |
---|
113 | bool hasOutputFile ; |
---|
114 | bool hasFieldOut ; |
---|
115 | |
---|
116 | /// Traitements /// |
---|
117 | void processEnabledField(void) ; |
---|
118 | |
---|
119 | void solveGridReference(void); |
---|
120 | void solveOperation(void); |
---|
121 | void solveCheckMaskIndex(bool doSendingIndex); |
---|
122 | void solveAllReferenceEnabledField(bool doSending2Sever); |
---|
123 | void buildAllExpressionEnabledField(); |
---|
124 | void solveGridDomainAxisRef(bool checkAtt); |
---|
125 | void solveTransformedGrid(); |
---|
126 | CGrid* getGridRefOfBaseReference(); |
---|
127 | |
---|
128 | // virtual void fromBinary(StdIStream & is); |
---|
129 | |
---|
130 | /// Destructeur /// |
---|
131 | virtual ~CField(void); |
---|
132 | |
---|
133 | /// Accesseurs statiques /// |
---|
134 | static StdString GetName(void); |
---|
135 | static StdString GetDefName(void); |
---|
136 | |
---|
137 | static ENodeType GetType(void); |
---|
138 | |
---|
139 | template <int N> void setData(const CArray<double, N>& _data) ; |
---|
140 | static bool dispatchEvent(CEventServer& event) ; |
---|
141 | void sendUpdateData(void) ; |
---|
142 | static void recvUpdateData(CEventServer& event) ; |
---|
143 | void recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) ; |
---|
144 | void writeField(void) ; |
---|
145 | void sendReadDataRequest(void); |
---|
146 | bool sendReadDataRequestIfNeeded(void); |
---|
147 | static void recvReadDataRequest(CEventServer& event); |
---|
148 | void recvReadDataRequest(void); |
---|
149 | bool readField(void); |
---|
150 | static void recvReadDataReady(CEventServer& event); |
---|
151 | void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); |
---|
152 | void outputField(CArray<double,3>& fieldOut) ; |
---|
153 | void outputField(CArray<double,2>& fieldOut) ; |
---|
154 | void outputField(CArray<double,1>& fieldOut) ; |
---|
155 | void inputField(CArray<double,3>& fieldOut); |
---|
156 | void inputField(CArray<double,2>& fieldOut); |
---|
157 | void inputField(CArray<double,1>& fieldOut); |
---|
158 | void scaleFactorAddOffset(double scaleFactor, double addOffset) ; |
---|
159 | void invertScaleFactorAddOffset(double scaleFactor, double addOffset); |
---|
160 | void parse(xml::CXMLNode & node) ; |
---|
161 | CArray<double,1>* getInstantData(void) ; |
---|
162 | |
---|
163 | void setVirtualVariableGroup(CVariableGroup* newVVariableGroup); |
---|
164 | void setVirtualVariableGroup(void); |
---|
165 | CVariableGroup* getVirtualVariableGroup(void) const; |
---|
166 | vector<CVariable*> getAllVariables(void) const; |
---|
167 | virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); |
---|
168 | |
---|
169 | CVariable* addVariable(const string& id="") ; |
---|
170 | CVariableGroup* addVariableGroup(const string& id="") ; |
---|
171 | void sendAddVariable(const string& id="") ; |
---|
172 | void sendAddVariableGroup(const string& id="") ; |
---|
173 | static void recvAddVariable(CEventServer& event) ; |
---|
174 | void recvAddVariable(CBufferIn& buffer) ; |
---|
175 | static void recvAddVariableGroup(CEventServer& event) ; |
---|
176 | void recvAddVariableGroup(CBufferIn& buffer) ; |
---|
177 | void sendAddAllVariables(); |
---|
178 | |
---|
179 | |
---|
180 | const std::pair<StdString, StdString>& getRefDomainAxisIds(); |
---|
181 | |
---|
182 | const std::vector<CField*>& getFilterSources(); |
---|
183 | void applyFilter(); |
---|
184 | void setAlgorithms(); |
---|
185 | public : |
---|
186 | /// Propriétés privées /// |
---|
187 | CVariableGroup* vVariableGroup ; |
---|
188 | |
---|
189 | CGrid* grid ; |
---|
190 | CFile* file; |
---|
191 | CField* fieldOut ; |
---|
192 | |
---|
193 | CDuration freq_operation, freq_write; |
---|
194 | CDuration freq_operation_srv, freq_write_srv; |
---|
195 | |
---|
196 | StdSize nstep, nstepMax; |
---|
197 | bool isEOF; |
---|
198 | boost::shared_ptr<CDate> last_Write, last_operation; |
---|
199 | boost::shared_ptr<CDate> lastlast_Write_srv,last_Write_srv, last_operation_srv; |
---|
200 | CDate lastDataRequestedFromServer; |
---|
201 | |
---|
202 | boost::shared_ptr<func::CFunctor> foperation; |
---|
203 | map<int,boost::shared_ptr<func::CFunctor> > foperation_srv; |
---|
204 | |
---|
205 | CArray<double, 1> data; |
---|
206 | CArray<double, 1> instantData; |
---|
207 | CArray<double, 1> filteredData; |
---|
208 | bool hasInstantData ; |
---|
209 | map<int, CArray<double,1>* > data_srv ; |
---|
210 | bool isOnceOperation ; |
---|
211 | bool isFirstOperation ; |
---|
212 | string content ; |
---|
213 | |
---|
214 | list< pair<CField *,int> > fieldDependency ; |
---|
215 | void buildExpression(void) ; |
---|
216 | void addDependency(CField* field, int slotId) ; |
---|
217 | void resetSlots(void) ; |
---|
218 | vector<bool> slots ; |
---|
219 | CDate* slotUpdateDate ; |
---|
220 | CFieldNode * expression ; |
---|
221 | bool hasExpression ; |
---|
222 | bool slotsFull(void) ; |
---|
223 | void setSlot(int slotId); |
---|
224 | bool processed ; |
---|
225 | bool areAllReferenceSolved; |
---|
226 | bool areAllExpressionBuilt; |
---|
227 | std::pair<StdString,StdString> domAxisIds_; |
---|
228 | bool isReadDataRequestPending; |
---|
229 | std::vector<CField*> filterSources_; |
---|
230 | std::vector<CGenericAlgorithm*> algorithms_; |
---|
231 | std::vector<ETransformationType> transformations_; |
---|
232 | DECLARE_REF_FUNC(Field,field) |
---|
233 | |
---|
234 | }; // class CField |
---|
235 | |
---|
236 | ///-------------------------------------------------------------- |
---|
237 | |
---|
238 | // Declare/Define CFieldGroup and CFieldDefinition |
---|
239 | DECLARE_GROUP(CField); |
---|
240 | |
---|
241 | ///----------------------------------------------------------------- |
---|
242 | |
---|
243 | template <> |
---|
244 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void); |
---|
245 | |
---|
246 | ///----------------------------------------------------------------- |
---|
247 | } // namespace xios |
---|
248 | |
---|
249 | |
---|
250 | #endif // __XIOS_CField__ |
---|