From 22c9193e181b1577c584855e971e83ec6ef9da48 Mon Sep 17 00:00:00 2001 From: Luca Scarabello Date: Tue, 14 May 2024 13:41:59 +0200 Subject: [PATCH] ENH: add option --inherit-mag Origins inherit the source origin magnitudes when combined with --xmlout option --- apps/scrtdd/rtddtool.cpp | 10 ++++++--- libs/hddsc/scutils.cpp | 45 +++++++++++++++++----------------------- libs/hddsc/scutils.h | 1 - 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/apps/scrtdd/rtddtool.cpp b/apps/scrtdd/rtddtool.cpp index b09a76e..fcf0bad 100644 --- a/apps/scrtdd/rtddtool.cpp +++ b/apps/scrtdd/rtddtool.cpp @@ -363,6 +363,9 @@ void RTDD::createCommandLineDescription() commandline().addOption("ModeOptions", "xmlout", "Enable XML output when combined with " "--reloc-catalog or --oring-id options"); + commandline().addOption("ModeOptions", "inherit-mag", + "Origins inherit the source origin magnitudes " + "when combined with --xmlout option"); } bool RTDD::validateParameters() @@ -1287,9 +1290,10 @@ bool RTDD::run() DataModel::OriginPtr newOrg; std::vector newOrgPicks; + bool includeMagnitude = commandline().hasOption("inherit-mag"); convertOrigin(dataSrc, *ev, srcOrg.get(), author(), agencyID(), - profile->methodID, profile->earthModelID, true, false, - true, newOrg, newOrgPicks); + profile->methodID, profile->earthModelID, + includeMagnitude, true, newOrg, newOrgPicks); evParam->add(newOrg.get()); for (DataModel::PickPtr p : newOrgPicks) evParam->add(p.get()); @@ -1858,7 +1862,7 @@ void RTDD::relocateOrigin(DataModel::Origin *org, DataSource dataSrc(query(), &_cache, _eventParameters.get()); convertOrigin(dataSrc, *relocatedOrg, org, author(), agencyID(), profile->methodID, profile->earthModelID, includeMagnitude, - true, false, newOrg, newOrgPicks); + false, newOrg, newOrgPicks); } std::unique_ptr diff --git a/libs/hddsc/scutils.cpp b/libs/hddsc/scutils.cpp index 4f84623..4cb184c 100644 --- a/libs/hddsc/scutils.cpp +++ b/libs/hddsc/scutils.cpp @@ -411,7 +411,6 @@ void convertOrigin(DataSource &dataSrc, const string &methodID, const string &earthModelID, bool includeMagnitude, - bool fullMagnitude, bool includeExistingPicks, DataModel::OriginPtr &newOrg, // return value std::vector &newOrgPicks) // return value @@ -475,20 +474,17 @@ void convertOrigin(DataSource &dataSrc, // if (includeMagnitude) { - dataSrc.loadMagnitudes(org, fullMagnitude, fullMagnitude); + dataSrc.loadMagnitudes(org, true, true); unordered_map staMagIdMap; - if (fullMagnitude) + for (size_t i = 0; i < org->stationMagnitudeCount(); i++) { - for (size_t i = 0; i < org->stationMagnitudeCount(); i++) - { - DataModel::StationMagnitude *staMag = org->stationMagnitude(i); - DataModel::StationMagnitude *newStaMag = - DataModel::StationMagnitude::Create(); - *newStaMag = *staMag; - newOrg->add(newStaMag); - staMagIdMap[staMag->publicID()] = newStaMag->publicID(); - } + DataModel::StationMagnitude *staMag = org->stationMagnitude(i); + DataModel::StationMagnitude *newStaMag = + DataModel::StationMagnitude::Create(); + *newStaMag = *staMag; + newOrg->add(newStaMag); + staMagIdMap[staMag->publicID()] = newStaMag->publicID(); } for (size_t i = 0; i < org->magnitudeCount(); i++) @@ -497,23 +493,20 @@ void convertOrigin(DataSource &dataSrc, DataModel::Magnitude *newMag = DataModel::Magnitude::Create(); *newMag = *mag; - if (fullMagnitude) + for (size_t j = 0; j < mag->stationMagnitudeContributionCount(); j++) { - for (size_t j = 0; j < mag->stationMagnitudeContributionCount(); j++) + DataModel::StationMagnitudeContribution *contrib = + mag->stationMagnitudeContribution(j); + DataModel::StationMagnitudeContributionPtr newContrib = + new DataModel::StationMagnitudeContribution(*contrib); + try { - DataModel::StationMagnitudeContribution *contrib = - mag->stationMagnitudeContribution(j); - DataModel::StationMagnitudeContributionPtr newContrib = - new DataModel::StationMagnitudeContribution(*contrib); - try - { - newContrib->setStationMagnitudeID( - staMagIdMap.at(contrib->stationMagnitudeID())); - } - catch (...) - {} - newMag->add(newContrib.get()); + newContrib->setStationMagnitudeID( + staMagIdMap.at(contrib->stationMagnitudeID())); } + catch (...) + {} + newMag->add(newContrib.get()); } newOrg->add(newMag); } diff --git a/libs/hddsc/scutils.h b/libs/hddsc/scutils.h index 4d1f6df..bf85d10 100644 --- a/libs/hddsc/scutils.h +++ b/libs/hddsc/scutils.h @@ -92,7 +92,6 @@ void convertOrigin(DataSource &dataSrc, const std::string &methodID, const std::string &earthModelID, bool includeMagnitude, - bool fullMagnitude, bool includeExistingPicks, Seiscomp::DataModel::OriginPtr &newOrg, std::vector &newOrgPicks);