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

Last change on this file since 549 was 549, checked in by rlacroix, 9 years ago

Revised calendar functionalities:

  • the calendar is now configured from a specific calendar child node of the context in the XML configuration file. Example: <calendar type="Gregorian" start_date="2012-03-01 15:00:00" time_origin="2012-02-29 15:00:00" timestep="1h" />
  • the calendar type should now be configured when defining the start time and/or the time origin.
  • the start time and the time origin are now optional, 0000-01-01 00:00:00 will be used by default. It is also possible to define them partially. For example, 2015 and 2014-12 are valid dates corresponding respectively to 2015-01-01 00:00:00 and 2014-12-01 00:00:00.
  • an optional duration offset can be added to the start date and time origin. For example, it's possible to define the date 2015-01-12 12:00:00 as 2015-01-11 + 36h or 2015-01-11 12:00:00 + 1d. The duration format is the same as the time step. Being that the date is optional, it is possible to only use a duration (for example + 42s is the same as 0000-01-01 00:00:00 + 42s). An error will be raised if a duration based on the time step is used before the time step was configured. For example, the following would cause an error: <calendar type="Gregorian" start_date="+ 1ts" /> but <calendar type="Gregorian" start_date="+ 1ts" timestep="0.5h" /> would not.
  • new Fortran interface to define the calendar:
    • xios_define_calendar(type[, timestep, start_date, time_origin]) will create a calendar when none had previously been defined. Only the type argument is mandatory, the rest is optional. Calendar operations on dates and durations are possible as soon as the calendar is created (either using this procedure or directly from the XML configuration file).
    • the following getter and setter procedures are available: xios_set_timestep, xios_set_start_date, xios_set_time_origin, xios_get_calendar_type, xios_get_timestep, xios_get_start_date, xios_get_time_origin.
  • new Fortran interface to interact with the calendar: xios_update_calendar, xios_get_current_date, xios_get_year_length_in_seconds, xios_get_day_length_in_seconds.
  • new Fortran interface for date conversion: xios_date_get_second_of_year, xios_date_get_day_of_year, xios_date_get_fraction_of_year, xios_date_get_second_of_day, xios_date_get_fraction_of_day.
  • two new placeholders are available to format the file name when splitting the output (split_freq_format attribute):
    • %S the number of seconds since the time origin
    • %D the integral number of days since the time origin
  • 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: 7.2 KB
Line 
1#ifndef __XMLIO_CContext__
2#define __XMLIO_CContext__
3
4/// xios headers ///
5#include "xmlioserver_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
14#include "mpi.hpp"
15
16
17namespace xios {
18   class CContextClient;
19   class CContextServer;
20
21
22   /// ////////////////////// Déclarations ////////////////////// ///
23   class CContextGroup;
24   class CContextAttributes;
25   class CContext;
26   class CFile;
27   ///--------------------------------------------------------------
28
29   // Declare/Define CFileAttribute
30   BEGIN_DECLARE_ATTRIBUTE_MAP(CContext)
31#  include "context_attribute.conf"
32   END_DECLARE_ATTRIBUTE_MAP(CContext)
33
34   ///--------------------------------------------------------------
35  /*!
36  \class CContext
37   This class corresponds to the concrete presentation of context in xml file and in play an essential role in XIOS
38   Each object of this class contains all root definition of elements: files, fiels, domains, axis, etc, ... from which
39   we can have access to each element.
40   In fact, every thing must a be inside a particuliar context. After the xml file (iodef.xml) is parsed,
41   object of the class is created and its contains all information of other elements in the xml file.
42  */
43   class CContext
44      : public CObjectTemplate<CContext>
45      , public CContextAttributes
46   {
47         public :
48         enum EEventId
49         {
50           EVENT_ID_CLOSE_DEFINITION,EVENT_ID_UPDATE_CALENDAR,
51           EVENT_ID_CREATE_FILE_HEADER,EVENT_ID_CONTEXT_FINALIZE,
52           EVENT_ID_POST_PROCESS
53         };
54
55         /// typedef ///
56         typedef CObjectTemplate<CContext>   SuperClass;
57         typedef CContextAttributes SuperClassAttribute;
58
59      public :
60
61         typedef CContextAttributes RelAttributes;
62         typedef CContext           RelGroup;
63
64         //---------------------------------------------------------
65
66      public :
67
68         /// Constructeurs ///
69         CContext(void);
70         explicit CContext(const StdString & id);
71         CContext(const CContext & context);       // Not implemented yet.
72         CContext(const CContext * const context); // Not implemented yet.
73
74         /// Destructeur ///
75         virtual ~CContext(void);
76
77         //---------------------------------------------------------
78
79      public :
80
81         /// Mutateurs ///
82         void setCalendar(boost::shared_ptr<CCalendar> newCalendar);
83
84         /// Accesseurs ///
85         boost::shared_ptr<CCalendar>      getCalendar(void) const;
86
87      public :
88         // Initialize server or client
89         void initServer(MPI_Comm intraComm, MPI_Comm interComm);
90         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer=0);
91         bool isInitialized(void);
92
93         // Put sever or client into loop state
94         bool eventLoop(void);
95         bool serverLoop(void);
96         void clientLoop(void);
97
98         // Finalize a context
99         void finalize(void);
100         void closeDefinition(void);
101
102         // Some functions to process context
103         void findAllEnabledFields(void);
104         void processEnabledFiles(void);
105         void solveAllInheritance(bool apply=true);
106         void findEnabledFiles(void);
107         void closeAllFile(void);
108         void updateCalendar(int step);
109         void createFileHeader(void );
110         void solveAllRefOfEnabledFields(bool sendToServer);
111         void buildAllExpressionOfEnabledFields();
112         void postProcessing();
113
114         std::map<int, StdSize>& getDataSize();
115         void setClientServerBuffer();
116
117         // Send context close definition
118         void sendCloseDefinition(void);
119         // There are something to send on closing context defintion
120         void sendUpdateCalendar(int step);
121         void sendCreateFileHeader(void);
122         void sendEnabledFiles();
123         void sendEnabledFields();
124         void sendRefDomainsAxis();
125         void sendRefGrid();
126         void sendPostProcessing();
127
128         const StdString& getIdServer();
129
130         // Client side: Receive and process messages
131         static void recvUpdateCalendar(CEventServer& event);
132         void recvUpdateCalendar(CBufferIn& buffer);
133         static void recvCloseDefinition(CEventServer& event);
134         static void recvCreateFileHeader(CEventServer& event);
135         void recvCreateFileHeader(CBufferIn& buffer);
136         static void recvSolveInheritanceContext(CEventServer& event);
137         void recvSolveInheritanceContext(CBufferIn& buffer);
138         static void recvPostProcessing(CEventServer& event);
139         void recvPostProcessing(CBufferIn& buffer);
140
141         // dispatch event
142         static bool dispatchEvent(CEventServer& event);
143
144      public:
145        // Get current context
146        static CContext* getCurrent(void);
147
148        // Get context root
149        static CContextGroup* getRoot(void);
150
151        // Set current context
152        static void setCurrent(const string& id);
153
154        // Create new context
155        static CContext* create(const string& id = "");
156
157        /// Accesseurs statiques ///
158        static StdString GetName(void);
159        static StdString GetDefName(void);
160        static ENodeType GetType(void);
161
162        static CContextGroup* GetContextGroup(void);
163
164        // Some functions to visualize structure of current context
165        static void ShowTree(StdOStream & out = std::clog);
166        static void CleanTree(void);
167
168      public :
169         // Parse xml node and write all info into context
170         virtual void parse(xml::CXMLNode & node);
171
172         // Visualize a context
173         virtual StdString toString(void) const;
174
175
176         // Solve all inheritance relation in current context
177         virtual void solveDescInheritance(bool apply, const CAttributeMap * const parent = 0);
178
179         // Verify if all root definition in a context have children
180         virtual bool hasChild(void) const;
181
182      public :
183         // Calendar of context
184         boost::shared_ptr<CCalendar>   calendar;
185
186         // List of all enabled files (files on which fields are written)
187         std::vector<CFile*> enabledFiles;
188
189         // Context root
190         static shared_ptr<CContextGroup> root;
191
192         // Determine context on client or not
193         bool hasClient;
194
195         // Determine context on server or not
196         bool hasServer;
197
198         // Concrete context server
199         CContextServer* server;
200
201         // Concrete contex client
202         CContextClient* client;
203
204      private:
205         bool isPostProcessed;
206         std::map<int, StdSize> dataSize_;
207         StdString idServer_;
208
209
210      public: // Some function maybe removed in the near future
211        // virtual void toBinary  (StdOStream & os) const;
212        // virtual void fromBinary(StdIStream & is);
213        // void solveAllGridRef(void);
214        // void solveAllOperation(void);
215        // void solveAllExpression(void);
216        // void solveFieldRefInheritance(bool apply);
217
218   }; // class CContext
219
220   ///--------------------------------------------------------------
221
222   // Declare/Define CContextGroup and CContextDefinition
223   DECLARE_GROUP(CContext);
224
225   ///--------------------------------------------------------------
226
227} // namespace xios
228
229#endif // __XMLIO_CContext__
Note: See TracBrowser for help on using the repository browser.