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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<unsigne
|
||||
tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
|
||||
std::string::size_type loc = tempName.rfind(curRunNumber.str());
|
||||
if (loc == tempName.length() - fRunNumberDigits) {
|
||||
outFile << tempName.substr(0, loc) << std::endl;
|
||||
outFile << StripRunNumberSuffix(tempName, curRunNumber.str()) << std::endl;
|
||||
} else {
|
||||
std::cerr << std::endl << ">> 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<unsigne
|
||||
tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
|
||||
std::string::size_type loc = tempName.rfind(curRunNumber.str());
|
||||
if (loc == tempName.length() - fRunNumberDigits) {
|
||||
outFile << " " << tempName.substr(0, loc);
|
||||
outFile << " " << StripRunNumberSuffix(tempName, curRunNumber.str());
|
||||
} else {
|
||||
std::cerr << std::endl << ">> 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<unsigne
|
||||
tempName = (*msrParamList)[idx].fName.Data();
|
||||
std::string::size_type loc = tempName.rfind(curRunNumber.str());
|
||||
if (loc == tempName.length() - fRunNumberDigits) {
|
||||
outFile << tempName.substr(0, loc) << " = ";
|
||||
outFile << StripRunNumberSuffix(tempName, curRunNumber.str()) << " = ";
|
||||
if ((*msrParamList)[idx].fPosErrorPresent) {
|
||||
WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, outFile.width(), db);
|
||||
outFile << ", ";
|
||||
@@ -2379,7 +2378,7 @@ int PMsr2Data::WriteOutput(const std::string &outfile, const std::vector<unsigne
|
||||
s = (*msrParamList)[idx].fName.Data();
|
||||
std::string::size_type loc = s.rfind(curRunNumber.str());
|
||||
if (loc == s.length() - fRunNumberDigits) {
|
||||
length = s.length() - fRunNumberDigits;
|
||||
length = StripRunNumberSuffix(s, curRunNumber.str()).length();
|
||||
if (length > maxlength)
|
||||
maxlength = length;
|
||||
} else {
|
||||
@@ -2440,7 +2439,7 @@ int PMsr2Data::WriteOutput(const std::string &outfile, const std::vector<unsigne
|
||||
s = (*msrParamList)[idx].fName.Data();
|
||||
std::string::size_type loc = s.rfind(curRunNumber.str());
|
||||
if (loc == s.length() - fRunNumberDigits) {
|
||||
s = s.substr(0, loc);
|
||||
s = StripRunNumberSuffix(s, curRunNumber.str());
|
||||
outFile << std::setw(maxlength) << std::left << s \
|
||||
<< std::setw(maxlength + 6) << std::left << s + "PosErr" \
|
||||
<< std::setw(maxlength + 6) << std::left << s + "NegErr";
|
||||
@@ -2745,6 +2744,30 @@ bool PMsr2Data::InParameterList(const unsigned int ¶mValue, const std::vecto
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------
|
||||
/**
|
||||
* \brief Strips the trailing run-number suffix (and an optional preceding
|
||||
* separator such as '_') from a run-specific parameter name.
|
||||
*
|
||||
* \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,
|
||||
* or the unmodified name if it does not end in runNumberStr
|
||||
*/
|
||||
std::string PMsr2Data::StripRunNumberSuffix(const std::string &name, const std::string &runNumberStr) const
|
||||
{
|
||||
if ((name.length() < runNumberStr.length()) ||
|
||||
(name.compare(name.length() - runNumberStr.length(), runNumberStr.length(), runNumberStr)))
|
||||
return name;
|
||||
|
||||
std::string::size_type loc(name.length() - runNumberStr.length());
|
||||
if ((loc > 0) && (name[loc-1] == '_'))
|
||||
--loc;
|
||||
|
||||
return name.substr(0, loc);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
// end
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -298,6 +298,20 @@ class PMsr2Data
|
||||
*/
|
||||
bool InParameterList(const unsigned int ¶mValue, const std::vector<unsigned int>& 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<unsigned int> fRunVector; ///< Vector of run numbers to process
|
||||
mutable std::vector<unsigned int>::const_iterator fRunVectorIter; ///< Iterator for current position in run vector
|
||||
|
||||
Reference in New Issue
Block a user