XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
field.hpp
Aller à la documentation de ce fichier.
1 #ifndef __XIOS_CField__
2 #define __XIOS_CField__
3 
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 
21 namespace xios {
22 
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 
42 
43  // Declare/Define CFieldAttribute
45 # include "field_attribute.conf"
47 
48 
49  class CField
50  : public CObjectTemplate<CField>
51  , public CFieldAttributes
52  {
54  friend class CFile;
55 
58  typedef CFieldAttributes SuperClassAttribute;
59 
61  {
62  RF_NODATA, RF_EOF, RF_DATA
63  };
64 
65  public:
66 
67  typedef CFieldAttributes RelAttributes;
68  typedef CFieldGroup RelGroup;
69 
70  enum EEventId
71  {
72  EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
73  EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP
74  };
75 
77  CField(void);
78  explicit CField(const StdString& id);
79  CField(const CField& field); // Not implemented yet.
80  CField(const CField* const field); // Not implemented yet.
81 
83 
84  CGrid* getRelGrid(void) const;
85  CFile* getRelFile(void) const;
86 
87  func::CFunctor::ETimeType getOperationTimeType() const;
88 
89  public:
90  int getNStep(void) const;
91 
92  template <int N> void getData(CArray<double, N>& _data) const;
93 
94  std::shared_ptr<COutputPin> getInstantDataFilter();
95 
97  void setRelFile(CFile* _file);
98  void incrementNStep(void);
99  void resetNStep(int nstep = 0);
100  void resetNStepMax();
101 
102  std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
103  // Grid data buffer size for each connection of contextclient
104  std::map<int, StdSize> getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false);
105 
106  void setContextClient(CContextClient* newContextClient);
107  CContextClient* getContextClient();
108 
109  public:
110  bool isActive(bool atCurrentTimestep = false) const;
112 
113  bool wasWritten() const;
114  void setWritten();
115 
116  bool getUseCompressedOutput() const;
117  void setUseCompressedOutput();
118 
120  void solveGridReference(void);
121  void solveServerOperation(void);
122  void solveCheckMaskIndex(bool doSendingIndex);
123  void solveAllReferenceEnabledField(bool doSending2Server);
124  void solveOnlyReferenceEnabledField(bool doSending2Server);
125  void generateNewTransformationGridDest();
126  void updateRef(CGrid* grid);
127  void buildGridTransformationGraph();
128  void solveGridDomainAxisRef(bool checkAtt);
129  void solveTransformedGrid();
130  void solveGenerateGrid();
131  void solveGridDomainAxisBaseRef();
132 
133  void solveAllEnabledFieldsAndTransform();
134  void checkGridOfEnabledFields();
135  void sendGridOfEnabledFields();
136  void sendGridComponentOfEnabledFields();
137 
139  void checkTimeAttributes(CDuration* freqOp=NULL);
140 
141  void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
142  size_t getGlobalWrittenSize(void) ;
143 
144 
145  std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
146  std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
147  std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
148  std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
149 
150 // virtual void fromBinary(StdIStream& is);
151 
153  virtual ~CField(void);
154 
156  static StdString GetName(void);
157  static StdString GetDefName(void);
158 
159  static ENodeType GetType(void);
160 
161  template <int N> void setData(const CArray<double, N>& _data);
162  static bool dispatchEvent(CEventServer& event);
163  void sendAllAttributesToServer(CContextClient* client) ;
164  void sendUpdateData(const CArray<double,1>& data);
165  void sendUpdateData(const CArray<double,1>& data, CContextClient* client);
166  static void recvUpdateData(CEventServer& event);
167  void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
168  void writeField(void);
169  bool sendReadDataRequest(const CDate& tsDataRequested);
170  bool sendReadDataRequestIfNeeded(void);
171  static void recvReadDataRequest(CEventServer& event);
172  void recvReadDataRequest(void);
173  EReadField readField(void);
174  static void recvReadDataReady(CEventServer& event);
175  void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
176  void checkForLateDataFromServer(void);
177  void checkIfMustAutoTrigger(void);
178  void autoTriggerIfNeeded(void);
179  void outputField(CArray<double,3>& fieldOut);
180  void outputField(CArray<double,2>& fieldOut);
181  void outputField(CArray<double,1>& fieldOut);
182  void inputField(CArray<double,3>& fieldOut);
183  void inputField(CArray<double,2>& fieldOut);
184  void inputField(CArray<double,1>& fieldOut);
185  void outputCompressedField(CArray<double, 1>& fieldOut);
186  void scaleFactorAddOffset(double scaleFactor, double addOffset);
187  void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
188  void parse(xml::CXMLNode& node);
189 
190  void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
191  CVariableGroup* getVirtualVariableGroup(void) const;
192  vector<CVariable*> getAllVariables(void) const;
193  virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
194 
195  CVariable* addVariable(const string& id = "");
196  CVariableGroup* addVariableGroup(const string& id = "");
197  void sendAddVariable(const string& id, CContextClient* client);
198  void sendAddVariableGroup(const string& id, CContextClient* client);
199  static void recvAddVariable(CEventServer& event);
200  void recvAddVariable(CBufferIn& buffer);
201  static void recvAddVariableGroup(CEventServer& event);
202  void recvAddVariableGroup(CBufferIn& buffer);
203  void sendAddAllVariables(CContextClient* client);
204  void writeUpdateData(const CArray<double,1>& data);
205 
206  const std::vector<StdString>& getRefDomainAxisIds();
207 
208  const string& getExpression(void);
209  bool hasExpression(void) const;
210 
211  bool hasGridMask(void) const;
212 
213  public:
215  CVariableGroup* vVariableGroup;
216 
219 
220  CDuration freq_operation_srv, freq_write_srv;
221 
222  bool written; //<! Was the field written at least once
223  int nstep, nstepMax;
224  bool isEOF;
225  CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
226  CDate lastDataRequestedFromServer, lastDataReceivedFromServer, dateEOF;
227  bool wasDataRequestedFromServer, wasDataAlreadyReceivedFromServer;
229 
230  map<int,std::shared_ptr<func::CFunctor> > foperation_srv;
231 
232  // map<int, CArray<double,1> > data_srv;
234 
235  std::shared_ptr<func::CFunctor> recvFoperationSrv;
236  string content;
237 
238  std::vector<StdString> domAxisScalarIds_;
240 
241  // Two variables to identify the time_counter meta data written in file, which has no time_counter
244 
245 
246  DECLARE_REF_FUNC(Field,field)
247 
248  private:
249  CContextClient* client;
250 
251  bool areAllReferenceSolved;
252  bool isReferenceSolved;
253  bool isReferenceSolvedAndTransformed;
254  bool isGridChecked;
255  bool nstepMaxRead;
256 
257  private:
259  func::CFunctor::ETimeType operationTimeType;
260 
262  std::shared_ptr<COutputPin> instantDataFilter;
264  std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
266  std::shared_ptr<COutputPin> selfReferenceFilter;
268  std::shared_ptr<CSourceFilter> clientSourceFilter;
270  std::shared_ptr<CSourceFilter> serverSourceFilter;
272  std::shared_ptr<CStoreFilter> storeFilter;
274  std::shared_ptr<CFileWriterFilter> fileWriterFilter;
276  std::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter;
277  }; // class CField
278 
280 
281  // Declare/Define CFieldGroup and CFieldDefinition
282  DECLARE_GROUP(CField);
283 
285 
286  template <>
287  void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
288 
290 } // namespace xios
291 
292 
293 #endif // __XIOS_CField__
bool hasOutputFile
Definition: field.hpp:111
CObjectTemplate< CField > SuperClass
typedef ///
Definition: field.hpp:57
#define END_DECLARE_ATTRIBUTE_MAP(type)
bool mustAutoTrigger
Definition: field.hpp:228
bool written
Definition: field.hpp:222
bool hasTimeCentered
Definition: field.hpp:243
bool useCompressedOutput
Definition: field.hpp:239
A terminal filter which transmits the packets it receives to a field for writting in a file...
CFieldAttributes SuperClassAttribute
Definition: field.hpp:58
std::string StdString
Definition: xios_spl.hpp:48
#define xios(arg)
A terminal filter which stores all the packets it receives.
////////////////////// Déclarations ////////////////////// ///
#define DECLARE_REF_FUNC(type, name_)
A terminal filter which writes the packets it receives in a file.
#define BEGIN_DECLARE_ATTRIBUTE_MAP(type)
CDate lastDataRequestedFromServer
Definition: field.hpp:226
map< int, std::shared_ptr< func::CFunctor > > foperation_srv
Definition: field.hpp:230
std::shared_ptr< func::CFunctor > recvFoperationSrv
Definition: field.hpp:235
A context can be both on client and on server side.
////////////////////// Déclarations ////////////////////// ///
CFile * file
Definition: field.hpp:218
CDuration freq_write_srv
Definition: field.hpp:220
////////////////////// Déclarations ////////////////////// ///
Definition: array.hpp:25
bool wasDataRequestedFromServer
Definition: field.hpp:227
string content
Definition: field.hpp:236
DECLARE_GROUP(CAxis)
CGrid * grid
Definition: field.hpp:217
CArray< double, 1 > recvDataSrv
Definition: field.hpp:233
int nstepMax
Definition: field.hpp:223
An output pin handles the connections with downstream filters.
Definition: output_pin.hpp:12
CFieldGroup RelGroup
Definition: field.hpp:68
Macros to add functions used to solve references in class CDomain, CAxis and CField.
CVariableGroup * vVariableGroup
Propriétés privées ///.
Definition: field.hpp:215
////////////////////// Déclarations ////////////////////// ///
enum xios::_node_type ENodeType
////////////////////// Définitions ////////////////////// ///
CDate lastlast_Write_srv
Definition: field.hpp:225
std::vector< StdString > domAxisScalarIds_
Definition: field.hpp:238
A basic garbage collector which ensures no old packets linger in the filter graph.
CFieldAttributes RelAttributes
Definition: field.hpp:67
A source filter is the entry point of the data in the graph of filters.
bool isEOF
Definition: field.hpp:224
bool hasTimeInstant
Definition: field.hpp:242