source: XIOS/dev/dev_trunk_omp/src/node/field.hpp @ 1711

Last change on this file since 1711 was 1681, checked in by yushan, 5 years ago

MARK: Dynamic workflow graph developement. Branch up to date with trunk @1676. Bug fixed

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