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

Last change on this file since 1021 was 1021, checked in by oabramkina, 7 years ago

Intermeadiate version for merging with new server functionalities.

  • 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.0 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         };
55
56         /// typedef ///
57         typedef CObjectTemplate<CContext>   SuperClass;
58         typedef CContextAttributes SuperClassAttribute;
59
60      public :
61
62         typedef CContextAttributes RelAttributes;
63         typedef CContext           RelGroup;
64
65         //---------------------------------------------------------
66
67      public :
68
69         /// Constructeurs ///
70         CContext(void);
71         explicit CContext(const StdString & id);
72         CContext(const CContext & context);       // Not implemented yet.
73         CContext(const CContext * const context); // Not implemented yet.
74
75         /// Destructeur ///
76         virtual ~CContext(void);
77
78         //---------------------------------------------------------
79
80      public :
81
82         /// Mutateurs ///
83         void setCalendar(boost::shared_ptr<CCalendar> newCalendar);
84
85         /// Accesseurs ///
86         boost::shared_ptr<CCalendar>      getCalendar(void) const;
87
88      public :
89         // Initialize server or client
90         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
91         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
92         bool isInitialized(void);
93
94         // Put sever or client into loop state
95         bool eventLoop(void);
96
97         bool checkBuffersAndListen(void);
98
99         // Finalize a context
100         void finalize(void);
101         void closeDefinition(void);
102
103         // Some functions to process context
104         void findAllEnabledFields(void);
105         void findAllEnabledFieldsInReadModeFiles(void);
106         void readAttributesOfEnabledFieldsInReadModeFiles();
107         void solveAllInheritance(bool apply=true);
108         void findEnabledFiles(void);
109         void findEnabledReadModeFiles(void);
110         void closeAllFile(void);
111         void updateCalendar(int step);
112         void createFileHeader(void );
113         void checkAxisDomainsGridsEligibilityForCompressedOutput();
114         void prepareTimeseries(void);
115         void solveOnlyRefOfEnabledFields(bool sendToServer);
116         void solveAllRefOfEnabledFields(bool sendToServer);
117         void buildFilterGraphOfEnabledFields();
118         void startPrefetchingOfEnabledReadModeFiles();
119         void checkPrefetchingOfEnabledReadModeFiles();
120         void findFieldsWithReadAccess(void);
121         void solveAllRefOfFieldsWithReadAccess();
122         void buildFilterGraphOfFieldsWithReadAccess();
123         void postProcessing();
124
125         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize);
126         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize);
127         void setClientServerBuffer();
128
129         // Send context close definition
130         void sendCloseDefinition(void);
131         // There are something to send on closing context defintion
132         void sendUpdateCalendar(int step);
133         void sendCreateFileHeader(void);
134         void sendEnabledFiles();
135         void sendEnabledFields();
136         void sendRefDomainsAxis();
137         void sendRefGrid();
138         void sendPostProcessing();
139         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
140         void sendRegistry(void) ;
141
142         const StdString& getIdServer();
143         const StdString& getIdServer(const int srvPoolNb);
144
145         // Client side: Receive and process messages
146         static void recvUpdateCalendar(CEventServer& event);
147         void recvUpdateCalendar(CBufferIn& buffer);
148         static void recvCloseDefinition(CEventServer& event);
149         static void recvCreateFileHeader(CEventServer& event);
150         void recvCreateFileHeader(CBufferIn& buffer);
151         static void recvSolveInheritanceContext(CEventServer& event);
152         void recvSolveInheritanceContext(CBufferIn& buffer);
153         static void recvPostProcessing(CEventServer& event);
154         void recvPostProcessing(CBufferIn& buffer);
155         static void recvRegistry(CEventServer& event) ;
156         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
157
158         // dispatch event
159         static bool dispatchEvent(CEventServer& event);
160
161      public:
162        // Get current context
163        static CContext* getCurrent(void);
164
165        // Get context root
166        static CContextGroup* getRoot(void);
167
168        // Set current context
169        static void setCurrent(const string& id);
170
171        // Create new context
172        static CContext* create(const string& id = "");
173
174        /// Accesseurs statiques ///
175        static StdString GetName(void);
176        static StdString GetDefName(void);
177        static ENodeType GetType(void);
178
179        static CContextGroup* GetContextGroup(void);
180
181        // Some functions to visualize structure of current context
182        static void ShowTree(StdOStream & out = std::clog);
183        static void CleanTree(void);
184
185      public :
186         // Parse xml node and write all info into context
187         virtual void parse(xml::CXMLNode & node);
188
189         // Visualize a context
190         virtual StdString toString(void) const;
191
192
193         // Solve all inheritance relation in current context
194         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
195
196         // Verify if all root definition in a context have children
197         virtual bool hasChild(void) const;
198
199      public :
200         // Calendar of context
201         boost::shared_ptr<CCalendar>   calendar;
202
203         // List of all enabled files (files on which fields are written or read)
204         std::vector<CFile*> enabledFiles;
205         // List of all enabled files in read mode (files on which fields are read)
206         std::vector<CFile*> enabledReadModeFiles;
207
208         // List of all enabled fields whose instant data is accessible from the public API
209         // but which are not part of a file
210         std::vector<CField*> fieldsWithReadAccess;
211
212         // Context root
213         static shared_ptr<CContextGroup> root;
214
215         // Determine context on client or not
216         bool hasClient;
217
218         // Determine context on server or not
219         bool hasServer;
220
221         // Concrete contex client
222         CContextClient* client;
223         CRegistry* registryIn ;  //!< input registry which is read from file
224         CRegistry* registryOut ; //!< output registry which will be wrote on file at the finalize
225
226         // Concrete context server
227         CContextServer* server;
228
229         // Client-server pair in case of secondary server pool
230//         CContextClient* clientPrimServer;
231//         CContextServer* serverPrimServer;
232         std::vector<CContextClient*> clientPrimServer;
233         std::vector<CContextServer*> serverPrimServer;
234
235      private:
236         bool isPostProcessed;
237         bool finalized;
238         StdString idServer_;
239         CGarbageCollector garbageCollector;
240         std::list<MPI_Comm> comms; //!< Communicators allocated internally
241
242      public: // Some function maybe removed in the near future
243        // virtual void toBinary  (StdOStream & os) const;
244        // virtual void fromBinary(StdIStream & is);
245   }; // class CContext
246
247   ///--------------------------------------------------------------
248
249   // Declare/Define CContextGroup and CContextDefinition
250   DECLARE_GROUP(CContext);
251
252   ///--------------------------------------------------------------
253
254} // namespace xios
255
256#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.