Skip to content

Commit

Permalink
Per #2699, update consensus deriviation logic in tc_pairs.cc to check…
Browse files Browse the repository at this point in the history
… for required and minimum number of diagnostic members.
  • Loading branch information
JohnHalleyGotway committed Oct 13, 2023
1 parent 695e51b commit 1f82b47
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 29 deletions.
73 changes: 54 additions & 19 deletions src/tools/tc_utils/tc_pairs/tc_pairs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1256,12 +1256,13 @@ void derive_interp12(TrackInfoArray &tracks) {
////////////////////////////////////////////////////////////////////////

int derive_consensus(TrackInfoArray &tracks) {
int i, j, k, l;
int i, j, k, l, n_diag_inputs;
ConcatString cur_case;
StringArray case_list, case_cmp, req_list;
StringArray case_list, case_cmp;
StringArray req_cons_mem, req_diag_mem;
TrackInfoArray con_tracks;
TrackInfo new_track;
bool found, skip;
bool found, skip_cons, skip_diag;
const char *sep = " ";
int n_add = 0;

Expand Down Expand Up @@ -1299,15 +1300,22 @@ int derive_consensus(TrackInfoArray &tracks) {
// Initialize
con_tracks.clear();
new_track.clear();
req_list.clear();
req_cons_mem.clear();
req_diag_mem.clear();
n_diag_inputs = 0;

// Loop through the consensus members
for(k=0, skip=false;
for(k=0, skip_cons=false, skip_diag=false;
k<conf_info.Consensus[j].Members.n(); k++) {

// Add required members to the list
if(conf_info.Consensus[j].Required[k]) {
req_list.add(conf_info.Consensus[j].Members[k]);
// Add members to the required consensus list
if(conf_info.Consensus[j].ConsRequired[k]) {
req_cons_mem.add(conf_info.Consensus[j].Members[k]);
}

// Add members to the required diagnostics list
if(conf_info.Consensus[j].DiagRequired[k]) {
req_diag_mem.add(conf_info.Consensus[j].Members[k]);
}

// Loop through the tracks looking for a match
Expand All @@ -1320,6 +1328,7 @@ int derive_consensus(TrackInfoArray &tracks) {
tracks[l].technique() == conf_info.Consensus[j].Members[k] &&
tracks[l].init() == yyyymmdd_hhmmss_to_unix(case_cmp[2].c_str())) {
con_tracks.add(tracks[l]);
if(tracks[l].n_diag() > 0) n_diag_inputs++;
found = true;
mlog << Debug(5)
<< "[Case " << i+1 << "] For case \""
Expand All @@ -1338,38 +1347,64 @@ int derive_consensus(TrackInfoArray &tracks) {
<< conf_info.Consensus[j].Members[k]
<< "\" was not found.\n";

// Check if it was a required model
if(conf_info.Consensus[j].Required[k]) {
// Check if it was a required diagnostics model
if(conf_info.Consensus[j].DiagRequired[k]) {
mlog << Debug(4)
<< "[Case " << i+1 << "] For case \"" << case_list[i]
<< "\" skipping consensus model \""
<< "\" skipping diagnostics for consensus model \""
<< conf_info.Consensus[j].Name
<< "\" since required diagnostics member \""
<< conf_info.Consensus[j].Members[k]
<< "\" was not found.\n";
skip_diag = true;
}

// Check if it was a required consensus model
if(conf_info.Consensus[j].ConsRequired[k]) {
mlog << Debug(4)
<< "[Case " << i+1 << "] For case \"" << case_list[i]
<< "\" skipping derivation of consensus model \""
<< conf_info.Consensus[j].Name
<< "\" since required member \""
<< conf_info.Consensus[j].Members[k]
<< "\" was not found.\n";
skip = true;
skip_cons = true;
break;
}
}

} // end for k

// If a required member was missing, continue to the next case
if(skip) continue;
if(skip_cons) continue;

// Check that the required number of diagnostics inputs were found
if(n_diag_inputs < conf_info.Consensus[j].MinDiagReq) {
mlog << Debug(4)
<< "[Case " << i+1 << "] For case \"" << case_list[i]
<< "\" skipping diagnostics for consensus model \""
<< conf_info.Consensus[j].Name
<< "\" since the minimum number of required members were not found ("
<< n_diag_inputs << " < " << conf_info.Consensus[j].MinDiagReq << ").\n";
skip_diag = true;
}

// Check that the required number of tracks were found
if(con_tracks.n() < conf_info.Consensus[j].MinReq) {
// Check that the required number of consensus tracks were found
if(con_tracks.n() < conf_info.Consensus[j].MinConsReq) {
mlog << Debug(4)
<< "[Case " << i+1 << "] For case \"" << case_list[i]
<< "\" skipping consensus model \"" << conf_info.Consensus[j].Name
<< "\" skipping derivation of consensus model \""
<< conf_info.Consensus[j].Name
<< "\" since the minimum number of required members were not found ("
<< con_tracks.n() << " < "
<< conf_info.Consensus[j].MinReq << ").\n";
<< con_tracks.n() << " < " << conf_info.Consensus[j].MinConsReq << ").\n";
continue;
}

// Derive the consensus model from the TrackInfoArray
new_track = consensus(con_tracks, conf_info.Consensus[j].Name,
conf_info.Consensus[j].MinReq, req_list);
req_cons_mem, conf_info.Consensus[j].MinConsReq,
req_diag_mem, conf_info.Consensus[j].MinDiagReq,
skip_diag);

if(mlog.verbosity_level() >= 5) {
mlog << Debug(5)
Expand Down
16 changes: 8 additions & 8 deletions src/tools/tc_utils/tc_pairs/tc_pairs_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,17 @@ void TCPairsConfInfo::process_config() {
for(i=0; i<NConsensus; i++) {

// Conf: Consensus: name, members, required (error if missing)
Consensus[i].Name = (*dict)[i]->dict_value()->lookup_string(conf_key_name);
Consensus[i].Members = (*dict)[i]->dict_value()->lookup_string_array(conf_key_members);
Consensus[i].Required = (*dict)[i]->dict_value()->lookup_bool_array(conf_key_required);
Consensus[i].Name = (*dict)[i]->dict_value()->lookup_string(conf_key_name);
Consensus[i].Members = (*dict)[i]->dict_value()->lookup_string_array(conf_key_members);
Consensus[i].ConsRequired = (*dict)[i]->dict_value()->lookup_bool_array(conf_key_required);

// If Required is empty, default to false.
if(Consensus[i].Required.n() == 0) {
// If ConsRequired is empty, default to false.
if(Consensus[i].ConsRequired.n() == 0) {
for(j=0; j<Consensus[i].Members.n(); j++) {
Consensus[i].Required.add(false);
Consensus[i].ConsRequired.add(false);
}
}
else if(Consensus[i].Required.n() !=
else if(Consensus[i].ConsRequired.n() !=
Consensus[i].Members.n()) {
mlog << Error << "\nTCPairsConfInfo::process_config() -> "
<< "\"consensus." << conf_key_required
Expand All @@ -260,7 +260,7 @@ void TCPairsConfInfo::process_config() {
}

// Conf: Consensus: min_req (error if missing)
Consensus[i].MinReq = (*dict)[i]->dict_value()->lookup_int(conf_key_min_req);
Consensus[i].MinConsReq = (*dict)[i]->dict_value()->lookup_int(conf_key_min_req);

// Conf: Consensus: diag_required (warn if missing)
Consensus[i].DiagRequired = (*dict)[i]->dict_value()->lookup_bool_array(conf_key_diag_required, false);
Expand Down
4 changes: 2 additions & 2 deletions src/tools/tc_utils/tc_pairs/tc_pairs_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
struct ConsensusInfo {
ConcatString Name;
StringArray Members;
BoolArray Required;
int MinReq;
BoolArray ConsRequired;
int MinConsReq;
BoolArray DiagRequired;
int MinDiagReq;
bool WriteMembers;
Expand Down

0 comments on commit 1f82b47

Please sign in to comment.