Newer
Older
Janik Zikovsky
committed
* @param parameterStr :: result of ParameterMap.asString()
*/
void ExperimentInfo::readParameterMap(const std::string & parameterStr)
{
Geometry::ParameterMap& pmap = this->instrumentParameters();
Instrument_const_sptr instr = this->getInstrument()->baseInstrument();
int options = Poco::StringTokenizer::TOK_IGNORE_EMPTY;
options += Poco::StringTokenizer::TOK_TRIM;
Poco::StringTokenizer splitter(parameterStr, "|", options);
Janik Zikovsky
committed
Poco::StringTokenizer::Iterator iend = splitter.end();
//std::string prev_name;
for( Poco::StringTokenizer::Iterator itr = splitter.begin(); itr != iend; ++itr )
{
Poco::StringTokenizer tokens(*itr, ";");
if( tokens.count() < 4 ) continue;
Janik Zikovsky
committed
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
std::string comp_name = tokens[0];
//if( comp_name == prev_name ) continue; this blocks reading in different parameters of the same component. RNT
//prev_name = comp_name;
const Geometry::IComponent* comp = 0;
if (comp_name.find("detID:") != std::string::npos)
{
int detID = atoi(comp_name.substr(6).c_str());
comp = instr->getDetector(detID).get();
if (!comp)
{
g_log.warning()<<"Cannot find detector "<<detID<<'\n';
continue;
}
}
else
{
comp = instr->getComponentByName(comp_name).get();
if (!comp)
{
g_log.warning()<<"Cannot find component "<<comp_name<<'\n';
continue;
}
}
if( !comp ) continue;
// create parameter's value as a sum of all tokens with index 3 or larger
// this allow a parameter's value to contain ";"
std::string paramValue = tokens[3];
int size = static_cast<int>(tokens.count());
for (int i = 4; i < size; i++ )
paramValue += ";" + tokens[4];
pmap.add(tokens[1], comp, tokens[2], paramValue);
Janik Zikovsky
committed
}
}
//------------------------------------------------------------------------------------------------------
// Private members
//------------------------------------------------------------------------------------------------------
Janik Zikovsky
committed
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
/**
* Fill map with given instrument parameter
* @param paramMap Map to populate
* @param name The name of the parameter
* @param paramInfo A reference to the object describing this parameter
* @param runData A reference to the run object
*/
void ExperimentInfo::populateWithParameter(Geometry::ParameterMap & paramMap,
const std::string & name, const Geometry::XMLlogfile & paramInfo,
const Run & runData)
{
const std::string & category = paramInfo.m_type;
ParameterValue paramValue(paramInfo, runData); //Defines implicit conversion operator
// Some names are special. Values should be convertible to double
if (name.compare("x") == 0 || name.compare("y") == 0 || name.compare("z") == 0)
{
paramMap.addPositionCoordinate(paramInfo.m_component, name, paramValue);
}
else if (name.compare("rot") == 0 || name.compare("rotx") == 0 || name.compare("roty") == 0 || name.compare("rotz") == 0)
{
paramMap.addRotationParam(paramInfo.m_component, name, paramValue);
}
else if(category.compare("fitting") == 0)
{
std::ostringstream str;
str << paramInfo.m_value << " , " << paramInfo.m_fittingFunction << " , " << name << " , " << paramInfo.m_constraint[0] << " , "
<< paramInfo.m_constraint[1] << " , " << paramInfo.m_penaltyFactor << " , "
<< paramInfo.m_tie << " , " << paramInfo.m_formula << " , "
<< paramInfo.m_formulaUnit << " , " << paramInfo.m_resultUnit << " , " << (*(paramInfo.m_interpolation));
paramMap.add("fitting",paramInfo.m_component, name, str.str());
}
else if(category.compare("string") == 0)
{
paramMap.addString(paramInfo.m_component,name, paramInfo.m_value);
}
else if(category.compare("bool") == 0)
{
paramMap.addBool(paramInfo.m_component,name, paramValue);
}
else if(category.compare("int") == 0)
{
paramMap.addInt(paramInfo.m_component, name, paramValue);
}
else // assume double
{
paramMap.addDouble(paramInfo.m_component, name, paramValue);
}
}
} // namespace Mantid
} // namespace API
Janik Zikovsky
committed
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
namespace Mantid
{
namespace Kernel
{
template<> MANTID_API_DLL
Mantid::API::ExperimentInfo_sptr IPropertyManager::getValue<Mantid::API::ExperimentInfo_sptr>(const std::string &name) const
{
PropertyWithValue<Mantid::API::ExperimentInfo_sptr>* prop =
dynamic_cast<PropertyWithValue<Mantid::API::ExperimentInfo_sptr>*>(getPointerToProperty(name));
if (prop)
{
return *prop;
}
else
{
std::string message = "Attempt to assign property "+ name +" to incorrect type. Expected ExperimentInfo.";
throw std::runtime_error(message);
}
}
template<> MANTID_API_DLL
Mantid::API::ExperimentInfo_const_sptr IPropertyManager::getValue<Mantid::API::ExperimentInfo_const_sptr>(const std::string &name) const
{
PropertyWithValue<Mantid::API::ExperimentInfo_sptr>* prop =
dynamic_cast<PropertyWithValue<Mantid::API::ExperimentInfo_sptr>*>(getPointerToProperty(name));
if (prop)
{
return prop->operator()();
}
else
{
std::string message = "Attempt to assign property "+ name +" to incorrect type. Expected const ExperimentInfo.";
throw std::runtime_error(message);
}
}
} // namespace Kernel
Janik Zikovsky
committed
} // namespace Mantid