source: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.hpp @ 1765

Last change on this file since 1765 was 1765, checked in by ymipsl, 5 years ago

Some cleaning On XIOS services branch

YM

  • 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: 12.3 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 "data_output.hpp"
11#include "garbage_collector.hpp"
12#include "registry.hpp"
13#include "mpi.hpp"
14#include "services_manager.hpp"
15#include "server_context.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           EVENT_ID_CONTEXT_FINALIZE_CLIENT,
57         };
58
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 :
84
85         /// Mutateurs ///
86         void setCalendar(std::shared_ptr<CCalendar> newCalendar);
87
88         /// Accesseurs ///
89         std::shared_ptr<CCalendar>      getCalendar(void) const;
90
91      public :
92         // Initialize server or client
93         void init(CServerContext* parentServerContext, MPI_Comm intraComm, int serviceType);
94         void initClient(MPI_Comm intraComm, int serviceType);
95         
96         void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
97         void initServer(MPI_Comm intraComm, int serviceType );
98         void createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer)  ;
99         void createServerInterComm(void)  ;
100
101         bool isInitialized(void);
102
103         StdString dumpClassAttributes(void);
104
105         // Put sever or client into loop state
106         bool eventLoop(bool enableEventsProcessing=true);
107         void globalEventLoop(void);
108
109         // Finalize a context
110         void finalize(void);
111
112         bool isFinalized(void);
113
114         void closeDefinition(void);
115
116         // Some functions to process context
117         void findAllEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
118         // void findAllEnabledFields(void);
119         // void findAllEnabledFieldsInReadModeFiles(void);
120         void readAttributesOfEnabledFieldsInReadModeFiles();
121         void solveAllInheritance(bool apply=true);
122         void findEnabledFiles(void);
123         void findEnabledWriteModeFiles(void);
124         void findEnabledReadModeFiles(void);
125         void closeAllFile(void);
126         void updateCalendar(int step);
127         void createFileHeader(void);
128         void initReadFiles(void);
129         void checkAxisDomainsGridsEligibilityForCompressedOutput();
130         void prepareTimeseries(void);
131         void solveOnlyRefOfEnabledFields(bool sendToServer);         
132         void buildFilterGraphOfEnabledFields();
133         void postProcessFilterGraph();
134         void startPrefetchingOfEnabledReadModeFiles();
135         void doPreTimestepOperationsForEnabledReadModeFiles();
136         void doPostTimestepOperationsForEnabledReadModeFiles();
137         void findFieldsWithReadAccess(void);
138         void solveAllRefOfFieldsWithReadAccess();
139         void buildFilterGraphOfFieldsWithReadAccess();
140         void postProcessing();
141         void postProcessingGlobalAttributes();         
142
143         void solveAllRefOfEnabledFieldsAndTransform(bool sendToServer);
144         void checkGridEnabledFields();
145         void checkGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
146         void sendGridEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles); 
147         void sendGridComponentEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles)       ;
148
149         std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
150         std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
151         void setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting = false);
152
153         // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
154         void distributeFiles(void);
155         void distributeFileOverBandwith() ;
156         void distributeFileOverMemoryBandwith() ;
157         
158         // Send context close definition
159         void sendCloseDefinition(void);
160         // There are something to send on closing context defintion
161         void sendUpdateCalendar(int step);
162         void sendCreateFileHeader(void);
163         void sendEnabledFiles(const std::vector<CFile*>& activeFiles);
164         void sendEnabledFieldsInFiles(const std::vector<CFile*>& activeFiles);
165         void sendRefDomainsAxisScalars(const std::vector<CFile*>& activeFiles);
166         void sendRefGrid(const std::vector<CFile*>& activeFiles);
167         void sendPostProcessing();
168         void sendPostProcessingGlobalAttributes();
169         void sendProcessingGridOfEnabledFields();
170         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
171         void sendRegistry(void) ;
172         void sendFinalizeClient(CContextClient* contextClient, const string& contextClientId);
173
174
175         const StdString& getIdServer();
176         void setIdServer(const StdString& idServer);
177         const StdString& getIdServer(const int srvPoolNb);
178         std::string getContextId() {return contextId_;}
179
180         // Client side: Receive and process messages
181         static void recvUpdateCalendar(CEventServer& event);
182         void recvUpdateCalendar(CBufferIn& buffer);
183         static void recvCloseDefinition(CEventServer& event);
184         static void recvCreateFileHeader(CEventServer& event);
185         void recvCreateFileHeader(CBufferIn& buffer);
186         static void recvSolveInheritanceContext(CEventServer& event);
187         void recvSolveInheritanceContext(CBufferIn& buffer);
188         static void recvPostProcessing(CEventServer& event);
189         void recvPostProcessing(CBufferIn& buffer);
190         static void recvProcessingGridOfEnabledFields(CEventServer& event);
191         static void recvPostProcessingGlobalAttributes(CEventServer& event);
192         void recvPostProcessingGlobalAttributes(CBufferIn& buffer);
193         static void recvRegistry(CEventServer& event) ;
194         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
195         static void recvFinalizeClient(CEventServer& event) ;
196         void recvFinalizeClient(CBufferIn& buffer);
197         
198         void freeComms(void);                  //!< Free internally allcoated communicators
199         void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
200
201         // dispatch event
202         static bool dispatchEvent(CEventServer& event);
203
204      public:
205        // Get current context
206        static CContext* getCurrent(void);
207
208        // Get context root
209        static CContextGroup* getRoot(void);
210
211        // Set current context
212        static void setCurrent(const string& id);
213
214        // Create new context
215        static CContext* create(const string& id = "");
216
217        /// Accesseurs statiques ///
218        static StdString GetName(void);
219        static StdString GetDefName(void);
220        static ENodeType GetType(void);
221
222        static CContextGroup* GetContextGroup(void);
223
224        // Some functions to visualize structure of current context
225        static void ShowTree(StdOStream & out = std::clog);
226        static void CleanTree(void);
227        int getServiceType(void) {return serviceType_;}
228
229      public :
230         // Parse xml node and write all info into context
231         virtual void parse(xml::CXMLNode & node);
232
233         // Visualize a context
234         virtual StdString toString(void) const;
235
236
237         // Solve all inheritance relation in current context
238         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
239
240         // Verify if all root definition in a context have children
241         virtual bool hasChild(void) const;
242
243         bool isProcessingEvent(void) {return isProcessingEvent_;}
244         bool setProcessingEvent(void) {isProcessingEvent_=true ;}
245         bool unsetProcessingEvent(void) {isProcessingEvent_=false ;}
246
247      public :
248         // Calendar of context
249         std::shared_ptr<CCalendar>   calendar;
250
251         // List of all enabled files (files on which fields are written or read)
252         std::vector<CFile*> enabledFiles;
253         // List of all enabled files in read mode (files on which fields are read)
254         std::vector<CFile*> enabledReadModeFiles;
255         // List of all enabled files in write mode
256         std::vector<CFile*> enabledWriteModeFiles;
257
258         // List of all enabled fields whose instant data is accessible from the public API
259         // but which are not part of a file
260         std::vector<CField*> fieldsWithReadAccess;
261
262         // Context root
263         static std::shared_ptr<CContextGroup> root;
264
265         // Determine context on client or not
266         bool hasClient;
267
268         // Determine context on server or not
269         bool hasServer;
270
271         CContextServer* server;    //!< Concrete context server
272         CContextClient* client;    //!< Concrete contex client
273         std::vector<CContextServer*> serverPrimServer;
274         std::vector<CContextClient*> clientPrimServer;
275         std::vector<std::string> primServerId_;
276
277         CRegistry* registryIn ;    //!< input registry which is read from file
278         CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
279
280
281        MPI_Comm intraComm_ ; //! context intra communicator
282
283      private:
284         bool isPostProcessed;
285         bool allProcessed;
286         bool finalized;
287         int countChildContextFinalized_;        //!< Counter of child contexts (for now it is the number of secondary server pools)
288         StdString idServer_;
289         CGarbageCollector garbageCollector;
290         std::list<MPI_Comm> comms; //!< Communicators allocated internally
291
292         int serviceType_;  //!< service associated to the context
293         string contextId_ ; //!< context client id for the servers. For clients this is same as getId()
294         bool isProcessingEvent_ ;
295         CServerContext* parentServerContext_ ;
296
297      public: // Some function maybe removed in the near future
298        // virtual void toBinary  (StdOStream & os) const;
299        // virtual void fromBinary(StdIStream & is);
300   }; // class CContext
301
302   ///--------------------------------------------------------------
303
304   // Declare/Define CContextGroup and CContextDefinition
305   DECLARE_GROUP(CContext);
306
307   ///--------------------------------------------------------------
308
309} // namespace xios
310
311#endif // __XIOS_CContext__
Note: See TracBrowser for help on using the repository browser.