mtime 1.3.0
Loading...
Searching...
No Matches
mtime_eventHandling.h
Go to the documentation of this file.
1// Copyright (c) 2013-2024 MPI-M, Luis Kornblueh, Rahul Sinha and DWD, Florian Prill. All rights reserved.
2//
3// SPDX-License-Identifier: BSD-3-Clause
4//
20#ifndef _MTIME_EVENTHANDLING_H
21#define _MTIME_EVENTHANDLING_H
22
23#include <stdint.h>
24#include <stdbool.h>
25
27#define MAX_EVENT_STR_LEN 132 // TODO- On Luis. Need to agree on how a event_string should look.
29#define MAX_GROUPNAME_STR_LEN 132
31#define MAX_EVENTNAME_STR_LEN 132
32
33struct _datetime;
34struct _timedelta;
35struct _event;
36
46{
47 int64_t eventGroupId;
49
50 struct _event *rootEvent;
51};
52
53struct _eventGroup *newEventGroup(const char *_eventGroupName);
54
55void deallocateEventGroup(struct _eventGroup *eg);
56
57bool addNewEventToEventGroup(struct _event *e, struct _eventGroup *eg);
58
59bool removeEventFromEventGroup(char *eventName, struct _eventGroup *eg);
60
61int64_t getEventGroupId(struct _eventGroup *eg);
62
63char *getEventGroupName(struct _eventGroup *eg, char *gname);
64
65struct _event *getEventGroupRootEvent(struct _eventGroup *eg);
66
73/* Note: all updates here must be mirrored in src/mtime_c_bindings.f90! */
74struct _event
75{
77
78 int64_t eventId;
79 char *eventName;
80
83
86
88 struct _timedelta
90
92
94
97
98 // Properties of the event being triggered.
99 /* The following flags make sense IFF the events are CURRENTLY in a triggered state i.e triggerCurrentEvent==true.Else the
100 * behavior is undefined.*/
107
109 struct _datetime
111};
112
113struct _event *newEvent(const char *_eventName, const char *_eventReferenceDate, const char *_eventFirstDate,
114 const char *_eventLastDate, const char *_eventInterval, const char *_eventOffset);
115
116struct _event *newEventWithDataType(const char *_eventName, struct _datetime *_eventReferenceDate,
117 struct _datetime *_eventFirstDate, struct _datetime *_eventLastDate,
118 struct _timedelta *_eventInterval, struct _timedelta *_eventOffset);
119
120void deallocateEvent(struct _event *e);
121
122struct _event *constructAndCopyEvent(struct _event *e);
123
124bool isCurrentEventActive(struct _event *e, struct _datetime *current_dt, struct _timedelta *plus_slack,
125 struct _timedelta *minus_slack);
126
127bool iseventNextInNextDay(struct _event *e);
128
129bool iseventNextInNextMonth(struct _event *e);
130
131bool iseventNextInNextYear(struct _event *e);
132
133char *eventToString(struct _event *e, char *string);
134
135struct _datetime *getTriggerNextEventAtDateTime(struct _event *e, struct _datetime *dt_current, struct _datetime *dt_return);
136
137struct _datetime *getTriggeredPreviousEventAtDateTime(struct _event *e, struct _datetime *dt_return);
138
139struct _event *getNextEventInGroup(struct _event *e);
140
141int64_t getEventId(struct _event *e);
142
143char *getEventName(struct _event *e, char *ename);
144
145struct _datetime *getEventReferenceDateTime(struct _event *e);
146
147struct _datetime *getEventFirstDateTime(struct _event *e);
148
149struct _datetime *getEventLastDateTime(struct _event *e);
150
151struct _timedelta *getEventInterval(struct _event *e);
152
153bool getNextEventIsFirst(struct _event *e);
154
155bool getEventisFirstInDay(struct _event *e);
156
157bool getEventisFirstInMonth(struct _event *e);
158
159bool getEventisFirstInYear(struct _event *e);
160
161bool getEventisLastInDay(struct _event *e);
162
163bool getEventisLastInMonth(struct _event *e);
164
165bool getEventisLastInYear(struct _event *e);
166
171#endif
bool eventisLastInDay
Is the event being triggered (i.e event when triggerCurrentEvent is true) Last-In-Day?
Definition mtime_eventHandling.h:104
bool eventisLastInMonth
Is the event being triggered (i.e event when triggerCurrentEvent is true) Last-In-Month?
Definition mtime_eventHandling.h:105
bool eventisFirstInDay
Is the event being triggered (i.e event when triggerCurrentEvent is true) First-In-Day?
Definition mtime_eventHandling.h:101
char * eventGroupName
Event Group's name.
Definition mtime_eventHandling.h:48
struct _datetime * triggeredPreviousEventDateTime
Last Trigger event happened at this DT. Initialized with "0-01-01T00:00:00.000".
Definition mtime_eventHandling.h:109
struct _datetime * eventReferenceDateTime
Anchor datetime. Can be NULL; Initialized to eventFirstDateTime. .
Definition mtime_eventHandling.h:82
struct _datetime * eventFirstDateTime
Start datetime of the event. Can be NULL; Initialized to 0-01-01T00:00:00.000.
Definition mtime_eventHandling.h:84
bool eventisLastInYear
Is the event being triggered (i.e event when triggerCurrentEvent is true) Last-In-Year?
Definition mtime_eventHandling.h:106
bool eventisFirstInMonth
Is the event being triggered (i.e event when triggerCurrentEvent is true) First-In-Month?
Definition mtime_eventHandling.h:102
bool neverTriggerEvent
for cases an event is set by an interval of 0
Definition mtime_eventHandling.h:91
struct _event * nextEventInGroup
Pointer to the next event in a given Event Group.
Definition mtime_eventHandling.h:76
bool lastEventWasFinal
Was the previously triggered event final?
Definition mtime_eventHandling.h:96
bool triggerCurrentEvent
is this event active?
Definition mtime_eventHandling.h:93
struct _datetime * triggerNextEventDateTime
Trigger the event next at this DT.
Definition mtime_eventHandling.h:108
struct _timedelta * eventOffset
Shift eventReferenceDateTime by 'eventOffset' . Can be NULL; stays a NULL pointer: Logically 0.
Definition mtime_eventHandling.h:88
struct _datetime * eventLastDateTime
Last datetime of the event. Can be NULL; stays a NULL pointer: Logically NULL.
Definition mtime_eventHandling.h:85
bool nextEventIsFirst
Is the next scheduled event the first to be triggered?
Definition mtime_eventHandling.h:95
char * eventName
Event's name.
Definition mtime_eventHandling.h:79
struct _timedelta * eventInterval
TimeDelta between succesive triggers. MUST be specified.
Definition mtime_eventHandling.h:87
bool eventisFirstInYear
Is the event being triggered (i.e event when triggerCurrentEvent is true) First-In-Year?
Definition mtime_eventHandling.h:103
struct _datetime * eventsLastEvaluationDateTime
Last evaluation datetime to allow for multiple queries.
Definition mtime_eventHandling.h:81
struct _event * rootEvent
Pointer to a List of events in this group.
Definition mtime_eventHandling.h:50
int64_t eventGroupId
Event Group's ID.
Definition mtime_eventHandling.h:47
int64_t eventId
Auto generated. (For future use. Not in use yet).
Definition mtime_eventHandling.h:78
struct _datetime * getTriggerNextEventAtDateTime(struct _event *e, struct _datetime *dt_current, struct _datetime *dt_return)
Get the Datetime when 'this' event will be triggered next.
Definition mtime_eventHandling.c:1187
void deallocateEventGroup(struct _eventGroup *eg)
Destructor of EventGroup.
Definition mtime_eventHandling.c:91
char * eventToString(struct _event *e, char *string)
Get Event as a string.
Definition mtime_eventHandling.c:904
void deallocateEvent(struct _event *e)
Destructor of Event.
Definition mtime_eventHandling.c:550
bool removeEventFromEventGroup(char *eventName, struct _eventGroup *eg)
Remove event from eventgroup. CRITICAL: Also, deallocate the event.
Definition mtime_eventHandling.c:147
struct _event * newEvent(const char *_eventName, const char *_eventReferenceDate, const char *_eventFirstDate, const char *_eventLastDate, const char *_eventInterval, const char *_eventOffset)
Construct new event using strings.
Definition mtime_eventHandling.c:226
struct _eventGroup * newEventGroup(const char *_eventGroupName)
Construct new event-Group using a string.
Definition mtime_eventHandling.c:52
struct _event * newEventWithDataType(const char *_eventName, struct _datetime *_eventReferenceDate, struct _datetime *_eventFirstDate, struct _datetime *_eventLastDate, struct _timedelta *_eventInterval, struct _timedelta *_eventOffset)
Construct new event using data-types.
Definition mtime_eventHandling.c:401
struct _datetime * getTriggeredPreviousEventAtDateTime(struct _event *e, struct _datetime *dt_return)
Get the Datetime when 'this' event was triggered last.
Definition mtime_eventHandling.c:1226
bool addNewEventToEventGroup(struct _event *e, struct _eventGroup *eg)
Add new event to an eventgroup.
Definition mtime_eventHandling.c:125
bool isCurrentEventActive(struct _event *e, struct _datetime *current_dt, struct _timedelta *plus_slack, struct _timedelta *minus_slack)
Check if this event is active by comparing event's trigger time with current_dt.
Definition mtime_eventHandling.c:699
struct _datetime contains a struct _date and a struct _time element.
Definition mtime_datetime.h:36
struct _event defines events. Events are set to be triggered at pre-specified intervals.
Definition mtime_eventHandling.h:75
struct _eventGroup defines an Event-group. Each event group has an associated list of events....
Definition mtime_eventHandling.h:46
Struct _timedelta containing timedelta and sign of year parameter.
Definition mtime_timedelta.h:40