#ifndef __XIOS_CField__ #define __XIOS_CField__ /// XIOS headers /// #include "xios_spl.hpp" #include "group_factory.hpp" #include "functor.hpp" #include "functor_type.hpp" #include "duration.hpp" #include "date.hpp" #include "declare_group.hpp" #include "calendar_util.hpp" #include "array_new.hpp" #include "attribute_array.hpp" #include "declare_ref_func.hpp" #include "transformation_enum.hpp" #include "variable.hpp" #include "context_client.hpp" #include "pass_through_filter.hpp" #include "temporal_filter.hpp" namespace xios { /// ////////////////////// Déclarations ////////////////////// /// class CFieldGroup; class CFieldAttributes; class CField; class CFile; class CCouplerIn ; class CCouplerOut ; class CGrid; class CContext; class CGenericFilter; class CGarbageCollector; class COutputPin; class CSourceFilter; class CStoreFilter; class CFileWriterFilter; class CFileServerWriterFilter; ///-------------------------------------------------------------- // Declare/Define CFieldAttribute BEGIN_DECLARE_ATTRIBUTE_MAP(CField) # include "field_attribute.conf" END_DECLARE_ATTRIBUTE_MAP(CField) class CContextClient ; ///-------------------------------------------------------------- class CField : public CObjectTemplate , public CFieldAttributes { /// friend /// friend class CFile; /// typedef /// typedef CObjectTemplate SuperClass; typedef CFieldAttributes SuperClassAttribute; enum EReadField { RF_NODATA, RF_EOF, RF_DATA }; public: typedef CFieldAttributes RelAttributes; typedef CFieldGroup RelGroup; enum EEventId { EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY, EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_GRID_COMPLETED }; /// Constructeurs /// CField(void); explicit CField(const StdString& id); CField(const CField& field); // Not implemented yet. CField(const CField* const field); // Not implemented yet. /// Accesseurs /// CGrid* getRelGrid(void) const; CFile* getRelFile(void) const; func::CFunctor::ETimeType getOperationTimeType() const; public: int getNStep(void) const; template void getData(CArray& _data) const; std::shared_ptr getInstantDataFilter(); /// Mutateur /// void setRelFile(CFile* _file); void incrementNStep(void); void resetNStep(int nstep = 0); void resetNStepMax(); std::map getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting = false); // Grid data buffer size for each connection of contextclient std::map getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false); public: void makeGridAliasForCoupling(void) ; public: bool isActive(bool atCurrentTimestep = false) const; bool hasOutputFile; bool wasWritten() const; void setWritten(); bool getUseCompressedOutput() const; void setUseCompressedOutput(); /// Traitements /// void solveGridReference(void); void solveServerOperation(void); void solveCheckMaskIndex(bool doSendingIndex); void solveAllReferenceEnabledField(bool doSending2Server); void solveOnlyReferenceEnabledField(void); void generateNewTransformationGridDest(); void updateRef(CGrid* grid); void buildGridTransformationGraph(); void solveGridDomainAxisRef(bool checkAtt); void solveTransformedGrid(); void solveGenerateGrid(); void solveGridDomainAxisBaseRef(); void solveAllEnabledFieldsAndTransform(); void checkGridOfEnabledFields(); void sendGridOfEnabledFields(); void sendGridComponentOfEnabledFields(); void sendFieldToFileServer(void) ; void sendCloseDefinition(void) ; public: void sendFieldToCouplerOut(void) ; private: bool sendFieldToCouplerOut_done_=false; public: void sendFieldToInputFileServer(void) ; /// Vérifications /// void checkTimeAttributes(CDuration* freqOp=NULL); void buildFilterGraph(CGarbageCollector& gc, bool enableOutput); bool buildWorkflowGraph(CGarbageCollector& gc) ; bool buildWorkflowGraphDone_ = false ; size_t getGlobalWrittenSize(void) ; std::shared_ptr getFieldReference(CGarbageCollector& gc); std::shared_ptr getSelfReference(CGarbageCollector& gc); std::shared_ptr getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq); std::shared_ptr getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq); // virtual void fromBinary(StdIStream& is); /// Destructeur /// virtual ~CField(void); /// Accesseurs statiques /// static StdString GetName(void); static StdString GetDefName(void); static ENodeType GetType(void); template void setData(const CArray& _data); static bool dispatchEvent(CEventServer& event); void sendAllAttributesToServer(CContextClient* client) ; void sendUpdateData(const CArray& data); void sendUpdateData(Time timestamp, const CArray& data, CContextClient* client); static void recvUpdateData(CEventServer& event); void recvUpdateData(std::map& rankBuffers); void recvUpdateDataFromClient(std::map& rankBuffers); void recvUpdateDataFromCoupler(std::map& rankBuffers); void writeField(void); bool sendReadDataRequest(const CDate& tsDataRequested, CContextClient* client); bool sendReadDataRequestIfNeeded(void); static void recvReadDataRequest(CEventServer& event); void recvReadDataRequest(CContextServer* server); EReadField readField(void); static void recvReadDataReady(CEventServer& event); void recvReadDataReady(vector ranks, vector buffers); void recvDataFromCoupler(vector ranks, vector buffers) ; void checkForLateDataFromServer(void); void checkForLateDataFromCoupler(void) ; void checkIfMustAutoTrigger(void); // ym obsolete void autoTriggerIfNeeded(void); //ym obsolete void triggerLateField(void) ; void outputField(CArray& fieldOut); void outputField(CArray& fieldOut); void outputField(CArray& fieldOut); void inputField(CArray& fieldOut); void inputField(CArray& fieldOut); void inputField(CArray& fieldOut); void outputCompressedField(CArray& fieldOut); void scaleFactorAddOffset(double scaleFactor, double addOffset); void invertScaleFactorAddOffset(double scaleFactor, double addOffset); void parse(xml::CXMLNode& node); void setVirtualVariableGroup(CVariableGroup* newVVariableGroup); CVariableGroup* getVirtualVariableGroup(void) const; vector getAllVariables(void) const; virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0); CVariable* addVariable(const string& id = ""); CVariableGroup* addVariableGroup(const string& id = ""); void sendAddVariable(const string& id, CContextClient* client); void sendAddVariableGroup(const string& id, CContextClient* client); static void recvAddVariable(CEventServer& event); void recvAddVariable(CBufferIn& buffer); static void recvAddVariableGroup(CEventServer& event); void recvAddVariableGroup(CBufferIn& buffer); void sendAddAllVariables(CContextClient* client); void writeUpdateData(const CArray& data); const std::vector& getRefDomainAxisIds(); const string& getExpression(void); bool hasExpression(void) const; bool hasGridMask(void) const; CGrid* getGrid(void) { return grid_; } void connectToFileServer(CGarbageCollector& gc) ; void connectToCouplerOut(CGarbageCollector& gc) ; void connectToCouplerIn(CGarbageCollector& gc) ; void connectToModelInput(CGarbageCollector& gc) ; void connectToFileWriter(CGarbageCollector& gc) ; void connectToClientInput(CGarbageCollector& gc) ; void connectToServerInput(CGarbageCollector& gc) ; void connectToModelOutput(CGarbageCollector& gc); void computeGridIndexToFileServer(void) ; void setContextClientDataBufferSize(map>& bufferSize, map>& maxEventSize, bool bufferForWriting) ; void setContextClientAttributesBufferSize(map>& bufferSize, map>& maxEventSize, bool bufferForWriting) ; private: bool isGridCompleted_ = true ; public: bool isGridCompleted() { return isGridCompleted_ ;} void setGridCompleted(void) { isGridCompleted_= true; } void unsetGridCompleted(void) { isGridCompleted_ = false ;} public: void sendGridCompleted(void) ; private: static void recvGridCompleted(CEventServer& event); void recvGridCompleted(CBufferIn& buffer); private: std::vector getGridPath(void) ; public: /// Propriétés privées /// CVariableGroup* vVariableGroup; CGrid* grid_=nullptr; // CFile* file; CFile* fileIn_ = nullptr ; // > foperation_srv; // map > data_srv; CArray recvDataSrv; std::shared_ptr recvFoperationSrv; string content; std::vector domAxisScalarIds_; bool useCompressedOutput; // Two variables to identify the time_counter meta data written in file, which has no time_counter bool hasTimeInstant; bool hasTimeCentered; DECLARE_REF_FUNC(Field,field) private: CContextClient* client; public: void setContextClient(CContextClient* newContextClient); CContextClient* getContextClient(void) {return client;} private: bool areAllReferenceSolved; bool isReferenceSolved; bool isReferenceSolvedAndTransformed; bool isGridChecked; bool nstepMaxRead; private: //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull bool workflowEnabled_ = false ; public: /*! workflowEnabled_ public accessor * \return Value of workflowEnabled_ */ bool getWorkflowEnabled(void) { return workflowEnabled_; } private: //! The type of operation attached to the field func::CFunctor::ETimeType operationTimeType; //! The output pin of the input filter of the field std::shared_ptr inputFilter; //! The self temporal data filter std::shared_ptr selfTemporalDataFilter ; //! The output pin of the filter providing the instant data for the field std::shared_ptr instantDataFilter; //! The output pin of the filters providing the result of the field's temporal operation std::map, DurationFakeLessComparator> temporalDataFilters; //! The output pin of the filter providing the instant data for self references std::shared_ptr selfReferenceFilter; // probably redondant with inputFilter //! The source filter for data provided by the client std::shared_ptr clientSourceFilter; //! The source filter for data provided by the server std::shared_ptr serverSourceFilter; //! The terminal filter which stores the instant data std::shared_ptr storeFilter; //! The terminal filter which writes the data to file std::shared_ptr fileWriterFilter; //! The terminal filter which writes data to file std::shared_ptr fileServerWriterFilter; }; // class CField ///-------------------------------------------------------------- // Declare/Define CFieldGroup and CFieldDefinition DECLARE_GROUP(CField); ///----------------------------------------------------------------- template <> void CGroupTemplate::solveRefInheritance(void); ///----------------------------------------------------------------- } // namespace xios #endif // __XIOS_CField__