Skip to content

Commit

Permalink
eb2: store dt histos in the counters. simplifies the interface a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
flueke committed Jan 27, 2025
1 parent 3666527 commit 085139b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
26 changes: 9 additions & 17 deletions src/mesytec-mvlc/event_builder2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ struct PerEventData
std::deque<TimestampType> allTimestamps;
// Module data and extracted timestamps are stored here.
std::vector<std::deque<ModuleStorage>> moduleDatas;
// timestamp delta histograms
std::vector<ModuleDeltaHisto> dtHistograms;
};

// Records module data and unmodified timestamps.
Expand Down Expand Up @@ -384,7 +382,7 @@ struct EventBuilder2::Private
// The back of each 'moduleDatas' queue now contains the newest data+timestamp.

// Fill dt histograms
for (auto &dtHisto: eventData.dtHistograms)
for (auto &dtHisto: eventCtrs.dtHistograms)
{
auto ts0 = eventData.moduleDatas[dtHisto.moduleIndexes.first].back().timestamp;
auto ts1 = eventData.moduleDatas[dtHisto.moduleIndexes.second].back().timestamp;
Expand Down Expand Up @@ -624,10 +622,9 @@ struct EventBuilder2::Private
fmt::join(debugStamps, ", "));

outputModuleData_.resize(moduleCount);

for (size_t mi = 0; mi < moduleCount; ++mi)
{
auto &mcfg = eventCfg.moduleConfigs.at(mi);

if (!size_consistency_check(outputModuleStorage_[mi]))
{
spdlog::error(" tryFlush: mi={}, size_consistency_check failed", mi);
Expand Down Expand Up @@ -734,13 +731,8 @@ EventBuilder2::EventBuilder2(const EventBuilderConfig &cfg, Callbacks callbacks,
resize_and_clear(ec.moduleConfigs.size(), ed.moduleDatas, ctrs.inputHits, ctrs.outputHits,
ctrs.emptyInputs, ctrs.discardsAge, ctrs.stampFailed, ctrs.currentEvents,
ctrs.currentMem, ctrs.maxEvents, ctrs.maxMem);
}

for (size_t ei = 0; ei < cfg.eventConfigs.size(); ++ei)
{
auto &ec = cfg.eventConfigs.at(ei);
auto &ed = d->perEventData_.at(ei);
ed.dtHistograms = create_dt_histograms(ec.moduleConfigs, cfg.dtHistoBinning);
ctrs.dtHistograms = create_dt_histograms(ec.moduleConfigs, cfg.dtHistoBinning);
}
}

Expand Down Expand Up @@ -871,25 +863,25 @@ BuilderCounters EventBuilder2::getCounters() const

std::vector<std::vector<ModuleDeltaHisto>> EventBuilder2::getDtHistograms() const
{
std::unique_lock<mvlc::TicketMutex> guard(d->mutex_);
const auto counters = getCounters();
std::vector<std::vector<ModuleDeltaHisto>> result;

for (const auto &ed: d->perEventData_)
for (const auto &eventCtrs: counters.eventCounters)
{
result.emplace_back(ed.dtHistograms);
result.emplace_back(eventCtrs.dtHistograms);
}

return result;
}

std::vector<ModuleDeltaHisto> EventBuilder2::getDtHistograms(int eventIndex) const
{
std::unique_lock<mvlc::TicketMutex> guard(d->mutex_);
const auto counters = getCounters();
std::vector<ModuleDeltaHisto> result;

if (0 <= eventIndex && static_cast<size_t>(eventIndex) < d->perEventData_.size())
if (0 <= eventIndex && static_cast<size_t>(eventIndex) < counters.eventCounters.size())
{
result = d->perEventData_.at(eventIndex).dtHistograms;
result = counters.eventCounters.at(eventIndex).dtHistograms;
}

return result;
Expand Down
24 changes: 15 additions & 9 deletions src/mesytec-mvlc/event_builder2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct MESYTEC_MVLC_EXPORT EmptyTimestampExtractor
std::optional<u32> operator()(const u32 *, size_t) { return {}; }
};

// Configuration ==========
// Timestamp delta histogramming =======================

struct MESYTEC_MVLC_EXPORT HistoBinning
{
Expand All @@ -101,6 +101,15 @@ inline size_t counts(const Histo &histo)
return std::accumulate(histo.bins.begin(), histo.bins.end(), static_cast<size_t>(0u));
}

// For histogramming timestamp deltas between modules.
struct ModuleDeltaHisto
{
std::pair<size_t, size_t> moduleIndexes;
Histo histo;
};

// Configuration ==========

struct MESYTEC_MVLC_EXPORT ModuleConfig
{
timestamp_extractor tsExtractor;
Expand Down Expand Up @@ -138,7 +147,7 @@ struct MESYTEC_MVLC_EXPORT EventCounters
std::vector<size_t> discardsAge; // number of event discarded due to stamp age
std::vector<size_t> stampFailed; // number of failed stamp extractions

// these can be determinted from the contents of the data buffers
// these can be determined from the contents of the data buffers
std::vector<size_t> currentEvents; // current events in the buffer
std::vector<size_t> currentMem; // current buffer memory usage

Expand All @@ -149,6 +158,10 @@ struct MESYTEC_MVLC_EXPORT EventCounters

// non-module specific
size_t recordingFailed = 0;

// List of all dt histograms for this event. One histo for each module pair.
// No duplicates.
std::vector<ModuleDeltaHisto> dtHistograms;
};

std::string MESYTEC_MVLC_EXPORT dump_counters(const EventCounters &counters);
Expand All @@ -158,13 +171,6 @@ struct MESYTEC_MVLC_EXPORT BuilderCounters
std::vector<EventCounters> eventCounters;
};

// For histogramming timestamp deltas between modules.
struct ModuleDeltaHisto
{
std::pair<size_t, size_t> moduleIndexes;
Histo histo;
};

std::vector<ModuleDeltaHisto> MESYTEC_MVLC_EXPORT
create_dt_histograms(const std::vector<ModuleConfig> &moduleConfigs, const HistoBinning &binConfig);

Expand Down

0 comments on commit 085139b

Please sign in to comment.