Revision: 2053
http://sourceforge.net/p/nsclspectcl/code/2053
Author: ron-fox
Date: 2012-12-24 19:56:53 +0000 (Mon, 24 Dec 2012)
Log Message:
-----------
Fix errors due to class name clashes with the base SpecTcl
program/library.
Added Paths:
-----------
tags/calibparams-1.0-003/
tags/calibparams-1.0-003/AUTHORS
tags/calibparams-1.0-003/CCalibratedFitCommand.cpp
tags/calibparams-1.0-003/CCalibratedParameter.cpp
tags/calibparams-1.0-003/CCalibratedParameter.h
tags/calibparams-1.0-003/CCalibratedParameterCommand.cpp
tags/calibparams-1.0-003/CCalibratedParameterCommand.h
tags/calibparams-1.0-003/CFit.cpp
tags/calibparams-1.0-003/CFit.h
tags/calibparams-1.0-003/CFitCreator.cpp
tags/calibparams-1.0-003/CFitCreator.h
tags/calibparams-1.0-003/CFitFactory.cpp
tags/calibparams-1.0-003/CFitFactory.h
tags/calibparams-1.0-003/CLinearFit.cpp
tags/calibparams-1.0-003/CLinearFit.h
tags/calibparams-1.0-003/CLinearFitCreator.cpp
tags/calibparams-1.0-003/CLinearFitCreator.h
tags/calibparams-1.0-003/CalibManagerTest.cpp
tags/calibparams-1.0-003/CalibParamTest.cpp
tags/calibparams-1.0-003/CalibrationPackage.cpp
tags/calibparams-1.0-003/ChangeLog
tags/calibparams-1.0-003/CommandTest.cpp
tags/calibparams-1.0-003/CreatorTest.cpp
tags/calibparams-1.0-003/FactoryTest.cpp
tags/calibparams-1.0-003/FitTest.cpp
tags/calibparams-1.0-003/NEWS
tags/calibparams-1.0-003/README
tags/calibparams-1.0-003/configure.in
Removed Paths:
-------------
tags/calibparams-1.0-003/CCalibratedFitCommand.cpp
tags/calibparams-1.0-003/CCalibratedParameter.cpp
tags/calibparams-1.0-003/CCalibratedParameter.h
tags/calibparams-1.0-003/CCalibratedParameterCommand.cpp
tags/calibparams-1.0-003/CCalibratedParameterCommand.h
tags/calibparams-1.0-003/CFit.cpp
tags/calibparams-1.0-003/CFit.h
tags/calibparams-1.0-003/CFitCommand.cpp
tags/calibparams-1.0-003/CFitCommand.h
tags/calibparams-1.0-003/CFitCreator.cpp
tags/calibparams-1.0-003/CFitCreator.h
tags/calibparams-1.0-003/CFitFactory.cpp
tags/calibparams-1.0-003/CFitFactory.h
tags/calibparams-1.0-003/CLinearFit.cpp
tags/calibparams-1.0-003/CLinearFit.h
tags/calibparams-1.0-003/CLinearFitCreator.cpp
tags/calibparams-1.0-003/CLinearFitCreator.h
tags/calibparams-1.0-003/CalibManagerTest.cpp
tags/calibparams-1.0-003/CalibParamTest.cpp
tags/calibparams-1.0-003/CalibrationPackage.cpp
tags/calibparams-1.0-003/CommandTest.cpp
tags/calibparams-1.0-003/CreatorTest.cpp
tags/calibparams-1.0-003/FactoryTest.cpp
tags/calibparams-1.0-003/FitTest.cpp
tags/calibparams-1.0-003/configure.in
Copied: tags/calibparams-1.0-003/AUTHORS (from rev 2051, trunk/plugins/calibparams/AUTHORS)
===================================================================
Deleted: tags/calibparams-1.0-003/CCalibratedFitCommand.cpp
===================================================================
--- trunk/plugins/calibparams/CCalibratedFitCommand.cpp 2012-11-11 23:56:02 UTC (rev 2050)
+++ tags/calibparams-1.0-003/CCalibratedFitCommand.cpp 2012-12-24 19:56:53 UTC (rev 2053)
@@ -1,859 +0,0 @@
-/*
- Implementation file for CFitCommand for a description of the
- class see CFitCommand.h
-*/
-
-
-
-// Include files required:
-
-#include <config.h>
-#include "CCalibratedFitCommand.h"
-#include "CFitFactory.h"
-#include "CFit.h"
-#include "CFitCreator.h"
-
-#include <TCLInterpreter.h>
-#include <TCLResult.h>
-#include <TCLList.h>
-#include <TCLString.h>
-#include <TCLException.h>
-#include <DesignByContract.h>
-
-#include <Point.h>
-#include <vector>
-#include <string>
-#include <algorithm>
-
-#include <stdio.h>
-
-#ifdef HAVE_STD_NAMESPACE
-using namespace std;
-#endif
-
-
-using namespace DesignByContract;
-
-// Static attribute storage and initialization for CCalibratedFitCommand
-
-static vector<string> SwitchTable;
-
-enum Switches {
- swCreate,
- swList,
- swDelete,
- swPerform,
- swAdd,
- swEvaluate
-};
-
-// Local helper classes used by STL algorithms.
-//
-
-
-/*!
- Create a list of fits. The list is created in a
- TCLList but returnable as a string.
-*/
-class CreateListResult
-{
-private:
- CTCLString& m_listListing;
- string m_sPattern;
-public:
- CreateListResult(string sPattern, CTCLString& result);
-
- bool operator()(pair<string, CFit*> Item);
- string GetResult();
- static string FormatFit(string sName, CFit* pFit);
- static string FormatPoints(CFit* pFit);
- static string FormatParameters(CFit* pFit);
-
-};
-/*!
- Construct a fit lister:
-*/
-CreateListResult::CreateListResult(string sPattern,
- CTCLString& result) :
- m_listListing(result),
- m_sPattern(sPattern)
-{
-
-}
-/*!
- If pattern is matched, add the fit to the listing:
-*/
-
-bool CreateListResult::operator()(pair<string, CFit*> Item)
-{
- CTCLString name(Item.first);
- if(name.Match(m_sPattern)) {
- m_listListing.AppendElement(FormatFit(Item.first, Item.second));
- }
-}
-/*!
- Return the current list result string.
-*/
-string
-CreateListResult::GetResult()
-{
- return m_listListing;
-}
-/*!
- Format the listing of a fit. Each fit is listed as a TCL list
- containing:
- {name state {points} {parameters} }
-
- - name is the name of the fit.
- - state is the state of the fit: accepting | performed
- - points is a list of lists of {x y} points.
- - parameters is empty ({}) if the fit state is not performed. Otherwise
- it is a list of the fit parameters in the form {paramname value}.
-
- \param sName (string)
- Name of the fit
- \param pFit (CFit*)
- Pointer to fit.
-
-*/
-string
-CreateListResult::FormatFit(string sName, CFit* pFit)
-{
- CTCLString Info;
- Info.AppendElement(sName);
- Info.AppendElement(pFit->Type());
- Info.AppendElement((pFit->GetState() == CFit::Accepting) ?
- "accepting" : "performed");
- // The points.
- Info.AppendElement(FormatPoints(pFit));
-
-
- // The fit parameters:
-
- Info.AppendElement(FormatParameters(pFit));
-
-
- // Done.
-
- return string((const char*)Info);
-
-}
-/*!
- Return a TCL formatted list of fit points.
- \param pFit (CFit*)
- Pointer to the fit object.
-*/
-string
-CreateListResult::FormatPoints(CFit* pFit)
-{
- CTCLString Info;
- CFit::PointIterator i = pFit->begin();
- while(i != pFit->end()) {
- char aPoint[100];
- sprintf(aPoint, "%g %g ", i->x, i->y);
- Info.AppendElement(aPoint);
- i++;
- }
- return string((const char*)Info);
-}
-/*!
- Format the Fit parameters into a TCL proper list.
- \param pFit (CFit*)
- Pointer to the fit object.
-*/
-string
-CreateListResult::FormatParameters(CFit* pFit)
-{
- CTCLString Info;
-
- if(pFit->GetState() == CFit::Performed) { // Otherwise no params.
- CFit::FitParameterList params = pFit->GetParameters();
- CFit::FitParameterIterator i = params.begin();
- while(i != params.end()) {
- Info.StartSublist();
- {
- char Value[100];
- sprintf(Value, "%g", i->second);
- Info.AppendElement(i->first);
- Info.AppendElement(Value);
- }
- Info.EndSublist();
- i++;
- }
-
- }
- return string((const char*)Info);
-}
-
-
-//////////////////////////////// CCalibratedFitCommand Implementation
-
-/*!
- Create an object of type CCalibratedFitCommand
-
- \param pInterp (CTCLInterpreter*)
- The interpreter on which this command is registsered.
- The command itself is unconditionally registered as 'fit'.
-*/
-CCalibratedFitCommand::CCalibratedFitCommand (CTCLInterpreter* pInterp) :
- CTCLProcessor("calibrationfit", pInterp)
-{
- // Stock the switch lookup table:
-
- if(SwitchTable.empty()) {
- SwitchTable.push_back("-create");
- SwitchTable.push_back("-list");
- SwitchTable.push_back("-delete");
- SwitchTable.push_back("-perform");
- SwitchTable.push_back("-add");
- SwitchTable.push_back("-evaluate");
- }
-
-}
-
-/*!
- Called to destroy an instance of CCalibratedFitCommand
-*/
- CCalibratedFitCommand::~CCalibratedFitCommand ( )
-{
-
-}
-
-/*!
-
-Description:
-
-Gains control when the fit command is to be executed.
-This function simply decodes the first switch and
-dispatches to the appropriate _parse function:
-- -type -> Create_parse
-- -list -> List_parse
-- -delete -> Delete_parse
-- -perform -> Perform_parse
-- -add -> AddPoints_parse
-- -evaluate -> Evaluate_parse
-
-
-
-Parameters:
-
-\param rInterp (CTCLInterpreter& )
- TCL Interpreter object.
-\param rResult (CTCLResult&)
- The result string
-\param argc (int)
- The number of command line parameters. Note that
- the first parameter is the command name itself.
-\param argv (char**)
- The parameters.
-
-\return int
-\retval TCL_OK - The command was successful, the result
- string contains subcommand specific stuff.
-\retval TC_ERROR - The command failed and the result string
- contains the error message.
-
-
-*/
-int
-CCalibratedFitCommand::operator()(CTCLInterpreter& rInterp, CTCLResult& rResult,
- int argc, char** argv)
-{
- // The first parameter is the command name:
-
- argc--;
- argv++;
-
- // The second parameter msut exist. It should be either a
- // valid switch or alternatively the type of a fit to be
- // created:
-
- if(!argc) {
- rResult = Usage();
- return TCL_ERROR;
- }
- // Now let's figure out what the switch is:
-
- char* pSubCommand = *argv;
-
- switch(MatchKeyword(SwitchTable,
- string(pSubCommand),
- (int)swCreate)) {
- case swCreate:
- if(pSubCommand[0] == '-') { // An actual switch:
- argc--;
- argv++;
- }
- return Create_parse(rInterp, rResult, argc, argv);
- case swList:
- argc--;
- argv++;
- return List_parse(rInterp, rResult, argc, argv);
- case swDelete:
- argc--;
- argv++;
- return Delete_parse(rInterp, rResult, argc, argv);
- case swPerform:
- argc--;
- argv++;
- return Perform_parse(rInterp, rResult, argc, argv);
- case swAdd:
- argc--;
- argv++;
- return AddPoints_parse(rInterp, rResult, argc, argv);
- case swEvaluate:
- argc--;
- argv++;
- return Evaluate_parse(rInterp, rResult, argc, argv);
- default: // Illegal:
- argc--;
- argv++;
- rResult = Usage();
- return TCL_ERROR;
- }
- // Control should not fall here:
-
- REQUIRE(0, "Defect in program logic");
-}
-
-/*!
-
-Description:
-
-Parses the command arguments and, if all goes well, calls Create to create a new
-fit object. This division of labor supports testing at low and high levels.
-The form of the command is:
-
-\verbatim
-fit ?-create? fittype fitname
- o fittype a fit type e.g. linear
- o fitname the name of a fit.
-\endverbatim
-
-Parameters:
-
-\param rInterp (CTCLInterpreter&)
- The interpreter object.
-\parm rResult (CTCLResult&)
- The result object.
-\param argc (int)
- number of arguments this has been adjusted to
- eat up both the fit command and the -create switch.
-\param argv (char**)
- Command line arguments. This has been adjusted to contain only the fit type and name
-(assuming the user's call is correct).
-
-
-
-\return int
-\retval TCK_OK
-\retval TCL_ERROR
-
-Requirements:
-- There are two command line parameters.
-- The fit must not yet exist.
-
-
-
-*/
-int
-CCalibratedFitCommand::Create_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc, char** argv)
-{
- // The requirements are like preconditions with a bit less
- // force behind them. Instead of an exception, violating one
- // leads to an error return.
-
- // Check the number of parameters:
-
- if(argc != 2) {
- rResult = Usage();
- return TCL_ERROR;
- }
-
- // Check the name does not yet exist:
-
- char* pType = argv[0];
- char* pName = argv[1];
-
- if(CFitFactory::FindFit(string(pName)) != CFitFactory::end()) {
- rResult = "Fit: ";
- rResult += pName;
- rResult += " already exists";
- return TCL_ERROR;
- }
-
- // Try to create the fit. Any failure is assumed to be because
- // the fit type was invalid at this point:
-
- CFit* pFit = CFitFactory::Create(string(pType), string(pName));
- if(pFit) {
- rResult = pName;
- return TCL_OK;
- }
- else {
- rResult = "Failed to create fit: ";
- rResult += pName;
- rResult += " probably not a valid type\n";
- rResult += Usage();
- return TCL_ERROR;
- }
-
- REQUIRE(0, "Program logic error");
-
-}
-
-/*!
-
-Description:
-
-Parses the -list command and passes control to the List function.
-In fact the list function produces a vector describing all fits. This vector is
-filtered by the pattern passed into or defaulted by this command.
-
-
-
-\pre
-
-\post
-
-Parameters:
-
-\param rInterp (CTCLInterpreter&)
- Intepreter object.
-\param rResult (CTCLResult&)
- Refers to the result string.
-\param argc (int)
- count of command line parameters. This has been
-adjusted so that the only remaining parameter is the optional
-pattern. If the pattern exists, it is used to filter the fit names.
-If not, it defaults to "*" which matches all fit names.
-\param argv (char**)
- Pointers to the parameters. Please look at argc to get an
-idea of what this points to.
-
-\return int
-\retval TCL_OK
-\retval TCL_ERROR
-
-
-
-*/
-int
-CCalibratedFitCommand::List_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc, char** argv)
-{
- // There may be at most one other parameter: The pattern:
-
- if(argc > 1) {
- rResult = Usage();
- return TCL_ERROR;
- }
- // Figure out the pattern:
-
- string Pattern;
-
- if(argc) {
- Pattern = *argv;
- }
- else {
- Pattern = "*";
- }
-
- // Build up the result list via a for_each loop:
-
- CTCLString listing;
- CreateListResult listPredicate(Pattern, listing);
-
- for_each(CFitFactory::begin(), CFitFactory::end(), listPredicate);
-
- rResult = listPredicate.GetResult();
- return TCL_OK;
-}
-
-/*!
-
-Parses the -delete switch and dispatches to the Delete function.
-
-Parameters:
-
-\param rInterp (CTCLInterpreter&)
- The interpreter executing us.
-\param rResult (CTCLResult&)
- The result string.
-\param argc (int)
- Remaining number of command line parameters (after -delete has been eaten)
-\param argv (char**)
- Remaining command line parameters.
-
-\return int
-\retval TCL_OK
-\retval TCL_ERROR
-
-
-*/
-int
-CCalibratedFitCommand::Delete_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc , char** argv)
-{
-
- // There must be a single additional parameter, the
- // name of the fit:
-
- if(argc != 1) {
- rResult = Usage();
- return TCL_ERROR;
- }
-
- // To delete a gate requires that it first exist:
- //
- string sFitName(*argv);
- CFitFactory::FitIterator pFit = CFitFactory::FindFit(sFitName);
- if(pFit != CFitFactory::end()) {
- if(CFitFactory::Delete(sFitName)) { // Deleted ok.
- rResult = sFitName;
- return TCL_OK;
- }
- else { // Failed but don't know why.
- rResult = "Unable to delete fit: ";
- rResult += sFitName;
- return TCL_ERROR;
- }
- }
- else { // No such fit:
- rResult = "Fit: ";
- rResult += sFitName;
- rResult += " does not exist!";
- return TCL_ERROR;
- }
-
-}
-
-/*!
-
-
-Parses the -perform switch. Then calls Perform which must locate the
-appropriate fit and perform it.
-
-
-
-\param rInterp (CTCLInterpreter&)
- The interpreter
-\param rResult (CTCLResult&)
- The result string.
-\param argc (int)
- The number of parameters after -delete.
-\param argv (char**)
- Pointer to these parameters
-
-*/
-int
-CCalibratedFitCommand::Perform_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc, char** argv)
-{
- // There must be a parameter; the name of the fit:
-
- if(argc != 1) {
- rResult = Usage();
- return TCL_ERROR;
- }
- string sFitName(*argv);
-
- // The fit must exist:
-
- CFitFactory::FitIterator pFit = CFitFactory::FindFit(sFitName);
- if(pFit != CFitFactory::end()) { // Fit exists.
- // The fit must perform with no error:
-
- if(CFitFactory::Perform(sFitName)) {
- CFit* p = pFit->second;
- rResult = CreateListResult::FormatParameters(p);
- return TCL_OK;
- }
- else { // Fit failed, likely isufficient pts
- rResult = "Fit: ";
- rResult += sFitName;
- rResult += " could not be performed. Probably needs more points";
- return TCL_ERROR;
- }
-
- }
- else { // Fit does not exist.
-
- rResult = "Fit: ";
- rResult += sFitName;
- rResult += " does not exist";
- return TCL_ERROR;
- }
-}
-
-/*!
-
-Description:
-
-Parses the fit -add command. This command adds points
-to the fit, by parsing the points on the command line and repeatedly
-calling AddPoint to add each point to the fit.
-
-
-
-\param rInterp (CTCLInterpreter&)
- Interpreter object.
-\param rResult (CTCLResult&)
- The TCL interpreter result string.
-\param argc (int)
- number of command line parameters after the -delete switch
-\param argv (char**)
- The parameters after the -delete switch.
-
-
-\return int
-\retval TCL_OK
-\retval TCL_ERROR
-
-
-*/
-int
-CCalibratedFitCommand::AddPoints_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc, char** argv)
-{
- // There must be at least two additional parameters...
- // A fit name and a point to add
- //
- if(argc < 2) {
- rResult = Usage();
- return TCL_ERROR;
- }
-
- // The fit must exist:
-
- string sFitName(*argv);
- CFitFactory::FitIterator p = CFitFactory::FindFit(sFitName);
- if(p == CFitFactory::end()) {
- rResult = "Fit: ";
- rResult += sFitName;
- rResult += " does not exist";
- return TCL_ERROR;
- }
- argc--;
- argv++;
-
- // All the remaining parameters must be 2 element lists
- // containing pairs of values that parse as doubles.
- //
-
- vector<FPoint> vPoints;
- try {
- vPoints = ParsePoints(rInterp, argc, argv);
- }
- catch (string failed) { // Points parse failed.
- rResult = "Fit points must be pairs of doubles and: ";
- rResult += failed;
- rResult += " is not.";
- return TCL_ERROR;
- }
- // Now we have enough stuff to ask for the points to be
- // added:
-
- if(CFitFactory::AddPoints(sFitName, vPoints)) { // OK!
- rResult = sFitName;
- return TCL_OK;
- }
- else { // Failed!
- rResult = "Unable to add points to ";
- rResult += sFitName;
- return TCL_ERROR;
- }
- rResult = "BUG report that control fell through to the end of CCalibratedFitCommand::AddPoints";
- return TCL_ERROR;
-}
-
-/*!
-
-Description:
-
-Parses the -evaluate subcommand.
-This command accpts a fit name and an x coordinate
-and invokes the Evaluate function to evaluate the
-fit at that x coordinate. Note that this can fail if
-the fit is in the adding points state.
-
-Parameters:
-
-\param rInterp (CTCLInterpreter&)
- The interpreter object executing this command.
-\param rResult (CTCLResult&)
- The interpreter result string.
-\param argc (int)
- The number of parameters after the -delete command.
-\param argv (char**)
- The parameters after the delete command.
-
-*/
-int
-CCalibratedFitCommand::Evaluate_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult, int argc,
- char** argv)
-{
- // There must be exactly two parameters, a fit name and
- // a point:
-
- if(argc != 2) {
- rResult = Usage();
- return TCL_ERROR;
- }
- string sFitName(*argv);
- argc--;
- argv++;
- string sPoint(*argv);
-
- // The point must evaluate to a double precision value:
-
- DFloat_t dPoint;
- try {
- dPoint = rInterp.ExprDouble(sPoint);
- }
- catch (CTCLException& rExcept) {
- rResult = "Point value: ";
- rResult += sPoint;
- rResult += " does not evaluate to a double expression";
- return TCL_ERROR;
- }
- // Now evaulate the fit:
-
-
- try {
- DFloat_t dResult = CFitFactory::Evaluate(sFitName, dPoint);
- char sResult[100];
- sprintf(sResult, "%g", dResult);
- rResult = sResult;
- return TCL_OK;
- }
- catch(...) { // Failed.
- rResult = "Evaluation of fit: ";
- rResult += sFitName;
- rResult += " @ ";
- rResult += sPoint;
- rResult += " failed. Fit may not have been performed yet.";
- return TCL_ERROR;
- }
-
-}
-
-/*!
-
-Description:
-
-Return the usage of the fit command as a string.
-
-\pre
-
-\post
-
-Parameters:
-
-\return string
-\return string
-\retval the reason the fit failed.
-
-\throw
-
-Pseudo code:
-
-\verbatim
-
-\endverbatim
-
-*/
-string
-CCalibratedFitCommand::Usage()
-{
- string sUsage("Usage:\n");
- sUsage += " calibrationfit ?-create? type name\n";
- sUsage += " calibrationfit -list ?pattern?\n";
- sUsage += " calibrationfit -delete name\n";
- sUsage += " calibrationfit -perform name\n";
- sUsage += " calibrationfit -add name point1 ?point2...?\n";
- sUsage += " calibrationfit -evaluate name x\n";
- sUsage += "\n";
- sUsage += "Where:\n";
- sUsage += " `type' is the type of calibrationfit to create (see below)\n";
- sUsage += " `name' is the name of the calibrationfit to create or manipulate\n";
- sUsage += " `pattern' Is a pattern to match in listing calibrationfits.\n";
- sUsage += " `pointn' are pairs of floating point numbers that\n";
- sUsage += " are independent and dependent values that\n";
- sUsage += " are the data points to be calibrationfit.\n";
- sUsage += " `x' Is a value to evaluate with the calibrationfit function\n";
- sUsage += "\n";
- sUsage += "And the valid calibrationfit types are:\n";
- CFitFactory::FitCreatorIterator i = CFitFactory::beginCreators();
- while(i != CFitFactory::endCreators()) {
- CFitCreator* pCreator = i->second;
- sUsage += " ";
- sUsage += i->first;
- sUsage += " - ";
- sUsage += pCreator->DescribeFit();
- sUsage += "\n";
- i++;
- }
- return sUsage;
-}
-
-
-// Private utilities:
-
-/*!
- Parse a set of parameters where each parameters is supposed to
- contain a two element list containing two doubles. If the
- parse fails, a string exception is thrown where the value of the
- string is the parameter the parse failed on.
-
- \param rInterp (CTCLInterpreter& rInterp)
- Refers to a TCL interpreter that can be used to assist the
- parse.
- \param argc (int)
- Number of parameters to parse.
- \param argv (char**)
- List of parameters to parse.
-
-
- \return vector<FPoint>
- Each element of the vector is a parsed pair.
-
-*/
-vector<FPoint>
-CCalibratedFitCommand::ParsePoints(CTCLInterpreter& rInterp,
- int argc, char** argv)
-{
- FPoint p;
- vector<FPoint> ParsedList;
-
- // Each point is processed in the loop below:
-
- for(int i =0; i < argc; i++) {
- CTCLList lPoint(&rInterp, argv[i]);
- try {
- StringArray s;
- int i = lPoint.Split(s);
- if((i != TCL_OK) ||
- (s.size() != 2)) { // Each parameter mb. a 2 element list
- throw string(argv[i]);
- }
- else {
- p = FPoint(rInterp.ExprDouble(s[0]),
- rInterp.ExprDouble(s[1]));
- ParsedList.push_back(p);
- }
- }
- catch(...) { // Turn any exceptions into a string...
- string FailedParam(argv[i]);
- throw FailedParam;
- }
- }
- return ParsedList;
-}
Copied: tags/calibparams-1.0-003/CCalibratedFitCommand.cpp (from rev 2052, trunk/plugins/calibparams/CCalibratedFitCommand.cpp)
===================================================================
--- tags/calibparams-1.0-003/CCalibratedFitCommand.cpp (rev 0)
+++ tags/calibparams-1.0-003/CCalibratedFitCommand.cpp 2012-12-24 19:56:53 UTC (rev 2053)
@@ -0,0 +1,859 @@
+/*
+ Implementation file for CFitCommand for a description of the
+ class see CFitCommand.h
+*/
+
+
+
+// Include files required:
+
+#include <config.h>
+#include "CCalibratedFitCommand.h"
+#include "./CFitFactory.h"
+#include "./CFit.h"
+#include "./CFitCreator.h"
+
+#include <TCLInterpreter.h>
+#include <TCLResult.h>
+#include <TCLList.h>
+#include <TCLString.h>
+#include <TCLException.h>
+#include <DesignByContract.h>
+
+#include <Point.h>
+#include <vector>
+#include <string>
+#include <algorithm>
+
+#include <stdio.h>
+
+#ifdef HAVE_STD_NAMESPACE
+using namespace std;
+#endif
+
+
+using namespace DesignByContract;
+
+// Static attribute storage and initialization for CCalibratedFitCommand
+
+static vector<string> SwitchTable;
+
+enum Switches {
+ swCreate,
+ swList,
+ swDelete,
+ swPerform,
+ swAdd,
+ swEvaluate
+};
+
+// Local helper classes used by STL algorithms.
+//
+
+
+/*!
+ Create a list of fits. The list is created in a
+ TCLList but returnable as a string.
+*/
+class CreateListResult
+{
+private:
+ CTCLString& m_listListing;
+ string m_sPattern;
+public:
+ CreateListResult(string sPattern, CTCLString& result);
+
+ bool operator()(pair<string, CCalibFit*> Item);
+ string GetResult();
+ static string FormatFit(string sName, CCalibFit* pFit);
+ static string FormatPoints(CCalibFit* pFit);
+ static string FormatParameters(CCalibFit* pFit);
+
+};
+/*!
+ Construct a fit lister:
+*/
+CreateListResult::CreateListResult(string sPattern,
+ CTCLString& result) :
+ m_listListing(result),
+ m_sPattern(sPattern)
+{
+
+}
+/*!
+ If pattern is matched, add the fit to the listing:
+*/
+
+bool CreateListResult::operator()(pair<string, CCalibFit*> Item)
+{
+ CTCLString name(Item.first);
+ if(name.Match(m_sPattern)) {
+ m_listListing.AppendElement(FormatFit(Item.first, Item.second));
+ }
+}
+/*!
+ Return the current list result string.
+*/
+string
+CreateListResult::GetResult()
+{
+ return m_listListing;
+}
+/*!
+ Format the listing of a fit. Each fit is listed as a TCL list
+ containing:
+ {name state {points} {parameters} }
+
+ - name is the name of the fit.
+ - state is the state of the fit: accepting | performed
+ - points is a list of lists of {x y} points.
+ - parameters is empty ({}) if the fit state is not performed. Otherwise
+ it is a list of the fit parameters in the form {paramname value}.
+
+ \param sName (string)
+ Name of the fit
+ \param pFit (CFit*)
+ Pointer to fit.
+
+*/
+string
+CreateListResult::FormatFit(string sName, CCalibFit* pFit)
+{
+ CTCLString Info;
+ Info.AppendElement(sName);
+ Info.AppendElement(pFit->Type());
+ Info.AppendElement((pFit->GetState() == CCalibFit::Accepting) ?
+ "accepting" : "performed");
+ // The points.
+ Info.AppendElement(FormatPoints(pFit));
+
+
+ // The fit parameters:
+
+ Info.AppendElement(FormatParameters(pFit));
+
+
+ // Done.
+
+ return string((const char*)Info);
+
+}
+/*!
+ Return a TCL formatted list of fit points.
+ \param pFit (CCalibFit*)
+ Pointer to the fit object.
+*/
+string
+CreateListResult::FormatPoints(CCalibFit* pFit)
+{
+ CTCLString Info;
+ CCalibFit::PointIterator i = pFit->begin();
+ while(i != pFit->end()) {
+ char aPoint[100];
+ sprintf(aPoint, "%g %g ", i->x, i->y);
+ Info.AppendElement(aPoint);
+ i++;
+ }
+ return string((const char*)Info);
+}
+/*!
+ Format the Fit parameters into a TCL proper list.
+ \param pFit (CCalibFit*)
+ Pointer to the fit object.
+*/
+string
+CreateListResult::FormatParameters(CCalibFit* pFit)
+{
+ CTCLString Info;
+
+ if(pFit->GetState() == CCalibFit::Performed) { // Otherwise no params.
+ CCalibFit::FitParameterList params = pFit->GetParameters();
+ CCalibFit::FitParameterIterator i = params.begin();
+ while(i != params.end()) {
+ Info.StartSublist();
+ {
+ char Value[100];
+ sprintf(Value, "%g", i->second);
+ Info.AppendElement(i->first);
+ Info.AppendElement(Value);
+ }
+ Info.EndSublist();
+ i++;
+ }
+
+ }
+ return string((const char*)Info);
+}
+
+
+//////////////////////////////// CCalibratedFitCommand Implementation
+
+/*!
+ Create an object of type CCalibratedFitCommand
+
+ \param pInterp (CTCLInterpreter*)
+ The interpreter on which this command is registsered.
+ The command itself is unconditionally registered as 'fit'.
+*/
+CCalibratedFitCommand::CCalibratedFitCommand (CTCLInterpreter* pInterp) :
+ CTCLProcessor("calibrationfit", pInterp)
+{
+ // Stock the switch lookup table:
+
+ if(SwitchTable.empty()) {
+ SwitchTable.push_back("-create");
+ SwitchTable.push_back("-list");
+ SwitchTable.push_back("-delete");
+ SwitchTable.push_back("-perform");
+ SwitchTable.push_back("-add");
+ SwitchTable.push_back("-evaluate");
+ }
+
+}
+
+/*!
+ Called to destroy an instance of CCalibratedFitCommand
+*/
+ CCalibratedFitCommand::~CCalibratedFitCommand ( )
+{
+
+}
+
+/*!
+
+Description:
+
+Gains control when the fit command is to be executed.
+This function simply decodes the first switch and
+dispatches to the appropriate _parse function:
+- -type -> Create_parse
+- -list -> List_parse
+- -delete -> Delete_parse
+- -perform -> Perform_parse
+- -add -> AddPoints_parse
+- -evaluate -> Evaluate_parse
+
+
+
+Parameters:
+
+\param rInterp (CTCLInterpreter& )
+ TCL Interpreter object.
+\param rResult (CTCLResult&)
+ The result string
+\param argc (int)
+ The number of command line parameters. Note that
+ the first parameter is the command name itself.
+\param argv (char**)
+ The parameters.
+
+\return int
+\retval TCL_OK - The command was successful, the result
+ string contains subcommand specific stuff.
+\retval TC_ERROR - The command failed and the result string
+ contains the error message.
+
+
+*/
+int
+CCalibratedFitCommand::operator()(CTCLInterpreter& rInterp, CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // The first parameter is the command name:
+
+ argc--;
+ argv++;
+
+ // The second parameter msut exist. It should be either a
+ // valid switch or alternatively the type of a fit to be
+ // created:
+
+ if(!argc) {
+ rResult = Usage();
+ return TCL_ERROR;
+ }
+ // Now let's figure out what the switch is:
+
+ char* pSubCommand = *argv;
+
+ switch(MatchKeyword(SwitchTable,
+ string(pSubCommand),
+ (int)swCreate)) {
+ case swCreate:
+ if(pSubCommand[0] == '-') { // An actual switch:
+ argc--;
+ argv++;
+ }
+ return Create_parse(rInterp, rResult, argc, argv);
+ case swList:
+ argc--;
+ argv++;
+ return List_parse(rInterp, rResult, argc, argv);
+ case swDelete:
+ argc--;
+ argv++;
+ return Delete_parse(rInterp, rResult, argc, argv);
+ case swPerform:
+ argc--;
+ argv++;
+ return Perform_parse(rInterp, rResult, argc, argv);
+ case swAdd:
+ argc--;
+ argv++;
+ return AddPoints_parse(rInterp, rResult, argc, argv);
+ case swEvaluate:
+ argc--;
+ argv++;
+ return Evaluate_parse(rInterp, rResult, argc, argv);
+ default: // Illegal:
+ argc--;
+ argv++;
+ rResult = Usage();
+ return TCL_ERROR;
+ }
+ // Control should not fall here:
+
+ REQUIRE(0, "Defect in program logic");
+}
+
+/*!
+
+Description:
+
+Parses the command arguments and, if all goes well, calls Create to create a new
+fit object. This division of labor supports testing at low and high levels.
+The form of the command is:
+
+\verbatim
+fit ?-create? fittype fitname
+ o fittype a fit type e.g. linear
+ o fitname the name of a fit.
+\endverbatim
+
+Parameters:
+
+\param rInterp (CTCLInterpreter&)
+ The interpreter object.
+\parm rResult (CTCLResult&)
+ The result object.
+\param argc (int)
+ number of arguments this has been adjusted to
+ eat up both the fit command and the -create switch.
+\param argv (char**)
+ Command line arguments. This has been adjusted to contain only the fit type and name
+(assuming the user's call is correct).
+
+
+
+\return int
+\retval TCK_OK
+\retval TCL_ERROR
+
+Requirements:
+- There are two command line parameters.
+- The fit must not yet exist.
+
+
+
+*/
+int
+CCalibratedFitCommand::Create_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // The requirements are like preconditions with a bit less
+ // force behind them. Instead of an exception, violating one
+ // leads to an error return.
+
+ // Check the number of parameters:
+
+ if(argc != 2) {
+ rResult = Usage();
+ return TCL_ERROR;
+ }
+
+ // Check the name does not yet exist:
+
+ char* pType = argv[0];
+ char* pName = argv[1];
+
+ if(CCalibFitFactory::FindFit(string(pName)) != CCalibFitFactory::end()) {
+ rResult = "Fit: ";
+ rResult += pName;
+ rResult += " already exists";
+ return TCL_ERROR;
+ }
+
+ // Try to create the fit. Any failure is assumed to be because
+ // the fit type was invalid at this point:
+
+ CCalibFit* pFit = CCalibFitFactory::Create(string(pType), string(pName));
+ if(pFit) {
+ rResult = pName;
+ return TCL_OK;
+ }
+ else {
+ rResult = "Failed to create fit: ";
+ rResult += pName;
+ rResult += " probably not a valid type\n";
+ rResult += Usage();
+ return TCL_ERROR;
+ }
+
+ REQUIRE(0, "Program logic error");
+
+}
+
+/*!
+
+Description:
+
+Parses the -list command and passes control to the List function.
+In fact the list function produces a vector describing all fits. This vector is
+filtered by the pattern passed into or defaulted by this command.
+
+
+
+\pre
+
+\post
+
+Parameters:
+
+\param rInterp (CTCLInterpreter&)
+ Intepreter object.
+\param rResult (CTCLResult&)
+ Refers to the result string.
+\param argc (int)
+ count of command line parameters. This has been
+adjusted so that the only remaining parameter is the optional
+pattern. If the pattern exists, it is used to filter the fit names.
+If not, it defaults to "*" which matches all fit names.
+\param argv (char**)
+ Pointers to the parameters. Please look at argc to get an
+idea of what this points to.
+
+\return int
+\retval TCL_OK
+\retval TCL_ERROR
+
+
+
+*/
+int
+CCalibratedFitCommand::List_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // There may be at most one other parameter: The pattern:
+
+ if(argc > 1) {
+ rResult = Usage();
+ return TCL_ERROR;
+ }
+ // Figure out the pattern:
+
+ string Pattern;
+
+ if(argc) {
+ Pattern = *argv;
+ }
+ else {
+ Pattern = "*";
+ }
+
+ // Build up the result list via a for_each loop:
+
+ CTCLString listing;
+ CreateListResult listPredicate(Pattern, listing);
+
+ for_each(CCalibFitFactory::begin(), CCalibFitFactory::end(), listPredicate);
+
+ rResult = listPredicate.GetResult();
+ return TCL_OK;
+}
+
+/*!
+
+Parses the -delete switch and dispatches to the Delete function.
+
+Parameters:
+
+\param rInterp (CTCLInterpreter&)
+ The interpreter executing us.
+\param rResult (CTCLResult&)
+ The result string.
+\param argc (int)
+ Remaining number of command line parameters (after -delete has been eaten)
+\param argv (char**)
+ Remaining command line parameters.
+
+\return int
+\retval TCL_OK
+\retval TCL_ERROR
+
+
+*/
+int
+CCalibratedFitCommand::Delete_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc , char** argv)
+{
+
+ // There must be a single additional parameter, the
+ // name of the fit:
+
+ if(argc != 1) {
+ rResult = Usage();
+ return TCL_ERROR;
+ }
+
+ // To delete a gate requires that it first exist:
+ //
+ string sFitName(*argv);
+ CCalibFitFactory::FitIterator pFit = CCalibFitFactory::FindFit(sFitName);
+ if(pFit != CCalibFitFactory::end()) {
+ if(CCalibFitFactory::Delete(sFitName)) { // Deleted ok.
+ rResult = sFitName;
+ return TCL_OK;
+ }
+ else { // Failed but don't know why.
+ rResult = "Unable to delete fit: ";
+ rResult += sFitName;
+ return TCL_ERROR;
+ }
+ }
+ else { // No such fit:
+ rResult = "Fit: ";
+ rResult += sFitName;
+ rResult += " does not exist!";
+ return TCL_ERROR;
+ }
+
+}
+
+/*!
+
+
+Parses the -perform switch. Then calls Perform which must locate the
+appropriate fit and perform it.
+
+
+
+\param rInterp (CTCLInterpreter&)
+ The interpreter
+\param rResult (CTCLResult&)
+ The result string.
+\param argc (int)
+ The number of parameters after -delete.
+\param argv (char**)
+ Pointer to these parameters
+
+*/
+int
+CCalibratedFitCommand::Perform_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // There must be a parameter; the name of the fit:
+
+ if(argc != 1) {
+ rResult = Usage();
+ return TCL_ERROR;
+ }
+ string sFitName(*argv);
+
+ // The fit must exist:
+
+ CCalibFitFactory::FitIterator pFit = CCalibFitFactory::FindFit(sFitName);
+ if(pFit != CCalibFitFactory::end()) { // Fit exists.
+ // The fit must perform with no error:
+
+ if(CCalibFitFactory::Perform(sFitName)) {
+ CCalibFit* p = pFit->second;
+ rResult = CreateListResult::FormatParameters(p);
+ return TCL_OK;
+ }
+ else { // Fit failed, likely isufficient pts
+ rResult = "Fit: ";
+ rResult += sFitName;
+ rResult += " could not be performed. Probably needs more points";
+ return TCL_ERROR;
+ }
+
+ }
+ else { // Fit does not exist.
+
+ rResult = "Fit: ";
+ rResult += sFitName;
+ rResult += " does not exist";
+ return TCL_ERROR;
+ }
+}
+
+/*!
+
+Description:
+
+Parses the fit -add command. This command adds points
+to the fit, by parsing the points on the command line and repeatedly
+calling AddPoint to add each point to the fit.
+
+
+
+\param rInterp (CTCLInterpreter&)
+ Interpreter object.
+\param rResult (CTCLResult&)
+ The TCL interpreter result string.
+\param argc (int)
+ number of command line parameters after the -delete switch
+\param argv (char**)
+ The parameters after the -delete switch.
+
+
+\return int
+\retval TCL_OK
+\retval TCL_ERROR
+
+
+*/
+int
+CCalibratedFitCommand::AddPoints_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // There must be at least two additional parameters...
+ // A fit name and a point to add
+ //
+ if(argc < 2) {
+ rResult = Usage();
+ return TCL_ERROR;
+ }
+
+ // The fit must exist:
+
+ string sFitName(*argv);
+ CCalibFitFactory::FitIterator p = CCalibFitFactory::FindFit(sFitName);
+ if(p == CCalibFitFactory::end()) {
+ rResult = "Fit: ";
+ rResult += sFitName;
+ rResult += " does not exist";
+ return TCL_ERROR;
+ }
+ argc--;
+ argv++;
+
+ // All the remaining parameters must be 2 element lists
+ // containing pairs of values that parse as doubles.
+ //
+
+ vector<FPoint> vPoints;
+ try {
+ vPoints = ParsePoints(rInterp, argc, argv);
+ }
+ catch (string failed) { // Points parse failed.
+ rResult = "Fit points must be pairs of doubles and: ";
+ rResult += failed;
+ rResult += " is not.";
+ return TCL_ERROR;
+ }
+ // Now we have enough stuff to ask for the points to be
+ // added:
+
+ if(CCalibFitFactory::AddPoints(sFitName, vPoints)) { // OK!
+ rResult = sFitName;
+ return TCL_OK;
+ }
+ else { // Failed!
+ rResult = "Unable to add points to ";
+ rResult += sFitName;
+ return TCL_ERROR;
+ }
+ rResult = "BUG report that control fell through to the end of CCalibratedFitCommand::AddPoints";
+ return TCL_ERROR;
+}
+
+/*!
+
+Description:
+
+Parses the -evaluate subcommand.
+This command accpts a fit name and an x coordinate
+and invokes the Evaluate function to evaluate the
+fit at that x coordinate. Note that this can fail if
+the fit is in the adding points state.
+
+Parameters:
+
+\param rInterp (CTCLInterpreter&)
+ The interpreter object executing this command.
+\param rResult (CTCLResult&)
+ The interpreter result string.
+\param argc (int)
+ The number of parameters after the -delete command.
+\param argv (char**)
+ The parameters after the delete command.
+
+*/
+int
+CCalibratedFitCommand::Evaluate_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult, int argc,
+ char** argv)
+{
+ // There must be exactly two parameters, a fit name and
+ // a point:
+
+ if(argc != 2) {
+ rResult = Usage();
+ return TCL_ERROR;
+ }
+ string sFitName(*argv);
+ argc--;
+ argv++;
+ string sPoint(*argv);
+
+ // The point must evaluate to a double precision value:
+
+ DFloat_t dPoint;
+ try {
+ dPoint = rInterp.ExprDouble(sPoint);
+ }
+ catch (CTCLException& rExcept) {
+ rResult = "Point value: ";
+ rResult += sPoint;
+ rResult += " does not evaluate to a double expression";
+ return TCL_ERROR;
+ }
+ // Now evaulate the fit:
+
+
+ try {
+ DFloat_t dResult = CCalibFitFactory::Evaluate(sFitName, dPoint);
+ char sResult[100];
+ sprintf(sResult, "%g", dResult);
+ rResult = sResult;
+ return TCL_OK;
+ }
+ catch(...) { // Failed.
+ rResult = "Evaluation of fit: ";
+ rResult += sFitName;
+ rResult += " @ ";
+ rResult += sPoint;
+ rResult += " failed. Fit may not have been performed yet.";
+ return TCL_ERROR;
+ }
+
+}
+
+/*!
+
+Description:
+
+Return the usage of the fit command as a string.
+
+\pre
+
+\post
+
+Parameters:
+
+\return string
+\return string
+\retval the reason the fit failed.
+
+\throw
+
+Pseudo code:
+
+\verbatim
+
+\endverbatim
+
+*/
+string
+CCalibratedFitCommand::Usage()
+{
+ string sUsage("Usage:\n");
+ sUsage += " calibrationfit ?-create? type name\n";
+ sUsage += " calibrationfit -list ?pattern?\n";
+ sUsage += " calibrationfit -delete name\n";
+ sUsage += " calibrationfit -perform name\n";
+ sUsage += " calibrationfit -add name point1 ?point2...?\n";
+ sUsage += " calibrationfit -evaluate name x\n";
+ sUsage += "\n";
+ sUsage += "Where:\n";
+ sUsage += " `type' is the type of calibrationfit to create (see below)\n";
+ sUsage += " `name' is the name of the calibrationfit to create or manipulate\n";
+ sUsage += " `pattern' Is a pattern to match in listing calibrationfits.\n";
+ sUsage += " `pointn' are pairs of floating point numbers that\n";
+ sUsage += " are independent and dependent values that\n";
+ sUsage += " are the data points to be calibrationfit.\n";
+ sUsage += " `x' Is a value to evaluate with the calibrationfit function\n";
+ sUsage += "\n";
+ sUsage += "And the valid calibrationfit types are:\n";
+ CCalibFitFactory::FitCreatorIterator i = CCalibFitFactory::beginCreators();
+ while(i != CCalibFitFactory::endCreators()) {
+ CCalibFitCreator* pCreator = i->second;
+ sUsage += " ";
+ sUsage += i->first;
+ sUsage += " - ";
+ sUsage += pCreator->DescribeFit();
+ sUsage += "\n";
+ i++;
+ }
+ return sUsage;
+}
+
+
+// Private utilities:
+
+/*!
+ Parse a set of parameters where each parameters is supposed to
+ contain a two element list containing two doubles. If the
+ parse fails, a string exception is thrown where the value of the
+ string is the parameter the parse failed on.
+
+ \param rInterp (CTCLInterpreter& rInterp)
+ Refers to a TCL interpreter that can be used to assist the
+ parse.
+ \param argc (int)
+ Number of parameters to parse.
+ \param argv (char**)
+ List of parameters to parse.
+
+
+ \return vector<FPoint>
+ Each element of the vector is a parsed pair.
+
+*/
+vector<FPoint>
+CCalibratedFitCommand::ParsePoints(CTCLInterpreter& rInterp,
+ int argc, char** argv)
+{
+ FPoint p;
+ vector<FPoint> ParsedList;
+
+ // Each point is processed in the loop below:
+
+ for(int i =0; i < argc; i++) {
+ CTCLList lPoint(&rInterp, argv[i]);
+ try {
+ StringArray s;
+ int i = lPoint.Split(s);
+ if((i != TCL_OK) ||
+ (s.size() != 2)) { // Each parameter mb. a 2 element list
+ throw string(argv[i]);
+ }
+ else {
+ p = FPoint(rInterp.ExprDouble(s[0]),
+ rInterp.ExprDouble(s[1]));
+ ParsedList.push_back(p);
+ }
+ }
+ catch(...) { // Turn any exceptions into a string...
+ string FailedParam(argv[i]);
+ throw FailedParam;
+ }
+ }
+ return ParsedList;
+}
Deleted: tags/calibparams-1.0-003/CCalibratedParameter.cpp
===================================================================
--- trunk/plugins/calibparams/CCalibratedParameter.cpp 2012-11-11 23:56:02 UTC (rev 2050)
+++ tags/calibparams-1.0-003/CCalibratedParameter.cpp 2012-12-24 19:56:53 UTC (rev 2053)
@@ -1,231 +0,0 @@
-
-
-/*
- Implementation file for CCalibratedParameter for a description of the
- class see CCalibratedParameter.h
-*/
-
-////////////////////////// FILE_NAME.cpp ///////////////////////////
-
-// Include files required:
-
-#include <config.h>
-#include "CCalibratedParameter.h"
-#include "CFit.h"
-#include <stdlib.h>
-
-#include <Event.h> // Required to set/get event values.
-
-#ifdef HAVE_STD_NAMESPACE
-using namespace std;
-#endif
-
-// Design by contract provides support for precondition, postcondition,
-// and invariance assertsions.
-//
-#include <DesignByContract.h>
-using namespace DesignByContract;
-
-// Static attribute storage and initialization for CCalibratedParameter
-
-/*!
- Create an object of type CCalibratedParameter
- \pre The fit pointer must not be null.
- \post The source parameter id member is positive.
- \post The target parameter id member is positive.
-*/
-CCalibratedParameter::CCalibratedParameter (int nTargetId, int nRawId,
- string sFitName, CFit* pFit)
- : m_nParameterId(nRawId),
- m_nTargetParameterId(nTargetId),
- m_sFitName(sFitName),
- m_pFit(0)
-
-
-{
- REQUIRE(pFit, "Fit pointer is null!");
- m_pFit = pFit->clone();
-
- ENSURE(m_nParameterId >= 0, "Source parameter id negative!");
- ENSURE(m_nTargetParameterId >= 0," Target parameter id negative");
-
-}
-
-/*!
- Called to destroy an instance of CCalibratedParameter
- \pre m_pFit is not null..
-*/
- CCalibratedParameter::~CCalibratedParameter ( )
-{
- REQUIRE(m_pFit, "Fit pointer became null somehow");
- delete m_pFit;
- m_pFit = (CFit*)NULL;
-}
-/*!
- Called to create an instance of CCalibratedParameter that is a
- functional duplicate of another instance.
- \param rSource (const CCalibratedParameter& ):
- The object that we will dupliate.
- \pre The RHS fit pointer is not null.
-*/
-CCalibratedParameter::CCalibratedParameter (const CCalibratedParameter& rhs) :
- m_nParameterId(rhs.m_nParameterId),
- m_nTargetParameterId(rhs.m_nTargetParameterId),
- m_sFitName(rhs.m_sFitName),
- m_pFit(0)
-{
- REQUIRE(rhs.m_pFit, "RHS Fit pointer is null");
- m_pFit = rhs.m_pFit->clone();
-}
-/*!
- Assign to *this from rhs so that *this becomes a functional
- duplicate of rhs.
- \param rhs (const CCalibratedParameter& rhs ):
- The object that will be functionally copied to *this.
-
- \pre RHS fit pointer is not null
- */
-CCalibratedParameter&
-CCalibratedParameter::operator= (const CCalibratedParameter& rhs)
-{
- REQUIRE(rhs.m_pFit, "RHS Fit pointer is null");
-
- if(this != &rhs) {
- m_nParameterId = rhs.m_nParameterId;
- m_nTargetParameterId = rhs.m_nTargetParameterId;
- m_sFitName = rhs.m_sFitName;
- delete m_pFit;
- m_pFit = (CFit*)NULL;
- m_pFit = rhs.m_pFit->clone();
- }
- return *this;
-
-}
-/*!
- Compare *this for functional equality with another object of
- type CCalibratedParameter.
- \param rhs (const CCalibratedParameter& rhs ):
- The object to be compared with *this.
-
- \pre this->m_pFit is not null.
- \pre rhs.m_pFit is not null.
- */
-int
-CCalibratedParameter::operator== (const CCalibratedParameter& rhs) const
-{
- REQUIRE(m_pFit, "My Fit pointer is null");
- REQUIRE(rhs.m_pFit, "RHS Fit pointer is null");
-
- return (
- (m_nParameterId == rhs.m_nParameterId) &&
- (m_nTargetParameterId == rhs.m_nTargetParameterId) &&
- (m_sFitName == rhs.m_sFitName) &&
- (*m_pFit == *(rhs.m_pFit) )
- );
-}
-/*!
- Compare *this for functional inequality with another object
- of type CCalibratedParameter. Functional inequality is defined as
- the boolean inverse of functional equality.
- \param rhs (const CCalibratedParameter& rhs ):
- The object to compare with *this.
-
- \pre Preconditions are inherited from operator== see that function
- for details.
-*/
-int
-CCalibratedParameter::operator!= (const CCalibratedParameter& rhs) const
-{
- return !(*this == rhs);
-}
-
-// Functions for class CCalibratedParameter
-
-/*!
-
-Description:
-
-Calcluates the resulting parameter
-from the corresponding raw parameter
-
-
-\pre m_pFit != (CFit*)NULL
-\pre m_nParameterId is positive.
-\pre m_nTargetParameterId is positive.
-
-Parameters:
-
-\param rEvent (CEvent&)
- The event which is being operated on.
-
-\return void
-
-Pseudo code:
-
-\verbatim
-If Raw parameter is valid & Fit is performedTHEN
- Calibrated paramter = m_pFit(raw parameter value)
-ENDIF
-\endverbatim
-
-*/
-void
-CCalibratedParameter::operator()(CEvent& rEvent) const
-{
- REQUIRE(m_pFit, "Fit pointer is null");
- REQUIRE(m_nParameterId >= 0, "Source parameter id negative!");
- REQUIRE(m_nTargetParameterId >= 0," Target parameter id negative");
-
- if(rEvent[m_nParameterId].isValid() &&
- (m_pFit->GetState() == CFit::Performed)) {
- double input = (double)(rEvent[m_nParameterId]) +
- (drand48() - 0.5); // undescretize the input.
- rEvent[m_nTargetParameterId] = (ParamType)(*m_pFit)(input);
-
- }
-}
-
-/*!
-
-Description:
-
-Replaces the current fit with a new fit.
-The fit passed in is cloned to create a local
-copy. In this way, if the actual fit is deleted, we still
-compute the parameter.
-
-\pre Current fit pointers is not null
-
-\post Current fit pointer is not null, and final fit == source fit.
-
-Parameters:
-
-\param rNewFit (const CFit&)
- Reference to the new fit.
-
-\return CFit*
-
-\throw
-
-Pseudo code:
-
-\verbatim
-temp <- m_pFit
-m_pFit = clone CFit(rNewFit)
-return temp
-\endverbatim
-
-*/
-CFit*
-CCalibratedParameter::ReplaceFit(CFit& rFit)
-{
- REQUIRE(m_pFit, "My fit pointer became null");
-
- CFit* pFit = m_pFit;
- m_pFit = (CFit*)NULL; // Safety.
- m_pFit = rFit.clone();
-
- ENSURE(m_pFit, "My fit pointer cloned to null");
- ENSURE(*m_pFit == rFit, "Cloned fit pointer != source");
- return pFit;
-}
Copied: tags/calibparams-1.0-003/CCalibratedParameter.cpp (from rev 2052, trunk/plugins/calibparams/CCalibratedParameter.cpp)
===================================================================
--- tags/calibparams-1.0-003/CCalibratedParameter.cpp (rev 0)
+++ tags/calibparams-1.0-003/CCalibratedParameter.cpp 2012-12-24 19:56:53 UTC (rev 2053)
@@ -0,0 +1,231 @@
+
+
+/*
+ Implementation file for CCalibratedParameter for a description of the
+ class see CCalibratedParameter.h
+*/
+
+////////////////////////// FILE_NAME.cpp ///////////////////////////
+
+// Include files required:
+
+#include <config.h>
+#include "CCalibratedParameter.h"
+#include "./CFit.h"
+#include <stdlib.h>
+
+#include <Event.h> // Required to set/get event values.
+
+#ifdef HAVE_STD_NAMESPACE
+using namespace std;
+#endif
+
+// Design by contract provides support for precondition, postcondition,
+// and invariance assertsions.
+//
+#include <DesignByContract.h>
+using namespace DesignByContract;
+
+// Static attribute storage and initialization for CCalibratedParameter
+
+/*!
+ Create an object of type CCalibratedParameter
+ \pre The fit pointer must not be null.
+ \post The source parameter id member is positive.
+ \post The target parameter id member is positive.
+*/
+CCalibratedParameter::CCalibratedParameter (int nTargetId, int nRawId,
+ string sFitName, CCalibFit* pFit)
+ : m_nParameterId(nRawId),
+ m_nTargetParameterId(nTargetId),
+ m_sFitName(sFitName),
+ m_pFit(0)
+
+
+{
+ REQUIRE(pFit, "Fit pointer is null!");
+ m_pFit = pFit->clone();
+
+ ENSURE(m_nParameterId >= 0, "Source parameter id negative!");
+ ENSURE(m_nTargetParameterId >= 0," Target parameter id negative");
+
+}
+
+/*!
+ Called to destroy an instance of CCalibratedParameter
+ \pre m_pFit is not null..
+*/
+ CCalibratedParameter::~CCalibratedParameter ( )
+{
+ REQUIRE(m_pFit, "Fit pointer became null somehow");
+ delete m_pFit;
+ m_pFit = (CCalibFit*)NULL;
+}
+/*!
+ Called to create an instance of CCalibratedParameter that is a
+ functional duplicate of another instance.
+ \param rSource (const CCalibratedParameter& ):
+ The object that we will dupliate.
+ \pre The RHS fit pointer is not null.
+*/
+CCalibratedParameter::CCalibratedParameter (const CCalibratedParameter& rhs) :
+ m_nParameterId(rhs.m_nParameterId),
+ m_nTargetParameterId(rhs.m_nTargetParameterId),
+ m_sFitName(rhs.m_sFitName),
+ m_pFit(0)
+{
+ REQUIRE(rhs.m_pFit, "RHS Fit pointer is null");
+ m_pFit = rhs.m_pFit->clone();
+}
+/*!
+ Assign to *this from rhs so that *this becomes a functional
+ duplicate of rhs.
+ \param rhs (const CCalibratedParameter& rhs ):
+ The object that will be functionally copied to *this.
+
+ \pre RHS fit pointer is not null
+ */
+CCalibratedParameter&
+CCalibratedParameter::operator= (const CCalibratedParameter& rhs)
+{
+ REQUIRE(rhs.m_pFit, "RHS Fit pointer is null");
+
+ if(this != &rhs) {
+ m_nParameterId = rhs.m_nParameterId;
+ m_nTargetParameterId = rhs.m_nTargetParameterId;
+ m_sFitName = rhs.m_sFitName;
+ delete m_pFit;
+ m_pFit = (CCalibFit*)NULL;
+ m_pFit = rhs.m_pFit->clone();
+ }
+ return *this;
+
+}
+/*!
+ Compare *this for functional equality with another object of
+ type CCalibratedParameter.
+ \param rhs (const CCalibratedParameter& rhs ):
+ The object to be compared with *this.
+
+ \pre this->m_pFit is not null.
+ \pre rhs.m_pFit is not null.
+ */
+int
+CCalibratedParameter::operator== (const CCalibratedParameter& rhs) const
+{
+ REQUIRE(m_pFit, "My Fit pointer is null");
+ REQUIRE(rhs.m_pFit, "RHS Fit pointer is null");
+
+ return (
+ (m_nParameterId == rhs.m_nParameterId) &&
+ (m_nTargetParameterId == rhs.m_nTargetParameterId) &&
+ (m_sFitName == rhs.m_sFitName) &&
+ (*m_pFit == *(rhs.m_pFit) )
+ );
+}
+/*!
+ Compare *this for functional inequality with another object
+ of type CCalibratedParameter. Functional inequality is defined as
+ the boolean inverse of functional equality.
+ \param rhs (const CCalibratedParameter& rhs ):
+ The object to compare with *this.
+
+ \pre Preconditions are inherited from operator== see that function
+ for details.
+*/
+int
+CCalibratedParameter::operator!= (const CCalibratedParameter& rhs) const
+{
+ return !(*this == rhs);
+}
+
+// Functions for class CCalibratedParameter
+
+/*!
+
+Description:
+
+Calcluates the resulting parameter
+from the corresponding raw parameter
+
+
+\pre m_pFit != (CCalibFit*)NULL
+\pre m_nParameterId is positive.
+\pre m_nTargetParameterId is positive.
+
+Parameters:
+
+\param rEvent (CEvent&)
+ The event which is being operated on.
+
+\return void
+
+Pseudo code:
+
+\verbatim
+If Raw parameter is valid & Fit is performedTHEN
+ Calibrated paramter = m_pFit(raw parameter value)
+ENDIF
+\endverbatim
+
+*/
+void
+CCalibratedParameter::operator()(CEvent& rEvent) const
+{
+ REQUIRE(m_pFit, "Fit pointer is null");
+ REQUIRE(m_nParameterId >= 0, "Source parameter id negative!");
+ REQUIRE(m_nTargetParameterId >= 0," Target parameter id negative");
+
+ if(rEvent[m_nParameterId].isValid() &&
+ (m_pFit->GetState() == CCalibFit::Performed)) {
+ double input = (double)(rEvent[m_nParameterId]) +
+ (drand48() - 0.5); // undescretize the input.
+ rEvent[m_nTargetParameterId] = (ParamType)(*m_pFit)(input);
+
+ }
+}
+
+/*!
+
+Description:
+
+Replaces the current fit with a new fit.
+The fit passed in is cloned to create a local
+copy. In this way, if the actual fit is deleted, we still
+compute the parameter.
+
+\pre Current fit pointers is not null
+
+\post Current fit pointer is not null, and final fit == source fit.
+
+Parameters:
+
+\param rNewFit (const CCalibFit&)
+ Reference to the new fit.
+
+\return CCalibFit*
+
+\throw
+
+Pseudo code:
+
+\verbatim
+temp <- m_pFit
+m_pFit = clone CCalibFit(rNewFit)
+return temp
+\endverbatim
+
+*/
+CCalibFit*
+CCalibratedParameter::ReplaceFit(CCalibFit& rFit)
+{
+ REQUIRE(m_pFit, "My fit pointer became null");
+
+ CCalibFit* pFit = m_pFit;
+ m_pFit = (CCalibFit*)NULL; // Safety.
+ m_pFit = rFit.clone();
+
+ ENSURE(m_pFit, "My fit pointer cloned to null");
+ ENSURE(*m_pFit == rFit, "Cloned fit pointer != source");
+ return pFit;
+}
Deleted: tags/calibparams-1.0-003/CCalibratedParameter.h
===================================================================
--- trunk/plugins/calibparams/CCalibratedParameter.h 2012-11-11 23:56:02 UTC (rev 2050)
+++ tags/calibparams-1.0-003/CCalibratedParameter.h 2012-12-24 19:56:53 UTC (rev 2053)
@@ -1,97 +0,0 @@
-
-
-// Author:
-// Ron Fox
-// NSCL
-// Michigan State University
-// East Lansing, MI 48824-1321
-// mailto:fox@...
-//
-// Copyright
-//! \class: CCalibratedParameter
-//! \file: .h
-/*!
- \class CCalibratedParameter
-
- A calibrated parameter is a parameter that is
- related to a raw parameter via a fit. For each
- event, the calibrated parameter is computed by
- evaluating the calibrated parameter's fit with respect
- to a raw parameter.
-
-*/
-
-
-#ifndef __CCALIBRATEDPARAMETER_H //Required for current class
-#define __CCALIBRATEDPARAMETER_H
-
-//
-// Include files:
-//
-
-#ifndef __STL_STRING
-#include <string> //Required for include files
-#ifndef __STL_STRING
-#define __STL_STRING
-#endif
-#endif
-
-#ifndef __HISTOTYPES_H
-#include <histotypes.h> //Required for include files
-#endif
-
-
-// Forward class definitions (convert to includes if required):
-
-class CFit;
-class CEvent;
-
-// The class interface
-
-class CCalibratedParameter
-{
-private:
-
- // Private Member data:
- int m_nParameterId; //!< Id of parameter raw parameter we calibrate..
- int m_nTargetParameterId; //!< Id of resulting parameter.
- STD(string) m_sFitName; //!< Name of fit that's set on us.
-
- CFit* m_pFit; //!< 1:1 association object data member
-
-public:
- // Constructors and other canonical operations.
- CCalibratedParameter (int nTargetId,
- int nRawId,
- STD(string) sFitName,
- CFit* pFit); //!< Constructor.
- virtual ~ CCalibratedParameter ( ); //!< Destructor.
- CCalibratedParameter (const CCalibratedParameter& rSource ); //!< Copy construction.
- CCalibratedParameter&
- operator= (const CCalibratedParameter& rhs); //!< Assignment.
- int operator== (const CCalibratedParameter& rhs) const; //!< == comparison.
- int operator!= (const CCalibratedParameter& rhs) const; //!< != comparison.
-
-
-
-public:
- int getTargetId() const {
- return m_nTargetParameterId;
- }
- int getRawId() const {
- return m_nParameterId;
- }
- STD(string) getFitName() const {
- return m_sFitName;
- }
- const CFit* getFit() const {
- return m_pFit;
- }
-
-public:
-
- void operator() (CEvent& rEvent) const ; //!< Evaluate the calibration
- CFit* ReplaceFit (CFit& rFit) ; //!< Set a new fit (name is fixed).
-};
-
-#endif
Copied: tags/calibparams-1.0-003/CCalibratedParameter.h (from rev 2052, trunk/plugins/calibparams/CCalibratedParameter.h)
===================================================================
--- tags/calibparams-1.0-003/CCalibratedParameter.h (rev 0)
+++ tags/calibparams-1.0-003/CCalibratedParameter.h 2012-12-24 19:56:53 UTC (rev 2053)
@@ -0,0 +1,97 @@
+
+
+// Author:
+// Ron Fox
+// NSCL
+// Michigan State University
+// East Lansing, MI 48824-1321
+// mailto:fox@...
+//
+// Copyright
+//! \class: CCalibratedParameter
+//! \file: .h
+/*!
+ \class CCalibratedParameter
+
+ A calibrated parameter is a parameter that is
+ related to a raw parameter via a fit. For each
+ event, the calibrated parameter is computed by
+ evaluating the calibrated parameter's fit with respect
+ to a raw parameter.
+
+*/
+
+
+#ifndef __CCALIBRATEDPARAMETER_H //Required for current class
+#define __CCALIBRATEDPARAMETER_H
+
+//
+// Include files:
+//
+
+#ifndef __STL_STRING
+#include <string> //Required for include files
+#ifndef __STL_STRING
+#define __STL_STRING
+#endif
+#endif
+
+#ifndef __HISTOTYPES_H
+#include <histotypes.h> //Required for include files
+#endif
+
+
+// Forward class definitions (convert to includes if required):
+
+class CCalibFit;
+class CEvent;
+
+// The class interface
+
+class CCalibratedParameter
+{
+private:
+
+ // Private Member data:
+ int m_nParameterId; //!< Id of parameter raw parameter we calibrate..
+ int m_nTargetParameterId; //!< Id of resulting parameter.
+ STD(string) m_sFitName; //!< Name of fit that's set on us.
+
+ CCalibFit* m_pFit; //!< 1:1 association object data member
+
+public:
+ // Constructors and other canonical operations.
+ CCalibratedParameter (int nTargetId,
+ int nRawId,
+ STD(string) sFitName,
+ CCalibFit* pFit); //!< Constructor.
+ virtual ~ CCalibratedParameter ( ); //!< Destructor.
+ CCalibratedParameter (const CCalibratedParameter& rSource ); //!< Copy construction.
+ CCalibratedParameter&
+ operator= (const CCalibratedParameter& rhs); //!< Assignment.
+ int operator== (const CCalibratedParameter& rhs) const; //!< == comparison.
+ int operator!= (const CCalibratedParameter& rhs) const; //!< != comparison.
+
+
+
+public:
+ int getTargetId() const {
+ return m_nTargetParameterId;
+ }
+ int getRawId() const {
+ return m_nParameterId;
+ }
+ STD(string) getFitName() const {
+ return m_sFitName;
+ }
+ const CCalibFit* getFit() const {
+ return m_pFit;
+ }
+
+public:
+
+ void operator() (CEvent& rEvent) const ; //!< Evaluate the calibration
+ CCalibFit* ReplaceFit (CCalibFit& rFit) ; //!< Set a new fit (name is fixed).
+};
+
+#endif
Deleted: tags/calibparams-1.0-003/CCalibratedParameterCommand.cpp
===================================================================
--- trunk/plugins/calibparams/CCalibratedParameterCommand.cpp 2012-11-11 23:56:02 UTC (rev 2050)
+++ tags/calibparams-1.0-003/CCalibratedParameterCommand.cpp 2012-12-24 19:56:53 UTC (rev 2053)
@@ -1,1061 +0,0 @@
-
-
-/*
- Implementation file for CCalibratedParameterCommand for a description of the
- class see CCalibratedParameterCommand.h
-*/
-
-////////////////////////// FILE_NAME.cpp ///////////////////////////
-
-
-// Include files required:
-
-#include <config.h>
-#include "CCalibratedParameterCommand.h"
-#include "CCalibratedParameterManager.h"
-#include "CCalibratedParameter.h"
-#include "CFit.h"
-#include "CFitFactory.h"
-
-#include <TCLInterpreter.h>
-#include <TCLResult.h>
-#include <TCLException.h>
-#include <TCLString.h>
-#include <Histogrammer.h>
-#include <Parameter.h>
-#include <Globals.h>
-
-#include <DesignByContract.h>
-
-#include <vector>
-#include <stdio.h>
-
-#ifdef HAVE_STD_NAMESPACE
-using namespace std;
-#endif
-
-
-using namespace DesignByContract;
-
-
-// Static attribute storage and initialization for CCalibratedParameterCommand
-
-static vector<string> SwitchTable;
-enum Switches {
- swCreate,
- swList,
- swDelete,
- swUpdate };
-
-// Helper class to build up a list of formatted calibrated parameters.
-
-class Format {
-private:
- CTCLString& m_rResult;
- string m_Pattern;
-public:
- Format(CTCLString& rResult, string pattern) :
- m_rResult(rResult),
- m_Pattern(pattern)
- {}
- void operator()(CCalibratedParameterManager::MapEntry entry)
- {
- REQUIRE(entry.second, "Null Parameter in map entry");
- if(Tcl_StringMatch(entry.first.c_str(), m_Pattern.c_str())) {
- string name = entry.first;
- CCalibratedParameter* pParam = entry.second;
-
- string item(CCalibratedParameterCommand::FormatParameter(name,
- *pParam));
- m_rResult.AppendElement(item);
-
- }
- }
-};
-// Helper class to update calibrated parameters with new fits.
-
-class Updater {
-private:
- string m_Pattern;
-public:
- Updater(string Pattern) :
- m_Pattern(Pattern) {}
- void operator()(CCalibratedParameterManager::MapEntry entry)
- {
- REQUIRE(entry.second, "Null parameter in map entry");
- if(Tcl_StringMatch(entry.first.c_str(), m_Pattern.c_str())) {
- CCalibratedParameter* pParam = entry.second;
- CFitFactory::FitIterator
- pF = CFitFactory::FindFit(pParam->getFitName());
- if(pF != CFitFactory::end()) {
- CFit* pFit = pF->second;
- if(pFit->GetState() == CFit::Performed) {
- CFit* p = pParam->ReplaceFit(*pFit);
- delete p;
- }
- }
-
- }
- }
-};
-/*!
- Create an object of type CCalibratedParameterCommand
- \post m_pHistogrammer is not null.
-*/
-CCalibratedParameterCommand::CCalibratedParameterCommand
- (CTCLInterpreter* pInterp) :
- CTCLProcessor("calibparam", pInterp),
- m_pHistogrammer(0)
-
-{
- // Set up the switch table vector.
-
- if (SwitchTable.empty()) {
- SwitchTable.push_back("-create");
- SwitchTable.push_back("-list");
- SwitchTable.push_back("-delete");
- SwitchTable.push_back("-refresh");
- }
-
- // Locate the histogrammer and save it in the
- // member variable.
-
- m_pHistogrammer = (CHistogrammer*)gpEventSink;
- ENSURE(m_pHistogrammer, "NULL Histogrammer pointer.");
-}
-
-/*!
- Called to destroy an instance of CCalibratedParameterCommand
-*/
- CCalibratedParameterCommand::~CCalibratedParameterCommand ( )
-{
-}
-
-// Functions for class CCalibratedParameterCommand
-
-/*!
-
-Description:
-
-Does a top level parse and dispatch of
-commands. The command is parsed
-ito its function and dispatched.
-
-
-Parameters:
-
-\param rInterp (CTCLInterpreter&)
- Reference to the interpreter that's executing
- this command.
-\param rResult (CTCLResult&)
- Reference to the interpreter result.
-\param argc (int)
- Number of command line parameters.
- Note that the command itself is
- included in this.
-\param argv (char**)
- The command line parameter.
-
-
-\return int
-\retval TCL_OK
- Function completed successfully.
- The contents of rResult will depend on the
- function.
-\retval TCL_ERROR
- Function failed. rResult will be an error message.
-Pseudo code:
-
-\verbatim
-Operation = argv[1]
-Opcode = MatchKeyword(Operation)
-
-if (Opcode == Create) {
- return Create_Parse(rInterp, rResult, remaining argc, remaining argv)
-}
-if (Opcode == List) {
- return List_Parse(rInterp, rResult, remainng argc, remaining argv)
-}
-if(Opcode == Delete) {
- return List_Parse(rInterp, rResult, remaining argc, remaining argv)
-}
-if(Opcode == Update) {
- return Update_Parse(rInterp, RResult, remaining argc, remaining argv)
-}
-if(Opcode == Create) {
- return Create_Parse(rInterp, rResult, remaining argc, remaining argv)
-}
-if(OpCode == unrecognized)
- return Create_Parse(rInterp, rResult, argc, argv)
-}
-FAIL
-\endverbatim
-
-*/
-int
-CCalibratedParameterCommand::operator()(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc, char** argv)
-{
- // The first parameter is the command itself and that can be ignored:
-
- NextParam(argc,argv);
-
- // There must be at least one parameter, either a command keyword,
- // or in the case of a create, the name of the target:
-
- if(!argc) {
- rResult = "Insufficient parameters: \n";
- rResult += Usage();
- return TCL_ERROR;
- }
-
- // Pull out the the dispatch switch. Note that the lack of a
- // recognized switch is equivalent to create.
-
- string Switch(argv[0]);
-
- switch (MatchKeyword(SwitchTable, Switch, (int) swCreate)) {
- case swCreate:
- if (Switch[0] == '-') { // The switch, not a default case.
- NextParam(argc,argv);
- }
- return Create_parse(rInterp, rResult, argc, argv);
- case swList:
- NextParam(argc,argv);
- return List_parse(rInterp, rResult, argc, argv);
- case swDelete:
- NextParam(argc,argv);
- return Delete_parse(rInterp, rResult, argc, argv);
- case swUpdate:
- NextParam(argc,argv);
- return Update_parse(rInterp, rResult, argc, argv);
- default:
- ENSURE(0, "Invalid switch: impossible condition");
- }
- ENSURE(0, "Fell past switch, impossible condition");
- rResult = "Defect in CCalibratedParameterCommand::operator()";
- return TCL_ERROR;
-}
-
-/*!
-
-Description:
-
-Parses the Create command and reports any
-parsing errors to the caller. If the parse is
-successful, Create is called to do the actual
-creation of a new calibrated parameter.
-
-
-
-Parameters:
-
-\param rInterp (CTCLInterpreter&)
- Reference to the interpreter that's executing
- this command.
-\param rResult (CTCLResult&)
- Reference to the interpreter result.
-\param argc (int)
- Number of command line parameters.
- Note that the command itself is
- included in this.
-\param argv (char**)
- The command line parameter.
-
-\return int
-\retval TCL_OK
- - Parse was correct.
- - Create returned TCL_OK.
-\retval TCL_ERROR
- - Parse failed OR
- - Create returned an error.
-
-Pseudo code:
-
-\verbatim
-targetname = argv[0]
-targetid = argv[1]
-rawname = argv[2]
-fitname = argv[3]
-
-If (argc == 5) {
- units = argv[4]
-} else
- units = ""
-}
-
-status = Create(message, targetname, targetid, rawname, fitname, units)
-rResult = message
-return status
-\endverbatim
-
-*/
-int
-CCalibratedParameterCommand::Create_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc, char** argv)
-{
- // There must be 4 or 5 parameters on the command line:
-
- if ((argc != 4) && (argc != 5)) {
- rResult = "Improper number of parmeters on command line";
- rResult += Usage();
- return TCL_ERROR;
- }
- // The first 4 are clear:
-
- string targetname = argv[0];
- string targetid = argv[1];
- string rawname = argv[2];
- string fitname = argv[3];
-
- // The last one is there only if the user supplies units:
-
- string units="";
- if (argc == 5) {
- units = argv[4];
- }
- // The target id must parse to an integer (long):
- Long_t nTargetId;
- try {
- nTargetId = rInterp.ExprLong(targetid);
- } catch (CTCLException& e) {
- rResult = "Target Id is not an integer and must be: ";
- rResult += e.ReasonText();
- rResult += "\n";
- rResult += Usage();
- return TCL_ERROR;
- }
- // Now that we have a good parse we let Create do the rest:
-
- string Result;
- int status = Create(Result, targetname, (int)nTargetId, rawname, fitname, units);
- rResult = Result;
- return status;
-
-}
-
-/*!
-
-Description:
-
-Parses the list command. If the parse is succesful,
-invokes List to do the listing. Parse failures
-will result in an error return and will also leave
-an error message and usage in the rResult parameter
-
-
-Parameters:
-
-\param rInterp (CTCLInterpreter&)
- Reference to the interpreter that's executing
- this command.
-\param rResult (CTCLResult&)
- Reference to the interpreter result.
-\param argc (int)
- Number of command line parameters.
- Note that the command itself is
- included in this.
-\param argv (char**)
- The command line parameter.
-
-
-\return int
-\retval TCL_OK
- The function and parse succeeded
-\retval TCL_ERROR
- The function or the parse failed.
-
-Pseudo code:
-
-\verbatim
-pattern = "*"
-if(argc) pattern = argv[0]
-
-rResult = List(pattern)
-return TCL_OK
-
-\endverbatim
-
-*/
-int
-CCalibratedParameterCommand::List_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc, char** argv)
-{
- // Ensure that the parameter count is 0 or 1.
-
- if(argc > 1) {
- rResult = "Improper Parameter count";
- rResult += Usage();
- return TCL_ERROR;
- }
- // Now we can't fail.. just need to figure out the pattern:
-
- string pattern("*");
- string listing;
- if(argc) {
- pattern = argv[0];
- }
- listing = List(pattern);
- rResult = listing;
- return TCL_OK;
-}
-
-/*!
-
-Description:
-
-Parses the delete subcommand. If the parse is successful,
-control is passed to Delete to do the actual delete.
-
-
-Parameters:
-
-\param rInterp (CTCLInterpreter&)
- Reference to the interpreter that's executing
- this command.
-\param rResult (CTCLResult&)
- Reference to the interpreter result.
-\param argc (int)
- Number of command line parameters.
- Note that the command itself is
- included in this.
-\param argv (char**)
- The command line parameter.
-
-\return int
-\retval TCL_OK
- The parse and the command succeeded.
-\retval TCL_ERROR
- The function or parse failed.
-
-
-Pseudo code:
-
-\verbatim
-name = argv[0]
-status = Delete(msg, name)
-rResult = msg
-return status
-
-
-
-\endverbatim
-
-*/
-int
-CCalibratedParameterCommand::Delete_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc, char** argv)
-{
- // we are required to have a parameter:
-
- if (argc != 1) {
- rResult = "Incorrect number of command line parameters";
- rResult += Usage();
- return TCL_ERROR;
- }
- // Now it's in the hands of Delete():
-
- string Result;
- int status = Delete(Result, string(argv[0]));
- rResult = Result;
- return status;
-}
-
-/*!
-
-Description:
-
-Parses the update command. The update
-command parse will then invoke the update member if
-the parse is successful.
-
-
-Parameters:
-
-\param rInterp (CTCLInterpreter&)
- Reference to the interpreter that's executing
- this command.
-\param rResult (CTCLResult&)
- Reference to the interpreter result.
-\param argc (int)
- Number of command line parameters.
- Note that the command itself is
- included in this.
-\param argv (char**)
- The command line parameter.
-
-
-\return int
-\retval TCL_OK
- The parse and call of Update succeeded.
-\retval TCL_ERROR
- The parse or call of Update failed.
-
-Pseudo code:
-
-\verbatim
-pattern = "*"
-if (argc) pattern = argv[0]
-Update(pattern)
-return TCL_OK
-\endverbatim
-
-*/
-int
-CCalibratedParameterCommand::Update_parse(CTCLInterpreter& rInterp,
- CTCLResult& rResult,
- int argc, char** argv)
-{
- // This can have either 0 or 1 parameters:
-
- if (argc > 1) {
- rResult = "Improper number of command line parameters";
- rResult += Usage();
- return TCL_ERROR;
- }
- // Now figure out the pattern (defaults to *)
-
- string pattern("*");
- if(argc) {
- pattern = argv[0];
- }
-
- // Leave it in the hands of Update:
-
- Update(pattern);
- return TCL_OK;
-
-}
-
-/*!
-
-Description:
-
-Creates a new calibrated parameter.
-The parameter is instantiated here and entered
-in the CCalibratedParameterManager via a call
-to CCalibratedParameterManager::AddParameter
-
-\post pCalibrated must be non null.
-\post Created parameter must be findable in parameter manager.
-
-Parameters:
-
-\param Result (string)
- A status string from the creation.
-\param name (string)
- Name of the parameter being created.
-\param id (int)
- Number of the parameter being created.
- This number must not correspond to an existing
- parameter.
-\param raw (string)
- Name of the raw parameter being calibrated.
-\param fitname (string)
- Name of the fit that is invoked to calibrate the parameter
-\param units (string)
- Parameter units (blank means no units).
-
-\return int
-\retval TCL_OK
- The calibrated parameter was made and successfully
- inserted into the calibration manager.\
- Result will be a string containing the parameter description
- list
-\retval TCL_ERROR
- The calibrated parameter specified could not be
- created.
- the Result will be a string that contains an error
- message.
-
-Pseudo code:
-
-\verbatim
-if exists name {
- Result = "$name exists"
- return TCL_ERROR
-}
-
-if exists number {
- Result = "Parameter $number already is defined"
- return TCL_ERROR
-}
-
-if !exists raw {
- Result = "Raw parameter $raw does not exist"
- return TCL_ERROR
-}
-
-if !exists fit {
- Result = "Fit $fit does not exist"
- return TCL_ERROR
-}
-
-pParameter = CreateParameter(name, number, units)
-pCalibParam = new CCalibratedParameter(number, pRaw->getNumber(),
- pFit, fit)
-CCalibratedParameterManager::AddParameter(name, pCalibParam)
-return TCL_OK
-
-\endverbatim
-
-*/
-int
-CCalibratedParameterCommand::Create(string& Result, string name,
- int id, string raw, string fitname,
- string units)
-{
- // The calibrated parameter must not exist
- // this could happen if the user deleted the target param
- // with parameter -delete not calibparam -delete.
- // or just overwriting an existing calibparam.
-
- if(CCalibratedParameterManager::FindParameter(name) !=
- CCalibratedParameterManager::end()) {
- Result = "The calibrated parameter: " ;
- Result += name;
- Result += " already exists.";
- return TCL_ERROR;
-
- }
- // The name and Id of the target must be unique and new so both the lookups
- // below must fail:
-
- CParameter* pParam = m_pHistogrammer->FindParameter(name);
- if(pParam) {
- Result = "A parameter named ";
- Result += name;
- Result += " already exists.";
- return TCL_ERROR;
- }
- pParam = m_pHistogrammer->FindParameter(id);
- if (pParam) {
- char sId[100];
- Result = "A parameter with the id: ";
- sprintf(sId, "%d", id);
- Result += sId;
- Result += " already exists";
- return TCL_ERROR;
- }
-
-
- // The raw parameter name must exist.
-
- pParam = m_pHistogrammer->FindParameter(raw);
- if(!pParam) {
- Result = "The Raw Parameter ";
- Result += raw;
- Result += " must exist and does not";
- return TCL_ERROR;
- }
- // The fit must also exists.
-
- CFit* pFit = FindFit(fitname);
- if(!pFit) {
- Result = "The fit ";
- Result += fitname;
- Result += " must already exist and does not";
- return TCL_ERROR;
- }
-
- // Now everything must work:
-
- try {
- CParameter* pTarget = m_pHistogrammer->AddParameter(name, id,
- units.c_str());
- CCalibratedParameter* pCalibrated = new CCalibratedParameter(id,
- pParam->getNumber(),
- fitname,
- pFit);
- CCalibratedParameterManager::AddParameter(name, pCalibrated);
- Result = name;
- ENSURE(pCalibrated, "Created parameter pointer is null");
- ENSURE(CCalibratedParameterManager::FindParameter(name) !=
- CCalibratedParameterManager::end(),
- "Added parameter could not be found");
- return TCL_OK;
-
- }
- catch (CException& e) {
- Result += "Unanticipated CException in CCalibratedParameter::Create() : ";
- Result += e.ReasonText();
- return TCL_ERROR;
- }
- catch (string& e) {
- Result += "Unanticipated string exception in CCalibratedParameter::Create() : ";
- Result += e;
- return TCL_ERROR;
- }
- catch (char* e) {
- Result += "Unanticipated cstring exception in CCalibratedParameter::Create() : ";
- Result += e;
- return TCL_ERROR;
- }
- catch (...) {
- Result += "Unrecognized exception type in CCalibratedParameter::Create() : ";
- return TCL_ERROR;
-
- }
-
-}
-
-/*!
-
-Description:
-
-Produces a listing of the parameters that match the
-pattern. The pattern can contain wild card characters
-from the glob set.
-
-
-Parameters:
-
-\param pattern (string)
- Pattern to match when doing the list.
-
-\return string
-\retval a list, containing one entry per matched parameter
- each element of the list is of the form:
- {name, number, rawname, fitname, units}
-
-Pseudo code:
-
-\verbatim
-result = <empty>
-for_each CalibratedParameter {
- if CalibratedParameter Name matches pattern {
- result.AddElement(FormatFit(name, CalibratedParameter)
-}
-return $result
-
-\endverbatim
-
-*/
-string
-CCalibratedParameterCommand::List(string pattern)
-{
- CTCLString Result;
- Format Formatter(Result, pattern);
- for_each(CCalibratedParameterManager::begin(),
- CCalibratedParameterManager::end(), Formatter);
- return string((const char*)Result);
-
-}
-
-/*!
-
-
-Deletes a parameter given a name.
-
-Parameters:
-
-\param Result string
- On success empty on failure an error message
-\param name string
- Name of the parameter to destroy.
-
-\return int
-\retval TCL_OK
- The named parameter was deleted.
-\retval TCL_ERROR
- The named parameter could not be
- deleted and the reason is textually given by
- Result.
-
-Pseudo code:
-
-\verbatim
-pParameter = CCalibratedParameterManager::DeleteParmeter(name)
-if ! pParameter{
-
- Result = "No such parameter $name"
- return TCL_ERROR
-}
-else {
- delete spectcl parameter.
- delete pParameter
- return TCL_OK
-}
-\endverbatim
-
-*/
-int
-CCalibratedParameterCommand::Delete(string& Result, string parameter)
-{
- CCalibratedParameter* pParameter =
- CCalibratedParameterManager::DeleteParameter(parameter);
- if(pParameter) {
- // Locate, and delete the parameter from the histogrammer too.
-
- CParameter* pHParameter =
- m_pHistogrammer->RemoveParameter(parameter); // dictionary remove
- if(pHParameter) {
- delete pHParameter; // My responsibility to delete the object.
- }
- delete pParameter;
- return TCL_OK;
- }
- else {
- Result = "No Such Parameter: ";
- Result += parameter;
- return TCL_ERROR;
- }
-}
-
-/*!
-
-Description:
-
-Updates the fit for all parameters that correspond
-to the pattern. The pattern may contain
-glob based wild card characters.
-
-
-Parameters:
-
-\param pattern (string)
- Only the parameters that match this pattern
- will be calibrated.
-
-\return void
-Pseudo code:
-
-\verbatim
-for_each name,pParameter {
- if name matches pattern {
- pFit = CFitFactory::FindFit(pParameter.getFitname())
- if pFit = CFitFactory::end() {
- // Last known fit is used.
- }
- else {
- if pFit.State() is Performed then
- pParameter.ReplaceFit(pFit) // Update with new fit.
- else {
- // fit unchanged, exists but is accepting.
- }
- }
- }
-}
-\endverbatim
-
-*/
-void
-CCalibratedParameterCommand::Update(string pattern)
-{
- Updater Update(pattern);
- for_each(CCalibratedParameterManager::begin(),
- CCalibratedParameterManager::end(),
- Update);
-}
-
-/*!
-
-Description:
-
-Local function to locate a fit in the CFitFactory.
-
-
-\pre
-
-\post
-
-Parameters:
-
-\param sName (string)
- The name of the fit to look for.
-
-
-\return CFitFactory::FitIterator
-\return CFitFactory::FitIterator
- \retval CFitFactory::end() - Fit not found.
- \retval other - Fit found and this an iterator that 'points' to the
- name, CFit* pair.
-
-
-\throw
-
-Pseudo code:
-
-\verbatim
-
-\endverbatim
-
-*/
-CFit*
-CCalibratedParameterCommand::FindFit(string sName)
-{
- CFitFactory::FitIterator i = CFitFactory::FindFit(sName);
- if(i != CFitFactory::end()) {
- return i->second;
- }
- else {
- return (CFit*)NULL;
- }
-}
-
-/*!
-
-Description:
-
-Returns a string that describes the command usage.
-
-Parameters:
-
-\return string
-
-Pseudo code:
-
-\verbatim
-message = "Usage:
- calibparam ?-create? name number raw fitname ?units?
- calibparam -list ?pattern?
- calibparam -delete name
- calibparam -refresh ?pattern?
- Where:
- name - the name of a calibrated parameter.
- number - The parameter id of a calibrated parameter.
- raw - The name of a raw parameter
- fitname- the name of a fit.
- units - Units of measure of the parameter.
- pattern- A match pattern that canuse glob wild card
- characters"
-return message
-\endverbatim
-
-*/
-string
-CCalibratedParameterCommand::Usage()
-{
- string message = "Usage:\n";
- message += " calibparam ?-create? name number raw fitname ?units?\n";
- message += " calibparam -list ?patern?\n";
- message += " calibparam -delete name\n";
- message += " calibparam -refresh ?pattern?\n";
- message += "Where:\n";
- message += " name - The name of a calibrated parameter\n";
- message += " number - The parameter id of the calibrated parameter\n";
- message += " raw - The name of a raw parameter\n";
- message += " fitname- The name of a fit.\n";
- message += " units - Units of measure of the parameter.\n";
- message += " pattern - A match pattern that can use glob wild cards\n";
- message += " ?param? - Means the parameter may be omitted\n";
-
- return message;
-}
-
-/*!
-
-Description:
-
-Formats a listing of parameter.
-The listing is of the form:
-{name number rawname fitname units}
-
-- If the parameter has been deleted, the name will be -deleted-
- and units will be blank.
-- If the raw parameter has been deleted, its name will be -deleted-
-- If the fit has been deleted its name will be "orignal name (deleted)"
-- If the parameter has no units assigned to it, the units field will be ""
-
-\pre
-
-\post
-
-Parameters:
-
-\param sName (string)
- Name of the parameter.
-\param pParameter (CCalibratedParameter& rParam)
- Pointer to the calibrated Parameter.
-
-
-\return string
-\return string
- \retval the listing of the parameter as described above.
-
-\throw
-
-Pseudo code:
-
-\verbatim
-pCalibrated = FindParameter(sName)
-pFit = FindFit(pParam->getFitName())
-pRaw = FindParameter(pParam->getParameterId())
-number = pParam->getTargetParameterId()
-
-if(!pCalibrated) {
- name = -deleted-
- units= ""
-} else {
- name = rCalibrated->getName()
- units= rCalibrated->getUnits()
-}
-if(pRaw) {
- rawname = pRaw->GetName()
-}
-else {
- rawname = -deleted-
-}
-if (pFit) {
- fitname = rParam->getFitName()
-}
-else {
- fitname = rParam->getFitName() + "(deleted)"
-}
-return List(name, number,rawname, fitname, units)
-
-\endverbatim
-
-*/
-string
-CCalibratedParameterCommand::FormatParameter(string sParamName,
- CCalibratedParameter& rParam)
-{
- CTCLString result;
- string name;
- string units;
- string number;
- string rawname;
- string fitname;
- char FormatBuffer[100];
-
-
- CHistogrammer* pHistogrammer = (CHistogrammer*)gpEventSink;
- CParameter* pHParameter = pHistogrammer->FindParameter(sParamName);
-
- sprintf(FormatBuffer, "%d", rParam.getTargetId());
- if(pHParameter) { // calibrated Parameter exists
- name = sParamName;
- number = FormatBuffer;
- units = pHParameter->getUnits();
-
- }
- else {
- name = "-deleted-";
- number= FormatBuffer;
- units = "";
- }
-
- pHParameter = pHistogrammer->FindParameter(rParam.getRawId());
- if(pHParameter) {
- rawname = pHParameter->getName();
- }
- else {
- rawname = "-deleted-";
- }
- fitname = rParam.getFitName();
- if(CFitFactory::FindFit(fitname) == CFitFactory::end()) {
- fitname += " (deleted)";
- }
- result.AppendElement(name);
- result.AppendElement(number);
- result.AppendElement(rawname);
- result.AppendElement(fitname);
- result.AppendElement(units);
- return string((const char*) result);
-
-}
Copied: tags/calibparams-1.0-003/CCalibratedParameterCommand.cpp (from rev 2052, trunk/plugins/calibparams/CCalibratedParameterCommand.cpp)
===================================================================
--- tags/calibparams-1.0-003/CCalibratedParameterCommand.cpp (rev 0)
+++ tags/calibparams-1.0-003/CCalibratedParameterCommand.cpp 2012-12-24 19:56:53 UTC (rev 2053)
@@ -0,0 +1,1061 @@
+
+
+/*
+ Implementation file for CCalibratedParameterCommand for a description of the
+ class see CCalibratedParameterCommand.h
+*/
+
+////////////////////////// FILE_NAME.cpp ///////////////////////////
+
+
+// Include files required:
+
+#include <config.h>
+#include "CCalibratedParameterCommand.h"
+#include "CCalibratedParameterManager.h"
+#include "CCalibratedParameter.h"
+#include "./CFit.h"
+#include "./CFitFactory.h"
+
+#include <TCLInterpreter.h>
+#include <TCLResult.h>
+#include <TCLException.h>
+#include <TCLString.h>
+#include <Histogrammer.h>
+#include <Parameter.h>
+#include <Globals.h>
+
+#include <DesignByContract.h>
+
+#include <vector>
+#include <stdio.h>
+
+#ifdef HAVE_STD_NAMESPACE
+using namespace std;
+#endif
+
+
+using namespace DesignByContract;
+
+
+// Static attribute storage and initialization for CCalibratedParameterCommand
+
+static vector<string> SwitchTable;
+enum Switches {
+ swCreate,
+ swList,
+ swDelete,
+ swUpdate };
+
+// Helper class to build up a list of formatted calibrated parameters.
+
+class Format {
+private:
+ CTCLString& m_rResult;
+ string m_Pattern;
+public:
+ Format(CTCLString& rResult, string pattern) :
+ m_rResult(rResult),
+ m_Pattern(pattern)
+ {}
+ void operator()(CCalibratedParameterManager::MapEntry entry)
+ {
+ REQUIRE(entry.second, "Null Parameter in map entry");
+ if(Tcl_StringMatch(entry.first.c_str(), m_Pattern.c_str())) {
+ string name = entry.first;
+ CCalibratedParameter* pParam = entry.second;
+
+ string item(CCalibratedParameterCommand::FormatParameter(name,
+ *pParam));
+ m_rResult.AppendElement(item);
+
+ }
+ }
+};
+// Helper class to update calibrated parameters with new fits.
+
+class Updater {
+private:
+ string m_Pattern;
+public:
+ Updater(string Pattern) :
+ m_Pattern(Pattern) {}
+ void operator()(CCalibratedParameterManager::MapEntry entry)
+ {
+ REQUIRE(entry.second, "Null parameter in map entry");
+ if(Tcl_StringMatch(entry.first.c_str(), m_Pattern.c_str())) {
+ CCalibratedParameter* pParam = entry.second;
+ CCalibFitFactory::FitIterator
+ pF = CCalibFitFactory::FindFit(pParam->getFitName());
+ if(pF != CCalibFitFactory::end()) {
+ CCalibFit* pFit = pF->second;
+ if(pFit->GetState() == CCalibFit::Performed) {
+ CCalibFit* p = pParam->ReplaceFit(*pFit);
+ delete p;
+ }
+ }
+
+ }
+ }
+};
+/*!
+ Create an object of type CCalibratedParameterCommand
+ \post m_pHistogrammer is not null.
+*/
+CCalibratedParameterCommand::CCalibratedParameterCommand
+ (CTCLInterpreter* pInterp) :
+ CTCLProcessor("calibparam", pInterp),
+ m_pHistogrammer(0)
+
+{
+ // Set up the switch table vector.
+
+ if (SwitchTable.empty()) {
+ SwitchTable.push_back("-create");
+ SwitchTable.push_back("-list");
+ SwitchTable.push_back("-delete");
+ SwitchTable.push_back("-refresh");
+ }
+
+ // Locate the histogrammer and save it in the
+ // member variable.
+
+ m_pHistogrammer = (CHistogrammer*)gpEventSink;
+ ENSURE(m_pHistogrammer, "NULL Histogrammer pointer.");
+}
+
+/*!
+ Called to destroy an instance of CCalibratedParameterCommand
+*/
+ CCalibratedParameterCommand::~CCalibratedParameterCommand ( )
+{
+}
+
+// Functions for class CCalibratedParameterCommand
+
+/*!
+
+Description:
+
+Does a top level parse and dispatch of
+commands. The command is parsed
+ito its function and dispatched.
+
+
+Parameters:
+
+\param rInterp (CTCLInterpreter&)
+ Reference to the interpreter that's executing
+ this command.
+\param rResult (CTCLResult&)
+ Reference to the interpreter result.
+\param argc (int)
+ Number of command line parameters.
+ Note that the command itself is
+ included in this.
+\param argv (char**)
+ The command line parameter.
+
+
+\return int
+\retval TCL_OK
+ Function completed successfully.
+ The contents of rResult will depend on the
+ function.
+\retval TCL_ERROR
+ Function failed. rResult will be an error message.
+Pseudo code:
+
+\verbatim
+Operation = argv[1]
+Opcode = MatchKeyword(Operation)
+
+if (Opcode == Create) {
+ return Create_Parse(rInterp, rResult, remaining argc, remaining argv)
+}
+if (Opcode == List) {
+ return List_Parse(rInterp, rResult, remainng argc, remaining argv)
+}
+if(Opcode == Delete) {
+ return List_Parse(rInterp, rResult, remaining argc, remaining argv)
+}
+if(Opcode == Update) {
+ return Update_Parse(rInterp, RResult, remaining argc, remaining argv)
+}
+if(Opcode == Create) {
+ return Create_Parse(rInterp, rResult, remaining argc, remaining argv)
+}
+if(OpCode == unrecognized)
+ return Create_Parse(rInterp, rResult, argc, argv)
+}
+FAIL
+\endverbatim
+
+*/
+int
+CCalibratedParameterCommand::operator()(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // The first parameter is the command itself and that can be ignored:
+
+ NextParam(argc,argv);
+
+ // There must be at least one parameter, either a command keyword,
+ // or in the case of a create, the name of the target:
+
+ if(!argc) {
+ rResult = "Insufficient parameters: \n";
+ rResult += Usage();
+ return TCL_ERROR;
+ }
+
+ // Pull out the the dispatch switch. Note that the lack of a
+ // recognized switch is equivalent to create.
+
+ string Switch(argv[0]);
+
+ switch (MatchKeyword(SwitchTable, Switch, (int) swCreate)) {
+ case swCreate:
+ if (Switch[0] == '-') { // The switch, not a default case.
+ NextParam(argc,argv);
+ }
+ return Create_parse(rInterp, rResult, argc, argv);
+ case swList:
+ NextParam(argc,argv);
+ return List_parse(rInterp, rResult, argc, argv);
+ case swDelete:
+ NextParam(argc,argv);
+ return Delete_parse(rInterp, rResult, argc, argv);
+ case swUpdate:
+ NextParam(argc,argv);
+ return Update_parse(rInterp, rResult, argc, argv);
+ default:
+ ENSURE(0, "Invalid switch: impossible condition");
+ }
+ ENSURE(0, "Fell past switch, impossible condition");
+ rResult = "Defect in CCalibratedParameterCommand::operator()";
+ return TCL_ERROR;
+}
+
+/*!
+
+Description:
+
+Parses the Create command and reports any
+parsing errors to the caller. If the parse is
+successful, Create is called to do the actual
+creation of a new calibrated parameter.
+
+
+
+Parameters:
+
+\param rInterp (CTCLInterpreter&)
+ Reference to the interpreter that's executing
+ this command.
+\param rResult (CTCLResult&)
+ Reference to the interpreter result.
+\param argc (int)
+ Number of command line parameters.
+ Note that the command itself is
+ included in this.
+\param argv (char**)
+ The command line parameter.
+
+\return int
+\retval TCL_OK
+ - Parse was correct.
+ - Create returned TCL_OK.
+\retval TCL_ERROR
+ - Parse failed OR
+ - Create returned an error.
+
+Pseudo code:
+
+\verbatim
+targetname = argv[0]
+targetid = argv[1]
+rawname = argv[2]
+fitname = argv[3]
+
+If (argc == 5) {
+ units = argv[4]
+} else
+ units = ""
+}
+
+status = Create(message, targetname, targetid, rawname, fitname, units)
+rResult = message
+return status
+\endverbatim
+
+*/
+int
+CCalibratedParameterCommand::Create_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // There must be 4 or 5 parameters on the command line:
+
+ if ((argc != 4) && (argc != 5)) {
+ rResult = "Improper number of parmeters on command line";
+ rResult += Usage();
+ return TCL_ERROR;
+ }
+ // The first 4 are clear:
+
+ string targetname = argv[0];
+ string targetid = argv[1];
+ string rawname = argv[2];
+ string fitname = argv[3];
+
+ // The last one is there only if the user supplies units:
+
+ string units="";
+ if (argc == 5) {
+ units = argv[4];
+ }
+ // The target id must parse to an integer (long):
+ Long_t nTargetId;
+ try {
+ nTargetId = rInterp.ExprLong(targetid);
+ } catch (CTCLException& e) {
+ rResult = "Target Id is not an integer and must be: ";
+ rResult += e.ReasonText();
+ rResult += "\n";
+ rResult += Usage();
+ return TCL_ERROR;
+ }
+ // Now that we have a good parse we let Create do the rest:
+
+ string Result;
+ int status = Create(Result, targetname, (int)nTargetId, rawname, fitname, units);
+ rResult = Result;
+ return status;
+
+}
+
+/*!
+
+Description:
+
+Parses the list command. If the parse is succesful,
+invokes List to do the listing. Parse failures
+will result in an error return and will also leave
+an error message and usage in the rResult parameter
+
+
+Parameters:
+
+\param rInterp (CTCLInterpreter&)
+ Reference to the interpreter that's executing
+ this command.
+\param rResult (CTCLResult&)
+ Reference to the interpreter result.
+\param argc (int)
+ Number of command line parameters.
+ Note that the command itself is
+ included in this.
+\param argv (char**)
+ The command line parameter.
+
+
+\return int
+\retval TCL_OK
+ The function and parse succeeded
+\retval TCL_ERROR
+ The function or the parse failed.
+
+Pseudo code:
+
+\verbatim
+pattern = "*"
+if(argc) pattern = argv[0]
+
+rResult = List(pattern)
+return TCL_OK
+
+\endverbatim
+
+*/
+int
+CCalibratedParameterCommand::List_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // Ensure that the parameter count is 0 or 1.
+
+ if(argc > 1) {
+ rResult = "Improper Parameter count";
+ rResult += Usage();
+ return TCL_ERROR;
+ }
+ // Now we can't fail.. just need to figure out the pattern:
+
+ string pattern("*");
+ string listing;
+ if(argc) {
+ pattern = argv[0];
+ }
+ listing = List(pattern);
+ rResult = listing;
+ return TCL_OK;
+}
+
+/*!
+
+Description:
+
+Parses the delete subcommand. If the parse is successful,
+control is passed to Delete to do the actual delete.
+
+
+Parameters:
+
+\param rInterp (CTCLInterpreter&)
+ Reference to the interpreter that's executing
+ this command.
+\param rResult (CTCLResult&)
+ Reference to the interpreter result.
+\param argc (int)
+ Number of command line parameters.
+ Note that the command itself is
+ included in this.
+\param argv (char**)
+ The command line parameter.
+
+\return int
+\retval TCL_OK
+ The parse and the command succeeded.
+\retval TCL_ERROR
+ The function or parse failed.
+
+
+Pseudo code:
+
+\verbatim
+name = argv[0]
+status = Delete(msg, name)
+rResult = msg
+return status
+
+
+
+\endverbatim
+
+*/
+int
+CCalibratedParameterCommand::Delete_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // we are required to have a parameter:
+
+ if (argc != 1) {
+ rResult = "Incorrect number of command line parameters";
+ rResult += Usage();
+ return TCL_ERROR;
+ }
+ // Now it's in the hands of Delete():
+
+ string Result;
+ int status = Delete(Result, string(argv[0]));
+ rResult = Result;
+ return status;
+}
+
+/*!
+
+Description:
+
+Parses the update command. The update
+command parse will then invoke the update member if
+the parse is successful.
+
+
+Parameters:
+
+\param rInterp (CTCLInterpreter&)
+ Reference to the interpreter that's executing
+ this command.
+\param rResult (CTCLResult&)
+ Reference to the interpreter result.
+\param argc (int)
+ Number of command line parameters.
+ Note that the command itself is
+ included in this.
+\param argv (char**)
+ The command line parameter.
+
+
+\return int
+\retval TCL_OK
+ The parse and call of Update succeeded.
+\retval TCL_ERROR
+ The parse or call of Update failed.
+
+Pseudo code:
+
+\verbatim
+pattern = "*"
+if (argc) pattern = argv[0]
+Update(pattern)
+return TCL_OK
+\endverbatim
+
+*/
+int
+CCalibratedParameterCommand::Update_parse(CTCLInterpreter& rInterp,
+ CTCLResult& rResult,
+ int argc, char** argv)
+{
+ // This can have either 0 or 1 parameters:
+
+ if (argc > 1) {
+ rResult = "Improper number of command line parameters";
+ rResult += Usage();
+ return TCL_ERROR;
+ }
+ // Now figure out the pattern (defaults to *)
+
+ string pattern("*");
+ if(argc) {
+ pattern = argv[0];
+ }
+
+ // Leave it in the hands of Update:
+
+ Update(pattern);
+ return TCL_OK;
+
+}
+
+/*!
+
+Description:
+
+Creates a new calibrated parameter.
+The parameter is instantiated here and entered
+in the CCalibratedParameterManager via a call
+to CCalibratedParameterManager::AddParameter
+
+\post pCalibrated must be non null.
+\post Created parameter must be findable in parameter manager.
+
+Parameters:
+
+\param Result (string)
+ A status string from the creation.
+\param name (string)
+ Name of the parameter being created.
+\param id (int)
+ Number of the parameter being created.
+ This number must not correspond to an existing
+ parameter.
+\param raw (string)
+ Name of the raw parameter being calibrated.
+\param fitname (string)
+ Name of the fit that is invoked to calibrate the parameter
+\param units (string)
+ Parameter units (blank means no units).
+
+\return int
+\retval TCL_OK
+ The calibrated parameter was made and successfully
+ inserted into the calibration manager.\
+ Result will be a string containing the parameter description
+ list
+\retval TCL_ERROR
+ The calibrated parameter specified could not be
+ created.
+ the Result will be a string that contains an error
+ message.
+
+Pseudo code:
+
+\verbatim
+if exists name {
+ Result = "$name exists"
+ return TCL_ERROR
+}
+
+if exists number {
+ Result = "Parameter $number already is defined"
+ return TCL_ERROR
+}
+
+if !exists raw {
+ Result = "Raw parameter $raw does not exist"
+ return TCL_ERROR
+}
+
+if !exists fit {
+ Result = "Fit $fit does not exist"
+ return TCL_ERROR
+}
+
+pParameter = CreateParameter(name, number, units)
+pCalibParam = new CCalibratedParameter(number, pRaw->getNumber(),
+ pFit, fit)
+CCalibratedParameterManager::AddParameter(name, pCalibParam)
+return TCL_OK
+
+\endverbatim
+
+*/
+int
+CCalibratedParameterCommand::Create(string& Result, string name,
+ int id, string raw, string fitname,
+ string units)
+{
+ // The calibrated parameter must not exist
+ // this could happen if the user deleted the target param
+ // with parameter -delete not calibparam -delete.
+ // or just overwriting an existing calibparam.
+
+ if(CCalibratedParameterManager::FindParameter(name) !=
+ CCalibratedParameterManager::end()) {
+ Result = "The calibrated parameter: " ;
+ Result += name;
+ Result += " already exists.";
+ return TCL_ERROR;
+
+ }
+ // The name and Id of the target must be unique and new so both the lookups
+ // below must fail:
+
+ CParameter* pParam = m_pHistogrammer->FindParameter(name);
+ if(pParam) {
+ Result = "A parameter named ";
+ Result += name;
+ Result += " already exists.";
+ return TCL_ERROR;
+ }
+ pParam = m_pHistogrammer->FindParameter(id);
+ if (pParam) {
+ char sId[100];
+ Result = "A parameter with the id: ";
+ sprintf(sId, "%d", id);
+ Result += sId;
+ Result += " already exists";
+ return TCL_ERROR;
+ }
+
+
+ // The raw parameter name must exist.
+
+ pParam = m_pHistogrammer->FindParameter(raw);
+ if(!pParam) {
+ Result = "The Raw Parameter ";
+ Result += raw;
+ Result += " must exist and does not";
+ return TCL_ERROR;
+ }
+ // The fit must also exists.
+
+ CCalibFit* pFit = FindFit(fitname);
+ if(!pFit) {
+ Result = "The fit ";
+ Result += fitname;
+ Result += " must already exist and does not";
+ return TCL_ERROR;
+ }
+
+ // Now everything must work:
+
+ try {
+ CParameter* pTarget = m_pHistogrammer->AddParameter(name, id,
+ units.c_str());
+ CCalibratedParameter* pCalibrated = new CCalibratedParameter(id,
+ pParam->getNumber(),
+ fitname,
+ pFit);
+ CCalibratedParameterManager::AddParameter(name, pCalibrated);
+ Result = name;
+ ENSURE(pCalibrated, "Created parameter pointer is null");
+ ENSURE(CCalibratedParameterManager::FindParameter(name) !=
+ CCalibratedParameterManager::end(),
+ "Added parameter could not be found");
+ return TCL_OK;
+
+ }
+ catch (CException& e) {
+ Result += "Unanticipated CException in CCalibratedParameter::Create() : ";
+ Result += e.ReasonText();
+ return TCL_ERROR;
+ }
+ catch (string& e) {
+ Result += "Unanticipated string exception in CCalibratedParameter::Create() : ";
+ Result += e;
+ return TCL_ERROR;
+ }
+ catch (char* e) {
+ Result += "Unanticipated cstring exception in CCalibratedParameter::Create() : ";
+ Result += e;
+ return TCL_ERROR;
+ }
+ catch (...) {
+ Result += "Unrecognized exception type in CCalibratedParameter::Create() : ";
+ return TCL_ERROR;
+
+ }
+
+}
+
+/*!
+
+Description:
+
+Produces a listing of the parameters that match the
+pattern. The pattern can contain wild card characters
+from the glob set.
+
+
+Parameters:
+
+\param pattern (string)
+ Pattern to match when doing the list.
+
+\return string
+\retval a list, containing one entry per matched parameter
+ each element of the list is of the form:
+ {name, number, rawname, fitname, units}
+
+Pseudo code:
+
+\verbatim
+result = <empty>
+for_each CalibratedParameter {
+ if CalibratedParameter Name matches pattern {
+ result.AddElement(FormatFit(name, CalibratedParameter)
+}
+return $result
+
+\endverbatim
+
+*/
+string
+CCalibratedParameterCommand::List(string pattern)
+{
+ CTCLString Result;
+ Format Formatter(Result, pattern);
+ for_each(CCalibratedParameterManager::begin(),
+ CCalibratedParameterManager::end(), Formatter);
+ return string((const char*)Result);
+
+}
+
+/*!
+
+
+Deletes a parameter given a name.
+
+Parameters:
+
+\param Result string
+ On success empty on failure an error message
+\param name string
+ Name of the parameter to destroy.
+
+\return int
+\retval TCL_OK
+ The named parameter was deleted.
+\retval TCL_ERROR
+ The named parameter could not be
+ deleted and the reason is textually given by
+ Result.
+
+Pseudo code:
+
+\verbatim
+pParameter = CCalibratedParameterManager::DeleteParmeter(name)
+if ! pParameter{
+
+ Result = "No such parameter $name"
+ return TCL_ERROR
+}
+else {
+ delete spectcl parameter.
+ delete pParameter
+ return TCL_OK
+}
+\endverbatim
+
+*/
+int
+CCalibratedParameterCommand::Delete(string& Result, string parameter)
+{
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|