helics 3.7.0
Loading...
Searching...
No Matches
Tracer.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-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
21namespace helics {
22class CloningFilter;
23
24namespace 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;
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 }
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
Definition FederateInfo.hpp:28
Definition helicsApp.hpp:32
Definition Tracer.hpp:26
void enableTextOutput()
Definition Tracer.hpp:105
std::unique_ptr< Endpoint > cloneEndpoint
the endpoint for cloned message delivery
Definition Tracer.hpp:142
std::deque< Input > subscriptions
the actual subscription objects
Definition Tracer.hpp:137
std::vector< std::string > captureInterfaces
storage for the interfaces to capture
Definition Tracer.hpp:143
void setValueCallback(std::function< void(Time, std::string_view, std::string_view)> callback)
Definition Tracer.hpp:100
std::map< std::string_view, int > subkeys
translate subscription names to an index
Definition Tracer.hpp:138
void setEndpointMessageCallback(std::function< void(Time, std::string_view, std::unique_ptr< Message >)> callback)
Definition Tracer.hpp:90
std::map< std::string_view, int > eptNames
translate endpoint name to index
Definition Tracer.hpp:141
std::deque< Endpoint > endpoints
the actual endpoint objects
Definition Tracer.hpp:140
Tracer(Tracer &&other_tracer)=default
void setClonedMessageCallback(std::function< void(Time, std::unique_ptr< Message >)> callback)
Definition Tracer.hpp:82
void disableTextOutput()
Definition Tracer.hpp:107
std::unique_ptr< CloningFilter > cFilt
a pointer to a clone filter
Definition Tracer.hpp:135
Tracer & operator=(Tracer &&tracer)=default
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14
TimeRepresentation< count_time< 9 > > Time
Definition helicsTime.hpp:27