| helics 3.6.1

Tracer.hpp
1 /*
2 Copyright (c) 2017-2025,
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& fedInfo);
33 explicit Tracer(std::vector<std::string> args);
34
36 Tracer(int argc, char* argv[]);
37
43 Tracer(std::string_view name,
44 const std::shared_ptr<Core>& core,
45 const FederateInfo& fedInfo);
46
52 Tracer(std::string_view name, CoreApp& core, const FederateInfo& fedInfo);
53
58 Tracer(std::string_view name, const std::string& configString);
60 Tracer(Tracer&& other_tracer) = default;
62 Tracer& operator=(Tracer&& tracer) = default;
64 ~Tracer();
65 virtual void runTo(Time runToTime) override;
67 void addSubscription(std::string_view key);
69 void addEndpoint(std::string_view endpoint);
71 void addSourceEndpointClone(std::string_view sourceEndpoint);
73 void addDestEndpointClone(std::string_view destEndpoint);
77 void addCapture(std::string_view captureDesc);
78
82 void setClonedMessageCallback(std::function<void(Time, std::unique_ptr<Message>)> callback)
83 {
84 clonedMessageCallback = std::move(callback);
85 }
90 void setEndpointMessageCallback(
91 std::function<void(Time, std::string_view, std::unique_ptr<Message>)> callback)
92 {
93 endpointMessageCallback = std::move(callback);
94 }
99 void
100 setValueCallback(std::function<void(Time, std::string_view, std::string_view)> callback)
101 {
102 valueCallback = std::move(callback);
103 }
105 void enableTextOutput() { printMessage = true; }
107 void disableTextOutput() { printMessage = false; }
108
109 private:
111 void initialSetup();
115 virtual void loadJsonFile(const std::string& jsonString,
116 bool enableFederateInterfaceRegistration) override;
118 virtual void loadTextFile(const std::string& textFile) override;
119
120 virtual void initialize() override;
121 void generateInterfaces();
122 void captureForCurrentTime(Time currentTime, int iteration = 0);
123 void loadCaptureInterfaces();
124
126 std::shared_ptr<helicsCLI11App> buildArgParserApp();
128 void processArgs();
129
130 protected:
131 bool printMessage = false;
132 bool allow_iteration =
133 false;
134 bool skiplog = false;
135 std::unique_ptr<CloningFilter> cFilt;
136
137 std::deque<Input> subscriptions;
138 std::map<std::string_view, int> subkeys;
139
140 std::deque<Endpoint> endpoints;
141 std::map<std::string_view, int> eptNames;
142 std::unique_ptr<Endpoint> cloneEndpoint;
143 std::vector<std::string> captureInterfaces;
144
145 std::function<void(Time, std::unique_ptr<Message>)> clonedMessageCallback;
146 std::function<void(Time, std::string_view, std::unique_ptr<Message>)>
147 endpointMessageCallback;
148 std::function<void(Time, std::string_view, std::string_view)> valueCallback;
149 };
150
151 } // namespace apps
152 } // namespace helics
helics::FederateInfo
Definition: FederateInfo.hpp:28
helics::apps::App
Definition: helicsApp.hpp:32
helics::apps::Tracer
Definition: Tracer.hpp:26
helics::apps::Tracer::enableTextOutput
void enableTextOutput()
Definition: Tracer.hpp:105
helics::apps::Tracer::cloneEndpoint
std::unique_ptr< Endpoint > cloneEndpoint
the endpoint for cloned message delivery
Definition: Tracer.hpp:142
helics::apps::Tracer::~Tracer
~Tracer()
helics::apps::Tracer::subscriptions
std::deque< Input > subscriptions
the actual subscription objects
Definition: Tracer.hpp:137
helics::apps::Tracer::captureInterfaces
std::vector< std::string > captureInterfaces
storage for the interfaces to capture
Definition: Tracer.hpp:143
helics::apps::Tracer::setValueCallback
void setValueCallback(std::function< void(Time, std::string_view, std::string_view)> callback)
Definition: Tracer.hpp:100
helics::apps::Tracer::subkeys
std::map< std::string_view, int > subkeys
translate subscription names to an index
Definition: Tracer.hpp:138
helics::apps::Tracer::operator=
Tracer & operator=(Tracer &&tracer)=default
helics::apps::Tracer::setEndpointMessageCallback
void setEndpointMessageCallback(std::function< void(Time, std::string_view, std::unique_ptr< Message >)> callback)
Definition: Tracer.hpp:90
helics::apps::Tracer::eptNames
std::map< std::string_view, int > eptNames
translate endpoint name to index
Definition: Tracer.hpp:141
helics::apps::Tracer::endpoints
std::deque< Endpoint > endpoints
the actual endpoint objects
Definition: Tracer.hpp:140
helics::apps::Tracer::Tracer
Tracer(Tracer &&other_tracer)=default
helics::apps::Tracer::setClonedMessageCallback
void setClonedMessageCallback(std::function< void(Time, std::unique_ptr< Message >)> callback)
Definition: Tracer.hpp:82
helics::apps::Tracer::disableTextOutput
void disableTextOutput()
Definition: Tracer.hpp:107
helics::apps::Tracer::cFilt
std::unique_ptr< CloningFilter > cFilt
a pointer to a clone filter
Definition: Tracer.hpp:135
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::Time
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27