PTheory: replace TObjArray/TObjString with PStringUtils
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+24
-72
@@ -29,19 +29,19 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
#include <TObject.h>
|
||||
#include <TString.h>
|
||||
#include <TF1.h>
|
||||
#include <TObjString.h>
|
||||
#include <TObjArray.h>
|
||||
#include <TClass.h>
|
||||
#include <TMath.h>
|
||||
|
||||
#include <Math/SpecFuncMathMore.h>
|
||||
|
||||
#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<std::string> 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<TObjString*>(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<UInt_t>(tokens->GetEntries()-1) < fNoOfParam) &&
|
||||
if ((static_cast<UInt_t>(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; i<tokens->GetEntries(); i++) {
|
||||
ostr = dynamic_cast<TObjString*>(tokens->At(i));
|
||||
str = ostr->GetString();
|
||||
for (UInt_t i=1; i<tokens.size(); i++) {
|
||||
str = tokens[i];
|
||||
|
||||
// if userFcn, the first entry is the function name and needs to be handled specially
|
||||
if ((fType == THEORY_USER_FCN) && ((i == 1) || (i == 2))) {
|
||||
@@ -304,11 +299,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;
|
||||
} 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; i<fullTheoryBlock->size(); 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<std::string> tokens = PStringUtils::Split(str.Data(), " \t");
|
||||
if (tokens.empty())
|
||||
continue;
|
||||
// make a handable string out of the asymmetry token
|
||||
ostr = dynamic_cast<TObjString*>(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<UInt_t>(tokens->GetEntries()) < fgTheoDataBase[idx].fNoOfParam + 1)
|
||||
if (static_cast<UInt_t>(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; j<tokens->GetEntries(); j++) {
|
||||
ostr = dynamic_cast<TObjString*>(tokens->At(j));
|
||||
str = ostr->GetString();
|
||||
for (UInt_t j=1; j<tokens.size(); j++) {
|
||||
str = tokens[j];
|
||||
snprintf(substr, sizeof(substr), "%6s", str.Data());
|
||||
tidy += TString(substr);
|
||||
}
|
||||
@@ -1005,19 +982,13 @@ void PTheory::MakeCleanAndTidyTheoryBlock(PMsrLines *fullTheoryBlock)
|
||||
} else {
|
||||
tidy += TString(" ");
|
||||
}
|
||||
if (static_cast<UInt_t>(tokens->GetEntries()) == fgTheoDataBase[idx].fNoOfParam + 1) // no tshift
|
||||
if (static_cast<UInt_t>(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<std::string> 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<Int_t>(tokens.size());
|
||||
for (Int_t j=1; j<max; j++) {
|
||||
ostr = dynamic_cast<TObjString*>(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<max; j++) {
|
||||
ostr = dynamic_cast<TObjString*>(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<std::string> tokens = PStringUtils::Split(str.Data(), " \t");
|
||||
|
||||
for (Int_t j=1; j<tokens->GetEntries(); j++) {
|
||||
ostr = dynamic_cast<TObjString*>(tokens->At(j));
|
||||
str = ostr->GetString();
|
||||
for (UInt_t j=1; j<tokens.size(); j++) {
|
||||
str = tokens[j];
|
||||
tidy += TString(" ") + str;
|
||||
}
|
||||
|
||||
// write tidy string back into theory block
|
||||
(*fullTheoryBlock)[i].fLine = tidy;
|
||||
|
||||
// clean up
|
||||
if (tokens) {
|
||||
delete tokens;
|
||||
tokens = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user