diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index d67f1769..852e1e8a 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -30,11 +30,12 @@ #include #include -#include #include #include #include +#include +#include #include #include "PMusr.h" @@ -451,6 +452,8 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) Int_t plotNo = -1; std::string line; TString logFileName, str, sstr, *pstr; + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; Bool_t found = false; Bool_t statisticBlockFound = false; Bool_t partialStatisticBlockFound = true; @@ -591,13 +594,15 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) else fout << str.Data() << std::endl; break; - case MSR_TAG_FITPARAMETER: { - std::vector tokens = PStringUtils::Split(str.Data(), " \t"); - if (tokens.empty()) { // not a parameter line + case MSR_TAG_FITPARAMETER: + tokens = str.Tokenize(" \t"); + if (tokens->GetEntries() == 0) { // not a parameter line fout << str.Data() << std::endl; } else { - if (PStringUtils::IsInt(tokens[0])) { // parameter - number = PStringUtils::ToInt(tokens[0]); + ostr = dynamic_cast(tokens->At(0)); + sstr = ostr->GetString(); + if (sstr.IsDigit()) { // parameter + number = sstr.Atoi(); number--; // make sure number makes sense assert ((number >= 0) && (number < (Int_t)fParam.size())); @@ -666,9 +671,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) } else { // not a parameter, hence just copy it fout << str.Data() << std::endl; } + // clean up tokens + delete tokens; } break; - } case MSR_TAG_THEORY: found = false; for (UInt_t i=0; i tokens; + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; + TString str; // fill param structure iter = lines.begin(); @@ -2858,72 +2866,99 @@ Bool_t PMsrHandler::HandleFitParameterEntry(PMsrLines &lines) param.fUpperBoundaryPresent = false; param.fUpperBoundary = 0.0; - tokens = PStringUtils::Split(iter->fLine.Data(), " \t"); + tokens = iter->fLine.Tokenize(" \t"); + if (!tokens) { + fLastErrorMsg.str(""); + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::HandleFitParameterEntry: **SEVERE ERROR** Couldn't tokenize Parameters in line " << iter->fLineNo << "\n"; + std::cerr << fLastErrorMsg.str(); + return false; + } // handle various input possiblities - if ((tokens.size() < 4) || (tokens.size() > 7) || (tokens.size() == 6)) { + if ((tokens->GetEntries() < 4) || (tokens->GetEntries() > 7) || (tokens->GetEntries() == 6)) { error = true; } else { // handle the first 4 parameter since they are always the same // parameter number - bool ok = false; - param.fNo = PStringUtils::ToInt(tokens[0], &ok); - if (!ok) + ostr = dynamic_cast(tokens->At(0)); + str = ostr->GetString(); + if (str.IsDigit()) + param.fNo = str.Atoi(); + else error = true; // parameter name - param.fName = tokens[1].c_str(); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + param.fName = str; // parameter value - param.fValue = PStringUtils::ToDouble(tokens[2], &ok); - if (!ok) + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fValue = static_cast(str.Atof()); + else error = true; - // parameter step - param.fStep = PStringUtils::ToDouble(tokens[3], &ok); - if (!ok) + // parameter value + ostr = dynamic_cast(tokens->At(3)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fStep = static_cast(str.Atof()); + else error = true; // 4 values, i.e. No Name Value Step - if (tokens.size() == 4) { + if (tokens->GetEntries() == 4) { param.fNoOfParams = 4; } // 5 values, i.e. No Name Value Neg_Error Pos_Error - if (tokens.size() == 5) { + if (tokens->GetEntries() == 5) { param.fNoOfParams = 5; // positive error - param.fPosError = PStringUtils::ToDouble(tokens[4], &ok); - if (ok) { + ostr = dynamic_cast(tokens->At(4)); + str = ostr->GetString(); + if (str.IsFloat()) { param.fPosErrorPresent = true; - } else if (PStringUtils::IsEqualNoCase(tokens[4], "none")) { - param.fPosErrorPresent = false; + param.fPosError = static_cast(str.Atof()); } else { - error = true; + str.ToLower(); + if (!str.CompareTo("none", TString::kIgnoreCase)) + param.fPosErrorPresent = false; + else + error = true; } } // 7 values, i.e. No Name Value Neg_Error Pos_Error Lower_Boundary Upper_Boundary - if (tokens.size() == 7) { + if (tokens->GetEntries() == 7) { param.fNoOfParams = 7; // positive error - param.fPosError = PStringUtils::ToDouble(tokens[4], &ok); - if (ok) { + ostr = dynamic_cast(tokens->At(4)); + str = ostr->GetString(); + if (str.IsFloat()) { param.fPosErrorPresent = true; - } else if (PStringUtils::IsEqualNoCase(tokens[4], "none")) { - param.fPosErrorPresent = false; + param.fPosError = static_cast(str.Atof()); } else { - error = true; + str.ToLower(); + if (!str.CompareTo("none", TString::kIgnoreCase)) + param.fPosErrorPresent = false; + else + error = true; } // lower boundary + ostr = dynamic_cast(tokens->At(5)); + str = ostr->GetString(); // check if lower boundary is "none", i.e. upper boundary limited only - if (PStringUtils::IsEqualNoCase(tokens[5], "none")) { // none + if (!str.CompareTo("none", TString::kIgnoreCase)) { // none param.fLowerBoundaryPresent = false; } else { // assuming that the lower boundary is a number - param.fLowerBoundary = PStringUtils::ToDouble(tokens[5], &ok); - if (ok) { + if (str.IsFloat()) { + param.fLowerBoundary = static_cast(str.Atof()); param.fLowerBoundaryPresent = true; } else { error = true; @@ -2931,12 +2966,14 @@ Bool_t PMsrHandler::HandleFitParameterEntry(PMsrLines &lines) } // upper boundary + ostr = dynamic_cast(tokens->At(6)); + str = ostr->GetString(); // check if upper boundary is "none", i.e. lower boundary limited only - if (PStringUtils::IsEqualNoCase(tokens[6], "none")) { // none + if (!str.CompareTo("none", TString::kIgnoreCase)) { // none param.fUpperBoundaryPresent = false; } else { // assuming a number - param.fUpperBoundary = PStringUtils::ToDouble(tokens[6], &ok); - if (ok) { + if (str.IsFloat()) { + param.fUpperBoundary = static_cast(str.Atof()); param.fUpperBoundaryPresent = true; } else { error = true; @@ -2976,6 +3013,12 @@ Bool_t PMsrHandler::HandleFitParameterEntry(PMsrLines &lines) fParam.push_back(param); } + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } + iter++; } @@ -3080,7 +3123,8 @@ Bool_t PMsrHandler::HandleGlobalEntry(PMsrLines &lines) Bool_t error = false; TString str; - std::vector tokens; + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; Int_t ival = 0; Double_t dval = 0.0; UInt_t addT0Counter = 0; @@ -3097,116 +3141,157 @@ Bool_t PMsrHandler::HandleGlobalEntry(PMsrLines &lines) str.Remove(idx); // tokenize line - tokens = PStringUtils::Split(str.Data(), " \t"); + tokens = str.Tokenize(" \t"); + if (!tokens) { + fLastErrorMsg.str(""); + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::HandleGlobalEntry: **SEVERE ERROR** Couldn't tokenize line " << iter->fLineNo << "\n\n"; + std::cerr << fLastErrorMsg.str(); + return false; + } if (iter->fLine.BeginsWith("fittype", TString::kIgnoreCase)) { // fittype - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - Int_t fittype = PStringUtils::ToInt(tokens[1], &ok); - if (ok && ((fittype == MSR_FITTYPE_SINGLE_HISTO) || - (fittype == MSR_FITTYPE_SINGLE_HISTO_RRF) || - (fittype == MSR_FITTYPE_ASYM) || - (fittype == MSR_FITTYPE_ASYM_RRF) || - (fittype == MSR_FITTYPE_MU_MINUS) || - (fittype == MSR_FITTYPE_BNMR) || - (fittype == MSR_FITTYPE_NON_MUSR))) { - global.SetFitType(fittype); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + Int_t fittype = str.Atoi(); + if ((fittype == MSR_FITTYPE_SINGLE_HISTO) || + (fittype == MSR_FITTYPE_SINGLE_HISTO_RRF) || + (fittype == MSR_FITTYPE_ASYM) || + (fittype == MSR_FITTYPE_ASYM_RRF) || + (fittype == MSR_FITTYPE_MU_MINUS) || + (fittype == MSR_FITTYPE_BNMR) || + (fittype == MSR_FITTYPE_NON_MUSR)) { + global.SetFitType(fittype); + } else { + error = true; + } } else { error = true; } } } else if (iter->fLine.BeginsWith("rrf_freq", TString::kIgnoreCase)) { - if (tokens.size() < 3) { + if (tokens->GetEntries() < 3) { error = true; } else { - bool ok = false; - dval = PStringUtils::ToDouble(tokens[1], &ok); - if (!ok || dval <= 0.0) - error = true; + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsFloat()) { + dval = str.Atof(); + if (dval <= 0.0) + error = true; + } if (!error) { - global.SetRRFFreq(dval, tokens[2].c_str()); - if (global.GetRRFFreq(tokens[2].c_str()) == RRF_FREQ_UNDEF) + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + global.SetRRFFreq(dval, str.Data()); + if (global.GetRRFFreq(str.Data()) == RRF_FREQ_UNDEF) error = true; } } } else if (iter->fLine.BeginsWith("rrf_packing", TString::kIgnoreCase)) { - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - ival = PStringUtils::ToInt(tokens[1], &ok); - if (ok && ival > 0) { - global.SetRRFPacking(ival); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if (ival > 0) { + global.SetRRFPacking(ival); + } else { + error = true; + } } else { error = true; } } } else if (iter->fLine.BeginsWith("rrf_phase", TString::kIgnoreCase)) { - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - dval = PStringUtils::ToDouble(tokens[1], &ok); - if (ok) + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsFloat()) { + dval = str.Atof(); global.SetRRFPhase(dval); - else + } else { error = true; + } } } else if (iter->fLine.BeginsWith("data", TString::kIgnoreCase)) { // data - if (tokens.size() < 3) { + if (tokens->GetEntries() < 3) { error = true; } else { - for (UInt_t i=1; i= 0) { - global.SetDataRange(ival, i-1); + for (Int_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if (ival >= 0) { + global.SetDataRange(ival, i-1); + } else { + error = true; + } } else { error = true; } } } } else if (iter->fLine.BeginsWith("t0", TString::kIgnoreCase)) { // t0 - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - for (UInt_t i=1; i= 0.0) - global.SetT0Bin(dval); - else + for (Int_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsFloat()) { + dval = str.Atof(); + if (dval >= 0.0) + global.SetT0Bin(dval); + else + error = true; + } else { error = true; + } } } } else if (iter->fLine.BeginsWith("addt0", TString::kIgnoreCase)) { // addt0 - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - for (UInt_t i=1; i= 0.0) - global.SetAddT0Bin(dval, addT0Counter, i-1); - else + for (Int_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsFloat()) { + dval = str.Atof(); + if (dval >= 0.0) + global.SetAddT0Bin(dval, addT0Counter, i-1); + else + error = true; + } else { error = true; + } } } addT0Counter++; } else if (iter->fLine.BeginsWith("fit", TString::kIgnoreCase)) { // fit range - if (tokens.size() < 3) { + if (tokens->GetEntries() < 3) { error = true; } else { // fit given in time, i.e. fit , where , are given as doubles if (iter->fLine.Contains("fgb", TString::kIgnoreCase)) { // fit given in bins, i.e. fit fgb+n0 lgb-n1 // check 1st entry, i.e. fgb[+n0] - std::string numStr = tokens[1]; - std::string::size_type pos = numStr.find('+'); - if (pos != std::string::npos) { // '+' present hence extract n0 - numStr = numStr.substr(pos+1); - if (PStringUtils::IsFloat(numStr)) { - global.SetFitRangeOffset(PStringUtils::ToInt(numStr), 0); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + Ssiz_t idx = str.First("+"); + TString numStr = str; + if (idx > -1) { // '+' present hence extract n0 + numStr.Remove(0,idx+1); + if (numStr.IsFloat()) { + global.SetFitRangeOffset(numStr.Atoi(), 0); } else { error = true; } @@ -3214,12 +3299,14 @@ Bool_t PMsrHandler::HandleGlobalEntry(PMsrLines &lines) global.SetFitRangeOffset(0, 0); } // check 2nd entry, i.e. lgb[-n1] - numStr = tokens[2]; - pos = numStr.find('-'); - if (pos != std::string::npos) { // '-' present hence extract n1 - numStr = numStr.substr(pos+1); - if (PStringUtils::IsFloat(numStr)) { - global.SetFitRangeOffset(PStringUtils::ToInt(numStr), 1); + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + idx = str.First("-"); + numStr = str; + if (idx > -1) { // '-' present hence extract n1 + numStr.Remove(0,idx+1); + if (numStr.IsFloat()) { + global.SetFitRangeOffset(numStr.Atoi(), 1); } else { error = true; } @@ -3229,42 +3316,55 @@ Bool_t PMsrHandler::HandleGlobalEntry(PMsrLines &lines) if (!error) global.SetFitRangeInBins(true); } else { // fit given in time, i.e. fit , where , are given as doubles - for (UInt_t i=1; i<3; i++) { - bool ok = false; - const double range = PStringUtils::ToDouble(tokens[i], &ok); - if (ok) - global.SetFitRange(range, i-1); + for (Int_t i=1; i<3; i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsFloat()) + global.SetFitRange(str.Atof(), i-1); else error = true; } } } } else if (iter->fLine.BeginsWith("packing", TString::kIgnoreCase)) { // packing - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - ival = PStringUtils::ToInt(tokens[1], &ok); - if (ok && ival >= 0) { - global.SetPacking(ival); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if (ival >= 0) { + global.SetPacking(ival); + } else { + error = true; + } } else { error = true; } } } else if (iter->fLine.BeginsWith("deadtime-cor", TString::kIgnoreCase)) { // deadtime correction - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - if (PStringUtils::IsEqualNoCase(tokens[1], "no") || - PStringUtils::IsEqualNoCase(tokens[1], "file") || - PStringUtils::IsEqualNoCase(tokens[1], "estimate")) { - global.SetDeadTimeCorrection(tokens[1].c_str()); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (!str.CompareTo("no", TString::kIgnoreCase) || + !str.CompareTo("file", TString::kIgnoreCase) || + !str.CompareTo("estimate", TString::kIgnoreCase)) { + global.SetDeadTimeCorrection(str); } else { error = true; } } } + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } + ++iter; } @@ -3304,7 +3404,8 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) Bool_t runLinePresent = false; TString str, line; - std::vector tokens; + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; UInt_t addT0Counter = 0; @@ -3323,7 +3424,14 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) str.Remove(idx); // tokenize line - tokens = PStringUtils::Split(str.Data(), " \t"); + tokens = str.Tokenize(" \t"); + if (!tokens) { + fLastErrorMsg.str(""); + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::HandleRunEntry: **SEVERE ERROR** Couldn't tokenize Parameters in line " << iter->fLineNo << "\n\n"; + std::cerr << fLastErrorMsg.str(); + return false; + } // copy of the current line line = iter->fLine; @@ -3344,26 +3452,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.size() < 5) { + if (tokens->GetEntries() < 5) { error = true; } else { // run name - std::string runName(""); - for (UInt_t i=1; iGetEntries()-3; i++) { + ostr = dynamic_cast(tokens->At(i)); + str += ostr->GetString(); + if (iGetEntries()-4) + str += TString(" "); } - str = runName.c_str(); param.SetRunName(str); // beamline - str = tokens[tokens.size()-3].c_str(); + ostr = dynamic_cast(tokens->At(tokens->GetEntries()-3)); + str = ostr->GetString(); param.SetBeamline(str); // institute - str = tokens[tokens.size()-2].c_str(); + ostr = dynamic_cast(tokens->At(tokens->GetEntries()-2)); + str = ostr->GetString(); param.SetInstitute(str); // data file format - str = tokens[tokens.size()-1].c_str(); + ostr = dynamic_cast(tokens->At(tokens->GetEntries()-1)); + str = ostr->GetString(); param.SetFileFormat(str); } @@ -3385,20 +3496,24 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) } // get run name, beamline, institute, and file-format - if (tokens.size() < 5) { + if (tokens->GetEntries() < 5) { error = true; } else { // run name - str = tokens[1].c_str(); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); param.SetRunName(str); // beamline - str = tokens[2].c_str(); + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); param.SetBeamline(str); // institute - str = tokens[3].c_str(); + ostr = dynamic_cast(tokens->At(3)); + str = ostr->GetString(); param.SetInstitute(str); // data file format - str = tokens[4].c_str(); + ostr = dynamic_cast(tokens->At(4)); + str = ostr->GetString(); param.SetFileFormat(str); } } @@ -3408,19 +3523,24 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - Int_t fittype = PStringUtils::ToInt(tokens[1], &ok); - if (ok && ((fittype == MSR_FITTYPE_SINGLE_HISTO) || - (fittype == MSR_FITTYPE_SINGLE_HISTO_RRF) || - (fittype == MSR_FITTYPE_ASYM) || - (fittype == MSR_FITTYPE_ASYM_RRF) || - (fittype == MSR_FITTYPE_MU_MINUS) || - (fittype == MSR_FITTYPE_BNMR) || - (fittype == MSR_FITTYPE_NON_MUSR))) { - param.SetFitType(fittype); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + Int_t fittype = str.Atoi(); + if ((fittype == MSR_FITTYPE_SINGLE_HISTO) || + (fittype == MSR_FITTYPE_SINGLE_HISTO_RRF) || + (fittype == MSR_FITTYPE_ASYM) || + (fittype == MSR_FITTYPE_ASYM_RRF) || + (fittype == MSR_FITTYPE_MU_MINUS) || + (fittype == MSR_FITTYPE_BNMR) || + (fittype == MSR_FITTYPE_NON_MUSR)) { + param.SetFitType(fittype); + } else { + error = true; + } } else { error = true; } @@ -3432,19 +3552,20 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - ival = PStringUtils::ToInt(tokens[1], &ok); - if (ok) { + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); if (ival > 0) param.SetAlphaParamNo(ival); else error = true; - } else if (tokens[1].find("fun") != std::string::npos) { + } else if (str.Contains("fun")) { Int_t no; - if (FilterNumber(tokens[1].c_str(), "fun", MSR_PARAM_FUN_OFFSET, no)) + if (FilterNumber(str, "fun", MSR_PARAM_FUN_OFFSET, no)) param.SetAlphaParamNo(no); else error = true; @@ -3459,19 +3580,20 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - ival = PStringUtils::ToInt(tokens[1], &ok); - if (ok) { + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); if (ival > 0) param.SetBetaParamNo(ival); else - error = true; - } else if (tokens[1].find("fun") != std::string::npos) { + error = true; + } else if (str.Contains("fun")) { Int_t no; - if (FilterNumber(tokens[1].c_str(), "fun", MSR_PARAM_FUN_OFFSET, no)) + if (FilterNumber(str, "fun", MSR_PARAM_FUN_OFFSET, no)) param.SetBetaParamNo(no); else error = true; @@ -3486,16 +3608,16 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - ival = PStringUtils::ToInt(tokens[1], &ok); - if (ok) { - param.SetNormParamNo(ival); - } else if (tokens[1].find("fun") != std::string::npos) { + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + param.SetNormParamNo(str.Atoi()); + } else if (str.Contains("fun")) { Int_t no; - if (FilterNumber(tokens[1].c_str(), "fun", MSR_PARAM_FUN_OFFSET, no)) + if (FilterNumber(str, "fun", MSR_PARAM_FUN_OFFSET, no)) param.SetNormParamNo(no); else error = true; @@ -3510,15 +3632,20 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - ival = PStringUtils::ToInt(tokens[1], &ok); - if (ok && ival > 0) - param.SetBkgFitParamNo(ival); - else + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if (ival > 0) + param.SetBkgFitParamNo(ival); + else + error = true; + } else { error = true; + } } } @@ -3527,15 +3654,20 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - bool ok = false; - ival = PStringUtils::ToInt(tokens[1], &ok); - if (ok && ival > 0) - param.SetLifetimeParamNo(ival); - else + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if (ival > 0) + param.SetLifetimeParamNo(ival); + else + error = true; + } else { error = true; + } } } @@ -3552,13 +3684,18 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - for (UInt_t i=1; i= 0) - param.SetMap(ival); - else + for (Int_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if (ival >= 0) + param.SetMap(ival); + else + error = true; + } else { error = true; + } } // check map entries, i.e. if the map values are within parameter bounds if (!fFourierOnly) { @@ -3580,7 +3717,7 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { PUIntVector group; @@ -3604,7 +3741,7 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { PUIntVector group; @@ -3628,14 +3765,14 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - for (UInt_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsFloat()) + param.SetBkgFix(str.Atof(), i-1); else error = true; } @@ -3647,16 +3784,21 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if ((tokens.size() < 3) || (tokens.size() % 2 != 1)) { // odd number (>=3) of entries needed + if ((tokens->GetEntries() < 3) || (tokens->GetEntries() % 2 != 1)) { // odd number (>=3) of entries needed error = true; } else { - for (UInt_t i=1; i 0) - param.SetBkgRange(ival, i-1); - else + for (Int_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if (ival > 0) + param.SetBkgRange(ival, i-1); + else + error = true; + } else { error = true; + } } } } @@ -3666,16 +3808,21 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if ((tokens.size() < 3) || (tokens.size() % 2 != 1)) { // odd number (>=3) of entries needed + if ((tokens->GetEntries() < 3) || (tokens->GetEntries() % 2 != 1)) { // odd number (>=3) of entries needed error = true; } else { - for (UInt_t i=1; i 0) - param.SetDataRange(ival, i-1); - else + for (Int_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if (ival > 0) + param.SetDataRange(ival, i-1); + else + error = true; + } else { error = true; + } } } } @@ -3685,16 +3832,21 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - for (UInt_t i=1; i= 0.0) - param.SetT0Bin(dval); - else + for (Int_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsFloat()) { + dval = str.Atof(); + if (dval >= 0.0) + param.SetT0Bin(dval); + else + error = true; + } else { error = true; + } } } } @@ -3704,16 +3856,21 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - for (UInt_t i=1; i= 0.0) - param.SetAddT0Bin(dval, addT0Counter, i-1); - else + for (Int_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsFloat()) { + dval = str.Atof(); + if (dval >= 0.0) + param.SetAddT0Bin(dval, addT0Counter, i-1); + else + error = true; + } else { error = true; + } } } @@ -3725,17 +3882,19 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 3) { + if (tokens->GetEntries() < 3) { error = true; } else { if (iter->fLine.Contains("fgb", TString::kIgnoreCase)) { // fit given in bins, i.e. fit fgb+n0 lgb-n1 // check 1st entry, i.e. fgb[+n0] - std::string numStr = tokens[1]; - std::string::size_type pos = numStr.find('+'); - if (pos != std::string::npos) { // '+' present hence extract n0 - numStr = numStr.substr(pos+1); - if (PStringUtils::IsFloat(numStr)) { - param.SetFitRangeOffset(PStringUtils::ToInt(numStr), 0); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + Ssiz_t idx = str.First("+"); + TString numStr = str; + if (idx > -1) { // '+' present hence extract n0 + numStr.Remove(0,idx+1); + if (numStr.IsFloat()) { + param.SetFitRangeOffset(numStr.Atoi(), 0); } else { error = true; } @@ -3743,12 +3902,14 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) param.SetFitRangeOffset(0, 0); } // check 2nd entry, i.e. lgb[-n1] - numStr = tokens[2]; - pos = numStr.find('-'); - if (pos != std::string::npos) { // '-' present hence extract n1 - numStr = numStr.substr(pos+1); - if (PStringUtils::IsFloat(numStr)) { - param.SetFitRangeOffset(PStringUtils::ToInt(numStr), 1); + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + idx = str.First("-"); + numStr = str; + if (idx > -1) { // '-' present hence extract n1 + numStr.Remove(0,idx+1); + if (numStr.IsFloat()) { + param.SetFitRangeOffset(numStr.Atoi(), 1); } else { error = true; } @@ -3759,11 +3920,11 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) if (!error) param.SetFitRangeInBins(true); } else { // fit given in time, i.e. fit , where , are given as doubles - for (UInt_t i=1; i<3; i++) { - bool ok = false; - const double range = PStringUtils::ToDouble(tokens[i], &ok); - if (ok) - param.SetFitRange(range, i-1); + for (Int_t i=1; i<3; i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsFloat()) + param.SetFitRange(str.Atof(), i-1); else error = true; } @@ -3776,15 +3937,20 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() != 2) { + if (tokens->GetEntries() != 2) { error = true; } else { - bool ok = false; - ival = PStringUtils::ToInt(tokens[1], &ok); - if (ok && ival > 0) - param.SetPacking(ival); - else + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if (ival > 0) + param.SetPacking(ival); + else + error = true; + } else { error = true; + } } } @@ -3793,13 +3959,15 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() < 2) { + if (tokens->GetEntries() < 2) { error = true; } else { - if (PStringUtils::IsEqualNoCase(tokens[1], "no") || - PStringUtils::IsEqualNoCase(tokens[1], "file") || - PStringUtils::IsEqualNoCase(tokens[1], "estimate")) { - param.SetDeadTimeCorrection(tokens[1].c_str()); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (!str.CompareTo("no", TString::kIgnoreCase) || + !str.CompareTo("file", TString::kIgnoreCase) || + !str.CompareTo("estimate", TString::kIgnoreCase)) { + param.SetDeadTimeCorrection(str); } else { error = true; } @@ -3811,13 +3979,17 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) runLinePresent = false; // this is needed to make sure that a run line is present before and ADDRUN is following - if (tokens.size() != 3) { // xy-data x-label y-label + if (tokens->GetEntries() != 3) { // xy-data x-label y-label error = true; } else { - if (PStringUtils::IsInt(tokens[1])) { // xy-data indices given - param.SetXDataIndex(PStringUtils::ToInt(tokens[1])); // x-index - if (PStringUtils::IsInt(tokens[2])) { - ival = PStringUtils::ToInt(tokens[2]); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { // xy-data indices given + param.SetXDataIndex(str.Atoi()); // x-index + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); if (ival > 0) param.SetYDataIndex(ival); // y-index else @@ -3826,14 +3998,20 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) error = true; } } else { // xy-data labels given - str = tokens[1].c_str(); param.SetXDataLabel(str); // x-label - str = tokens[2].c_str(); + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); param.SetYDataLabel(str); // y-label } } } + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } + ++iter; } @@ -3995,25 +4173,34 @@ Bool_t PMsrHandler::ParseFourierPhaseValueVector(PMsrFourierStructure &fourier, { Bool_t result = true; - std::vector tok = PStringUtils::Split(str.Data(), " ,;\t"); + TObjArray *tok = str.Tokenize(" ,;\t"); + if (tok == nullptr) { + fLastErrorMsg.str(""); + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseValueVector: **ERROR** couldn't tokenize Fourier phase line.\n\n"; + std::cerr << fLastErrorMsg.str(); + return false; + } // make sure there are enough tokens - if (tok.size() < 2) { + if (tok->GetEntries() < 2) { error = true; return false; } // convert all acceptable tokens - for (UInt_t i=1; iGetEntries(); i++) { + ostr = dynamic_cast(tok->At(i)); + sstr = ostr->GetString(); + if (sstr.IsFloat()) { + fourier.fPhase.push_back(sstr.Atof()); } else { result = false; if (i>1) { // make sure that no 'phase val, parX' mixture is present fLastErrorMsg.str(""); - fLastErrorMsg.clear(); + fLastErrorMsg.clear(); fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseValueVector: **ERROR** in Fourier phase line.\n"; fLastErrorMsg << ">> Attempt to mix val, parX? This is currently not supported.\n\n"; std::cerr << fLastErrorMsg.str(); @@ -4023,6 +4210,11 @@ Bool_t PMsrHandler::ParseFourierPhaseValueVector(PMsrFourierStructure &fourier, } } + // clean up + if (tok) { + delete tok; + } + return result; } @@ -4047,32 +4239,42 @@ Bool_t PMsrHandler::ParseFourierPhaseParVector(PMsrFourierStructure &fourier, co Bool_t result = true; Int_t refCount = 0; - std::vector tok = PStringUtils::Split(str.Data(), " ,;\t"); + TObjArray *tok = str.Tokenize(" ,;\t"); + if (tok == nullptr) { + fLastErrorMsg.str(""); + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParVector: **ERROR** couldn't tokenize Fourier phase line.\n\n"; + std::cerr << fLastErrorMsg.str(); + return false; + } // make sure there are enough tokens - if (tok.size() < 2) { + if (tok->GetEntries() < 2) { error = true; return false; } // check that all tokens start with par - for (UInt_t i=1; iGetEntries(); i++) { + TObjString *ostr = dynamic_cast(tok->At(i)); + sstr = ostr->GetString(); + if (!sstr.BeginsWith("par")) { fLastErrorMsg.str(""); - fLastErrorMsg.clear(); - fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParVector: **ERROR** found unhandable token '" << tok[i] << "'\n"; + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParVector: **ERROR** found unhandable token '" << sstr << "'\n"; std::cerr << fLastErrorMsg.str(); error = true; result = false; break; } - if (tok[i].rfind("parR", 0) == 0) { + if (sstr.BeginsWith("parR")) { refCount++; } // rule out par(X, offset, #Param) syntax - if (tok[i].rfind("par(", 0) == 0) { + if (sstr.BeginsWith("par(")) { result = false; break; } @@ -4080,7 +4282,7 @@ Bool_t PMsrHandler::ParseFourierPhaseParVector(PMsrFourierStructure &fourier, co if (refCount > 1) { fLastErrorMsg.str(""); - fLastErrorMsg.clear(); + fLastErrorMsg.clear(); fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParVector: **ERROR** found multiple parR's! Only one reference phase is accepted.\n"; std::cerr << fLastErrorMsg.str(); result = false; @@ -4089,23 +4291,22 @@ Bool_t PMsrHandler::ParseFourierPhaseParVector(PMsrFourierStructure &fourier, co // check that token has the form parX, where X is an int Int_t rmNoOf = 3; if (result != false) { - for (UInt_t i=1; iGetEntries(); i++) { + TObjString *ostr = dynamic_cast(tok->At(i)); + sstr = ostr->GetString(); rmNoOf = 3; - if (sstr.rfind("parR", 0) == 0) { + if (sstr.BeginsWith("parR")) { rmNoOf++; } - sstr = sstr.substr(rmNoOf); // remove 'par' of 'parR' part. Rest should be an integer - bool ok = false; - Int_t val = PStringUtils::ToInt(sstr, &ok); - if (ok) { + sstr.Remove(0, rmNoOf); // remove 'par' of 'parR' part. Rest should be an integer + if (sstr.IsDigit()) { if (rmNoOf == 4) // parR - fourier.fPhaseRef = val; - fourier.fPhaseParamNo.push_back(val); + fourier.fPhaseRef = sstr.Atoi(); + fourier.fPhaseParamNo.push_back(sstr.Atoi()); } else { fLastErrorMsg.str(""); - fLastErrorMsg.clear(); - fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParVector: **ERROR** found token '" << tok[i] << "' which is not parX with X an integer.\n"; + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParVector: **ERROR** found token '" << ostr->GetString() << "' which is not parX with X an integer.\n"; std::cerr << fLastErrorMsg.str(); fourier.fPhaseParamNo.clear(); error = true; @@ -4114,12 +4315,17 @@ Bool_t PMsrHandler::ParseFourierPhaseParVector(PMsrFourierStructure &fourier, co } } - if (fourier.fPhaseParamNo.size() == tok.size()-1) { // everything as expected + if (fourier.fPhaseParamNo.size() == tok->GetEntries()-1) { // everything as expected result = true; } else { result = false; } + // clean up + if (tok) { + delete tok; + } + return result; } @@ -4170,51 +4376,71 @@ Bool_t PMsrHandler::ParseFourierPhaseParIterVector(PMsrFourierStructure &fourier wstr.Remove(idx, wstr.Length()-idx); // tokenize rest which should have the form 'X0, offset, #Param' - std::vector tok = PStringUtils::Split(wstr.Data(), ",;"); + TObjArray *tok = wstr.Tokenize(",;"); + if (tok == nullptr) { + fLastErrorMsg.str(""); + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParIterVector: **ERROR** tokenize failed.\n"; + std::cerr << fLastErrorMsg.str(); + error = true; + return false; + } // check for proper number of expected elements - if (tok.size() != 3) { + if (tok->GetEntries() != 3) { fLastErrorMsg.str(""); - fLastErrorMsg.clear(); + fLastErrorMsg.clear(); fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParIterVector: **ERROR** wrong syntax for the expected par(X0, offset, #param).\n"; std::cerr << fLastErrorMsg.str(); error = true; + delete tok; return false; } Int_t x0, offset, noParam; // get X0 - bool ok = false; - x0 = PStringUtils::ToInt(tok[0], &ok); - if (!ok) { + TObjString *ostr = dynamic_cast(tok->At(0)); + wstr = ostr->GetString(); + if (wstr.IsDigit()) { + x0 = wstr.Atoi(); + } else { fLastErrorMsg.str(""); - fLastErrorMsg.clear(); - fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParIterVector: **ERROR** X0='" << tok[0] << "' is not an integer.\n"; + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParIterVector: **ERROR** X0='" << wstr << "' is not an integer.\n"; std::cerr << fLastErrorMsg.str(); error = true; + delete tok; return false; } // get offset - offset = PStringUtils::ToInt(tok[1], &ok); - if (!ok) { + ostr = dynamic_cast(tok->At(1)); + wstr = ostr->GetString(); + if (wstr.IsDigit()) { + offset = wstr.Atoi(); + } else { fLastErrorMsg.str(""); - fLastErrorMsg.clear(); - fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParIterVector: **ERROR** offset='" << tok[1] << "' is not an integer.\n"; + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParIterVector: **ERROR** offset='" << wstr << "' is not an integer.\n"; std::cerr << fLastErrorMsg.str(); error = true; + delete tok; return false; } // get noParam - noParam = PStringUtils::ToInt(tok[2], &ok); - if (!ok) { + ostr = dynamic_cast(tok->At(2)); + wstr = ostr->GetString(); + if (wstr.IsDigit()) { + noParam = wstr.Atoi(); + } else { fLastErrorMsg.str(""); - fLastErrorMsg.clear(); - fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParIterVector: **ERROR** #Param='" << tok[2] << "' is not an integer.\n"; + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::ParseFourierPhaseParIterVector: **ERROR** #Param='" << wstr << "' is not an integer.\n"; std::cerr << fLastErrorMsg.str(); error = true; + delete tok; return false; } @@ -4227,6 +4453,11 @@ Bool_t PMsrHandler::ParseFourierPhaseParIterVector(PMsrFourierStructure &fourier for (Int_t i=0; i tokens; - TString pcStr=TString(""); + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; + TString str, pcStr=TString(""); Int_t ival; iter = lines.begin(); while ((iter != lines.end()) && !error) { // tokenize line - tokens = PStringUtils::Split(iter->fLine.Data(), " \t"); + tokens = iter->fLine.Tokenize(" \t"); + if (!tokens) { + fLastErrorMsg.str(""); + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::HandleFourierEntry: **SEVERE ERROR** Couldn't tokenize Parameters in line " << iter->fLineNo << "\n\n"; + std::cerr << fLastErrorMsg.str(); + return false; + } if (iter->fLine.BeginsWith("units", TString::kIgnoreCase)) { // units - if (tokens.size() < 2) { // units are missing + if (tokens->GetEntries() < 2) { // units are missing error = true; continue; } else { - if (PStringUtils::IsEqualNoCase(tokens[1], "gauss")) { + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (!str.CompareTo("gauss", TString::kIgnoreCase)) { fourier.fUnits = FOURIER_UNIT_GAUSS; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "tesla")) { + } else if (!str.CompareTo("tesla", TString::kIgnoreCase)) { fourier.fUnits = FOURIER_UNIT_TESLA; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "mhz")) { + } else if (!str.CompareTo("mhz", TString::kIgnoreCase)) { fourier.fUnits = FOURIER_UNIT_FREQ; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "mc/s")) { + } else if (!str.CompareTo("mc/s", TString::kIgnoreCase)) { fourier.fUnits = FOURIER_UNIT_CYCLES; } else { error = true; @@ -4286,27 +4527,35 @@ Bool_t PMsrHandler::HandleFourierEntry(PMsrLines &lines) } } } else if (iter->fLine.BeginsWith("fourier_power", TString::kIgnoreCase)) { // fourier power (zero padding) - if (tokens.size() < 2) { // fourier power exponent is missing + if (tokens->GetEntries() < 2) { // fourier power exponent is missing error = true; continue; } else { - bool ok = false; - ival = PStringUtils::ToInt(tokens[1], &ok); - if (ok && (ival >= 0) && (ival <= 20)) { - fourier.fFourierPower = ival; - } else { // fourier power not a number or out of range + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); + if ((ival >= 0) && (ival <= 20)) { + fourier.fFourierPower = ival; + } else { // fourier power out of range + error = true; + continue; + } + } else { // fourier power not a number error = true; continue; } } } else if (iter->fLine.BeginsWith("dc-corrected", TString::kIgnoreCase)) { // dc-corrected - if (tokens.size() < 2) { // dc-corrected tag is missing + if (tokens->GetEntries() < 2) { // dc-corrected tag is missing error = true; continue; } else { - if (PStringUtils::IsEqualNoCase(tokens[1], "true") || (tokens[1] == "1")) { + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (!str.CompareTo("true", TString::kIgnoreCase) || !str.CompareTo("1")) { fourier.fDCCorrected = true; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "false") || (tokens[1] == "0")) { + } else if (!str.CompareTo("false", TString::kIgnoreCase) || !str.CompareTo("0")) { fourier.fDCCorrected = false; } else { // unrecognized dc-corrected tag error = true; @@ -4314,17 +4563,19 @@ Bool_t PMsrHandler::HandleFourierEntry(PMsrLines &lines) } } } else if (iter->fLine.BeginsWith("apodization", TString::kIgnoreCase)) { // apodization - if (tokens.size() < 2) { // apodization tag is missing + if (tokens->GetEntries() < 2) { // apodization tag is missing error = true; continue; } else { - if (PStringUtils::IsEqualNoCase(tokens[1], "none")) { + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (!str.CompareTo("none", TString::kIgnoreCase)) { fourier.fApodization = FOURIER_APOD_NONE; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "weak")) { + } else if (!str.CompareTo("weak", TString::kIgnoreCase)) { fourier.fApodization = FOURIER_APOD_WEAK; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "medium")) { + } else if (!str.CompareTo("medium", TString::kIgnoreCase)) { fourier.fApodization = FOURIER_APOD_MEDIUM; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "strong")) { + } else if (!str.CompareTo("strong", TString::kIgnoreCase)) { fourier.fApodization = FOURIER_APOD_STRONG; } else { // unrecognized apodization tag error = true; @@ -4332,21 +4583,23 @@ Bool_t PMsrHandler::HandleFourierEntry(PMsrLines &lines) } } } else if (iter->fLine.BeginsWith("plot", TString::kIgnoreCase)) { // plot tag - if (tokens.size() < 2) { // plot tag is missing + if (tokens->GetEntries() < 2) { // plot tag is missing error = true; continue; } else { - if (PStringUtils::IsEqualNoCase(tokens[1], "real")) { + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (!str.CompareTo("real", TString::kIgnoreCase)) { fourier.fPlotTag = FOURIER_PLOT_REAL; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "imag")) { + } else if (!str.CompareTo("imag", TString::kIgnoreCase)) { fourier.fPlotTag = FOURIER_PLOT_IMAG; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "real_and_imag")) { + } else if (!str.CompareTo("real_and_imag", TString::kIgnoreCase)) { fourier.fPlotTag = FOURIER_PLOT_REAL_AND_IMAG; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "power")) { + } else if (!str.CompareTo("power", TString::kIgnoreCase)) { fourier.fPlotTag = FOURIER_PLOT_POWER; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "phase")) { + } else if (!str.CompareTo("phase", TString::kIgnoreCase)) { fourier.fPlotTag = FOURIER_PLOT_PHASE; - } else if (PStringUtils::IsEqualNoCase(tokens[1], "phase_opt_real")) { + } else if (!str.CompareTo("phase_opt_real", TString::kIgnoreCase)) { fourier.fPlotTag = FOURIER_PLOT_PHASE_OPT_REAL; } else { // unrecognized plot tag error = true; @@ -4354,7 +4607,7 @@ Bool_t PMsrHandler::HandleFourierEntry(PMsrLines &lines) } } } else if (iter->fLine.BeginsWith("phase", TString::kIgnoreCase)) { // phase - if (tokens.size() < 2) { // phase value(s)/par(s) is(are) missing + if (tokens->GetEntries() < 2) { // phase value(s)/par(s) is(are) missing error = true; continue; } else { @@ -4425,14 +4678,16 @@ Bool_t PMsrHandler::HandleFourierEntry(PMsrLines &lines) // available at this point. pcStr = iter->fLine; } else if (iter->fLine.BeginsWith("range", TString::kIgnoreCase)) { // fourier plot range - if (tokens.size() < 3) { // plot range values are missing + if (tokens->GetEntries() < 3) { // plot range values are missing error = true; continue; } else { for (UInt_t i=0; i<2; i++) { - bool ok = false; - fourier.fPlotRange[i] = PStringUtils::ToDouble(tokens[i+1], &ok); - if (!ok) { + ostr = dynamic_cast(tokens->At(i+1)); + str = ostr->GetString(); + if (str.IsFloat()) { + fourier.fPlotRange[i] = str.Atof(); + } else { error = true; continue; } @@ -4444,17 +4699,31 @@ Bool_t PMsrHandler::HandleFourierEntry(PMsrLines &lines) continue; } + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } + ++iter; } + // clean up after error + if (tokens) { + delete tokens; + tokens = nullptr; + } + // handle range_for_phase_correction if present if ((pcStr.Length() != 0) && !error) { // tokenize line - tokens = PStringUtils::Split(pcStr.Data(), " \t"); + tokens = pcStr.Tokenize(" \t"); - switch (tokens.size()) { + switch (tokens->GetEntries()) { case 2: - if (PStringUtils::IsEqualNoCase(tokens[1], "all")) { + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (!str.CompareTo("all", TString::kIgnoreCase)) { fourier.fRangeForPhaseCorrection[0] = fourier.fPlotRange[0]; fourier.fRangeForPhaseCorrection[1] = fourier.fPlotRange[1]; } else { @@ -4463,16 +4732,25 @@ Bool_t PMsrHandler::HandleFourierEntry(PMsrLines &lines) break; case 3: for (UInt_t i=0; i<2; i++) { - bool ok = false; - fourier.fRangeForPhaseCorrection[i] = PStringUtils::ToDouble(tokens[i+1], &ok); - if (!ok) + ostr = dynamic_cast(tokens->At(i+1)); + str = ostr->GetString(); + if (str.IsFloat()) { + fourier.fRangeForPhaseCorrection[i] = str.Atof(); + } else { error = true; + } } break; default: error = true; break; } + + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } } if (error) { @@ -4525,7 +4803,9 @@ Bool_t PMsrHandler::HandlePlotEntry(PMsrLines &lines) PMsrLines::iterator iter1; PMsrLines::iterator iter2; - std::vector tokens; + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; + TString str; if (lines.empty()) { std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry(): **WARNING**: There is no PLOT block! Do you really want this?"; @@ -4568,15 +4848,29 @@ Bool_t PMsrHandler::HandlePlotEntry(PMsrLines &lines) line.Resize(line.First('#')); if (line.Contains("PLOT")) { // handle plot header - tokens = PStringUtils::Split(line.Data(), " \t"); - if (tokens.size() < 2) { // plot type missing + tokens = line.Tokenize(" \t"); + if (!tokens) { + fLastErrorMsg.str(""); + fLastErrorMsg.clear(); + fLastErrorMsg << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize PLOT in line " << iter1->fLineNo << "\n\n"; + std::cerr << fLastErrorMsg.str(); + return false; + } + if (tokens->GetEntries() < 2) { // plot type missing error = true; } else { - bool ok = false; - param.fPlotType = PStringUtils::ToInt(tokens[1], &ok); - if (!ok) + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) + param.fPlotType = str.Atoi(); + else error = true; } + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } } else if (line.Contains("lifetimecorrection", TString::kIgnoreCase)) { param.fLifeTimeCorrection = true; } else if (line.Contains("runs", TString::kIgnoreCase)) { // handle plot runs @@ -4623,43 +4917,56 @@ Bool_t PMsrHandler::HandlePlotEntry(PMsrLines &lines) param.fYmin.clear(); param.fYmax.clear(); - tokens = PStringUtils::Split(line.Data(), " \t"); - if ((tokens.size() != 3) && (tokens.size() != 5)) { + tokens = line.Tokenize(" \t"); + if (!tokens) { + std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize PLOT in line " << iter1->fLineNo; + std::cerr << std::endl << std::endl; + return false; + } + if ((tokens->GetEntries() != 3) && (tokens->GetEntries() != 5)) { error = true; } else { // handle t_min - bool ok = false; - const double tmin = PStringUtils::ToDouble(tokens[1], &ok); - if (ok) - param.fTmin.push_back(tmin); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fTmin.push_back(static_cast(str.Atof())); else error = true; // handle t_max - const double tmax = PStringUtils::ToDouble(tokens[2], &ok); - if (ok) - param.fTmax.push_back(tmax); + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fTmax.push_back(static_cast(str.Atof())); else error = true; - if (tokens.size() == 5) { // y-axis interval given as well + if (tokens->GetEntries() == 5) { // y-axis interval given as well // handle y_min - const double ymin = PStringUtils::ToDouble(tokens[3], &ok); - if (ok) - param.fYmin.push_back(ymin); + ostr = dynamic_cast(tokens->At(3)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fYmin.push_back(static_cast(str.Atof())); else error = true; // handle y_max - const double ymax = PStringUtils::ToDouble(tokens[4], &ok); - if (ok) - param.fYmax.push_back(ymax); + ostr = dynamic_cast(tokens->At(4)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fYmax.push_back(static_cast(str.Atof())); else error = true; } } + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } } else if (line.Contains("sub_ranges", TString::kIgnoreCase)) { // remove previous entries param.fTmin.clear(); @@ -4667,77 +4974,102 @@ Bool_t PMsrHandler::HandlePlotEntry(PMsrLines &lines) param.fYmin.clear(); param.fYmax.clear(); - tokens = PStringUtils::Split(line.Data(), " \t"); - if ((tokens.size() != 2*param.fRuns.size() + 1) && (tokens.size() != 2*param.fRuns.size() + 3)) { + tokens = line.Tokenize(" \t"); + if (!tokens) { + std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize PLOT in line " << iter1->fLineNo; + std::cerr << std::endl << std::endl; + return false; + } + if ((tokens->GetEntries() != static_cast(2*param.fRuns.size() + 1)) && (tokens->GetEntries() != static_cast(2*param.fRuns.size() + 3))) { error = true; } else { // get all the times for (UInt_t i=0; i(tokens->At(2*i+1)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fTmin.push_back(static_cast(str.Atof())); else error = true; // handle t_max - const double tmax = PStringUtils::ToDouble(tokens[2*i+2], &ok); - if (ok) - param.fTmax.push_back(tmax); + ostr = dynamic_cast(tokens->At(2*i+2)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fTmax.push_back(static_cast(str.Atof())); else error = true; } // get y-range if present - if (tokens.size() == 2*param.fRuns.size() + 3) { + if (tokens->GetEntries() == static_cast(2*param.fRuns.size() + 3)) { // handle y_min - bool ok = false; - const double ymin = PStringUtils::ToDouble(tokens[2*param.fRuns.size()+1], &ok); - if (ok) - param.fYmin.push_back(ymin); + ostr = dynamic_cast(tokens->At(2*param.fRuns.size()+1)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fYmin.push_back(static_cast(str.Atof())); else error = true; // handle y_max - const double ymax = PStringUtils::ToDouble(tokens[2*param.fRuns.size()+2], &ok); - if (ok) - param.fYmax.push_back(ymax); + ostr = dynamic_cast(tokens->At(2*param.fRuns.size()+2)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fYmax.push_back(static_cast(str.Atof())); else error = true; } } + + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } } else if (line.Contains("use_fit_ranges", TString::kIgnoreCase)) { param.fUseFitRanges = true; // check if y-ranges are given - tokens = PStringUtils::Split(line.Data(), " \t"); + tokens = line.Tokenize(" \t"); + if (!tokens) { + std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize PLOT in line " << iter1->fLineNo; + std::cerr << std::endl << std::endl; + return false; + } - if (tokens.size() == 3) { // i.e. use_fit_ranges ymin ymax + if (tokens->GetEntries() == 3) { // i.e. use_fit_ranges ymin ymax // handle y_min - bool ok = false; - const double ymin = PStringUtils::ToDouble(tokens[1], &ok); - if (ok) - param.fYmin.push_back(ymin); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fYmin.push_back(static_cast(str.Atof())); else error = true; // handle y_max - const double ymax = PStringUtils::ToDouble(tokens[2], &ok); - if (ok) - param.fYmax.push_back(ymax); + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + if (str.IsFloat()) + param.fYmax.push_back(static_cast(str.Atof())); else error = true; } - if ((tokens.size() != 1) && (tokens.size() != 3)) { + if ((tokens->GetEntries() != 1) && (tokens->GetEntries() != 3)) { std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry: **WARNING** use_fit_ranges with undefined additional parameters in line " << iter1->fLineNo; std::cerr << std::endl << ">> Will ignore this PLOT block command line, sorry."; std::cerr << std::endl << ">> Proper syntax: use_fit_ranges [ymin ymax]"; std::cerr << std::endl << ">> Found: '" << iter1->fLine.Data() << "'" << std::endl; } + + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } } else if (iter1->fLine.Contains("logx", TString::kIgnoreCase)) { param.fLogX = true; } else if (iter1->fLine.Contains("logy", TString::kIgnoreCase)) { @@ -4745,83 +5077,139 @@ Bool_t PMsrHandler::HandlePlotEntry(PMsrLines &lines) } else if (iter1->fLine.Contains("lifetimecorrection", TString::kIgnoreCase)) { param.fLifeTimeCorrection = true; } else if (iter1->fLine.Contains("view_packing", TString::kIgnoreCase)) { - tokens = PStringUtils::Split(iter1->fLine.Data(), " \t"); - if (tokens.size() != 2) { - error = true; - } else { - bool ok = false; - Int_t val = PStringUtils::ToInt(tokens[1], &ok); - if (ok && val > 0) - param.fViewPacking = val; - else - error = true; + tokens = iter1->fLine.Tokenize(" \t"); + if (!tokens) { + std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize view_packing in line " << iter1->fLineNo; + std::cerr << std::endl << std::endl; + return false; } - } else if (iter1->fLine.Contains("rrf_freq", TString::kIgnoreCase)) { - // expected entry: rrf_freq value unit - // allowed units: kHz, MHz, Mc/s, G, T - tokens = PStringUtils::Split(iter1->fLine.Data(), " \t"); - if (tokens.size() != 3) { + if (tokens->GetEntries() != 2) { error = true; } else { - // get rrf frequency - bool ok = false; - param.fRRFFreq = PStringUtils::ToDouble(tokens[1], &ok); - if (!ok) - error = true; - // get unit - if (PStringUtils::ContainsNoCase(tokens[2], "kHz")) - param.fRRFUnit = RRF_UNIT_kHz; - else if (PStringUtils::ContainsNoCase(tokens[2], "MHz")) - param.fRRFUnit = RRF_UNIT_MHz; - else if (PStringUtils::ContainsNoCase(tokens[2], "Mc/s")) - param.fRRFUnit = RRF_UNIT_Mcs; - else if (PStringUtils::ContainsNoCase(tokens[2], "G")) - param.fRRFUnit = RRF_UNIT_G; - else if (PStringUtils::ContainsNoCase(tokens[2], "T")) - param.fRRFUnit = RRF_UNIT_T; - else - error = true; - } - } else if (iter1->fLine.Contains("rrf_phase", TString::kIgnoreCase)) { - // expected entry: rrf_phase value. value given in units of degree. or - // rrf_phase parX. where X is the parameter number, e.g. par3 - tokens = PStringUtils::Split(iter1->fLine.Data(), " \t"); - if (tokens.size() != 2) { - error = true; - } else { - // get rrf phase - bool ok = false; - const double rrfPhase = PStringUtils::ToDouble(tokens[1], &ok); - if (ok) { - param.fRRFPhase = rrfPhase; - } else if (PStringUtils::BeginsWithNoCase(tokens[1], "par")) { // parameter value - Int_t no = 0; - if (FilterNumber(tokens[1].c_str(), "par", 0, no)) { - // check that the parameter is in range - if (static_cast(fParam.size()) < no) { - error = true; - } else { - // keep the parameter number in case parX was used - param.fRRFPhaseParamNo = no; - // get parameter value - param.fRRFPhase = fParam[no-1].fValue; - } - } + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + Int_t val = str.Atoi(); + if (val > 0) + param.fViewPacking = val; + else + error = true; } else { error = true; } } + + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } + } else if (iter1->fLine.Contains("rrf_freq", TString::kIgnoreCase)) { + // expected entry: rrf_freq value unit + // allowed units: kHz, MHz, Mc/s, G, T + tokens = iter1->fLine.Tokenize(" \t"); + if (!tokens) { + std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize rrf_freq in line " << iter1->fLineNo; + std::cerr << std::endl << std::endl; + return false; + } + if (tokens->GetEntries() != 3) { + error = true; + } else { + // get rrf frequency + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsFloat()) { + param.fRRFFreq = str.Atof(); + } else { + error = true; + } + // get unit + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + if (str.Contains("kHz", TString::kIgnoreCase)) + param.fRRFUnit = RRF_UNIT_kHz; + else if (str.Contains("MHz", TString::kIgnoreCase)) + param.fRRFUnit = RRF_UNIT_MHz; + else if (str.Contains("Mc/s", TString::kIgnoreCase)) + param.fRRFUnit = RRF_UNIT_Mcs; + else if (str.Contains("G", TString::kIgnoreCase)) + param.fRRFUnit = RRF_UNIT_G; + else if (str.Contains("T", TString::kIgnoreCase)) + param.fRRFUnit = RRF_UNIT_T; + else + error = true; + } + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } + } else if (iter1->fLine.Contains("rrf_phase", TString::kIgnoreCase)) { + // expected entry: rrf_phase value. value given in units of degree. or + // rrf_phase parX. where X is the parameter number, e.g. par3 + tokens = iter1->fLine.Tokenize(" \t"); + if (!tokens) { + std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize rrf_phase in line " << iter1->fLineNo; + std::cerr << std::endl << std::endl; + return false; + } + if (tokens->GetEntries() != 2) { + error = true; + } else { + // get rrf phase + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsFloat()) { + param.fRRFPhase = str.Atof(); + } else { + if (str.BeginsWith("par", TString::kIgnoreCase)) { // parameter value + Int_t no = 0; + if (FilterNumber(str, "par", 0, no)) { + // check that the parameter is in range + if (static_cast(fParam.size()) < no) { + error = true; + } else { + // keep the parameter number in case parX was used + param.fRRFPhaseParamNo = no; + // get parameter value + param.fRRFPhase = fParam[no-1].fValue; + } + } + } else { + error = true; + } + } + } + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; + } } else if (iter1->fLine.Contains("rrf_packing", TString::kIgnoreCase)) { // expected entry: rrf_phase value. value given in units of degree - tokens = PStringUtils::Split(iter1->fLine.Data(), " \t"); - if (tokens.size() != 2) { + tokens = iter1->fLine.Tokenize(" \t"); + if (!tokens) { + std::cerr << std::endl << ">> PMsrHandler::HandlePlotEntry: **SEVERE ERROR** Couldn't tokenize rrf_packing in line " << iter1->fLineNo; + std::cerr << std::endl << std::endl; + return false; + } + if (tokens->GetEntries() != 2) { error = true; } else { // get rrf packing - bool ok = false; - param.fRRFPacking = PStringUtils::ToInt(tokens[1], &ok); - if (!ok) + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str.IsDigit()) { + param.fRRFPacking = str.Atoi(); + } else { error = true; + } + } + // clean up + if (tokens) { + delete tokens; + tokens = nullptr; } } else { error = true; @@ -4993,7 +5381,7 @@ Bool_t PMsrHandler::HandleStatisticEntry(PMsrLines &lines) if (status == 2) { fStatistic.fDate = TString(date)+TString(", ")+TString(time); } else { - fStatistic.fDate = TString("\?\?\?\?-\?\?-\?\?, \?\?:\?\?:\?\?"); + fStatistic.fDate = TString("????-??-??, ??:??:??"); } } // extract chisq @@ -5060,7 +5448,8 @@ UInt_t PMsrHandler::GetNoOfFitParameters(UInt_t idx) PUIntVector paramVector; PUIntVector funVector; PUIntVector mapVector; - std::vector tokens; + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; TString str; UInt_t k, dval; Int_t status, pos; @@ -5109,31 +5498,42 @@ UInt_t PMsrHandler::GetNoOfFitParameters(UInt_t idx) if (pos >= 0) str.Resize(pos); // tokenize - tokens = PStringUtils::Split(str.Data(), " \t"); + tokens = str.Tokenize(" \t"); + if (!tokens) { + mapVector.clear(); + funVector.clear(); + paramVector.clear(); + return 0; + } - for (UInt_t j=0; jGetEntries(); j++) { + ostr = dynamic_cast(tokens->At(j)); + str = ostr->GetString(); // check for parameter number - if (PStringUtils::IsInt(tokens[j])) { - dval = PStringUtils::ToInt(tokens[j]); + if (str.IsDigit()) { + dval = str.Atoi(); paramVector.push_back(dval); } // check for map - if (tokens[j].find("map") != std::string::npos) { - status = sscanf(tokens[j].c_str(), "map%d", &dval); + if (str.Contains("map")) { + status = sscanf(str.Data(), "map%d", &dval); if (status == 1) { mapVector.push_back(dval); } } // check for function - if (tokens[j].find("fun") != std::string::npos) { - status = sscanf(tokens[j].c_str(), "fun%d", &dval); + if (str.Contains("fun")) { + status = sscanf(str.Data(), "fun%d", &dval); if (status == 1) { funVector.push_back(dval); } } } + + delete tokens; + tokens = nullptr; } // go through the function block and collect parameters @@ -5167,21 +5567,29 @@ UInt_t PMsrHandler::GetNoOfFitParameters(UInt_t idx) str.Resize(pos); // tokenize - tokens = PStringUtils::Split(str.Data(), " \t"); + tokens = str.Tokenize(" \t"); + if (!tokens) { + mapVector.clear(); + funVector.clear(); + paramVector.clear(); + return 0; + } // filter out parameters and maps - for (UInt_t j=0; jGetEntries(); j++) { + ostr = dynamic_cast(tokens->At(j)); + str = ostr->GetString(); // check for parameter - if (tokens[j].rfind("par", 0) == 0) { - status = sscanf(tokens[j].c_str(), "par%d", &dval); + if (str.BeginsWith("par")) { + status = sscanf(str.Data(), "par%d", &dval); if (status == 1) paramVector.push_back(dval); } // check for map - if (tokens[j].rfind("map", 0) == 0) { - status = sscanf(tokens[j].c_str(), "map%d", &dval); + if (str.BeginsWith("map")) { + status = sscanf(str.Data(), "map%d", &dval); if (status == 1) mapVector.push_back(dval); } @@ -5236,7 +5644,8 @@ void PMsrHandler::FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLi PIntVector map; PIntVector fun; PMsrLines::iterator iter; - std::vector tokens; + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; TString str; Int_t ival, funNo; @@ -5255,23 +5664,33 @@ void PMsrHandler::FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLi str.ToLower(); // tokenize string - tokens = PStringUtils::Split(str.Data(), " \t"); + tokens = str.Tokenize(" \t"); + if (!tokens) + continue; // filter param no, map no, and fun no - for (UInt_t i=0; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + if (str.IsDigit()) { // parameter number + ival = str.Atoi(); if ((ival > 0) && (ival < static_cast(fParam.size())+1)) { fParamInUse[ival-1]++; } - } else if (tokens[i].find("map") != std::string::npos) { // map - if (FilterNumber(tokens[i].c_str(), "map", MSR_PARAM_MAP_OFFSET, ival)) + } else if (str.Contains("map")) { // map + if (FilterNumber(str, "map", MSR_PARAM_MAP_OFFSET, ival)) map.push_back(ival-MSR_PARAM_MAP_OFFSET); - } else if (tokens[i].find("fun") != std::string::npos) { // fun - if (FilterNumber(tokens[i].c_str(), "fun", MSR_PARAM_FUN_OFFSET, ival)) + } else if (str.Contains("fun")) { // fun + if (FilterNumber(str, "fun", MSR_PARAM_FUN_OFFSET, ival)) fun.push_back(ival-MSR_PARAM_FUN_OFFSET); } } + + // delete tokens + if (tokens) { + delete tokens; + tokens = nullptr; + } } // go through all the function lines: 1st time ----------------------------- @@ -5284,12 +5703,14 @@ void PMsrHandler::FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLi // everything to lower case str.ToLower(); - tokens = PStringUtils::Split(str.Data(), " /t"); - if (tokens.empty()) + tokens = str.Tokenize(" /t"); + if (!tokens) continue; // filter fun number - if (!FilterNumber(tokens[0].c_str(), "fun", MSR_PARAM_FUN_OFFSET, funNo)) + ostr = dynamic_cast(tokens->At(0)); + str = ostr->GetString(); + if (!FilterNumber(str, "fun", MSR_PARAM_FUN_OFFSET, funNo)) continue; funNo -= MSR_PARAM_FUN_OFFSET; @@ -5338,6 +5759,12 @@ void PMsrHandler::FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLi break; // since function was found, break the loop } } + + // delete tokens + if (tokens) { + delete tokens; + tokens = nullptr; + } } // go through all the run block lines ------------------------------------- @@ -5356,42 +5783,61 @@ void PMsrHandler::FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLi str.Contains("norm") || str.Contains("backgr.fit") || str.Contains("lifetime ")) { // tokenize string - tokens = PStringUtils::Split(str.Data(), " \t"); - if (tokens.size()<2) + tokens = str.Tokenize(" \t"); + if (!tokens) + continue; + if (tokens->GetEntries()<2) continue; - std::string tok1 = tokens[1]; // parameter number or function + ostr = dynamic_cast(tokens->At(1)); // parameter number or function + str = ostr->GetString(); // check if parameter number - if (PStringUtils::IsInt(tok1)) { - ival = PStringUtils::ToInt(tok1); + if (str.IsDigit()) { + ival = str.Atoi(); fParamInUse[ival-1]++; } // check if fun - if (tok1.find("fun") != std::string::npos) { - if (FilterNumber(tok1.c_str(), "fun", MSR_PARAM_FUN_OFFSET, ival)) { + if (str.Contains("fun")) { + if (FilterNumber(str, "fun", MSR_PARAM_FUN_OFFSET, ival)) { fun.push_back(ival-MSR_PARAM_FUN_OFFSET); } } + + // delete tokens + if (tokens) { + delete tokens; + tokens = nullptr; + } } // handle the maps if (str.Contains("map")) { // tokenize string - tokens = PStringUtils::Split(str.Data(), " \t"); + tokens = str.Tokenize(" \t"); + if (!tokens) + continue; // get the parameter number via map for (UInt_t i=0; i(tokens.size())) { - if (PStringUtils::IsInt(tokens[map[i]])) { - ival = PStringUtils::ToInt(tokens[map[i]]); + if (map[i] < tokens->GetEntries()) { + ostr = dynamic_cast(tokens->At(map[i])); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); if (ival > 0) { fParamInUse[ival-1]++; // this is OK since map is ranging from 1 .. } } } } + + // delete tokens + if (tokens) { + delete tokens; + tokens = nullptr; + } } } @@ -5405,12 +5851,14 @@ void PMsrHandler::FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLi // everything to lower case str.ToLower(); - tokens = PStringUtils::Split(str.Data(), " /t"); - if (tokens.empty()) + tokens = str.Tokenize(" /t"); + if (!tokens) continue; // filter fun number - if (!FilterNumber(tokens[0].c_str(), "fun", MSR_PARAM_FUN_OFFSET, funNo)) + ostr = dynamic_cast(tokens->At(0)); + str = ostr->GetString(); + if (!FilterNumber(str, "fun", MSR_PARAM_FUN_OFFSET, funNo)) continue; funNo -= MSR_PARAM_FUN_OFFSET; @@ -5458,6 +5906,12 @@ void PMsrHandler::FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLi } } } + + // delete tokens + if (tokens) { + delete tokens; + tokens = nullptr; + } } // go through all the run block lines 2nd time to filter remaining maps @@ -5473,21 +5927,31 @@ void PMsrHandler::FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLi // handle the maps if (str.Contains("map")) { // tokenize string - tokens = PStringUtils::Split(str.Data(), " \t"); + tokens = str.Tokenize(" \t"); + if (!tokens) + continue; // get the parameter number via map for (UInt_t i=0; i(tokens.size())) { - if (PStringUtils::IsInt(tokens[map[i]])) { - ival = PStringUtils::ToInt(tokens[map[i]]); + if (map[i] < tokens->GetEntries()) { + ostr = dynamic_cast(tokens->At(map[i])); + str = ostr->GetString(); + if (str.IsDigit()) { + ival = str.Atoi(); if (ival > 0) { fParamInUse[ival-1]++; // this is OK since map is ranging from 1 .. } } } } + + // delete tokens + if (tokens) { + delete tokens; + tokens = nullptr; + } } } @@ -5903,7 +6367,9 @@ Bool_t PMsrHandler::CheckMaps() PIntVector mapBlock; PIntVector mapLineNo; - std::vector tokens; + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; + TString str; Int_t no; @@ -5911,16 +6377,23 @@ Bool_t PMsrHandler::CheckMaps() for (UInt_t i=0; iGetEntries(); j++) { + ostr = dynamic_cast(tokens->At(j)); + str = ostr->GetString(); + if (str.Contains("map", TString::kIgnoreCase)) { + if (FilterNumber(str, "map", MSR_PARAM_MAP_OFFSET, no)) { mapVec.push_back(no); mapBlock.push_back(0); // 0 = theory-block mapLineNo.push_back(fTheory[i].fLineNo); } } } + // clean up tokens + if (tokens) { + delete tokens; + tokens = nullptr; + } } } @@ -5928,16 +6401,23 @@ Bool_t PMsrHandler::CheckMaps() for (UInt_t i=0; iGetEntries(); j++) { + ostr = dynamic_cast(tokens->At(j)); + str = ostr->GetString(); + if (str.Contains("map", TString::kIgnoreCase)) { + if (FilterNumber(str, "map", MSR_PARAM_MAP_OFFSET, no)) { mapVec.push_back(no); mapBlock.push_back(1); // 1 = theory-block mapLineNo.push_back(fFunctions[i].fLineNo); } } } + // clean up tokens + if (tokens) { + delete tokens; + tokens = nullptr; + } } } @@ -6008,7 +6488,8 @@ Bool_t PMsrHandler::CheckFuncs() PIntVector funBlock; PIntVector funLineBlockNo; - std::vector tokens; + TObjArray *tokens = nullptr; + TObjString *ostr = nullptr; TString str; Int_t no; @@ -6017,16 +6498,23 @@ Bool_t PMsrHandler::CheckFuncs() for (UInt_t i=0; iGetEntries(); j++) { + ostr = dynamic_cast(tokens->At(j)); + str = ostr->GetString(); + if (str.Contains("fun", TString::kIgnoreCase)) { + if (FilterNumber(str, "fun", MSR_PARAM_FUN_OFFSET, no)) { funVec.push_back(no); funBlock.push_back(0); // 0 = theory-block funLineBlockNo.push_back(fTheory[i].fLineNo); } } } + // clean up tokens + if (tokens) { + delete tokens; + tokens = nullptr; + } } } @@ -6675,54 +7163,43 @@ UInt_t PMsrHandler::GetDKSTag() */ void PMsrHandler::HandleTheoryArguments(const TString theo, PStringVector &args) { - TObjArray *tok=theo.Tokenize(" \t"); - TObjString *ostr=0; - TString str, argStr; + std::vector tokens = PStringUtils::Split(theo.Data(), " \t"); + std::string str; Int_t ival; args.clear(); // make sure vector is empty - if (tok == 0) { + if (tokens.empty()) { std::cerr << ">> PMsrHandler::HandleTheoryArguments(): **ERROR** couldn't tokensize '" << theo << "'" << std::endl; return; } - for (Int_t i=0; iGetEntries(); i++) { - ostr = dynamic_cast(tok->At(i)); - str = ostr->GetString(); - if (str.BeginsWith("#") || str.BeginsWith("(")) { // comment or description + for (const auto &tok : tokens) { + str = tok; + if ((str[0] == '#') || (str[0] == '(')) { // comment or description continue; - } else if (str.IsDigit()) { // parameter - ival = str.Atoi(); + } else if (PStringUtils::IsInt(str)) { // parameter + ival = PStringUtils::ToInt(str); ival -= 1; - str = TString::Format("%d",ival); - argStr = "p["+ str +"]"; - args.push_back(argStr); - } else if (str.BeginsWith("map", TString::kIgnoreCase)) { // map - str.Remove(0,3); - if (!str.IsDigit()) { + args.push_back(TString::Format("p[%d]", ival)); + } else if (PStringUtils::BeginsWithNoCase(str, "map")) { // map + str = str.substr(3); + if (!PStringUtils::IsInt(str)) { return; } - ival = str.Atoi(); + ival = PStringUtils::ToInt(str); ival -= 1; - str = TString::Format("%d",ival); - argStr = "p[m[" + str + "]]"; - args.push_back(argStr); - } else if (str.BeginsWith("fun", TString::kIgnoreCase)) { // function - str.Remove(0,3); - if (!str.IsDigit()) { + args.push_back(TString::Format("p[m[%d]]", ival)); + } else if (PStringUtils::BeginsWithNoCase(str, "fun")) { // function + str = str.substr(3); + if (!PStringUtils::IsInt(str)) { return; } - ival = str.Atoi(); + ival = PStringUtils::ToInt(str); ival -= 1; - str = TString::Format("%d",ival); - argStr = "f[" + str + "]"; - args.push_back(argStr); + args.push_back(TString::Format("f[%d]", ival)); } } - - // clean up - delete tok; } //--------------------------------------------------------------------------