[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" |
---|
[639] | 13 | #include "garbage_collector.hpp" |
---|
[697] | 14 | #include "registry.hpp" |
---|
[382] | 15 | #include "mpi.hpp" |
---|
[300] | 16 | |
---|
[219] | 17 | |
---|
[335] | 18 | namespace xios { |
---|
[549] | 19 | class CContextClient; |
---|
| 20 | class CContextServer; |
---|
[509] | 21 | |
---|
| 22 | |
---|
[219] | 23 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 24 | class CContextGroup; |
---|
| 25 | class CContextAttributes; |
---|
| 26 | class CContext; |
---|
[352] | 27 | class CFile; |
---|
[219] | 28 | ///-------------------------------------------------------------- |
---|
| 29 | |
---|
| 30 | // Declare/Define CFileAttribute |
---|
| 31 | BEGIN_DECLARE_ATTRIBUTE_MAP(CContext) |
---|
| 32 | # include "context_attribute.conf" |
---|
| 33 | END_DECLARE_ATTRIBUTE_MAP(CContext) |
---|
| 34 | |
---|
| 35 | ///-------------------------------------------------------------- |
---|
[509] | 36 | /*! |
---|
| 37 | \class CContext |
---|
| 38 | This class corresponds to the concrete presentation of context in xml file and in play an essential role in XIOS |
---|
| 39 | Each object of this class contains all root definition of elements: files, fiels, domains, axis, etc, ... from which |
---|
| 40 | we can have access to each element. |
---|
| 41 | In fact, every thing must a be inside a particuliar context. After the xml file (iodef.xml) is parsed, |
---|
| 42 | object of the class is created and its contains all information of other elements in the xml file. |
---|
| 43 | */ |
---|
[219] | 44 | class CContext |
---|
| 45 | : public CObjectTemplate<CContext> |
---|
| 46 | , public CContextAttributes |
---|
| 47 | { |
---|
[300] | 48 | public : |
---|
| 49 | enum EEventId |
---|
| 50 | { |
---|
| 51 | EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR, |
---|
[509] | 52 | EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE, |
---|
[1139] | 53 | EVENT_ID_CONTEXT_POST_FINALIZE, |
---|
[1025] | 54 | EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY, |
---|
| 55 | EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES, |
---|
| 56 | EVENT_ID_PROCESS_GRID_ENABLED_FIELDS |
---|
[549] | 57 | }; |
---|
[509] | 58 | |
---|
[219] | 59 | /// typedef /// |
---|
| 60 | typedef CObjectTemplate<CContext> SuperClass; |
---|
| 61 | typedef CContextAttributes SuperClassAttribute; |
---|
| 62 | |
---|
| 63 | public : |
---|
| 64 | |
---|
| 65 | typedef CContextAttributes RelAttributes; |
---|
| 66 | typedef CContext RelGroup; |
---|
| 67 | |
---|
| 68 | //--------------------------------------------------------- |
---|
| 69 | |
---|
| 70 | public : |
---|
| 71 | |
---|
| 72 | /// Constructeurs /// |
---|
| 73 | CContext(void); |
---|
| 74 | explicit CContext(const StdString & id); |
---|
| 75 | CContext(const CContext & context); // Not implemented yet. |
---|
| 76 | CContext(const CContext * const context); // Not implemented yet. |
---|
| 77 | |
---|
| 78 | /// Destructeur /// |
---|
| 79 | virtual ~CContext(void); |
---|
| 80 | |
---|
| 81 | //--------------------------------------------------------- |
---|
| 82 | |
---|
| 83 | public : |
---|
[509] | 84 | |
---|
[219] | 85 | /// Mutateurs /// |
---|
[343] | 86 | void setCalendar(boost::shared_ptr<CCalendar> newCalendar); |
---|
[509] | 87 | |
---|
[219] | 88 | /// Accesseurs /// |
---|
[343] | 89 | boost::shared_ptr<CCalendar> getCalendar(void) const; |
---|
[219] | 90 | |
---|
| 91 | public : |
---|
[509] | 92 | // Initialize server or client |
---|
[983] | 93 | void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0); |
---|
[597] | 94 | void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0); |
---|
[549] | 95 | bool isInitialized(void); |
---|
[219] | 96 | |
---|
[509] | 97 | // Put sever or client into loop state |
---|
[597] | 98 | bool checkBuffersAndListen(void); |
---|
| 99 | |
---|
[509] | 100 | // Finalize a context |
---|
[549] | 101 | void finalize(void); |
---|
[1130] | 102 | void postFinalize(void); |
---|
[1071] | 103 | bool isFinalized(void); |
---|
[509] | 104 | |
---|
[1130] | 105 | void closeDefinition(void); |
---|
| 106 | |
---|
[509] | 107 | // Some functions to process context |
---|
[300] | 108 | void findAllEnabledFields(void); |
---|
[775] | 109 | void findAllEnabledFieldsInReadModeFiles(void); |
---|
| 110 | void readAttributesOfEnabledFieldsInReadModeFiles(); |
---|
[549] | 111 | void solveAllInheritance(bool apply=true); |
---|
[300] | 112 | void findEnabledFiles(void); |
---|
[598] | 113 | void findEnabledReadModeFiles(void); |
---|
[549] | 114 | void closeAllFile(void); |
---|
| 115 | void updateCalendar(int step); |
---|
| 116 | void createFileHeader(void ); |
---|
[676] | 117 | void checkAxisDomainsGridsEligibilityForCompressedOutput(); |
---|
[711] | 118 | void prepareTimeseries(void); |
---|
[1129] | 119 | void solveOnlyRefOfEnabledFields(bool sendToServer); |
---|
[640] | 120 | void buildFilterGraphOfEnabledFields(); |
---|
[598] | 121 | void startPrefetchingOfEnabledReadModeFiles(); |
---|
| 122 | void checkPrefetchingOfEnabledReadModeFiles(); |
---|
[593] | 123 | void findFieldsWithReadAccess(void); |
---|
| 124 | void solveAllRefOfFieldsWithReadAccess(); |
---|
[640] | 125 | void buildFilterGraphOfFieldsWithReadAccess(); |
---|
[509] | 126 | void postProcessing(); |
---|
[1025] | 127 | void postProcessingGlobalAttributes(); |
---|
[509] | 128 | |
---|
[1129] | 129 | void solveAllRefOfEnabledFieldsAndTransform(bool sendToServer); |
---|
[1025] | 130 | void solveAllEnabledFields(); |
---|
[1099] | 131 | void checkGridEnabledFields(); |
---|
| 132 | void sendGridEnabledFields(); |
---|
[1025] | 133 | |
---|
[917] | 134 | std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize); |
---|
| 135 | std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize); |
---|
[509] | 136 | void setClientServerBuffer(); |
---|
| 137 | |
---|
| 138 | // Send context close definition |
---|
[549] | 139 | void sendCloseDefinition(void); |
---|
[509] | 140 | // There are something to send on closing context defintion |
---|
[549] | 141 | void sendUpdateCalendar(int step); |
---|
| 142 | void sendCreateFileHeader(void); |
---|
[509] | 143 | void sendEnabledFiles(); |
---|
| 144 | void sendEnabledFields(); |
---|
| 145 | void sendRefDomainsAxis(); |
---|
| 146 | void sendRefGrid(); |
---|
| 147 | void sendPostProcessing(); |
---|
[1025] | 148 | void sendPostProcessingGlobalAttributes(); |
---|
| 149 | void sendProcessingGridOfEnabledFields(); |
---|
[983] | 150 | //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers |
---|
| 151 | void sendRegistry(void) ; |
---|
| 152 | |
---|
[511] | 153 | const StdString& getIdServer(); |
---|
[1009] | 154 | const StdString& getIdServer(const int srvPoolNb); |
---|
[511] | 155 | |
---|
[509] | 156 | // Client side: Receive and process messages |
---|
[549] | 157 | static void recvUpdateCalendar(CEventServer& event); |
---|
| 158 | void recvUpdateCalendar(CBufferIn& buffer); |
---|
| 159 | static void recvCloseDefinition(CEventServer& event); |
---|
| 160 | static void recvCreateFileHeader(CEventServer& event); |
---|
| 161 | void recvCreateFileHeader(CBufferIn& buffer); |
---|
[509] | 162 | static void recvSolveInheritanceContext(CEventServer& event); |
---|
| 163 | void recvSolveInheritanceContext(CBufferIn& buffer); |
---|
| 164 | static void recvPostProcessing(CEventServer& event); |
---|
| 165 | void recvPostProcessing(CBufferIn& buffer); |
---|
[1025] | 166 | static void recvProcessingGridOfEnabledFields(CEventServer& event); |
---|
| 167 | static void recvPostProcessingGlobalAttributes(CEventServer& event); |
---|
| 168 | void recvPostProcessingGlobalAttributes(CBufferIn& buffer); |
---|
[697] | 169 | static void recvRegistry(CEventServer& event) ; |
---|
[983] | 170 | void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers |
---|
[509] | 171 | |
---|
[1130] | 172 | void freeComms(void); //!< Free internally allcoated communicators |
---|
| 173 | void releaseClientBuffers(void); //! Deallocate buffers allocated by clientContexts |
---|
[1054] | 174 | |
---|
[509] | 175 | // dispatch event |
---|
[549] | 176 | static bool dispatchEvent(CEventServer& event); |
---|
[509] | 177 | |
---|
| 178 | public: |
---|
| 179 | // Get current context |
---|
| 180 | static CContext* getCurrent(void); |
---|
| 181 | |
---|
| 182 | // Get context root |
---|
| 183 | static CContextGroup* getRoot(void); |
---|
| 184 | |
---|
| 185 | // Set current context |
---|
| 186 | static void setCurrent(const string& id); |
---|
| 187 | |
---|
| 188 | // Create new context |
---|
| 189 | static CContext* create(const string& id = ""); |
---|
| 190 | |
---|
| 191 | /// Accesseurs statiques /// |
---|
| 192 | static StdString GetName(void); |
---|
| 193 | static StdString GetDefName(void); |
---|
| 194 | static ENodeType GetType(void); |
---|
| 195 | |
---|
| 196 | static CContextGroup* GetContextGroup(void); |
---|
| 197 | |
---|
| 198 | // Some functions to visualize structure of current context |
---|
| 199 | static void ShowTree(StdOStream & out = std::clog); |
---|
| 200 | static void CleanTree(void); |
---|
| 201 | |
---|
[219] | 202 | public : |
---|
[509] | 203 | // Parse xml node and write all info into context |
---|
[219] | 204 | virtual void parse(xml::CXMLNode & node); |
---|
| 205 | |
---|
[509] | 206 | // Visualize a context |
---|
[219] | 207 | virtual StdString toString(void) const; |
---|
[509] | 208 | |
---|
| 209 | |
---|
| 210 | // Solve all inheritance relation in current context |
---|
| 211 | virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0); |
---|
| 212 | |
---|
| 213 | // Verify if all root definition in a context have children |
---|
| 214 | virtual bool hasChild(void) const; |
---|
| 215 | |
---|
[1054] | 216 | |
---|
[300] | 217 | public : |
---|
[509] | 218 | // Calendar of context |
---|
| 219 | boost::shared_ptr<CCalendar> calendar; |
---|
| 220 | |
---|
[598] | 221 | // List of all enabled files (files on which fields are written or read) |
---|
[347] | 222 | std::vector<CFile*> enabledFiles; |
---|
[598] | 223 | // List of all enabled files in read mode (files on which fields are read) |
---|
| 224 | std::vector<CFile*> enabledReadModeFiles; |
---|
[509] | 225 | |
---|
[740] | 226 | // List of all enabled fields whose instant data is accessible from the public API |
---|
| 227 | // but which are not part of a file |
---|
[593] | 228 | std::vector<CField*> fieldsWithReadAccess; |
---|
| 229 | |
---|
[509] | 230 | // Context root |
---|
[549] | 231 | static shared_ptr<CContextGroup> root; |
---|
[219] | 232 | |
---|
[509] | 233 | // Determine context on client or not |
---|
[549] | 234 | bool hasClient; |
---|
[300] | 235 | |
---|
[509] | 236 | // Determine context on server or not |
---|
[549] | 237 | bool hasServer; |
---|
[509] | 238 | |
---|
[1130] | 239 | CContextServer* server; //!< Concrete context server |
---|
| 240 | CContextClient* client; //!< Concrete contex client |
---|
[1071] | 241 | std::vector<CContextServer*> serverPrimServer; |
---|
| 242 | std::vector<CContextClient*> clientPrimServer; |
---|
| 243 | |
---|
[1130] | 244 | CRegistry* registryIn ; //!< input registry which is read from file |
---|
| 245 | CRegistry* registryOut ; //!< output registry which will be written into file at the finalize |
---|
[775] | 246 | |
---|
[509] | 247 | private: |
---|
| 248 | bool isPostProcessed; |
---|
[1025] | 249 | bool allProcessed; |
---|
[1139] | 250 | bool finalized; |
---|
[1130] | 251 | int countChildCtx_; //!< Counter of child contexts (for now it is the number of secondary server pools) |
---|
[511] | 252 | StdString idServer_; |
---|
[639] | 253 | CGarbageCollector garbageCollector; |
---|
[1071] | 254 | std::list<MPI_Comm> comms; //!< Communicators allocated internally |
---|
[509] | 255 | |
---|
| 256 | public: // Some function maybe removed in the near future |
---|
| 257 | // virtual void toBinary (StdOStream & os) const; |
---|
| 258 | // virtual void fromBinary(StdIStream & is); |
---|
[219] | 259 | }; // class CContext |
---|
| 260 | |
---|
| 261 | ///-------------------------------------------------------------- |
---|
| 262 | |
---|
| 263 | // Declare/Define CContextGroup and CContextDefinition |
---|
| 264 | DECLARE_GROUP(CContext); |
---|
| 265 | |
---|
| 266 | ///-------------------------------------------------------------- |
---|
| 267 | |
---|
[335] | 268 | } // namespace xios |
---|
[219] | 269 | |
---|
[591] | 270 | #endif // __XIOS_CContext__ |
---|