From 82f668c140d97025aa356ab232c86c98c766b630 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Sat, 6 Jun 2026 16:17:05 +0200 Subject: [PATCH] PTheory: replace TObjArray/TObjString with PStringUtils Co-Authored-By: Claude Opus 4.8 --- src/classes/PTheory.cpp | 96 +++++++++++------------------------------ 1 file changed, 24 insertions(+), 72 deletions(-) diff --git a/src/classes/PTheory.cpp b/src/classes/PTheory.cpp index 9ad728378..1bed428c3 100644 --- a/src/classes/PTheory.cpp +++ b/src/classes/PTheory.cpp @@ -29,19 +29,19 @@ #include #include +#include #include #include #include #include -#include -#include #include #include #include #include "PMsrHandler.h" +#include "PStringUtils.h" #include "PTheory.h" #define SQRT_TWO 1.41421356237 @@ -169,18 +169,14 @@ PTheory::PTheory(PMsrHandler *msrInfo, UInt_t runNo, const Bool_t hasParent) : f str.Resize(index); // tokenize line - TObjArray *tokens; - TObjString *ostr; - - tokens = str.Tokenize(" \t"); - if (!tokens) { + std::vector tokens = PStringUtils::Split(str.Data(), " \t"); + if (tokens.empty()) { std::cerr << std::endl << ">> PTheory::PTheory: **SEVERE ERROR** Couldn't tokenize theory block line " << line->fLineNo << "."; std::cerr << std::endl << ">> line content: " << line->fLine.Data(); std::cerr << std::endl; exit(0); } - ostr = dynamic_cast(tokens->At(0)); - str = ostr->GetString(); + str = tokens[0]; // search the theory function UInt_t idx = SearchDataBase(str); @@ -195,11 +191,11 @@ PTheory::PTheory(PMsrHandler *msrInfo, UInt_t runNo, const Bool_t hasParent) : f } // line is a valid function, hence analyze parameters - if ((static_cast(tokens->GetEntries()-1) < fNoOfParam) && + if ((static_cast(tokens.size()-1) < fNoOfParam) && ((idx != THEORY_USER_FCN) && (idx != THEORY_POLYNOM))) { std::cerr << std::endl << ">> PTheory::PTheory: **ERROR** Theory line '" << line->fLine.Data() << "'"; std::cerr << std::endl << ">> in line no " << line->fLineNo; - std::cerr << std::endl << ">> expecting " << fgTheoDataBase[idx].fNoOfParam << ", but found " << tokens->GetEntries()-1; + std::cerr << std::endl << ">> expecting " << fgTheoDataBase[idx].fNoOfParam << ", but found " << tokens.size()-1; std::cerr << std::endl; fValid = false; } @@ -209,9 +205,8 @@ PTheory::PTheory(PMsrHandler *msrInfo, UInt_t runNo, const Bool_t hasParent) : f Int_t status; UInt_t value; Bool_t ok = false; - for (Int_t i=1; iGetEntries(); i++) { - ostr = dynamic_cast(tokens->At(i)); - str = ostr->GetString(); + for (UInt_t i=1; i> See line no " << line->fLineNo; std::cerr << std::endl; fValid = false; - // clean up - if (tokens) { - delete tokens; - tokens = nullptr; - } return; } else if (!TClass::GetDict(fUserFcnClassName.Data())) { std::cerr << std::endl << ">> PTheory::PTheory: **ERROR** user function class '" << fUserFcnClassName.Data() << "' not found."; @@ -316,11 +306,6 @@ PTheory::PTheory(PMsrHandler *msrInfo, UInt_t runNo, const Bool_t hasParent) : f std::cerr << std::endl << ">> See line no " << line->fLineNo; std::cerr << std::endl; fValid = false; - // clean up - if (tokens) { - delete tokens; - tokens = nullptr; - } return; } } @@ -347,12 +332,6 @@ PTheory::PTheory(PMsrHandler *msrInfo, UInt_t runNo, const Bool_t hasParent) : f } } } - - // clean up - if (tokens) { - delete tokens; - tokens = nullptr; - } } //-------------------------------------------------------------------------- @@ -945,8 +924,6 @@ void PTheory::MakeCleanAndTidyTheoryBlock(PMsrLines *fullTheoryBlock) PMsrLineStructure *line; TString str, tidy; Char_t substr[256]; - TObjArray *tokens = nullptr; - TObjString *ostr = nullptr; Int_t idx = THEORY_UNDEFINED; for (UInt_t i=1; isize(); i++) { @@ -959,10 +936,11 @@ void PTheory::MakeCleanAndTidyTheoryBlock(PMsrLines *fullTheoryBlock) if (index > 0) // theory line comment present str.Resize(index); // tokenize line - tokens = str.Tokenize(" \t"); + std::vector tokens = PStringUtils::Split(str.Data(), " \t"); + if (tokens.empty()) + continue; // make a handable string out of the asymmetry token - ostr = dynamic_cast(tokens->At(0)); - str = ostr->GetString(); + str = tokens[0]; // check if the line is just a '+' if so nothing to be done if (str.Contains("+")) continue; @@ -987,14 +965,13 @@ void PTheory::MakeCleanAndTidyTheoryBlock(PMsrLines *fullTheoryBlock) if (idx == THEORY_UNDEFINED) return; // check that there enough tokens. This should not be necessay at this point but ... - if (static_cast(tokens->GetEntries()) < fgTheoDataBase[idx].fNoOfParam + 1) + if (static_cast(tokens.size()) < fgTheoDataBase[idx].fNoOfParam + 1) return; // make tidy string snprintf(substr, sizeof(substr), "%-10s", fgTheoDataBase[idx].fName.Data()); tidy = TString(substr); - for (Int_t j=1; jGetEntries(); j++) { - ostr = dynamic_cast(tokens->At(j)); - str = ostr->GetString(); + for (UInt_t j=1; j(tokens->GetEntries()) == fgTheoDataBase[idx].fNoOfParam + 1) // no tshift + if (static_cast(tokens.size()) == fgTheoDataBase[idx].fNoOfParam + 1) // no tshift tidy += fgTheoDataBase[idx].fComment; else tidy += fgTheoDataBase[idx].fCommentTimeShift; } // write tidy string back into theory block (*fullTheoryBlock)[i].fLine = tidy; - - // clean up - if (tokens) { - delete tokens; - tokens = nullptr; - } } } @@ -1041,8 +1012,6 @@ void PTheory::MakeCleanAndTidyPolynom(UInt_t i, PMsrLines *fullTheoryBlock) { PMsrLineStructure *line; TString str, tidy; - TObjArray *tokens = nullptr; - TObjString *ostr; Char_t substr[256]; // init tidy @@ -1052,13 +1021,12 @@ void PTheory::MakeCleanAndTidyPolynom(UInt_t i, PMsrLines *fullTheoryBlock) // copy line content to str in order to remove comments str = line->fLine.Copy(); // tokenize line - tokens = str.Tokenize(" \t"); + std::vector tokens = PStringUtils::Split(str.Data(), " \t"); // check if comment is already present, and if yes ignore it by setting max correctly - Int_t max = tokens->GetEntries(); + Int_t max = static_cast(tokens.size()); for (Int_t j=1; j(tokens->At(j)); - str = ostr->GetString(); + str = tokens[j]; if (str.Contains("(")) { // comment present max=j; break; @@ -1066,8 +1034,7 @@ void PTheory::MakeCleanAndTidyPolynom(UInt_t i, PMsrLines *fullTheoryBlock) } for (Int_t j=1; j(tokens->At(j)); - str = ostr->GetString(); + str = tokens[j]; snprintf(substr, sizeof(substr), "%6s", str.Data()); tidy += TString(substr); } @@ -1077,12 +1044,6 @@ void PTheory::MakeCleanAndTidyPolynom(UInt_t i, PMsrLines *fullTheoryBlock) // write tidy string back into theory block (*fullTheoryBlock)[i].fLine = tidy; - - // clean up - if (tokens) { - delete tokens; - tokens = nullptr; - } } //-------------------------------------------------------------------------- @@ -1104,8 +1065,6 @@ void PTheory::MakeCleanAndTidyUserFcn(UInt_t i, PMsrLines *fullTheoryBlock) { PMsrLineStructure *line; TString str, tidy; - TObjArray *tokens = nullptr; - TObjString *ostr; // init tidy tidy = TString("userFcn "); @@ -1114,22 +1073,15 @@ void PTheory::MakeCleanAndTidyUserFcn(UInt_t i, PMsrLines *fullTheoryBlock) // copy line content to str in order to remove comments str = line->fLine.Copy(); // tokenize line - tokens = str.Tokenize(" \t"); + std::vector tokens = PStringUtils::Split(str.Data(), " \t"); - for (Int_t j=1; jGetEntries(); j++) { - ostr = dynamic_cast(tokens->At(j)); - str = ostr->GetString(); + for (UInt_t j=1; j