From 8dc871e0826754f1be8c25f4969532157473d395 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Sat, 18 Jan 2025 13:35:08 +0100 Subject: [PATCH] path-run-name in RUN block of the msr-file can now handle spaces. --- CMakeLists.txt | 2 +- ChangeLog | 5 +++ src/classes/PMsr2Data.cpp | 69 +++++++++++++++++++++++-------------- src/classes/PMsrHandler.cpp | 18 ++++++---- 4 files changed, 61 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dc72763..1cbf2103 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # - musrfit --- DKS ----------------------------------------------------------- cmake_minimum_required(VERSION 3.17) -project(musrfit VERSION 1.9.6 LANGUAGES C CXX) +project(musrfit VERSION 1.9.7 LANGUAGES C CXX) #--- musrfit specific options ------------------------------------------------- option(dks "build musrfit with DKS (GPU/MIC) support" ON) diff --git a/ChangeLog b/ChangeLog index 62db8047..88793ae1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,11 @@ or https://bitbucket.org/muonspin/musrfit/commits/all +Release of V1.9.7, 2025/01/18 +============================= + +allow spaces in RUN block path-filename + Release of V1.9.6, 2024/12/02 ============================= diff --git a/src/classes/PMsr2Data.cpp b/src/classes/PMsr2Data.cpp index bc8132de..0cd73eb9 100644 --- a/src/classes/PMsr2Data.cpp +++ b/src/classes/PMsr2Data.cpp @@ -140,29 +140,32 @@ int PMsr2Data::DetermineRunNumberDigits(unsigned int runNo, bool normalMode) con strLine.str(line); strLine >> firstOnLine; if (!to_lower_copy(firstOnLine).compare("run")) { - firstOnLine.clear(); - strLine >> firstOnLine; - std::string::size_type loc = firstOnLine.rfind(tempRunNumber.str()); - if ( loc != std::string::npos ) { - while ( loc > 0 ) { - if (isdigit(firstOnLine.at(--loc))) { - ++fRunNumberDigits; - } else { - break; + // for path-names with spaces + std::string::size_type loc{0}; + while (!strLine.eof()) { + firstOnLine.clear(); + strLine >> firstOnLine; + loc = firstOnLine.rfind(tempRunNumber.str()); + if ( loc != std::string::npos ) { + while ( loc > 0 ) { + if (isdigit(firstOnLine.at(--loc))) { + ++fRunNumberDigits; + } else { + break; + } } + in->close(); + fRunVectorIter = fRunVector.begin(); // set back the runlist-iterator which might have changed during the search for the correct file + return 0; } - in->close(); - fRunVectorIter = fRunVector.begin(); // set back the runlist-iterator which might have changed during the search for the correct file - return 0; - } else { - std::cerr << std::endl << ">> msr2data: **ERROR** The first processed run file number does not match the \"file index\"!"; - std::cerr << std::endl << ">> msr2data: **ERROR** The number of digits to be used for formatting the run numbers cannot be determined!"; - std::cerr << std::endl << ">> msr2data: **ERROR** Please check the first msr-file that should be processed;"; - std::cerr << std::endl << ">> msr2data: **ERROR** this is either some template or the first existing file from the run list."; - std::cerr << std::endl; - in->close(); - return -2; } + std::cerr << std::endl << ">> msr2data: **ERROR** The first processed run file number does not match the \"file index\"!"; + std::cerr << std::endl << ">> msr2data: **ERROR** The number of digits to be used for formatting the run numbers cannot be determined!"; + std::cerr << std::endl << ">> msr2data: **ERROR** Please check the first msr-file that should be processed;"; + std::cerr << std::endl << ">> msr2data: **ERROR** this is either some template or the first existing file from the run list."; + std::cerr << std::endl; + in->close(); + return -2; } } std::cerr << std::endl << ">> msr2data: **ERROR** Please check the first msr-file that should be processed;"; @@ -558,11 +561,23 @@ bool PMsr2Data::PrepareNewInputFile(unsigned int tempRun, bool calledFromGlobalM strLine.str(line); strLine >> firstOnLine; if (!to_lower_copy(firstOnLine).compare("run")) { - strLine >> firstOnLine; - std::string::size_type loc = firstOnLine.rfind(tempRunNumber.str()); - if ( loc != std::string::npos ) { - firstOnLine.replace(loc, fRunNumberDigits, newRunNumber.str()); - } else { + // needed for path-fln with spaces + std::string::size_type loc; + std::string sstr{""}; + firstOnLine.clear(); + while (!strLine.eof()) { + strLine >> sstr; + if (firstOnLine.empty()) + firstOnLine = sstr; + else + firstOnLine += " " + sstr; + loc = firstOnLine.rfind(tempRunNumber.str()); + if ( loc != std::string::npos ) { + firstOnLine.replace(loc, fRunNumberDigits, newRunNumber.str()); + break; + } + } + if (strLine.eof()) { std::cerr << std::endl << ">> msr2data: **WARNING** The template run file number does not match the \"file index\""; std::cerr << std::endl << ">> msr2data: **WARNING** Unexpected things will happen... (for sure)"; std::cerr << std::endl; @@ -694,7 +709,6 @@ bool PMsr2Data::PrepareGlobalInputFile(unsigned int tempRun, const std::string & msrParamList->at(i).fIsGlobal = true; ++fNumGlobalParam; } - // std::cout << "debug> " << msrParamList->at(i).fNo << ": " << msrParamList->at(i).fName.Data() << " is global: " << msrParamList->at(i).fIsGlobal << std::endl; } // there should be at least one run specific parameter, otherwise the GLOBAL option doesn't make sense @@ -1801,6 +1815,9 @@ int PMsr2Data::WriteOutput(const std::string &outfile, const std::vectorGetRunData((*msrRunList)[0].GetRunName()->Data()); } + if (rawRunData == nullptr) + return -1; + switch (rawRunData->GetNoOfTemperatures()) { case 1: dataParamNames.push_back("dataT"); diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index e116fd27..30686720 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -3244,7 +3244,7 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) while ((iter != lines.end()) && !error) { // remove potential comment at the end of lines str = iter->fLine; - Ssiz_t idx = str.Index("#"); + Ssiz_t idx = str.Index("("); if (idx != -1) str.Remove(idx); @@ -3274,23 +3274,29 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) } // get run name, beamline, institute, and file-format + // the path/filename could potentially contain spaces! Hence the run name needs to be reconstructed from the parsing if (tokens->GetEntries() < 5) { error = true; } else { // run name - ostr = dynamic_cast(tokens->At(1)); - str = ostr->GetString(); + str = TString(""); + for (Int_t i=1; iGetEntries()-3; i++) { + ostr = dynamic_cast(tokens->At(i)); + str += ostr->GetString(); + if (iGetEntries()-4) + str += TString(" "); + } param.SetRunName(str); // beamline - ostr = dynamic_cast(tokens->At(2)); + ostr = dynamic_cast(tokens->At(tokens->GetEntries()-3)); str = ostr->GetString(); param.SetBeamline(str); // institute - ostr = dynamic_cast(tokens->At(3)); + ostr = dynamic_cast(tokens->At(tokens->GetEntries()-2)); str = ostr->GetString(); param.SetInstitute(str); // data file format - ostr = dynamic_cast(tokens->At(4)); + ostr = dynamic_cast(tokens->At(tokens->GetEntries()-1)); str = ostr->GetString(); param.SetFileFormat(str); }