Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworking TC-type configs #351

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/trigger/Issues.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace dunedaq {

ERS_DECLARE_ISSUE(trigger, InvalidConfiguration, "An invalid configuration object was received", ERS_EMPTY)
ERS_DECLARE_ISSUE(trigger, InvalidConfiguration, "Invalid configuration error:" << conferror, ((std::string)conferror))
ERS_DECLARE_ISSUE(trigger, TriggerActive, "Trigger is active now", ERS_EMPTY)
ERS_DECLARE_ISSUE(trigger, TriggerPaused, "Trigger is paused", ERS_EMPTY)
ERS_DECLARE_ISSUE(trigger, TriggerInhibited, "Trigger is inhibited in run " << runno, ((int64_t)runno))
Expand Down
7 changes: 3 additions & 4 deletions integtest/td_leakage_between_runs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,19 @@
conf_dict["trigger"]["mlt_merge_overlapping_tcs"] = True
conf_dict["trigger"]["mlt_send_timed_out_tds"] = True
conf_dict["trigger"]["mlt_buffer_timeout"] = 1000
conf_dict["trigger"]["mlt_use_readout_map"] = True
conf_dict["trigger"]["mlt_td_readout_map"] = []
rmap_conf = {}
rmap_conf["candidate_type"] = 1
rmap_conf["tc_type_name"] = "kTiming"
rmap_conf["time_before"] = readout_window_time_before
rmap_conf["time_after"] = readout_window_time_after
conf_dict["trigger"]["mlt_td_readout_map"].append(rmap_conf)
rmap_conf = {}
rmap_conf["candidate_type"] = 2
rmap_conf["tc_type_name"] = "kTPCLowE"
rmap_conf["time_before"] = readout_window_time_before
rmap_conf["time_after"] = readout_window_time_after
conf_dict["trigger"]["mlt_td_readout_map"].append(rmap_conf)
rmap_conf = {}
rmap_conf["candidate_type"] = 3
rmap_conf["tc_type_name"] = "kSupernova"
rmap_conf["time_before"] = readout_window_time_before
rmap_conf["time_after"] = readout_window_time_after
conf_dict["trigger"]["mlt_td_readout_map"].append(rmap_conf)
Expand Down
25 changes: 16 additions & 9 deletions plugins/RandomTCMakerModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,25 @@ RandomTCMakerModule::init(std::shared_ptr<appfwk::ModuleConfiguration> mcfg)
m_conf = mtrg->get_configuration();

// Get the TC out configuration
m_tc_readout = m_conf->get_tc_readout();
const appmodel::TCReadoutMap* tc_readout = m_conf->get_tc_readout();
m_tcout_time_before = tc_readout->get_time_before();
m_tcout_time_after = tc_readout->get_time_after();
m_tcout_type = static_cast<TCType>(
dunedaq::trgdataformats::string_to_fragment_type_value(tc_readout->get_tc_type_name()));

// Throw error if unknown TC type
if (m_tcout_type == TCType::kUnknown) {
throw(InvalidConfiguration(ERS_HERE, "Provided an unknown TC type output to RandomTCMakerModule!"));
}

m_latency_monitoring.store( m_conf->get_latency_monitoring() );

// Get the clock speed from detector configuration
m_clock_speed_hz = mcfg->configuration_manager()->session()->get_detector_configuration()->get_clock_speed_hz();
m_trigger_rate_hz.store(m_conf->get_trigger_rate_hz());
TLOG() << "RandomTCMaker will output TC of type: " << tc_readout->get_tc_type_name();
TLOG() << "TC window time before: " << m_tcout_time_before
<< " time after: " << m_tcout_time_after;
TLOG() << "Clock speed is: " << m_clock_speed_hz;
TLOG() << "Output trigger rate is: " << m_trigger_rate_hz.load();
}
Expand Down Expand Up @@ -174,16 +186,11 @@ triggeralgs::TriggerCandidate
RandomTCMakerModule::create_candidate(dfmessages::timestamp_t timestamp)
{
triggeralgs::TriggerCandidate candidate;
candidate.time_start = (timestamp - m_tc_readout->get_time_before());
candidate.time_end = (timestamp + m_tc_readout->get_time_after());
candidate.time_start = (timestamp - m_tcout_time_before);
candidate.time_end = (timestamp + m_tcout_time_after);
candidate.time_candidate = timestamp;
candidate.detid = { 0 };
candidate.type = static_cast<triggeralgs::TriggerCandidate::Type>(m_tc_readout->get_candidate_type());

// Throw error if unknown TC type
if (candidate.type == triggeralgs::TriggerCandidate::Type::kUnknown) {
throw InvalidConfiguration(ERS_HERE);
}
candidate.type = m_tcout_type;

// TODO: Originally kHSIEventToTriggerCandidate
candidate.algorithm = triggeralgs::TriggerCandidate::Algorithm::kCustom;
Expand Down
13 changes: 11 additions & 2 deletions plugins/RandomTCMakerModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class RandomTCMakerModule : public dunedaq::appfwk::DAQModule
void generate_opmon_data() override;

private:
using TCType = triggeralgs::TriggerCandidate::Type;
// Commands
void do_configure(const nlohmann::json& obj);
void do_start(const nlohmann::json& obj);
Expand All @@ -97,9 +98,17 @@ class RandomTCMakerModule : public dunedaq::appfwk::DAQModule
std::shared_ptr<iomanager::ReceiverConcept<dfmessages::TimeSync>> m_time_sync_source;
std::shared_ptr<iomanager::SenderConcept<triggeralgs::TriggerCandidate>> m_trigger_candidate_sink;

//randomtriggercandidatemaker::Conf m_conf;
const appmodel::RandomTCMakerConf* m_conf;
const appmodel::TCReadoutMap* m_tc_readout;

/// @brief Output TC type
TCType m_tcout_type;
/// @brief Output window start time, based off trigger timestamp
dfmessages::timestamp_t m_tcout_time_before;
/// @brief Output window end time, based off trigger timestamp
dfmessages::timestamp_t m_tcout_time_after;




/// @brief Clock speed in hz, taken from detector configuration
uint64_t m_clock_speed_hz;
Expand Down
36 changes: 22 additions & 14 deletions src/TCProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TCProcessor::conf(const appmodel::DataHandlerModule* cfg)
{
auto mtrg = cfg->cast<appmodel::TriggerDataHandlerModule>();
if (mtrg == nullptr) {
throw(InvalidConfiguration(ERS_HERE));
throw(InvalidConfiguration(ERS_HERE, "Provided null TriggerDataHandlerModule configuration!"));
}
for (auto output : mtrg->get_outputs()) {
try {
Expand Down Expand Up @@ -134,31 +134,31 @@ TCProcessor::conf(const appmodel::DataHandlerModule* cfg)
m_send_timed_out_tds = (m_ignore_tc_pileup) ? false : proc_conf->get_td_out_of_timeout();
m_td_readout_limit = proc_conf->get_td_readout_limit();
m_ignored_tc_types = proc_conf->get_ignore_tc();
m_ignoring_tc_types = (m_ignored_tc_types.size() > 0) ? true : false;
m_use_readout_map = proc_conf->get_use_readout_map();
m_use_roi_readout = proc_conf->get_use_roi_readout();
m_ignoring_tc_types = !m_ignored_tc_types.empty();
m_use_bitwords = proc_conf->get_use_bitwords();
TLOG_DEBUG(3) << "Allow merging: " << m_tc_merging;
TLOG_DEBUG(3) << "Ignore pileup: " << m_ignore_tc_pileup;
TLOG_DEBUG(3) << "Buffer timeout: " << m_buffer_timeout;
TLOG_DEBUG(3) << "Should send timed out TDs: " << m_send_timed_out_tds;
TLOG_DEBUG(3) << "TD readout limit: " << m_td_readout_limit;
TLOG_DEBUG(3) << "Use ROI readout?: " << m_use_roi_readout;

// ROI map
if(m_use_roi_readout){
m_roi_conf_data = proc_conf->get_roi_group_conf();
m_roi_conf_data = proc_conf->get_roi_group_conf();
m_use_roi_readout = !m_roi_conf_data.empty();
if (m_use_roi_readout) {
parse_roi_conf(m_roi_conf_data);
print_roi_conf(m_roi_conf);
}
TLOG_DEBUG(3) << "Use ROI readout?: " << m_use_roi_readout;

// Custom readout map
TLOG_DEBUG(3) << "Use readout map: " << m_use_readout_map;
if(m_use_readout_map){
m_readout_window_map_data = proc_conf->get_tc_readout_map();
m_readout_window_map_data = proc_conf->get_tc_readout_map();
m_use_readout_map = !m_readout_window_map_data.empty();
if (m_use_readout_map) {
parse_readout_map(m_readout_window_map_data);
print_readout_map(m_readout_window_map);
}
TLOG_DEBUG(3) << "Use readout map: " << m_use_readout_map;

// Ignoring TC types
TLOG_DEBUG(3) << "Ignoring TC types: " << m_ignoring_tc_types;
Expand Down Expand Up @@ -275,7 +275,7 @@ TCProcessor::create_decision(const PendingTD& pending_td)
decision.readout_type = dfmessages::ReadoutType::kLocalized;

if (m_hsi_passthrough == true) {
if (pending_td.contributing_tcs[m_earliest_tc_index].type == triggeralgs::TriggerCandidate::Type::kTiming) {
if (pending_td.contributing_tcs[m_earliest_tc_index].type == TCType::kTiming) {
decision.trigger_type = pending_td.contributing_tcs[m_earliest_tc_index].detid & 0xff;
} else {
m_trigger_type_shifted = (static_cast<int>(pending_td.contributing_tcs[m_earliest_tc_index].type) << 8);
Expand Down Expand Up @@ -617,15 +617,23 @@ void
TCProcessor::parse_readout_map(const std::vector<const appmodel::TCReadoutMap*>& data)
{
for (auto readout_type : data) {
m_readout_window_map[static_cast<trgdataformats::TriggerCandidateData::Type>(readout_type->get_candidate_type())] = {
TCType tc_type = static_cast<TCType>(
dunedaq::trgdataformats::string_to_fragment_type_value(readout_type->get_tc_type_name()));

// Throw error if unknown TC type
if (tc_type == TCType::kUnknown) {
throw(InvalidConfiguration(ERS_HERE, "Provided an unknown TC type in the TCReadoutMap for the TCProcessor"));
}

m_readout_window_map[tc_type] = {
readout_type->get_time_before(), readout_type->get_time_after()
};
}
return;
}
void
TCProcessor::print_readout_map(std::map<trgdataformats::TriggerCandidateData::Type,
std::pair<triggeralgs::timestamp_t, triggeralgs::timestamp_t>> map)
TCProcessor::print_readout_map(std::map<TCType,
std::pair<triggeralgs::timestamp_t, triggeralgs::timestamp_t>> map)
{
TLOG_DEBUG(3) << "MLT TD Readout map:";
for (auto const& [key, val] : map) {
Expand Down
7 changes: 4 additions & 3 deletions src/trigger/TCProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class TCProcessor : public datahandlinglibs::TaskRawDataProcessorModel<TCWrapper

void make_td(const TCWrapper* tc);

private:
private:
using TCType = triggeralgs::TriggerCandidate::Type;
void send_trigger_decisions();
std::thread m_send_trigger_decisions_thread;

Expand Down Expand Up @@ -156,10 +157,10 @@ class TCProcessor : public datahandlinglibs::TaskRawDataProcessorModel<TCWrapper
// Readout map config
bool m_use_readout_map;
std::vector<const appmodel::TCReadoutMap*> m_readout_window_map_data;
std::map<trgdataformats::TriggerCandidateData::Type, std::pair<triggeralgs::timestamp_t, triggeralgs::timestamp_t>>
std::map<TCType, std::pair<triggeralgs::timestamp_t, triggeralgs::timestamp_t>>
m_readout_window_map;
void parse_readout_map(const std::vector<const appmodel::TCReadoutMap*>& data);
void print_readout_map(std::map<trgdataformats::TriggerCandidateData::Type,
void print_readout_map(std::map<TCType,
std::pair<triggeralgs::timestamp_t, triggeralgs::timestamp_t>> map);

// Create the next trigger decision
Expand Down
Loading