[591] | 1 | #ifndef __XIOS_CField__ |
---|
| 2 | #define __XIOS_CField__ |
---|
[219] | 3 | |
---|
[591] | 4 | /// XIOS headers /// |
---|
| 5 | #include "xios_spl.hpp" |
---|
[219] | 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" |
---|
[231] | 12 | #include "calendar_util.hpp" |
---|
[369] | 13 | #include "array_new.hpp" |
---|
| 14 | #include "attribute_array.hpp" |
---|
[540] | 15 | #include "declare_ref_func.hpp" |
---|
[619] | 16 | #include "transformation_enum.hpp" |
---|
[646] | 17 | #include "variable.hpp" |
---|
[1021] | 18 | #include "context_client.hpp" |
---|
[219] | 19 | |
---|
[300] | 20 | |
---|
[335] | 21 | namespace xios { |
---|
[509] | 22 | |
---|
[219] | 23 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 24 | |
---|
| 25 | class CFieldGroup; |
---|
| 26 | class CFieldAttributes; |
---|
| 27 | class CField; |
---|
| 28 | |
---|
| 29 | class CFile; |
---|
| 30 | class CGrid; |
---|
[640] | 31 | class CContext; |
---|
[619] | 32 | class CGenericFilter; |
---|
| 33 | |
---|
[640] | 34 | class CGarbageCollector; |
---|
| 35 | class COutputPin; |
---|
| 36 | class CSourceFilter; |
---|
| 37 | class CStoreFilter; |
---|
| 38 | class CFileWriterFilter; |
---|
[1024] | 39 | class CFileServerWriterFilter; |
---|
[640] | 40 | |
---|
[219] | 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 | |
---|
[1232] | 60 | enum EReadField |
---|
| 61 | { |
---|
| 62 | RF_NODATA, RF_EOF, RF_DATA |
---|
| 63 | }; |
---|
| 64 | |
---|
[707] | 65 | public: |
---|
[219] | 66 | |
---|
| 67 | typedef CFieldAttributes RelAttributes; |
---|
| 68 | typedef CFieldGroup RelGroup; |
---|
| 69 | |
---|
[300] | 70 | enum EEventId |
---|
| 71 | { |
---|
[598] | 72 | EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY, |
---|
| 73 | EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP |
---|
[651] | 74 | }; |
---|
[509] | 75 | |
---|
[219] | 76 | /// Constructeurs /// |
---|
| 77 | CField(void); |
---|
[651] | 78 | explicit CField(const StdString& id); |
---|
| 79 | CField(const CField& field); // Not implemented yet. |
---|
| 80 | CField(const CField* const field); // Not implemented yet. |
---|
[219] | 81 | |
---|
| 82 | /// Accesseurs /// |
---|
| 83 | |
---|
[651] | 84 | CGrid* getRelGrid(void) const; |
---|
| 85 | CFile* getRelFile(void) const; |
---|
[219] | 86 | |
---|
[645] | 87 | func::CFunctor::ETimeType getOperationTimeType() const; |
---|
| 88 | |
---|
[707] | 89 | public: |
---|
[952] | 90 | int getNStep(void) const; |
---|
[266] | 91 | |
---|
[593] | 92 | template <int N> void getData(CArray<double, N>& _data) const; |
---|
[219] | 93 | |
---|
[641] | 94 | boost::shared_ptr<COutputPin> getInstantDataFilter(); |
---|
[219] | 95 | |
---|
| 96 | /// Mutateur /// |
---|
[347] | 97 | void setRelFile(CFile* _file); |
---|
[266] | 98 | void incrementNStep(void); |
---|
[952] | 99 | void resetNStep(int nstep = 0); |
---|
[599] | 100 | void resetNStepMax(); |
---|
[219] | 101 | |
---|
[1236] | 102 | std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client); |
---|
| 103 | std::map<int, StdSize> getGridDataBufferSize(CContextClient* client); // Grid data buffer size for each connection of contextclient |
---|
[509] | 104 | |
---|
[707] | 105 | public: |
---|
[1158] | 106 | bool isActive(bool atCurrentTimestep = false) const; |
---|
[651] | 107 | bool hasOutputFile; |
---|
[219] | 108 | |
---|
[707] | 109 | bool wasWritten() const; |
---|
| 110 | void setWritten(); |
---|
| 111 | |
---|
[676] | 112 | bool getUseCompressedOutput() const; |
---|
| 113 | void setUseCompressedOutput(); |
---|
| 114 | |
---|
[219] | 115 | /// Traitements /// |
---|
| 116 | void solveGridReference(void); |
---|
[645] | 117 | void solveServerOperation(void); |
---|
[509] | 118 | void solveCheckMaskIndex(bool doSendingIndex); |
---|
[823] | 119 | void solveAllReferenceEnabledField(bool doSending2Server); |
---|
| 120 | void solveOnlyReferenceEnabledField(bool doSending2Server); |
---|
| 121 | void generateNewTransformationGridDest(); |
---|
| 122 | void updateRef(CGrid* grid); |
---|
| 123 | void buildGridTransformationGraph(); |
---|
[509] | 124 | void solveGridDomainAxisRef(bool checkAtt); |
---|
[619] | 125 | void solveTransformedGrid(); |
---|
[687] | 126 | void solveGenerateGrid(); |
---|
[775] | 127 | void solveGridDomainAxisBaseRef(); |
---|
[219] | 128 | |
---|
[1129] | 129 | void solveAllEnabledFieldsAndTransform(); |
---|
[1024] | 130 | void checkGridOfEnabledFields(); |
---|
| 131 | void sendGridOfEnabledFields(); |
---|
[1239] | 132 | void sendGridComponentOfEnabledFields(); |
---|
[1024] | 133 | |
---|
[640] | 134 | void buildFilterGraph(CGarbageCollector& gc, bool enableOutput); |
---|
[1215] | 135 | size_t getGlobalWrittenSize(void) ; |
---|
| 136 | |
---|
| 137 | |
---|
[737] | 138 | boost::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc); |
---|
[642] | 139 | boost::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc); |
---|
[643] | 140 | boost::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq); |
---|
[1021] | 141 | boost::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq); |
---|
[640] | 142 | |
---|
[651] | 143 | // virtual void fromBinary(StdIStream& is); |
---|
[219] | 144 | |
---|
| 145 | /// Destructeur /// |
---|
| 146 | virtual ~CField(void); |
---|
| 147 | |
---|
| 148 | /// Accesseurs statiques /// |
---|
| 149 | static StdString GetName(void); |
---|
| 150 | static StdString GetDefName(void); |
---|
[509] | 151 | |
---|
[219] | 152 | static ENodeType GetType(void); |
---|
[509] | 153 | |
---|
[651] | 154 | template <int N> void setData(const CArray<double, N>& _data); |
---|
| 155 | static bool dispatchEvent(CEventServer& event); |
---|
[638] | 156 | void sendUpdateData(const CArray<double,1>& data); |
---|
[1099] | 157 | void sendUpdateData(const CArray<double,1>& data, CContextClient* client); |
---|
[651] | 158 | static void recvUpdateData(CEventServer& event); |
---|
[1024] | 159 | void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers); |
---|
[651] | 160 | void writeField(void); |
---|
[1158] | 161 | bool sendReadDataRequest(const CDate& tsDataRequested); |
---|
[598] | 162 | bool sendReadDataRequestIfNeeded(void); |
---|
| 163 | static void recvReadDataRequest(CEventServer& event); |
---|
| 164 | void recvReadDataRequest(void); |
---|
[1232] | 165 | EReadField readField(void); |
---|
[598] | 166 | static void recvReadDataReady(CEventServer& event); |
---|
| 167 | void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); |
---|
[1158] | 168 | void outputField(CArray<double,3>& fieldOut); |
---|
| 169 | void outputField(CArray<double,2>& fieldOut); |
---|
[651] | 170 | void outputField(CArray<double,1>& fieldOut); |
---|
[1158] | 171 | void inputField(CArray<double,3>& fieldOut); |
---|
| 172 | void inputField(CArray<double,2>& fieldOut); |
---|
[599] | 173 | void inputField(CArray<double,1>& fieldOut); |
---|
[676] | 174 | void outputCompressedField(CArray<double, 1>& fieldOut); |
---|
[651] | 175 | void scaleFactorAddOffset(double scaleFactor, double addOffset); |
---|
[599] | 176 | void invertScaleFactorAddOffset(double scaleFactor, double addOffset); |
---|
[651] | 177 | void parse(xml::CXMLNode& node); |
---|
[509] | 178 | |
---|
[472] | 179 | void setVirtualVariableGroup(CVariableGroup* newVVariableGroup); |
---|
| 180 | CVariableGroup* getVirtualVariableGroup(void) const; |
---|
| 181 | vector<CVariable*> getAllVariables(void) const; |
---|
[651] | 182 | virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0); |
---|
[509] | 183 | |
---|
[651] | 184 | CVariable* addVariable(const string& id = ""); |
---|
[1144] | 185 | CVariableGroup* addVariableGroup(const string& id = ""); |
---|
[1021] | 186 | void sendAddVariable(const string& id, CContextClient* client); |
---|
[1144] | 187 | void sendAddVariableGroup(const string& id, CContextClient* client); |
---|
[651] | 188 | static void recvAddVariable(CEventServer& event); |
---|
| 189 | void recvAddVariable(CBufferIn& buffer); |
---|
| 190 | static void recvAddVariableGroup(CEventServer& event); |
---|
[1144] | 191 | void recvAddVariableGroup(CBufferIn& buffer); |
---|
[1021] | 192 | void sendAddAllVariables(CContextClient* client); |
---|
[1024] | 193 | void writeUpdateData(const CArray<double,1>& data); |
---|
[509] | 194 | |
---|
[887] | 195 | const std::vector<StdString>& getRefDomainAxisIds(); |
---|
[619] | 196 | |
---|
[1021] | 197 | const string& getExpression(void); |
---|
| 198 | bool hasExpression(void) const; |
---|
| 199 | |
---|
[707] | 200 | public: |
---|
[219] | 201 | /// Propriétés privées /// |
---|
[651] | 202 | CVariableGroup* vVariableGroup; |
---|
[509] | 203 | |
---|
[651] | 204 | CGrid* grid; |
---|
[347] | 205 | CFile* file; |
---|
[219] | 206 | |
---|
[343] | 207 | CDuration freq_operation_srv, freq_write_srv; |
---|
[219] | 208 | |
---|
[707] | 209 | bool written; //<! Was the field written at least once |
---|
[952] | 210 | int nstep, nstepMax; |
---|
[599] | 211 | bool isEOF; |
---|
[651] | 212 | CDate lastlast_Write_srv, last_Write_srv, last_operation_srv; |
---|
[1021] | 213 | CDate lastDataRequestedFromServer, lastDataReceivedFromServer; |
---|
| 214 | bool wasDataAlreadyReceivedFromServer; |
---|
[509] | 215 | |
---|
[300] | 216 | map<int,boost::shared_ptr<func::CFunctor> > foperation_srv; |
---|
[509] | 217 | |
---|
[1144] | 218 | // map<int, CArray<double,1> > data_srv; |
---|
[1024] | 219 | CArray<double,1> recvDataSrv; |
---|
| 220 | |
---|
| 221 | boost::shared_ptr<func::CFunctor> recvFoperationSrv; |
---|
[651] | 222 | string content; |
---|
[509] | 223 | |
---|
[887] | 224 | std::vector<StdString> domAxisScalarIds_; |
---|
[676] | 225 | bool useCompressedOutput; |
---|
[645] | 226 | |
---|
[1021] | 227 | // Two variables to identify the time_counter meta data written in file, which has no time_counter |
---|
| 228 | bool hasTimeInstant; |
---|
| 229 | bool hasTimeCentered; |
---|
| 230 | |
---|
[1129] | 231 | |
---|
[540] | 232 | DECLARE_REF_FUNC(Field,field) |
---|
[219] | 233 | |
---|
[640] | 234 | private: |
---|
[1129] | 235 | bool areAllReferenceSolved; |
---|
| 236 | bool isReferenceSolved; |
---|
| 237 | bool isReferenceSolvedAndTransformed; |
---|
[1232] | 238 | bool nstepMaxRead; |
---|
[1129] | 239 | |
---|
| 240 | private: |
---|
[645] | 241 | //! The type of operation attached to the field |
---|
| 242 | func::CFunctor::ETimeType operationTimeType; |
---|
| 243 | |
---|
[640] | 244 | //! The output pin of the filter providing the instant data for the field |
---|
| 245 | boost::shared_ptr<COutputPin> instantDataFilter; |
---|
[643] | 246 | //! The output pin of the filters providing the result of the field's temporal operation |
---|
| 247 | std::map<CDuration, boost::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters; |
---|
[737] | 248 | //! The output pin of the filter providing the instant data for self references |
---|
| 249 | boost::shared_ptr<COutputPin> selfReferenceFilter; |
---|
[640] | 250 | //! The source filter for data provided by the client |
---|
| 251 | boost::shared_ptr<CSourceFilter> clientSourceFilter; |
---|
| 252 | //! The source filter for data provided by the server |
---|
| 253 | boost::shared_ptr<CSourceFilter> serverSourceFilter; |
---|
| 254 | //! The terminal filter which stores the instant data |
---|
| 255 | boost::shared_ptr<CStoreFilter> storeFilter; |
---|
[1158] | 256 | //! The terminal filter which writes the data to file |
---|
[640] | 257 | boost::shared_ptr<CFileWriterFilter> fileWriterFilter; |
---|
[1024] | 258 | //! The terminal filter which writes data to file |
---|
| 259 | boost::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter; |
---|
[219] | 260 | }; // class CField |
---|
| 261 | |
---|
| 262 | ///-------------------------------------------------------------- |
---|
| 263 | |
---|
| 264 | // Declare/Define CFieldGroup and CFieldDefinition |
---|
| 265 | DECLARE_GROUP(CField); |
---|
| 266 | |
---|
| 267 | ///----------------------------------------------------------------- |
---|
| 268 | |
---|
| 269 | template <> |
---|
| 270 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void); |
---|
| 271 | |
---|
| 272 | ///----------------------------------------------------------------- |
---|
[335] | 273 | } // namespace xios |
---|
[219] | 274 | |
---|
| 275 | |
---|
[591] | 276 | #endif // __XIOS_CField__ |
---|