22#include "PCG/pcg_random.hpp"
25#include <boost/property_tree/ptree.hpp>
44 mCurrentTimesliceID(0),
45 mLastDecision(false){};
50 void configure(
const boost::property_tree::ptree& config)
override
52 mThreshold =
static_cast<uint32_t
>(config.get<
double>(
"fraction") * std::numeric_limits<uint32_t>::max());
54 auto seed = config.get<uint64_t>(
"seed");
55 mGenerator.seed((seed == 0) ? std::random_device()() : seed);
57 mCurrentTimesliceID = 0;
58 mLastDecision =
false;
60 auto timeslideID = config.get_optional<std::string>(
"timesliceId").value_or(
"startTime");
61 if (timeslideID ==
"startTime") {
63 const auto* dph = get<DataProcessingHeader*>(dataRef.header);
65 return dph->startTime;
67 }
else if (timeslideID ==
"tfCounter") {
69 const auto* dh = get<DataHeader*>(dataRef.header);
73 }
else if (timeslideID ==
"firstTForbit") {
75 const auto* dh = get<DataHeader*>(dataRef.header);
77 return dh->firstTForbit;
80 throw std::runtime_error(
"Data Sampling Condition Random does not support timesliceId '" + timeslideID +
"'");
87 auto tid = mGetTimesliceID(dataRef);
89 int64_t diff = tid - mCurrentTimesliceID;
92 }
else if (diff < -1) {
93 mGenerator.backstep(
static_cast<uint64_t
>(-diff));
94 }
else if (diff > 0) {
95 mGenerator.advance(
static_cast<uint64_t
>(diff));
98 mLastDecision = mGenerator() < mThreshold;
99 mCurrentTimesliceID = tid + 1;
100 return mLastDecision;
105 pcg32_fast mGenerator;
107 uint64_t mCurrentTimesliceID;
113 return std::make_unique<DataSamplingConditionRandom>();
A definition of DataSamplingConditionFactory.
A standarised data sampling condition, to decide if given data sample should be passed forward.
static std::unique_ptr< DataSamplingCondition > createDataSamplingConditionRandom()
Getter for DataSamplingConditionRandom.
A DataSamplingCondition which makes decisions randomly, but with determinism.
DataSamplingConditionRandom()
Constructor.
~DataSamplingConditionRandom() override=default
Default destructor.
void configure(const boost::property_tree::ptree &config) override
Reads 'fraction' parameter (type double, between 0 and 1) and seed (int).
bool decide(const o2::framework::DataRef &dataRef) override
Makes pseudo-random, deterministic decision based on TimesliceID. The reason behind using TimesliceID...
A standardised data sampling condition, to decide if given data sample should be passed forward.
Defining PrimaryVertex explicitly as messageable.
A header which contains some meta-data generated by Data Sampling.