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