[591] | 1 | #ifndef __XIOS_CContext__ |
---|
| 2 | #define __XIOS_CContext__ |
---|
[219] | 3 | |
---|
[591] | 4 | /// XIOS headers /// |
---|
| 5 | #include "xios_spl.hpp" |
---|
[352] | 6 | //#include "node_type.hpp" |
---|
[549] | 7 | #include "calendar_wrapper.hpp" |
---|
[219] | 8 | |
---|
| 9 | #include "declare_group.hpp" |
---|
[300] | 10 | //#include "context_client.hpp" |
---|
| 11 | //#include "context_server.hpp" |
---|
| 12 | #include "data_output.hpp" |
---|
[219] | 13 | |
---|
[382] | 14 | #include "mpi.hpp" |
---|
[300] | 15 | |
---|
[219] | 16 | |
---|
[335] | 17 | namespace xios { |
---|
[549] | 18 | class CContextClient; |
---|
| 19 | class CContextServer; |
---|
[509] | 20 | |
---|
| 21 | |
---|
[219] | 22 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 23 | class CContextGroup; |
---|
| 24 | class CContextAttributes; |
---|
| 25 | class CContext; |
---|
[352] | 26 | class CFile; |
---|
[219] | 27 | ///-------------------------------------------------------------- |
---|
| 28 | |
---|
| 29 | // Declare/Define CFileAttribute |
---|
| 30 | BEGIN_DECLARE_ATTRIBUTE_MAP(CContext) |
---|
| 31 | # include "context_attribute.conf" |
---|
| 32 | END_DECLARE_ATTRIBUTE_MAP(CContext) |
---|
| 33 | |
---|
| 34 | ///-------------------------------------------------------------- |
---|
[509] | 35 | /*! |
---|
| 36 | \class CContext |
---|
| 37 | This class corresponds to the concrete presentation of context in xml file and in play an essential role in XIOS |
---|
| 38 | Each object of this class contains all root definition of elements: files, fiels, domains, axis, etc, ... from which |
---|
| 39 | we can have access to each element. |
---|
| 40 | In fact, every thing must a be inside a particuliar context. After the xml file (iodef.xml) is parsed, |
---|
| 41 | object of the class is created and its contains all information of other elements in the xml file. |
---|
| 42 | */ |
---|
[219] | 43 | class CContext |
---|
| 44 | : public CObjectTemplate<CContext> |
---|
| 45 | , public CContextAttributes |
---|
| 46 | { |
---|
[300] | 47 | public : |
---|
| 48 | enum EEventId |
---|
| 49 | { |
---|
| 50 | EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR, |
---|
[509] | 51 | EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE, |
---|
| 52 | EVENT_ID_POST_PROCESS |
---|
[549] | 53 | }; |
---|
[509] | 54 | |
---|
[219] | 55 | /// typedef /// |
---|
| 56 | typedef CObjectTemplate<CContext> SuperClass; |
---|
| 57 | typedef CContextAttributes SuperClassAttribute; |
---|
| 58 | |
---|
| 59 | public : |
---|
| 60 | |
---|
| 61 | typedef CContextAttributes RelAttributes; |
---|
| 62 | typedef CContext RelGroup; |
---|
| 63 | |
---|
| 64 | //--------------------------------------------------------- |
---|
| 65 | |
---|
| 66 | public : |
---|
| 67 | |
---|
| 68 | /// Constructeurs /// |
---|
| 69 | CContext(void); |
---|
| 70 | explicit CContext(const StdString & id); |
---|
| 71 | CContext(const CContext & context); // Not implemented yet. |
---|
| 72 | CContext(const CContext * const context); // Not implemented yet. |
---|
| 73 | |
---|
| 74 | /// Destructeur /// |
---|
| 75 | virtual ~CContext(void); |
---|
| 76 | |
---|
| 77 | //--------------------------------------------------------- |
---|
| 78 | |
---|
| 79 | public : |
---|
[509] | 80 | |
---|
[219] | 81 | /// Mutateurs /// |
---|
[343] | 82 | void setCalendar(boost::shared_ptr<CCalendar> newCalendar); |
---|
[509] | 83 | |
---|
[219] | 84 | /// Accesseurs /// |
---|
[343] | 85 | boost::shared_ptr<CCalendar> getCalendar(void) const; |
---|
[219] | 86 | |
---|
| 87 | public : |
---|
[509] | 88 | // Initialize server or client |
---|
[597] | 89 | void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0); |
---|
| 90 | void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0); |
---|
[549] | 91 | bool isInitialized(void); |
---|
[219] | 92 | |
---|
[509] | 93 | // Put sever or client into loop state |
---|
[549] | 94 | bool eventLoop(void); |
---|
[509] | 95 | |
---|
[597] | 96 | bool checkBuffersAndListen(void); |
---|
| 97 | |
---|
[509] | 98 | // Finalize a context |
---|
[549] | 99 | void finalize(void); |
---|
| 100 | void closeDefinition(void); |
---|
[509] | 101 | |
---|
| 102 | // Some functions to process context |
---|
[300] | 103 | void findAllEnabledFields(void); |
---|
[549] | 104 | void processEnabledFiles(void); |
---|
| 105 | void solveAllInheritance(bool apply=true); |
---|
[300] | 106 | void findEnabledFiles(void); |
---|
[598] | 107 | void findEnabledReadModeFiles(void); |
---|
[549] | 108 | void closeAllFile(void); |
---|
| 109 | void updateCalendar(int step); |
---|
| 110 | void createFileHeader(void ); |
---|
[509] | 111 | void solveAllRefOfEnabledFields(bool sendToServer); |
---|
| 112 | void buildAllExpressionOfEnabledFields(); |
---|
[598] | 113 | void startPrefetchingOfEnabledReadModeFiles(); |
---|
| 114 | void checkPrefetchingOfEnabledReadModeFiles(); |
---|
[593] | 115 | void findFieldsWithReadAccess(void); |
---|
| 116 | void solveAllRefOfFieldsWithReadAccess(); |
---|
| 117 | void buildAllExpressionOfFieldsWithReadAccess(); |
---|
[509] | 118 | void postProcessing(); |
---|
| 119 | |
---|
| 120 | std::map<int, StdSize>& getDataSize(); |
---|
| 121 | void setClientServerBuffer(); |
---|
| 122 | |
---|
| 123 | // Send context close definition |
---|
[549] | 124 | void sendCloseDefinition(void); |
---|
[509] | 125 | // There are something to send on closing context defintion |
---|
[549] | 126 | void sendUpdateCalendar(int step); |
---|
| 127 | void sendCreateFileHeader(void); |
---|
[509] | 128 | void sendEnabledFiles(); |
---|
| 129 | void sendEnabledFields(); |
---|
| 130 | void sendRefDomainsAxis(); |
---|
| 131 | void sendRefGrid(); |
---|
| 132 | void sendPostProcessing(); |
---|
| 133 | |
---|
[511] | 134 | const StdString& getIdServer(); |
---|
| 135 | |
---|
[509] | 136 | // Client side: Receive and process messages |
---|
[549] | 137 | static void recvUpdateCalendar(CEventServer& event); |
---|
| 138 | void recvUpdateCalendar(CBufferIn& buffer); |
---|
| 139 | static void recvCloseDefinition(CEventServer& event); |
---|
| 140 | static void recvCreateFileHeader(CEventServer& event); |
---|
| 141 | void recvCreateFileHeader(CBufferIn& buffer); |
---|
[509] | 142 | static void recvSolveInheritanceContext(CEventServer& event); |
---|
| 143 | void recvSolveInheritanceContext(CBufferIn& buffer); |
---|
| 144 | static void recvPostProcessing(CEventServer& event); |
---|
| 145 | void recvPostProcessing(CBufferIn& buffer); |
---|
| 146 | |
---|
| 147 | // dispatch event |
---|
[549] | 148 | static bool dispatchEvent(CEventServer& event); |
---|
[509] | 149 | |
---|
| 150 | public: |
---|
| 151 | // Get current context |
---|
| 152 | static CContext* getCurrent(void); |
---|
| 153 | |
---|
| 154 | // Get context root |
---|
| 155 | static CContextGroup* getRoot(void); |
---|
| 156 | |
---|
| 157 | // Set current context |
---|
| 158 | static void setCurrent(const string& id); |
---|
| 159 | |
---|
| 160 | // Create new context |
---|
| 161 | static CContext* create(const string& id = ""); |
---|
| 162 | |
---|
| 163 | /// Accesseurs statiques /// |
---|
| 164 | static StdString GetName(void); |
---|
| 165 | static StdString GetDefName(void); |
---|
| 166 | static ENodeType GetType(void); |
---|
| 167 | |
---|
| 168 | static CContextGroup* GetContextGroup(void); |
---|
| 169 | |
---|
| 170 | // Some functions to visualize structure of current context |
---|
| 171 | static void ShowTree(StdOStream & out = std::clog); |
---|
| 172 | static void CleanTree(void); |
---|
| 173 | |
---|
[219] | 174 | public : |
---|
[509] | 175 | // Parse xml node and write all info into context |
---|
[219] | 176 | virtual void parse(xml::CXMLNode & node); |
---|
| 177 | |
---|
[509] | 178 | // Visualize a context |
---|
[219] | 179 | virtual StdString toString(void) const; |
---|
[509] | 180 | |
---|
| 181 | |
---|
| 182 | // Solve all inheritance relation in current context |
---|
| 183 | virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); |
---|
| 184 | |
---|
| 185 | // Verify if all root definition in a context have children |
---|
| 186 | virtual bool hasChild(void) const; |
---|
| 187 | |
---|
[300] | 188 | public : |
---|
[509] | 189 | // Calendar of context |
---|
| 190 | boost::shared_ptr<CCalendar> calendar; |
---|
| 191 | |
---|
[598] | 192 | // List of all enabled files (files on which fields are written or read) |
---|
[347] | 193 | std::vector<CFile*> enabledFiles; |
---|
[598] | 194 | // List of all enabled files in read mode (files on which fields are read) |
---|
| 195 | std::vector<CFile*> enabledReadModeFiles; |
---|
[509] | 196 | |
---|
[593] | 197 | // List of all fields whose instant data is accessible from the public API |
---|
| 198 | std::vector<CField*> fieldsWithReadAccess; |
---|
| 199 | |
---|
[509] | 200 | // Context root |
---|
[549] | 201 | static shared_ptr<CContextGroup> root; |
---|
[219] | 202 | |
---|
[509] | 203 | // Determine context on client or not |
---|
[549] | 204 | bool hasClient; |
---|
[300] | 205 | |
---|
[509] | 206 | // Determine context on server or not |
---|
[549] | 207 | bool hasServer; |
---|
[509] | 208 | |
---|
| 209 | // Concrete context server |
---|
[549] | 210 | CContextServer* server; |
---|
[509] | 211 | |
---|
| 212 | // Concrete contex client |
---|
[549] | 213 | CContextClient* client; |
---|
[509] | 214 | |
---|
| 215 | private: |
---|
| 216 | bool isPostProcessed; |
---|
[597] | 217 | bool finalized; |
---|
[509] | 218 | std::map<int, StdSize> dataSize_; |
---|
[511] | 219 | StdString idServer_; |
---|
[509] | 220 | |
---|
| 221 | |
---|
| 222 | public: // Some function maybe removed in the near future |
---|
| 223 | // virtual void toBinary (StdOStream & os) const; |
---|
| 224 | // virtual void fromBinary(StdIStream & is); |
---|
| 225 | // void solveAllGridRef(void); |
---|
| 226 | // void solveAllOperation(void); |
---|
| 227 | // void solveAllExpression(void); |
---|
| 228 | // void solveFieldRefInheritance(bool apply); |
---|
| 229 | |
---|
[219] | 230 | }; // class CContext |
---|
| 231 | |
---|
| 232 | ///-------------------------------------------------------------- |
---|
| 233 | |
---|
| 234 | // Declare/Define CContextGroup and CContextDefinition |
---|
| 235 | DECLARE_GROUP(CContext); |
---|
| 236 | |
---|
| 237 | ///-------------------------------------------------------------- |
---|
| 238 | |
---|
[335] | 239 | } // namespace xios |
---|
[219] | 240 | |
---|
[591] | 241 | #endif // __XIOS_CContext__ |
---|