The Sparta Modeling Framework
Loading...
Searching...
No Matches
EventSet.hpp
Go to the documentation of this file.
1// <StatisticSet> -*- C++ -*-
2
3
10#pragma once
11
12#include <iostream>
13#include <array>
14
18
19namespace sparta
20{
25 class EventSet : public TreeNode
26 {
27 public:
28
30 static constexpr char NODE_NAME[] = "events";
31
39 EventSet(TreeNode* parent) :
43 "Event Set")
44 {
45 if(parent){
46 setExpectedParent_(parent);
47 parent->addChild(this);
48 }
49 }
50
55
56 // Overload of TreeNode::stringize
57 virtual std::string stringize(bool pretty=false) const override {
58 (void) pretty;
59 std::stringstream ss;
60 std::array<EventsVector, NUM_SCHEDULING_PHASES>::size_type event_cnt = 0;
61 for(const auto & ea : events_) {
62 event_cnt += ea.size();
63 }
64 ss << '<' << getLocation() << ' ' << event_cnt << " events>";
65 return ss.str();
66 }
67
68 public:
70 typedef std::vector<EventNode *> EventsVector;
71
75 return events_[static_cast<uint32_t>(phase)];
76 }
77
78 private:
79
92 virtual void onAddingChild_(TreeNode* child) override {
93 if(isFinalized()){
94 throw SpartaException("Cannot add a child event once a EventSet is finalized. "
95 "Error with: ")
96 << getLocation();
97 }
98
99 EventNode* event_node = dynamic_cast<EventNode*>(child);
100 if(nullptr != event_node){
101 // Add event to events_ list for tracking.
102 events_[static_cast<uint32_t>(event_node->getSchedulingPhase())].push_back(event_node);
103 return;
104 }
105
106 throw SpartaException("Cannot add TreeNode child ")
107 << child->getName() << " to EventSet " << getLocation()
108 << " because the child is not a CounterBase or Event";
109 }
110
115 std::array<EventsVector, NUM_SCHEDULING_PHASES> events_;
116 };
117}
118
File that defines the EventNode class.
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
Set of Events that a unit (or sparta::TreeNode, sparta::Resource) contains and are visible through a ...
Definition EventSet.hpp:26
static constexpr char NODE_NAME[]
Name of all EventSet nodes.
Definition EventSet.hpp:30
virtual std::string stringize(bool pretty=false) const override
Create a string representation of this node.
Definition EventSet.hpp:57
EventSet(TreeNode *parent)
Constructor.
Definition EventSet.hpp:39
std::vector< EventNode * > EventsVector
Type for holding outside events.
Definition EventSet.hpp:70
~EventSet()
Destructor.
Definition EventSet.hpp:54
EventsVector & getEvents(sparta::SchedulingPhase phase)
Definition EventSet.hpp:74
virtual bool isFinalized() const
Is this node (and thus the entire tree above it) "finalized".
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
static const group_idx_type GROUP_IDX_NONE
GroupIndex indicating that a node has no group index because it belongs to no group.
Definition TreeNode.hpp:303
std::string getLocation() const override final
static constexpr char GROUP_NAME_BUILTIN[]
Reserved name for built-in nodes.
Definition TreeNode.hpp:370
void addChild(TreeNode *child, bool inherit_phase=true)
Adds a TreeNode to this node as a child.
const std::string & getName() const override
Gets the name of this node.
void setExpectedParent_(const TreeNode *parent)
Tracks a node as an expected parent without actually adding this node as a child. This is used almost...
Macros for handling exponential backoff.
SchedulingPhase
The SchedulingPhases used for events (Tick, Update, PortUpdate, etc)