source: XIOS/dev/dev_olga/src/node/context.hpp @ 1025

Last change on this file since 1025 was 1025, checked in by mhnguyen, 7 years ago

Merging working version of coupler

+) Add some changes of domain and axis: Retransfer the atttributes in a generic ways for each level of client (or server)
+) Remove some spoiled files from the previous commits

Test
+) No test

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 9.5 KB
Line 
1#ifndef __XIOS_CContext__
2#define __XIOS_CContext__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6//#include "node_type.hpp"
7#include "calendar_wrapper.hpp"
8
9#include "declare_group.hpp"
10//#include "context_client.hpp"
11//#include "context_server.hpp"
12#include "data_output.hpp"
13#include "garbage_collector.hpp"
14#include "registry.hpp"
15#include "mpi.hpp"
16
17
18namespace xios {
19   class CContextClient;
20   class CContextServer;
21
22
23   /// ////////////////////// Déclarations ////////////////////// ///
24   class CContextGroup;
25   class CContextAttributes;
26   class CContext;
27   class CFile;
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   ///--------------------------------------------------------------
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  */
44   class CContext
45      : public CObjectTemplate<CContext>
46      , public CContextAttributes
47   {
48         public :
49         enum EEventId
50         {
51           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
52           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
53           EVENT_ID_POST_PROCESS, EVENT_ID_SEND_REGISTRY,
54           EVENT_ID_POST_PROCESS_GLOBAL_ATTRIBUTES,
55           EVENT_ID_PROCESS_GRID_ENABLED_FIELDS
56         };
57
58         /// typedef ///
59         typedef CObjectTemplate<CContext>   SuperClass;
60         typedef CContextAttributes SuperClassAttribute;
61
62      public :
63
64         typedef CContextAttributes RelAttributes;
65         typedef CContext           RelGroup;
66
67         //---------------------------------------------------------
68
69      public :
70
71         /// Constructeurs ///
72         CContext(void);
73         explicit CContext(const StdString & id);
74         CContext(const CContext & context);       // Not implemented yet.
75         CContext(const CContext * const context); // Not implemented yet.
76
77         /// Destructeur ///
78         virtual ~CContext(void);
79
80         //---------------------------------------------------------
81
82      public :
83
84         /// Mutateurs ///
85         void setCalendar(boost::shared_ptr<CCalendar> newCalendar);
86
87         /// Accesseurs ///
88         boost::shared_ptr<CCalendar>      getCalendar(void) const;
89
90      public :
91         // Initialize server or client
92         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
93         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
94         bool isInitialized(void);
95
96         // Put sever or client into loop state
97         bool eventLoop(void);
98
99         bool checkBuffersAndListen(void);
100
101         // Finalize a context
102         void finalize(void);
103         void closeDefinition(void);
104
105         // Some functions to process context
106         void findAllEnabledFields(void);
107         void findAllEnabledFieldsInReadModeFiles(void);
108         void readAttributesOfEnabledFieldsInReadModeFiles();
109         void solveAllInheritance(bool apply=true);
110         void findEnabledFiles(void);
111         void findEnabledReadModeFiles(void);
112         void closeAllFile(void);
113         void updateCalendar(int step);
114         void createFileHeader(void );
115         void checkAxisDomainsGridsEligibilityForCompressedOutput();
116         void prepareTimeseries(void);
117         void solveOnlyRefOfEnabledFields(bool sendToServer);
118         void solveAllRefOfEnabledFields(bool sendToServer);
119         void buildFilterGraphOfEnabledFields();
120         void startPrefetchingOfEnabledReadModeFiles();
121         void checkPrefetchingOfEnabledReadModeFiles();
122         void findFieldsWithReadAccess(void);
123         void solveAllRefOfFieldsWithReadAccess();
124         void buildFilterGraphOfFieldsWithReadAccess();
125         void postProcessing();
126         void postProcessingGlobalAttributes();         
127
128         void solveAllEnabledFields();
129         void processGridEnabledFields();
130
131         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize);
132         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize);
133         void setClientServerBuffer();
134
135         // Send context close definition
136         void sendCloseDefinition(void);
137         // There are something to send on closing context defintion
138         void sendUpdateCalendar(int step);
139         void sendCreateFileHeader(void);
140         void sendEnabledFiles();
141         void sendEnabledFields();
142         void sendRefDomainsAxis();
143         void sendRefGrid();
144         void sendPostProcessing();
145         void sendPostProcessingGlobalAttributes();
146         void sendProcessingGridOfEnabledFields();
147         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
148         void sendRegistry(void) ;
149
150         const StdString& getIdServer();
151         const StdString& getIdServer(const int srvPoolNb);
152
153         // Client side: Receive and process messages
154         static void recvUpdateCalendar(CEventServer& event);
155         void recvUpdateCalendar(CBufferIn& buffer);
156         static void recvCloseDefinition(CEventServer& event);
157         static void recvCreateFileHeader(CEventServer& event);
158         void recvCreateFileHeader(CBufferIn& buffer);
159         static void recvSolveInheritanceContext(CEventServer& event);
160         void recvSolveInheritanceContext(CBufferIn& buffer);
161         static void recvPostProcessing(CEventServer& event);
162         void recvPostProcessing(CBufferIn& buffer);
163         static void recvProcessingGridOfEnabledFields(CEventServer& event);
164         static void recvPostProcessingGlobalAttributes(CEventServer& event);
165         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
166         static void recvRegistry(CEventServer& event) ;
167         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
168
169         // dispatch event
170         static bool dispatchEvent(CEventServer& event);
171
172      public:
173        // Get current context
174        static CContext* getCurrent(void);
175
176        // Get context root
177        static CContextGroup* getRoot(void);
178
179        // Set current context
180        static void setCurrent(const string& id);
181
182        // Create new context
183        static CContext* create(const string& id = "");
184
185        /// Accesseurs statiques ///
186        static StdString GetName(void);
187        static StdString GetDefName(void);
188        static ENodeType GetType(void);
189
190        static CContextGroup* GetContextGroup(void);
191
192        // Some functions to visualize structure of current context
193        static void ShowTree(StdOStream & out = std::clog);
194        static void CleanTree(void);
195
196      public :
197         // Parse xml node and write all info into context
198         virtual void parse(xml::CXMLNode & node);
199
200         // Visualize a context
201         virtual StdString toString(void) const;
202
203
204         // Solve all inheritance relation in current context
205         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
206
207         // Verify if all root definition in a context have children
208         virtual bool hasChild(void) const;
209
210      public :
211         // Calendar of context
212         boost::shared_ptr<CCalendar>   calendar;
213
214         // List of all enabled files (files on which fields are written or read)
215         std::vector<CFile*> enabledFiles;
216         // List of all enabled files in read mode (files on which fields are read)
217         std::vector<CFile*> enabledReadModeFiles;
218
219         // List of all enabled fields whose instant data is accessible from the public API
220         // but which are not part of a file
221         std::vector<CField*> fieldsWithReadAccess;
222
223         // Context root
224         static shared_ptr<CContextGroup> root;
225
226         // Determine context on client or not
227         bool hasClient;
228
229         // Determine context on server or not
230         bool hasServer;
231
232         // Concrete contex client
233         CContextClient* client;
234         CRegistry* registryIn ;  //!< input registry which is read from file
235         CRegistry* registryOut ; //!< output registry which will be wrote on file at the finalize
236
237         // Concrete context server
238         CContextServer* server;
239
240         // Client-server pair in case of secondary server pool
241//         CContextClient* clientPrimServer;
242//         CContextServer* serverPrimServer;
243         std::vector<CContextClient*> clientPrimServer;
244         std::vector<CContextServer*> serverPrimServer;
245
246      private:
247         bool isPostProcessed;
248         bool allProcessed;
249         bool finalized;
250         StdString idServer_;
251         CGarbageCollector garbageCollector;
252         std::list<MPI_Comm> comms; //!< Communicators allocated internally
253
254      public: // Some function maybe removed in the near future
255        // virtual void toBinary  (StdOStream & os) const;
256        // virtual void fromBinary(StdIStream & is);
257   }; // class CContext
258
259   ///--------------------------------------------------------------
260
261   // Declare/Define CContextGroup and CContextDefinition
262   DECLARE_GROUP(CContext);
263
264   ///--------------------------------------------------------------
265
266} // namespace xios
267
268#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.