Refactoring #1588

Feature #284: === Fit ===

FitSuiteParameters inhibits Python iterator

Added by wuttke over 4 years ago. Updated about 4 years ago.

Status:ArchivedStart date:10 Aug 2016
Priority:LowDue date:
Assignee:pospelov% Done:


Target version:Sprint32


When controlling a fit from Python I would expect to be able to write

for par in fit_suite.getFitParameters():

This doesn't work. I have to write
pars = fit_suite.getFitParameters()
for i in range(pars.size()):
    par = pars[i]

This restriction is due to the design of class FitSuiteParameters, which almost behaves like std::vector<FitParameter*> but not entirely so. Differences are:
  • bound checking in operator[]
  • different names for some operations ("addParameter" instead of "push_back")
  • not automatically converted to a Python list; no suport for len(..) or for iterators
Possible solutions:
  • Let FitSuiteParameters inherit from std::vector<FitParameter*> instead of having it as sole data member
  • Get rid of FitSuiteParameters altogether; let FitSuite have a member of type std::vector<FitParameter*>

Do we want bound checking? Also elsewhere? Or why just here? Maybe we need a index-checking vector template class??


#1 Updated by wuttke over 4 years ago

  • Description updated (diff)

#2 Updated by wuttke over 4 years ago

  • Priority changed from Normal to Low

#3 Updated by wuttke over 4 years ago

  • Parent task set to #284

#4 Updated by pospelov over 4 years ago

  • FitSuiteParameters has a lot of convenience methods (see FitSuiteParameters.cpp file)
    • initially it was vector<FitParameter *> on board of FitSuite, but it was extracted into separate class because of these methods and because FitSuite was too overloaded with responsibilities.
  • Inheritance from std containers is technically possible but considered to be bad practice


  • I'm fully agree that access to fit results from Python should be revised
    • one possibility is to make FitSuite return std::vector<FitParameter*>, or better std::vector<std::shared_ptr<FitParameter>>

internally the call will be just forwarded to FitSuiteParameters::getParameters

  • the existence of FitSuiteParameters will be hidden from Python users
  • in principle, it is possible to remove all methods begin(), end(), size()
  • This question is in relation to another one - accessing fit results from Python and from GUI
    • access to correlation matrix, access to EDM (estimated distance to the minimum), access to best chi2, access to fit parameter's global correlation coefficient etc
  • One possibility is to introduce new class FitResults to report it to external environment
    • will have better understanding as soon as I implement accessing of fit results into GUI

#5 Updated by pospelov over 4 years ago

  • Assignee set to pospelov
  • Target version set to Sprint32

#6 Updated by pospelov over 4 years ago

  • Status changed from Rfc to Resolved

#7 Updated by herck about 4 years ago

  • Status changed from Resolved to Archived

Also available in: Atom PDF