helics  3.3.0
Clone.hpp
1 /*
2 Copyright (c) 2017-2022,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 
8 #pragma once
9 #include "../application_api/Endpoints.hpp"
10 #include "../application_api/Publications.hpp"
11 #include "../application_api/Subscriptions.hpp"
12 #include "helicsApp.hpp"
13 
14 #include <deque>
15 #include <map>
16 #include <memory>
17 #include <set>
18 #include <string>
19 #include <tuple>
20 #include <utility>
21 #include <vector>
22 
23 namespace helics {
24 class CloningFilter;
25 
26 namespace apps {
28  class HELICS_CXX_EXPORT Clone: public App {
29  public:
35  Clone(std::string_view appName, FederateInfo& fi);
39  explicit Clone(std::vector<std::string> args);
41  Clone(int argc, char* argv[]);
42 
49  Clone(std::string_view appName, const std::shared_ptr<Core>& core, const FederateInfo& fi);
50 
56  Clone(std::string_view appName, CoreApp& core, const FederateInfo& fi);
57 
62  Clone(std::string_view appName, const std::string& jsonString);
64  Clone(Clone&& other_recorder) = default;
66  Clone& operator=(Clone&& record) = default;
68  ~Clone();
70  virtual void runTo(Time runToTime) override;
72  void saveFile(const std::string& filename = std::string{});
74  auto pointCount() const { return points.size(); }
76  auto messageCount() const { return messages.size(); }
81  std::tuple<Time, std::string, std::string> getValue(int index) const;
86  std::unique_ptr<Message> getMessage(int index) const;
87 
91  void setFederateToClone(std::string_view federateName);
94  void setOutputFile(std::string_view fileName) { outFileName = fileName; }
95 
96  private:
98  void addSubscription(std::string_view key);
99 
101  void addSourceEndpointClone(std::string_view sourceEndpoint);
102 
103  virtual void initialize() override;
104  void generateInterfaces();
105  void captureForCurrentTime(Time currentTime, int iteration = 0);
107  std::shared_ptr<helicsCLI11App> buildArgParserApp();
109  void processArgs();
110 
111  protected:
113  class ValueCapture {
114  public:
115  helics::Time time;
116  int index{-1};
117  int16_t iteration{0};
118  bool first{false};
119  std::string value;
120  ValueCapture() = default;
121  ValueCapture(helics::Time t1, int id1, std::string_view val):
122  time(t1), index(id1), value(val)
123  {
124  }
125  };
126 
127  bool allow_iteration{false};
128  bool verbose{false};
129  bool fileSaved{false};
130  Time nextPrintTimeStep{
132  std::unique_ptr<CloningFilter> cFilt;
133  std::vector<ValueCapture> points;
134  std::deque<Input> subscriptions;
135  std::vector<std::string>
137  std::unique_ptr<Endpoint> cloneEndpoint;
138  std::vector<std::unique_ptr<Message>> messages;
139  std::map<helics::InterfaceHandle, int> subids;
140  std::map<std::string_view, int> subkeys;
141  std::map<helics::InterfaceHandle, int> eptids; // translate subscription id to index
142  std::map<std::string_view, int> eptNames;
143  std::string captureFederate;
144  std::string fedConfig;
145  std::string outFileName{"clone.json"};
146  std::vector<int> pubPointCount;
147  };
148 
149 } // namespace apps
150 } // namespace helics
helics::timeZero
constexpr Time timeZero
Definition: helicsTime.hpp:31
helics::apps::Clone::Clone
Clone(std::string_view appName, FederateInfo &fi)
Definition: Clone.cpp:44
helics::apps::Clone::cFilt
std::unique_ptr< CloningFilter > cFilt
a pointer to a clone filter
Definition: Clone.hpp:132
helics::apps::App::loadJsonFile
virtual void loadJsonFile(const std::string &jsonString)
Definition: helicsApp.cpp:153
helics::apps::Clone::points
std::vector< ValueCapture > points
lists of points that were captured
Definition: Clone.hpp:133
HELICS_SEQUENCING_MODE_ORDERED
@ HELICS_SEQUENCING_MODE_ORDERED
Definition: helics_enums.h:399
helics::apps::Clone::saveFile
void saveFile(const std::string &filename=std::string{})
Definition: Clone.cpp:105
helics::getValue
X getValue(ValueFederate &fed, std::string_view key)
Definition: Subscriptions.hpp:31
helics::apps::Clone::fedConfig
std::string fedConfig
storage for the federateConfiguration
Definition: Clone.hpp:144
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::vectorizeQueryResult
std::vector< std::string > vectorizeQueryResult(std::string_view queryres)
Definition: queryFunctions.cpp:19
helics::apps::Clone::ValueCapture
Definition: Clone.hpp:113
HELICS_FLAG_OBSERVER
@ HELICS_FLAG_OBSERVER
Definition: helics_enums.h:101
helics::apps::Clone::messageCount
auto messageCount() const
Definition: Clone.hpp:76
helics::apps::Clone::verbose
bool verbose
print all captured values to the screen
Definition: Clone.hpp:128
helics::apps::App::masterFileName
std::string masterFileName
the name of the master file used to do the construction
Definition: helicsApp.hpp:132
helics::apps::Clone::fileSaved
bool fileSaved
true if the file has been saved already
Definition: Clone.hpp:129
helics::apps::Clone::setOutputFile
void setOutputFile(std::string_view fileName)
Definition: Clone.hpp:94
helics::apps::Clone::cloneEndpoint
std::unique_ptr< Endpoint > cloneEndpoint
the endpoint for cloned message delivery
Definition: Clone.hpp:137
helics::apps::Clone::setFederateToClone
void setFederateToClone(std::string_view federateName)
Definition: Clone.cpp:334
helics::apps::Clone::messages
std::vector< std::unique_ptr< Message > > messages
list of messages
Definition: Clone.hpp:138
helics::FederateInfo
Definition: FederateInfo.hpp:24
helics::apps::Clone::subids
std::map< helics::InterfaceHandle, int > subids
map of the subscription ids
Definition: Clone.hpp:139
helics::apps::Clone::~Clone
~Clone()
Definition: Clone.cpp:94
helics::apps::Clone::allow_iteration
bool allow_iteration
trigger to allow Iteration
Definition: Clone.hpp:127
helics::apps::Clone::subscriptions
std::deque< Input > subscriptions
the actual subscription objects
Definition: Clone.hpp:134
helics::apps::Clone
Definition: Clone.hpp:28
helics::apps::Clone::nextPrintTimeStep
Time nextPrintTimeStep
the time advancement period for printing markers
Definition: Clone.hpp:130
helics::IterationRequest::ITERATE_IF_NEEDED
@ ITERATE_IF_NEEDED
indicator that the iterations need to continue
helics::apps::Clone::outFileName
std::string outFileName
the final output file
Definition: Clone.hpp:145
helics::apps::Clone::getMessage
std::unique_ptr< Message > getMessage(int index) const
Definition: Clone.cpp:349
helics::queryFederateSubscriptions
std::string queryFederateSubscriptions(helics::Federate *fed, std::string_view fedName)
Definition: queryFunctions.cpp:136
helics::waitForInit
bool waitForInit(helics::Federate *fed, std::string_view fedName, std::chrono::milliseconds timeout)
Definition: queryFunctions.cpp:101
helics::apps::Clone::cloneSubscriptionNames
std::vector< std::string > cloneSubscriptionNames
string of the subscriptions of the cloned federate
Definition: Clone.hpp:136
helics::apps::Clone::eptNames
std::map< std::string_view, int > eptNames
translate endpoint name to index
Definition: Clone.hpp:142
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::apps::Clone::captureFederate
std::string captureFederate
storage for the name of the federate to clone
Definition: Clone.hpp:143
helics::IterationResult::NEXT_STEP
@ NEXT_STEP
helics::apps::Clone::runTo
virtual void runTo(Time runToTime) override
Definition: Clone.cpp:276
helics::FunctionExecutionFailure
Definition: core-exceptions.hpp:29
helics::apps::Clone::pointCount
auto pointCount() const
Definition: Clone.hpp:74
helics::apps::App::fed
std::shared_ptr< CombinationFederate > fed
the federate created for the Player
Definition: helicsApp.hpp:130
helics::apps::App
Definition: helicsApp.hpp:29
helics::apps::Clone::getValue
std::tuple< Time, std::string, std::string > getValue(int index) const
Definition: Clone.cpp:339
helics::apps::Clone::subkeys
std::map< std::string_view, int > subkeys
translate subscription names to an index
Definition: Clone.hpp:140
helics::apps::App::loadFile
void loadFile(const std::string &filename)
Definition: helicsApp.cpp:123
helics::apps::Clone::pubPointCount
std::vector< int > pubPointCount
a vector containing the counts of each publication
Definition: Clone.hpp:146
helics::isValidIndex
bool isValidIndex(sizeType testSize, const SizedDataType &vec)
Definition: core-data.hpp:171