OnixS C++ CME Market Data Handler  5.4.0
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  Handler
42 );
43 
44 /// Ordered list of logs to be replayed.
45 typedef
46 std::vector<std::string>
47 FileList;
48 
49 /// Gathers log files logs which are available for
50 /// given channel and are stored in a given folder.
51 /// Gathering assumes log files are named by log file
52 /// naming routine exposed by given SDK.
53 ONIXS_CMEMDH_EXPORTED
54 void
56  FileList&,
57  ChannelId,
58  const std::string&);
59 
60 /// Gathers log files logs which are available for
61 /// given channel and are stored in a given folder.
62 /// Gathering assumes log files are named by log file
63 /// naming routine exposed by given SDK. In contrast
64 /// to other overloads, given one allows to define
65 /// prefix pattern for logs to be gathered.
66 ONIXS_CMEMDH_EXPORTED
67 void
69  FileList&,
70  ChannelId,
71  const std::string&,
72  const std::string&);
73 
74 /// Gathers files which are stored in the given folder with
75 /// the given extension. Gathered files are sorted by name.
76 ///
77 /// In contrast to the gatherLogFiles function gathering log
78 /// files, which collects log files in exact order the files
79 /// were produced by a logger, the given one represents a generic
80 /// routine finding files according to the given pattern (extension).
81 ONIXS_CMEMDH_EXPORTED
82 void
84  FileList&,
85  const std::string&,
86  const std::string&);
87 
88 #if !defined (ONIXS_CMEMDH_NO_DEPRECATED)
89 
90 /// Gathers files which are stored in the given folder with
91 /// the given extension. Gathered files are sorted by name.
92 ///
93 /// \warning The given function is deprecated.
94 /// Consider using `gatherFiles` instead.
95 inline
96 void
98  FileList& files,
99  const std::string& location,
100  const std::string& ext)
101 {
102  gatherFiles(files, location, ext);
103 }
104 
105 #endif // !ONIXS_CMEMDH_NO_DEPRECATED
106 
107 /// Defines whether processing and other settings
108 /// must be extracted from logs and used during the
109 /// replay, or the original settings as they were
110 /// defined by replay invoker must be used.
112 {
113  enum Enum
114  {
115  /// Handler settings aren't touched and
116  /// used as they are during the replay.
118 
119  /// Settings affecting the way the data
120  /// is processed must be extracted from
121  /// the logs and applied to the Handlers
122  /// before replay starts.
123  Suggested
124  };
125 };
126 
127 /// Defines range of log entries to be replayed.
129 {
130  Timestamp begin_;
131  Timestamp end_;
132 
133 public:
134  /// Initializes empty span.
136  : begin_()
137  , end_()
138  {
139  }
140 
141  /// Initializes the instance
142  /// according to the given bounds.
144  const Timestamp& begin,
145  const Timestamp& end)
146  : begin_(begin)
147  , end_(end)
148  {
149  }
150 
151  /// Initializes the instance
152  /// as a copy of the other one.
154  const ReplaySpan& other)
155  : begin_(other.begin_)
156  , end_(other.end_)
157  {
158  }
159 
160  /// Indicates whether span is empty or not.
161  bool empty() const
162  {
163  return (begin_ >= end_);
164  }
165 
166  /// Indicates whether the given timestamp
167  /// belongs to the given time span.
168  bool
170  const Timestamp& timestamp) const
171  {
172  return (
173  begin_ <= timestamp &&
174  timestamp < end_);
175  }
176 
177  /// Indicates the beginning of the range.
178  const Timestamp& begin() const
179  {
180  return begin_;
181  }
182 
183  /// Updates the beginning of the range.
184  void
186  const Timestamp& value)
187  {
188  begin_ = value;
189  }
190 
191  /// Indicates the end of the range.
192  const Timestamp& end() const
193  {
194  return end_;
195  }
196 
197  /// Indicates the end of the range.
198  void
200  const Timestamp& value)
201  {
202  end_ = value;
203  }
204 
205  /// Re-initializes as a copy of the other one.
206  ReplaySpan&
207  operator =(
208  const ReplaySpan& other)
209  {
210  begin_ = other.begin_;
211  end_ = other.end_;
212 
213  return *this;
214  }
215 };
216 
217 /// Controls speed of market data replay.
219 {
220  /// Controls speed of market data replay.
221  enum Enum
222  {
223  /// Replays run at maximal speed.
224  NoDelay = 0,
225 
226  /// Data is replayed with the original speed.
227  Original = 1,
228 
229  /// Data is replayed two times faster in
230  /// compare to the original speed at which
231  /// the Handler was receiving that data.
232  X2 = 2
233  };
234 };
235 
236 /// Various supplemental settings affecting
237 /// the way the logged data is replayed.
238 template
239 <
240  class DataSource,
241  class DataSourceLess = std::less<DataSource>
242 >
244 {
245 public:
246  /// The table of data source aliases.
247  typedef
248  std::map
249  <
250  DataSource,
251  DataSource,
252  DataSourceLess
253  >
255 
256  /// Initializes the settings with the default values.
258  : settingsUse_(
260  Suggested)
261  , aliases_()
262  , timeSpan_()
263  , speed_(
264  ReplaySpeed::
265  NoDelay)
266  {
267  }
268 
269  /// Initializes as a copy of the other one.
271  const ReplaySupplements& other)
272  : settingsUse_(
273  other.settingsUse_)
274  , aliases_(
275  other.aliases_)
276  , timeSpan_(
277  other.timeSpan_)
278  , speed_(
279  other.speed_)
280  {
281  }
282 
283  /// Handler settings use policy.
285  settingsUse() const
286  {
287  return settingsUse_;
288  }
289 
290  /// Defines handler settings use policy.
291  void
294  {
295  settingsUse_ = policy;
296  }
297 
298  /// Aliases to be used during the replay.
299  ///
300  /// Aliases allow redirecting data from one source
301  /// (feed, multicast group, channel, etc.) to the other
302  /// one.
303  const
304  Aliases&
305  aliases() const
306  {
307  return aliases_;
308  }
309 
310  /// Aliases to be used during the replay.
311  ///
312  /// Aliases allow redirecting data from one source
313  /// (feed, multicast group, channel, etc.) to the other
314  /// one.
316  {
317  return aliases_;
318  }
319 
320  /// Time span for which entries are to be processed.
321  const
322  ReplaySpan&
323  timeSpan() const
324  {
325  return timeSpan_;
326  }
327 
328  /// Time span for which entries are to be processed.
329  ReplaySpan&
331  {
332  return timeSpan_;
333  }
334 
335  /// Indicates processing speed policy.
337  speed() const
338  {
339  return speed_;
340  }
341 
342  /// Defines processing speed.
343  void
345  ReplaySpeed::Enum policy)
346  {
347  speed_ = policy;
348  }
349 
350  /// Re-initializes as a copy of the other one.
352  operator =(
353  const ReplaySupplements& other)
354  {
355  settingsUse_ =
356  other.settingsUse_;
357 
358  aliases_ =
359  other.aliases_;
360 
361  timeSpan_ =
362  other.timeSpan_;
363 
364  speed_ =
365  other.speed_;
366 
367  return *this;
368  }
369 
370 private:
371  HandlerSettingsUse::Enum settingsUse_;
372  Aliases aliases_;
373 
374  ReplaySpan timeSpan_;
375  ReplaySpeed::Enum speed_;
376 };
377 
378 /// Replay supplements for log replay functionality.
379 typedef
381 <
382  NetFeedId
383 >
385 
386 /// Collection of logged data sources (feed
387 /// identifiers) to be used by the Log Replay
388 /// to replace logged sources with the sources
389 /// used by Handlers involved into replay.
390 typedef
393 
394 /// Replay supplements for the PCAP replay functionality.
397 : public ReplaySupplements
398  <
401  >
402 {
403  typedef
405  <
406  NetFeedConnection,
408  >
409  Base;
410 
411  // Not applicable for the PCAP replay as no
412  // parameters are stored in the captured files.
413  using Base::settingsUse;
414 
415 public:
416  /// Initializes settings with the default values.
418  {
419  settingsUse(HandlerSettingsUse::AsIs);
420  }
421 
422  /// Settings aren't stored in PCAPs
423  /// thus constant value is returned.
425  {
426  return HandlerSettingsUse::AsIs;
427  }
428 };
429 
430 /// Collection of data sources (feed identifiers)
431 /// to be used by the PCAP file replay to replace
432 /// captured sources with the sources used by Handlers
433 /// involved into replay.
434 typedef
437 
438 /// Replay supplements for the CME DataMine
439 /// historical data replay functionality.
443 {
444  typedef
446  Base;
447 
448  // Not applicable for the Datamine replay as no
449  // parameters are stored in the captured files.
450  using Base::settingsUse;
451 
452 public:
453  /// Initializes settings with the default values.
455  {
456  settingsUse(HandlerSettingsUse::AsIs);
457  }
458 
459  /// Settings aren't stored in Datamine
460  /// thus constant value is returned.
462  {
463  return HandlerSettingsUse::AsIs;
464  }
465 };
466 
467 /// Collection of channels to be used by the CME Datamine
468 /// historical file replay to replace captured sources
469 /// with the sources used by Handlers involved into replay.
470 typedef
473 
474 /// Extracts market data stored in the given
475 /// log files and pushes it to the given handlers
476 /// for further processing.
477 ONIXS_CMEMDH_EXPORTED
478 void
480  const FileList&,
481  Handler**,
482  size_t,
483  const LogReplaySupplements&);
484 
485 /// Extracts market data stored in the given
486 /// log files and pushes it to the given handler
487 /// for further processing.
488 inline
489 void
491  const FileList& logs,
492  Handler& handler,
493  const LogReplaySupplements& supplements)
494 {
495  Handler* handlers[] = { &handler };
496 
498  logs,
499  handlers,
500  1,
501  supplements);
502 }
503 
504 /// Processes market data stored in the log
505 /// files according to specified settings.
506 inline
507 void
509  const FileList& logs,
510  Handler** handlers,
511  size_t handlerQty)
512 {
514  logs,
515  handlers,
516  handlerQty,
518 }
519 
520 /// Processes market data stored in the log
521 /// files according to specified settings.
522 inline
523 void
525  const FileList& logs,
526  Handler& handler)
527 {
528  Handler* handlers[] = { &handler };
529 
530  replayLogFiles(logs, handlers, 1);
531 }
532 
533 /// A Marker instructing the log replay procedure to
534 /// use Hander settings as they are without applying
535 /// any modifications based on logged information.
537 
538 /// Processes market data stored in the log
539 /// files according to specified settings.
540 inline
541 void
543  const FileList& logs,
544  Handler** handlers,
545  size_t handlerQty,
546  const UseHandlerSettingsAsIs&)
547 {
548  LogReplaySupplements supplements;
549 
550  supplements.
551  settingsUse(
553  AsIs);
554 
556  logs,
557  handlers,
558  handlerQty,
559  supplements);
560 }
561 
562 /// Processes market data stored in the log
563 /// files according to specified settings.
564 inline
565 void
567  const FileList& logs,
568  Handler& handler,
569  const UseHandlerSettingsAsIs& marker)
570 {
571  Handler* handlers[] = { &handler };
572 
573  replayLogFiles(logs, handlers, 1, marker);
574 }
575 
576 /// Replays the given list of PCAP files for the
577 /// given Handlers according to the given settings.
578 ONIXS_CMEMDH_EXPORTED
579 void
581  const FileList&,
582  Handler**,
583  size_t,
584  const PcapReplaySupplements&);
585 
586 /// Replays the given list of PCAP files for the
587 /// given Handler according to the given settings.
588 inline
589 void
591  const FileList& logs,
592  Handler& handler,
593  const PcapReplaySupplements& supplements)
594 {
595  Handler* handlers[] = { &handler };
596 
597  replayPcapFiles(logs, handlers, 1, supplements);
598 }
599 
600 /// Replays the given list of PCAP files for the
601 /// given Handler according to the default settings.
602 inline
603 void
605  const FileList& logs,
606  Handler& handler)
607 {
609  logs,
610  handler,
612 }
613 
614 /// Replays the given list of Datamine files for the
615 /// given Handlers according to the given settings.
616 ONIXS_CMEMDH_EXPORTED
617 void
619  const FileList&,
620  Handler**,
621  size_t,
623 
624 /// Replays the given list of Datamine files for the
625 /// given Handlers according to the given settings.
626 inline
627 void
629  const FileList& logs,
630  Handler& handler,
631  const DatamineReplaySupplements& supplements)
632 {
633  Handler* handlers[] = { &handler };
634 
636  logs,
637  handlers,
638  1,
639  supplements);
640 }
641 
642 /// Replays the given list of historical data for the
643 /// given Handler according to the default settings.
644 inline
645 void
647  const FileList& logs,
648  Handler& handler)
649 {
651  logs,
652  handler,
654 }
655 
Defines range of log entries to be replayed.
Definition: Replay.h:128
ReplaySpan(const ReplaySpan &other)
Definition: Replay.h:153
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
ONIXS_CMEMDH_EXPORTED void gatherLogFiles(FileList &, ChannelId, const std::string &, const std::string &)
Replay supplements for the PCAP replay functionality.
Definition: Replay.h:395
std::string NetFeedId
The feed identifier.
ReplaySupplements(const ReplaySupplements &other)
Initializes as a copy of the other one.
Definition: Replay.h:270
Network feed connection attributes.
PcapReplaySupplements::Aliases NetAddressAliases
Definition: Replay.h:436
std::vector< std::string > FileList
Ordered list of logs to be replayed.
Definition: Replay.h:42
UInt32 ChannelId
Identifies CME channel.
Definition: Domain.h:28
ReplaySpan()
Initializes empty span.
Definition: Replay.h:135
void gatherPcapFiles(FileList &files, const std::string &location, const std::string &ext)
Definition: Replay.h:97
const Aliases & aliases() const
Definition: Replay.h:305
const ReplaySpan & timeSpan() const
Time span for which entries are to be processed.
Definition: Replay.h:323
Represents time point without time-zone information.
Definition: Time.h:471
ReplaySupplements< NetFeedId > LogReplaySupplements
Replay supplements for log replay functionality.
Definition: Replay.h:384
LogReplaySupplements::Aliases FeedIdAliases
Definition: Replay.h:392
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:46
void settingsUse(HandlerSettingsUse::Enum policy)
Defines handler settings use policy.
Definition: Replay.h:292
void replayLogFiles(const FileList &logs, Handler &handler, const UseHandlerSettingsAsIs &marker)
Definition: Replay.h:566
void replayDatamineFiles(const FileList &logs, Handler &handler)
Definition: Replay.h:646
bool value(Number &number, const MultiContainer &container, Tag tag)
HandlerSettingsUse::Enum settingsUse() const
Definition: Replay.h:461
#define ONIXS_CMEMDH_LTWT_STRUCT
Definition: Bootstrap.h:98
bool empty() const
Indicates whether span is empty or not.
Definition: Replay.h:161
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:152
ReplaySpan & timeSpan()
Time span for which entries are to be processed.
Definition: Replay.h:330
void begin(const Timestamp &value)
Updates the beginning of the range.
Definition: Replay.h:185
std::map< DataSource, DataSource, DataSourceLess > Aliases
The table of data source aliases.
Definition: Replay.h:254
ONIXS_CMEMDH_EXPORTED void gatherFiles(FileList &, const std::string &, const std::string &)
const Timestamp & end() const
Indicates the end of the range.
Definition: Replay.h:192
Controls speed of market data replay.
Definition: Replay.h:218
HandlerSettingsUse::Enum settingsUse() const
Definition: Replay.h:424
const Timestamp & begin() const
Indicates the beginning of the range.
Definition: Replay.h:178
DatamineReplaySupplements::Aliases ChannelIdAliases
Definition: Replay.h:472
void speed(ReplaySpeed::Enum policy)
Defines processing speed.
Definition: Replay.h:344
ONIXS_CMEMDH_EXPORTED Timestamp timestamp(const MultiContainer &, Tag)
Retrieves last update time field value.
Enum
Controls speed of market data replay.
Definition: Replay.h:221
bool contain(const Timestamp &timestamp) const
Definition: Replay.h:169
ReplaySupplements()
Initializes the settings with the default values.
Definition: Replay.h:257
ReplaySpeed::Enum speed() const
Indicates processing speed policy.
Definition: Replay.h:337
PcapReplaySupplements()
Initializes settings with the default values.
Definition: Replay.h:417
ReplaySpan(const Timestamp &begin, const Timestamp &end)
Definition: Replay.h:143
Establishes the order between two connections.
void end(const Timestamp &value)
Indicates the end of the range.
Definition: Replay.h:199
DatamineReplaySupplements()
Initializes settings with the default values.
Definition: Replay.h:454
HandlerSettingsUse::Enum settingsUse() const
Handler settings use policy.
Definition: Replay.h:285
void replayPcapFiles(const FileList &logs, Handler &handler)
Definition: Replay.h:604
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:156