helics  3.3.0
Tracer.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 #pragma once
8 
9 #include "../application_api/Endpoints.hpp"
10 #include "../application_api/Subscriptions.hpp"
11 #include "helicsApp.hpp"
12 
13 #include <deque>
14 #include <functional>
15 #include <map>
16 #include <memory>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 namespace helics {
22 class CloningFilter;
23 
24 namespace apps {
26  class HELICS_CXX_EXPORT Tracer: public App {
27  public:
29  explicit Tracer(std::string_view name, FederateInfo& fi);
33  explicit Tracer(std::vector<std::string> args);
34 
36  Tracer(int argc, char* argv[]);
37 
43  Tracer(std::string_view name, const std::shared_ptr<Core>& core, const FederateInfo& fi);
44 
50  Tracer(std::string_view name, CoreApp& core, const FederateInfo& fi);
51 
56  Tracer(std::string_view name, const std::string& file);
58  Tracer(Tracer&& other_tracer) = default;
60  Tracer& operator=(Tracer&& tracer) = default;
62  ~Tracer();
63  virtual void runTo(Time runToTime) override;
65  void addSubscription(std::string_view key);
67  void addEndpoint(std::string_view endpoint);
69  void addSourceEndpointClone(std::string_view sourceEndpoint);
71  void addDestEndpointClone(std::string_view destEndpoint);
75  void addCapture(std::string_view captureDesc);
76 
80  void setClonedMessageCallback(std::function<void(Time, std::unique_ptr<Message>)> callback)
81  {
82  clonedMessageCallback = std::move(callback);
83  }
89  std::function<void(Time, std::string_view, std::unique_ptr<Message>)> callback)
90  {
91  endpointMessageCallback = std::move(callback);
92  }
97  void
98  setValueCallback(std::function<void(Time, std::string_view, std::string_view)> callback)
99  {
100  valueCallback = std::move(callback);
101  }
103  void enableTextOutput() { printMessage = true; }
105  void disableTextOutput() { printMessage = false; }
106 
107  private:
111  virtual void loadJsonFile(const std::string& jsonString) override;
113  virtual void loadTextFile(const std::string& textFile) override;
114 
115  virtual void initialize() override;
116  void generateInterfaces();
117  void captureForCurrentTime(Time currentTime, int iteration = 0);
118  void loadCaptureInterfaces();
119 
121  std::shared_ptr<helicsCLI11App> buildArgParserApp();
123  void processArgs();
124 
125  protected:
126  bool printMessage = false;
127  bool allow_iteration =
128  false;
129  bool skiplog = false;
130  std::unique_ptr<CloningFilter> cFilt;
131 
132  std::deque<Input> subscriptions;
133  std::map<std::string_view, int> subkeys;
134 
135  std::deque<Endpoint> endpoints;
136  std::map<std::string_view, int> eptNames;
137  std::unique_ptr<Endpoint> cloneEndpoint;
138  std::vector<std::string> captureInterfaces;
139 
140  std::function<void(Time, std::unique_ptr<Message>)> clonedMessageCallback;
141  std::function<void(Time, std::string_view, std::unique_ptr<Message>)>
142  endpointMessageCallback;
143  std::function<void(Time, std::string_view, std::string_view)> valueCallback;
144  };
145 
146 } // namespace apps
147 } // namespace helics
helics::apps::Tracer::Tracer
Tracer(std::string_view name, FederateInfo &fi)
Definition: Tracer.cpp:35
helics::apps::Tracer::runTo
virtual void runTo(Time runToTime) override
Definition: Tracer.cpp:353
HELICS_SEQUENCING_MODE_ORDERED
@ HELICS_SEQUENCING_MODE_ORDERED
Definition: helics_enums.h:399
helics::apps::Tracer::cFilt
std::unique_ptr< CloningFilter > cFilt
a pointer to a clone filter
Definition: Tracer.hpp:130
helics::apps::Tracer
Definition: Tracer.hpp:26
helics::apps::Tracer::~Tracer
~Tracer()
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27
helics::apps::Tracer::enableTextOutput
void enableTextOutput()
Definition: Tracer.hpp:103
helics::apps::Tracer::setClonedMessageCallback
void setClonedMessageCallback(std::function< void(Time, std::unique_ptr< Message >)> callback)
Definition: Tracer.hpp:80
helics::vectorizeQueryResult
std::vector< std::string > vectorizeQueryResult(std::string_view queryres)
Definition: queryFunctions.cpp:19
helics::apps::Tracer::eptNames
std::map< std::string_view, int > eptNames
translate endpoint name to index
Definition: Tracer.hpp:136
HELICS_FLAG_OBSERVER
@ HELICS_FLAG_OBSERVER
Definition: helics_enums.h:101
helics::apps::Tracer::addSubscription
void addSubscription(std::string_view key)
Definition: Tracer.cpp:398
helics::apps::Tracer::endpoints
std::deque< Endpoint > endpoints
the actual endpoint objects
Definition: Tracer.hpp:135
helics::apps::App::masterFileName
std::string masterFileName
the name of the master file used to do the construction
Definition: helicsApp.hpp:132
helics::apps::App::loadJsonFileConfiguration
void loadJsonFileConfiguration(const std::string &appName, const std::string &jsonString)
Definition: helicsApp.cpp:158
helics::apps::Tracer::addSourceEndpointClone
void addSourceEndpointClone(std::string_view sourceEndpoint)
Definition: Tracer.cpp:418
helics::apps::Tracer::skiplog
bool skiplog
skip the log function and print directly to cout
Definition: Tracer.hpp:129
helics::FederateInfo
Definition: FederateInfo.hpp:24
helics::apps::Tracer::cloneEndpoint
std::unique_ptr< Endpoint > cloneEndpoint
the endpoint for cloned message delivery
Definition: Tracer.hpp:137
helics::apps::Tracer::addDestEndpointClone
void addDestEndpointClone(std::string_view destEndpoint)
Definition: Tracer.cpp:428
helics::Federate::Modes::INITIALIZING
@ INITIALIZING
helics::apps::Tracer::subkeys
std::map< std::string_view, int > subkeys
translate subscription names to an index
Definition: Tracer.hpp:133
helics::apps::Tracer::subscriptions
std::deque< Input > subscriptions
the actual subscription objects
Definition: Tracer.hpp:132
helics::IterationRequest::ITERATE_IF_NEEDED
@ ITERATE_IF_NEEDED
indicator that the iterations need to continue
helics::waitForInit
bool waitForInit(helics::Federate *fed, std::string_view fedName, std::chrono::milliseconds timeout)
Definition: queryFunctions.cpp:101
helics::apps::App::loadTextFile
virtual void loadTextFile(const std::string &textFile)
Definition: helicsApp.cpp:133
helics::apps::Tracer::setValueCallback
void setValueCallback(std::function< void(Time, std::string_view, std::string_view)> callback)
Definition: Tracer.hpp:98
helics::apps::Tracer::addCapture
void addCapture(std::string_view captureDesc)
Definition: Tracer.cpp:438
helics::apps::Tracer::allow_iteration
bool allow_iteration
flag to allow iteration of the federate for time requests
Definition: Tracer.hpp:127
helics::apps::Tracer::setEndpointMessageCallback
void setEndpointMessageCallback(std::function< void(Time, std::string_view, std::unique_ptr< Message >)> callback)
Definition: Tracer.hpp:88
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::IterationResult::NEXT_STEP
@ NEXT_STEP
helics::apps::Tracer::disableTextOutput
void disableTextOutput()
Definition: Tracer.hpp:105
helics::apps::Tracer::addEndpoint
void addEndpoint(std::string_view endpoint)
Definition: Tracer.cpp:409
helics::apps::Tracer::captureInterfaces
std::vector< std::string > captureInterfaces
storage for the interfaces to capture
Definition: Tracer.hpp:138
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::Federate::Modes::STARTUP
@ STARTUP
helics::apps::App::loadFile
void loadFile(const std::string &filename)
Definition: helicsApp.cpp:123