From b21b26d307ce896aa0c2c56283d84fdf7ece0120 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Wed, 26 Aug 2026 12:46:54 +0200 Subject: [PATCH] fix msr2data: strip separator when removing run-number suffix from parameter names Parameter names in run-specific FITPARAMETER blocks (e.g. alpha_ForwBackw_0139) kept a trailing '_' after the run-number suffix was stripped for the single-run and global-mode output. Add StripRunNumberSuffix() and use it at all sites that remove the suffix, so an immediately preceding separator is removed too. Co-Authored-By: Claude Sonnet 5 --- src/classes/PMsr2Data.cpp | 37 ++++++++++++++++++++++++++++++------- src/include/PMsr2Data.h | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/classes/PMsr2Data.cpp b/src/classes/PMsr2Data.cpp index b29db270..90752554 100644 --- a/src/classes/PMsr2Data.cpp +++ b/src/classes/PMsr2Data.cpp @@ -1705,8 +1705,7 @@ bool PMsr2Data::PrepareNewSortedInputFile(unsigned int tempRun) const tempParamName = msrParamList->at(l).fName.Data(); std::string::size_type loc = tempParamName.rfind(tempRunNumber.str()); if ( loc != std::string::npos ) { - tempParamName.erase(loc); - msrParamList->at(l).fName = tempParamName; + msrParamList->at(l).fName = StripRunNumberSuffix(tempParamName, tempRunNumber.str()); } else { std::cerr << std::endl << ">> msr2data: **ERROR** The indices of the run specific parameters do not match the template run number!"; std::cerr << std::endl << ">> msr2data: **ERROR** This should not happen! Please report a bug!"; @@ -2159,7 +2158,7 @@ int PMsr2Data::WriteOutput(const std::string &outfile, const std::vector> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!"; std::cerr << std::endl << ">> msr2data: **ERROR** The output will be flawed!"; @@ -2214,7 +2213,7 @@ int PMsr2Data::WriteOutput(const std::string &outfile, const std::vector> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!"; std::cerr << std::endl << ">> msr2data: **ERROR** The output will be flawed!"; @@ -2291,7 +2290,7 @@ int PMsr2Data::WriteOutput(const std::string &outfile, const std::vector maxlength) maxlength = length; } else { @@ -2440,7 +2439,7 @@ int PMsr2Data::WriteOutput(const std::string &outfile, const std::vector 0) && (name[loc-1] == '_')) + --loc; + + return name.substr(0, loc); +} + //------------------------------------------------------------------------------------------------------- // end //------------------------------------------------------------------------------------------------------- diff --git a/src/include/PMsr2Data.h b/src/include/PMsr2Data.h index a7ca3149..7d212089 100644 --- a/src/include/PMsr2Data.h +++ b/src/include/PMsr2Data.h @@ -298,6 +298,20 @@ class PMsr2Data */ bool InParameterList(const unsigned int ¶mValue, const std::vector& paramList) const; + //----------------------------------------------------------------------- + /** + * \brief Strips the trailing run-number suffix (and an optional preceding + * separator such as '_') from a run-specific parameter name. + * + * E.g. "alpha_ForwBackw_0139" with runNumberStr=="0139" becomes + * "alpha_ForwBackw" rather than "alpha_ForwBackw_". + * + * \param name run-specific parameter name (e.g. "Asy_0420") + * \param runNumberStr zero-padded run number string used as suffix (e.g. "0420") + * \return the base parameter name with the run-number suffix (and its separator) removed + */ + std::string StripRunNumberSuffix(const std::string &name, const std::string &runNumberStr) const; + std::string fFileExtension; ///< File extension for data files (e.g., "bin", "root") std::vector fRunVector; ///< Vector of run numbers to process mutable std::vector::const_iterator fRunVectorIter; ///< Iterator for current position in run vector