OnixS C++ CME MDP Premium Market Data Handler  5.8.3
API Documentation
Replay.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include <functional>
27 
28 #include <OnixS/CME/MDH/Integral.h>
29 #include <OnixS/CME/MDH/Time.h>
30 
31 #include <OnixS/CME/MDH/Domain.h>
35 
37 
38 // A bit of forward declarations.
40 
41 /// Ordered list of logs to be replayed.
42 typedef std::vector<std::string> FileList;
43 
44 /// Gathers log files logs which are available for
45 /// given channel and are stored in a given folder.
46 /// Gathering assumes log files are named by log file
47 /// naming routine exposed by given SDK.
49 void gatherLogFiles(FileList&, ChannelId, const std::string&);
50 
51 /// Gathers log files logs which are available for
52 /// given channel and are stored in a given folder.
53 /// Gathering assumes log files are named by log file
54 /// naming routine exposed by given SDK. In contrast
55 /// to other overloads, given one allows to define
56 /// prefix pattern for logs to be gathered.
58 void gatherLogFiles(FileList&, ChannelId, const std::string&, const std::string&);
59 
60 /// Gathers files which are stored in the given folder with
61 /// the given extension. Gathered files are sorted by name.
62 ///
63 /// In contrast to the gatherLogFiles function gathering log
64 /// files, which collects log files in exact order the files
65 /// were produced by a logger, the given one represents a generic
66 /// routine finding files according to the given pattern (extension).
68 void gatherFiles(FileList&, const std::string&, const std::string&);
69 
70 #if !defined(ONIXS_CMEMDH_NO_DEPRECATED)
71 
72 /// Gathers files which are stored in the given folder with
73 /// the given extension. Gathered files are sorted by name.
74 ///
75 /// \warning The given function is deprecated.
76 /// Consider using `gatherFiles` instead.
77 inline void gatherPcapFiles(FileList& files, const std::string& location, const std::string& ext)
78 {
79  gatherFiles(files, location, ext);
80 }
81 
82 #endif // !ONIXS_CMEMDH_NO_DEPRECATED
83 
84 /// Defines whether processing and other settings
85 /// must be extracted from logs and used during the
86 /// replay, or the original settings as they were
87 /// defined by replay invoker must be used.
89 {
90  enum Enum
91  {
92  /// Handler settings aren't touched and
93  /// used as they are during the replay.
95 
96  /// Settings affecting the way the data
97  /// is processed must be extracted from
98  /// the logs and applied to the Handlers
99  /// before replay starts.
100  Suggested
101  };
102 };
103 
104 /// Defines range of log entries to be replayed.
106 {
107 public:
108  /// Initializes empty span.
110  : begin_()
111  , end_()
112  {
113  }
114 
115  /// Initializes the instance
116  /// according to the given bounds.
117  ReplaySpan(const Timestamp& begin, const Timestamp& end)
118  : begin_(begin)
119  , end_(end)
120  {
121  }
122 
123  /// Initializes the instance
124  /// as a copy of the other one.
125  ReplaySpan(const ReplaySpan& other)
126  : begin_(other.begin_)
127  , end_(other.end_)
128  {
129  }
130 
131  /// Indicates whether span is empty or not.
132  bool empty() const
133  {
134  return (begin_ >= end_);
135  }
136 
137  /// Indicates whether the given timestamp
138  /// belongs to the given time span.
139  bool contain(const Timestamp& timestamp) const
140  {
141  return (begin_ <= timestamp && timestamp < end_);
142  }
143 
144  /// Indicates the beginning of the range.
145  const Timestamp& begin() const
146  {
147  return begin_;
148  }
149 
150  /// Updates the beginning of the range.
151  void begin(const Timestamp& value)
152  {
153  begin_ = value;
154  }
155 
156  /// Indicates the end of the range.
157  const Timestamp& end() const
158  {
159  return end_;
160  }
161 
162  /// Indicates the end of the range.
163  void end(const Timestamp& value)
164  {
165  end_ = value;
166  }
167 
168  /// Re-initializes as a copy of the other one.
170  {
171  begin_ = other.begin_;
172  end_ = other.end_;
173 
174  return *this;
175  }
176 
177 private:
178  Timestamp begin_;
179  Timestamp end_;
180 };
181 
182 /// Controls speed of market data replay.
184 {
185  /// Controls speed of market data replay.
186  enum Enum
187  {
188  /// Replays run at maximal speed.
189  NoDelay = 0,
190 
191  /// Data is replayed with the original speed.
192  Original = 1,
193 
194  /// Data is replayed two times faster in
195  /// compare to the original speed at which
196  /// the Handler was receiving that data.
197  X2 = 2
198  };
199 };
200 
201 /// Various supplemental settings affecting
202 /// the way the logged data is replayed.
203 template <class DataSource, class DataSourceLess = std::less<DataSource> >
205 {
206 public:
207  /// The table of data source aliases.
208  typedef std::map<DataSource, DataSource, DataSourceLess> Aliases;
209 
210  /// Initializes the settings with the default values.
212  : settingsUse_(HandlerSettingsUse::Suggested)
213  , aliases_()
214  , timeSpan_()
215  , speed_(ReplaySpeed::NoDelay)
216  {
217  }
218 
219  /// Initializes as a copy of the other one.
221  : settingsUse_(other.settingsUse_)
222  , aliases_(other.aliases_)
223  , timeSpan_(other.timeSpan_)
224  , speed_(other.speed_)
225  {
226  }
227 
228  /// Handler settings use policy.
230  {
231  return settingsUse_;
232  }
233 
234  /// Defines handler settings use policy.
236  {
237  settingsUse_ = policy;
238  }
239 
240  /// Aliases to be used during the replay.
241  ///
242  /// Aliases allow redirecting data from one source
243  /// (feed, multicast group, channel, etc.) to the other
244  /// one.
245  const Aliases& aliases() const
246  {
247  return aliases_;
248  }
249 
250  /// Aliases to be used during the replay.
251  ///
252  /// Aliases allow redirecting data from one source
253  /// (feed, multicast group, channel, etc.) to the other
254  /// one.
255  Aliases& aliases()
256  {
257  return aliases_;
258  }
259 
260  /// Time span for which entries are to be processed.
261  const ReplaySpan& timeSpan() const
262  {
263  return timeSpan_;
264  }
265 
266  /// Time span for which entries are to be processed.
268  {
269  return timeSpan_;
270  }
271 
272  /// Indicates processing speed policy.
274  {
275  return speed_;
276  }
277 
278  /// Defines processing speed.
280  {
281  speed_ = policy;
282  }
283 
284  /// Re-initializes as a copy of the other one.
286  {
287  settingsUse_ = other.settingsUse_;
288 
289  aliases_ = other.aliases_;
290 
291  timeSpan_ = other.timeSpan_;
292 
293  speed_ = other.speed_;
294 
295  return *this;
296  }
297 
298 private:
299  HandlerSettingsUse::Enum settingsUse_;
300  Aliases aliases_;
301 
302  ReplaySpan timeSpan_;
303  ReplaySpeed::Enum speed_;
304 };
305 
306 /// Replay supplements for log replay functionality.
308 
309 /// Collection of logged data sources (feed
310 /// identifiers) to be used by the Log Replay
311 /// to replace logged sources with the sources
312 /// used by Handlers involved into replay.
314 
315 /// Replay supplements for the PCAP replay functionality.
316 class ONIXS_CMEMDH_LTWT PcapReplaySettings : public ReplaySettings<NetFeedConnection, NetFeedConnectionLess>
317 {
318 public:
319  /// Initializes settings with the default values.
321  {
322  settingsUse(HandlerSettingsUse::AsIs);
323  }
324 
325  /// Settings aren't stored in PCAPs
326  /// thus constant value is returned.
328  {
329  return HandlerSettingsUse::AsIs;
330  }
331 
332 private:
334 
335  // Not applicable for the PCAP replay as no
336  // parameters are stored in the captured files.
337  using Base::settingsUse;
338 };
339 
340 /// Collection of data sources (feed identifiers)
341 /// to be used by the PCAP file replay to replace
342 /// captured sources with the sources used by Handlers
343 /// involved into replay.
345 
346 /// Replay supplements for the CME DataMine
347 /// historical data replay functionality.
349 {
350 public:
351  /// Initializes settings with the default values.
353  {
354  settingsUse(HandlerSettingsUse::AsIs);
355  }
356 
357  /// Settings aren't stored in Datamine
358  /// thus constant value is returned.
360  {
361  return HandlerSettingsUse::AsIs;
362  }
363 
364 private:
366 
367  // Not applicable for the Datamine replay as no
368  // parameters are stored in the captured files.
369  using Base::settingsUse;
370 };
371 
372 /// Collection of channels to be used by the CME Datamine
373 /// historical file replay to replace captured sources
374 /// with the sources used by Handlers involved into replay.
376 
377 /// Extracts market data stored in the given
378 /// log files and pushes it to the given handlers
379 /// for further processing.
381 void replayLogFiles(const FileList&, Handler**, size_t, const LogReplaySettings&);
382 
383 /// Extracts market data stored in the given
384 /// log files and pushes it to the given handler
385 /// for further processing.
386 inline void replayLogFiles(const FileList& logs, Handler& handler, const LogReplaySettings& supplements)
387 {
388  Handler* handlers[] = {&handler};
389 
390  replayLogFiles(logs, handlers, 1, supplements);
391 }
392 
393 /// Processes market data stored in the log
394 /// files according to specified settings.
395 inline void replayLogFiles(const FileList& logs, Handler** handlers, size_t handlerQty)
396 {
397  replayLogFiles(logs, handlers, handlerQty, LogReplaySettings());
398 }
399 
400 /// Processes market data stored in the log
401 /// files according to specified settings.
402 inline void replayLogFiles(const FileList& logs, Handler& handler)
403 {
404  Handler* handlers[] = {&handler};
405 
406  replayLogFiles(logs, handlers, 1);
407 }
408 
409 /// A Marker instructing the log replay procedure to
410 /// use Handler settings as they are without applying
411 /// any modifications based on logged information.
413 {};
414 
415 /// Processes market data stored in the log
416 /// files according to specified settings.
417 inline void replayLogFiles(const FileList& logs, Handler** handlers, size_t handlerQty, const UseHandlerSettingsAsIs&)
418 {
419  LogReplaySettings supplements;
420 
421  supplements.settingsUse(HandlerSettingsUse::AsIs);
422 
423  replayLogFiles(logs, handlers, handlerQty, supplements);
424 }
425 
426 /// Processes market data stored in the log
427 /// files according to specified settings.
428 inline void replayLogFiles(const FileList& logs, Handler& handler, const UseHandlerSettingsAsIs& marker)
429 {
430  Handler* handlers[] = {&handler};
431 
432  replayLogFiles(logs, handlers, 1, marker);
433 }
434 
435 /// Replays the given list of PCAP files for the
436 /// given Handlers according to the given settings.
438 void replayPcapFiles(const FileList&, Handler**, size_t, const PcapReplaySettings&);
439 
440 /// Applies the given list of PCAP files with snapshots then
441 /// replays the given list of PCAP files with incrementals for the
442 /// given Handlers according to the given settings.
443 /// @note snapshots are being applied with no delay
444 /// @note only the first snapshot cycle from the given snapshots is applied, the rest are skipped
446 void replayPcapFiles(
447  const FileList& snapshots,
448  MarketRecoveryOptions::Enum snapshotsApplyOptions,
449  const FileList& incrementals,
450  Handler** handlers,
451  size_t handlerQty,
452  const PcapReplaySettings& supplements
453 );
454 
455 /// Applies the given list of PCAP files with snapshots then
456 /// replays the given list of PCAP files with incrementals for the
457 /// given Handler according to the given settings.
458 /// @note snapshots are being applied with no delay
459 /// @note only the first snapshot cycle from the given snapshots is applied, the rest are skipped
460 inline void replayPcapFiles(
461  const FileList& snapshots,
462  MarketRecoveryOptions::Enum snapshotsApplyOptions,
463  const FileList& incrementals,
464  Handler& handler,
465  const PcapReplaySettings& supplements = PcapReplaySettings()
466 )
467 {
468  Handler* handlers[] = {&handler};
469 
470  replayPcapFiles(snapshots, snapshotsApplyOptions, incrementals, handlers, 1, supplements);
471 }
472 
473 /// Replays the given list of PCAP files for the
474 /// given Handler according to the given settings.
475 inline void replayPcapFiles(const FileList& logs, Handler& handler, const PcapReplaySettings& supplements)
476 {
477  Handler* handlers[] = {&handler};
478 
479  replayPcapFiles(logs, handlers, 1, supplements);
480 }
481 
482 /// Replays the given list of PCAP files for the
483 /// given Handler according to the default settings.
484 inline void replayPcapFiles(const FileList& logs, Handler& handler)
485 {
486  replayPcapFiles(logs, handler, PcapReplaySettings());
487 }
488 
489 /// Replays the given list of Datamine files for the
490 /// given Handlers according to the given settings.
492 void replayDatamineFiles(const FileList&, Handler**, size_t, const DatamineReplaySettings&);
493 
494 /// Replays the given list of Datamine files for the
495 /// given Handlers according to the given settings.
496 inline void replayDatamineFiles(const FileList& logs, Handler& handler, const DatamineReplaySettings& supplements)
497 {
498  Handler* handlers[] = {&handler};
499 
500  replayDatamineFiles(logs, handlers, 1, supplements);
501 }
502 
503 /// Replays the given list of historical data for the
504 /// given Handler according to the default settings.
505 inline void replayDatamineFiles(const FileList& logs, Handler& handler)
506 {
508 }
509 
Defines range of log entries to be replayed.
Definition: Replay.h:105
ReplaySpan(const ReplaySpan &other)
Initializes the instance as a copy of the other one.
Definition: Replay.h:125
Handler settings aren&#39;t touched and used as they are during the replay.
Definition: Replay.h:94
Replay supplements for the CME DataMine historical data replay functionality.
Definition: Replay.h:348
Replay supplements for the PCAP replay functionality.
Definition: Replay.h:316
std::vector< std::string > FileList
Ordered list of logs to be replayed.
Definition: Replay.h:39
Encapsulates all the machinery related with market data processing from CME Market Data Platform...
Definition: Handler.h:55
DatamineReplaySettings()
Initializes settings with the default values.
Definition: Replay.h:352
UInt32 ChannelId
Identifies CME channel.
Definition: Domain.h:28
void settingsUse(HandlerSettingsUse::Enum policy)
Defines handler settings use policy.
Definition: Replay.h:235
ReplaySpan()
Initializes empty span.
Definition: Replay.h:109
void gatherPcapFiles(FileList &files, const std::string &location, const std::string &ext)
Gathers files which are stored in the given folder with the given extension.
Definition: Replay.h:77
Represents time point without time-zone information.
Definition: Time.h:387
ReplaySettings< NetFeedId > LogReplaySettings
Replay supplements for log replay functionality.
Definition: Replay.h:307
const Aliases & aliases() const
Aliases to be used during the replay.
Definition: Replay.h:245
Timestamp timestamp(const MultiContainer &, Tag)
Retrieves last update time field value.
PcapReplaySettings()
Initializes settings with the default values.
Definition: Replay.h:320
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:35
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
const ReplaySpan & timeSpan() const
Time span for which entries are to be processed.
Definition: Replay.h:261
Various supplemental settings affecting the way the logged data is replayed.
Definition: Replay.h:204
std::map< DataSource, DataSource, DataSourceLess > Aliases
The table of data source aliases.
Definition: Replay.h:208
void replayLogFiles(const FileList &logs, Handler &handler, const UseHandlerSettingsAsIs &marker)
Processes market data stored in the log files according to specified settings.
Definition: Replay.h:428
void replayDatamineFiles(const FileList &logs, Handler &handler)
Replays the given list of historical data for the given Handler according to the default settings...
Definition: Replay.h:505
bool value(Number &number, const MultiContainer &container, Tag tag)
Finds a tag-value entry in the given collection by the given tag and returns its value component tran...
bool empty() const
Indicates whether span is empty or not.
Definition: Replay.h:132
Defines whether processing and other settings must be extracted from logs and used during the replay...
Definition: Replay.h:88
DatamineReplaySettings::Aliases ChannelIdAliases
Collection of channels to be used by the CME Datamine historical file replay to replace captured sour...
Definition: Replay.h:375
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
void begin(const Timestamp &value)
Updates the beginning of the range.
Definition: Replay.h:151
A Marker instructing the log replay procedure to use Handler settings as they are without applying an...
Definition: Replay.h:412
ReplaySpan & timeSpan()
Time span for which entries are to be processed.
Definition: Replay.h:267
HandlerSettingsUse::Enum settingsUse() const
Settings aren&#39;t stored in Datamine thus constant value is returned.
Definition: Replay.h:359
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:135
void speed(ReplaySpeed::Enum policy)
Defines processing speed.
Definition: Replay.h:279
HandlerSettingsUse::Enum settingsUse() const
Handler settings use policy.
Definition: Replay.h:229
const Timestamp & end() const
Indicates the end of the range.
Definition: Replay.h:157
ReplaySpeed::Enum speed() const
Indicates processing speed policy.
Definition: Replay.h:273
Controls speed of market data replay.
Definition: Replay.h:183
ReplaySettings & operator=(const ReplaySettings &other)
Re-initializes as a copy of the other one.
Definition: Replay.h:285
Aliases & aliases()
Aliases to be used during the replay.
Definition: Replay.h:255
LogReplaySettings::Aliases FeedIdAliases
Collection of logged data sources (feed identifiers) to be used by the Log Replay to replace logged s...
Definition: Replay.h:313
const Timestamp & begin() const
Indicates the beginning of the range.
Definition: Replay.h:145
HandlerSettingsUse::Enum settingsUse() const
Settings aren&#39;t stored in PCAPs thus constant value is returned.
Definition: Replay.h:327
PcapReplaySettings::Aliases NetAddressAliases
Collection of data sources (feed identifiers) to be used by the PCAP file replay to replace captured ...
Definition: Replay.h:344
ReplaySettings(const ReplaySettings &other)
Initializes as a copy of the other one.
Definition: Replay.h:220
ReplaySettings()
Initializes the settings with the default values.
Definition: Replay.h:211
Enum
Controls speed of market data replay.
Definition: Replay.h:186
void gatherFiles(FileList &, const std::string &, const std::string &)
Gathers files which are stored in the given folder with the given extension.
bool contain(const Timestamp &timestamp) const
Indicates whether the given timestamp belongs to the given time span.
Definition: Replay.h:139
ReplaySpan(const Timestamp &begin, const Timestamp &end)
Initializes the instance according to the given bounds.
Definition: Replay.h:117
ReplaySpan & operator=(const ReplaySpan &other)
Re-initializes as a copy of the other one.
Definition: Replay.h:169
void end(const Timestamp &value)
Indicates the end of the range.
Definition: Replay.h:163
void gatherLogFiles(FileList &, ChannelId, const std::string &, const std::string &)
Gathers log files logs which are available for given channel and are stored in a given folder...
void replayPcapFiles(const FileList &logs, Handler &handler)
Replays the given list of PCAP files for the given Handler according to the default settings...
Definition: Replay.h:484
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68