source: XIOS/trunk/src/node/context.hpp @ 1318

Last change on this file since 1318 was 1318, checked in by rlacroix, 7 years ago

Fix: Handle end-of-file correctly for files in read mode.

Previously desynchronizations between clients could occur, leading to invalid events being received by the server(s).

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