14#include "sparta/utils/Utils.hpp"
15#include "sparta/log/MessageSource.hpp"
68template <
typename IterableType, SchedulingPhase collection_phase = SchedulingPhase::Collection,
bool sparse_array_type = false>
72 typedef typename IterableType::size_type size_type;
85 const std::string & name,
86 const std::string & group,
88 const std::string & desc,
89 const IterableType * iterable,
90 const size_type expected_capacity) :
92 iterable_object_(iterable),
93 expected_capacity_(expected_capacity),
95 ev_close_record_(&event_set_, name +
"_pipeline_collectable_close_event",
98 for (size_type i = 0; i < expected_capacity_; ++i)
100 std::stringstream name_str;
101 name_str << name << i;
102 positions_.emplace_back(
new CollectableT(
this, name_str.str(), group, i));
118 const std::string & name,
119 const std::string & group,
120 const uint32_t index,
121 const std::string & desc,
122 const IterableType & iterable,
123 const size_type expected_capacity) :
124 IterableCollector(parent, name, group, index, desc, &iterable, expected_capacity)
136 const std::string & name,
137 const std::string & desc,
138 const IterableType * iterable,
139 const size_type expected_capacity) :
152 const std::string & name,
153 const std::string & desc,
154 const IterableType & iterable,
155 const size_type expected_capacity) :
167 const std::string & name,
168 const IterableType * iterable,
169 const size_type expected_capacity) :
171 iterable, expected_capacity)
184 const std::string & name,
185 const IterableType & iterable,
186 const size_type expected_capacity) :
188 &iterable, expected_capacity)
200 const std::string & name,
201 const size_type expected_capacity) :
203 nullptr, expected_capacity)
214 std::ostringstream oss;
215 oss <<
"Collecting non-trivial classes using operator<< is no longer supported. Use PairDefinition.\n";
217 oss <<
" - type: " << simdb::demangle_type<BinValueT>() <<
" (container)";
218 argos_collector->postNotif(oss.str(), simdb::argos::NotifType::WARNING);
223 entry_point_ = argos_collector->createContainerCollector(loc, clk_name, type);
225 auto tiny_strings = argos_collector->getTinyStrings();
226 auto enum_inspector = argos_collector->getEnumInspector();
227 bit_bucket_ = std::make_shared<IterableCollectorBitBucket<sparse_array_type>>(tiny_strings, enum_inspector, expected_capacity_);
228 for (
auto & bin : positions_) {
229 bin->setBitBucket(bit_bucket_);
238 positions_.at(0)->serializeStructSchema(db_mgr, serialized_types);
243 auto type = positions_.at(0)->encodeCollectedType();
244 auto human_readable_type = positions_.at(0)->encodeCollectedType(
true);
245 auto human_readable_desc = human_readable_type.substr(type.size() + 1);
247 if constexpr (sparse_array_type) {
252 type +=
"_capacity" + std::to_string(expected_capacity_);
253 if (human_readable) {
254 type +=
" " + human_readable_desc;
263 void collect(
const IterableType * iterable_object)
266 if(
nullptr == iterable_object) {
276 <<
"WARNING! The collected object '"
278 <<
"expected capacity (given at construction) for collection. "
279 <<
"Expected " << expected_capacity_ <<
" but grew to "
280 << iterable_object->size()
281 <<
" This is your first and last warning.";
282 warn_on_size_ =
false;
285 collectImpl_(iterable_object, std::integral_constant<bool, sparse_array_type>());
313 auto_collect_ =
false;
329 iterable_object_ = obj;
333 typedef typename std::iterator_traits<typename IterableType::iterator>::value_type BinT;
334 typedef MetaStruct::remove_any_pointer_t<BinT> BinValueT;
339 void collectImpl_(
const IterableType * iterable_object, std::false_type)
348 "Can't collect iterable_object because it's a nullptr! How did we get here?");
349 auto itr = iterable_object->begin();
350 auto eitr = iterable_object->end();
351 auto size = std::distance(itr, eitr);
352 bit_bucket_->clear();
353 for (uint32_t i = 0; i < size; ++i)
355 bit_bucket_->setActiveBinIdx(i);
356 positions_[i]->collect(*itr);
366 void collectImpl_(
const IterableType * iterable_object, std::true_type)
375 "Can't collect iterable_object because it's a nullptr! How did we get here?");
376 auto itr = iterable_object->begin();
377 bit_bucket_->clear();
378 for (uint32_t i = 0; i < expected_capacity_; ++i)
382 bit_bucket_->setActiveBinIdx(i);
383 positions_[i]->collect(*itr);
393 void setCollecting_(
bool collect, Collector * collector)
override
396 PipelineCollector * pipeline_col =
dynamic_cast<PipelineCollector *
>(collector);
401 pipeline_col->addToAutoCollection(
this, collection_phase);
408 const IterableType * iterable_object_;
409 std::vector<std::unique_ptr<CollectableT>> positions_;
410 const size_type expected_capacity_ = 0;
411 bool auto_collect_ =
true;
412 bool warn_on_size_ =
true;
413 std::shared_ptr<BitBucketT> bit_bucket_;
define a CollectableTreeNode type TreeNode.
Implementation of the Collectable class that allows a user to collect an object into an pipeViewer pi...
Class to facilitate pipeline collection operations.
File that defines the phases used in simulation.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
#define SPARTA_EXPECT_FALSE(x)
A macro for hinting to the compiler a particular condition should be considered most likely false.
#define CREATE_SPARTA_HANDLER_WITH_DATA(clname, meth, dataT)
Set of Events that a unit (or sparta::TreeNode, sparta::Resource) contains and are visible through a ...
Class to schedule a Scheduleable in the future with a payload, typed on both the data type and the sc...
ScheduleableHandle preparePayload(const DataT &payload)
Prepare a Scheduleable Payload for scheduling either now or later.
void schedule()
Schedule this event with its pre-set delay using the pre-set Clock.
Node in a composite tree representing a sparta Tree item.
std::string getLocation() const override final
const Clock * getClock() override
Walks up parents (starting with self) until a parent with an associated local clock is found,...
An abstract type of TreeNode that has virtual calls to start collection on this node,...
simdb::argos::EntryPoint * entry_point_
Entry point into the SimDB collection system.
bool isCollected() const
Determine whether or not this node has collection turned on or off.
BitBucket implementation for sparse IterableCollectors.
A collector of any iterable type (std::vector, std::list, sparta::Buffer, etc)
void createSimDbEntryPoint(simdb::argos::ArgosCollector *argos_collector) override final
void reattach(const IterableType *obj)
Reattach to a new iterable object (used for moves)
void collect(const IterableType *iterable_object)
std::string encodeCollectedType(bool human_readable=false) const override final
Encode the collected data type in a way Argos python deserializers will understand:
void setManualCollection()
Do not perform any automatic collection The SchedulingPhase is ignored.
void scheduleCloseRecord(sparta::Clock::Cycle cycle)
Schedule event to close all records for this iterable type.
IterableCollector(TreeNode *parent, const std::string &name, const std::string &desc, const IterableType &iterable, const size_type expected_capacity)
constructor
IterableCollector(TreeNode *parent, const std::string &name, const IterableType &iterable, const size_type expected_capacity)
constructor with no description
void collect() override
Collect the contents of the associated iterable object.
void serializeStructSchema(simdb::DatabaseManager *db_mgr, std::set< std::string > &serialized_types) override final
IterableCollector(TreeNode *parent, const std::string &name, const IterableType *iterable, const size_type expected_capacity)
constructor with no description
IterableCollector(TreeNode *parent, const std::string &name, const std::string &group, const uint32_t index, const std::string &desc, const IterableType *iterable, const size_type expected_capacity)
constructor
IterableCollector(TreeNode *parent, const std::string &name, const std::string &group, const uint32_t index, const std::string &desc, const IterableType &iterable, const size_type expected_capacity)
constructor
void collectWithDuration(sparta::Clock::Cycle duration)
Perform a collection, then close the records in the future.
IterableCollector(TreeNode *parent, const std::string &name, const size_type expected_capacity)
constructor with no iterable object associated
void closeRecord(const bool &=false) override
IterableCollector(TreeNode *parent, const std::string &name, const std::string &desc, const IterableType *iterable, const size_type expected_capacity)
constructor
static MessageSource & getGlobalWarn()
Gets the global warning logger. These messages can be picked up by placing a Tap on the sparta::TreeN...
Macros for handling exponential backoff.
T * notNull(T *p)
Ensures that a pointer is not null.