msr2data gets a new option paramList which allows to select the number of parameters to be exported.

This commit is contained in:
suter_a 2016-04-28 11:11:06 +02:00
parent b0bb5f94a5
commit cb14afbe07
4 changed files with 332 additions and 160 deletions

View File

@ -4,6 +4,9 @@
changes since 0.17.0 changes since 0.17.0
=================================== ===================================
NEW 2016-04-28 msr2data gets a new option: paramList which allows to
extract a subset of all the parameters of a collection
of msr-files.
NEW 2016-04-22 Added the theory function muMinusExpTF for mu minus fits NEW 2016-04-22 Added the theory function muMinusExpTF for mu minus fits
NEW 2016-02-23 It is now possible to export the averaged data/Fourier NEW 2016-02-23 It is now possible to export the averaged data/Fourier
CHANGED 2016-04-26 start-/endTimeBin are now class members. This reduces CHANGED 2016-04-26 start-/endTimeBin are now class members. This reduces

View File

@ -1643,13 +1643,23 @@ bool PMsr2Data::PrepareNewSortedInputFile(unsigned int tempRun) const
* - -2 if a fit has not converged (and the data is not appended to the output file) * - -2 if a fit has not converged (and the data is not appended to the output file)
* *
* \param outfile name of the DB/ASCII output file * \param outfile name of the DB/ASCII output file
* \param paramList parameter list which shall be written to the output file
* \param db DB or plain ASCII output * \param db DB or plain ASCII output
* \param withHeader write output file header or not * \param withHeader write output file header or not
* \param global global mode or not * \param global global mode or not
* \param counter counter used within the global mode to determine how many runs have been processed already * \param counter counter used within the global mode to determine how many runs have been processed already
*/ */
int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHeader, bool global, unsigned int counter) const int PMsr2Data::WriteOutput(const string &outfile, const vector<unsigned int>& paramList, bool db,
unsigned int withHeader, bool global, unsigned int counter) const
{ {
// make sure that the parameter number of the parameter list stays within proper bounds
for (unsigned int i=0; i<paramList.size(); i++) {
if (paramList[i] > fMsrHandler->GetMsrParamList()->size()) {
cerr << "msr2data: **ERROR** found parameter " << paramList[i] << " which is out of bound (>" << fMsrHandler->GetMsrParamList()->size() << ")." << endl;
return -1;
}
}
if (!to_lower_copy(outfile).compare("none")) { if (!to_lower_copy(outfile).compare("none")) {
fRunVectorIter++; fRunVectorIter++;
return PMUSR_SUCCESS; return PMUSR_SUCCESS;
@ -2022,9 +2032,11 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
if (global) { if (global) {
string tempName; string tempName;
for (unsigned int i(0); i < fNumGlobalParam; ++i) { for (unsigned int i(0); i < fNumGlobalParam; ++i) {
if (InParameterList(i, paramList))
outFile << (*msrParamList)[i].fName.Data() << endl; outFile << (*msrParamList)[i].fName.Data() << endl;
} }
for (unsigned int i(0); i < fNumSpecParam; ++i) { for (unsigned int i(0); i < fNumSpecParam; ++i) {
if (InParameterList(fNumGlobalParam + fNumSpecParam*counter + i, paramList)) {
tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data(); tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
string::size_type loc = tempName.rfind(curRunNumber.str()); string::size_type loc = tempName.rfind(curRunNumber.str());
if (loc == tempName.length() - fRunNumberDigits) { if (loc == tempName.length() - fRunNumberDigits) {
@ -2035,8 +2047,10 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
cerr << endl; cerr << endl;
} }
} }
}
} else { } else {
for (unsigned int i(0); i < msrNoOfParams; ++i) { for (unsigned int i(0); i < msrNoOfParams; ++i) {
if (InParameterList(i, paramList))
outFile << (*msrParamList)[i].fName.Data() << endl; outFile << (*msrParamList)[i].fName.Data() << endl;
} }
} }
@ -2073,9 +2087,11 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
if (global) { if (global) {
string tempName; string tempName;
for (unsigned int i(0); i < fNumGlobalParam; ++i) { for (unsigned int i(0); i < fNumGlobalParam; ++i) {
if (InParameterList(i, paramList))
outFile << " " << (*msrParamList)[i].fName.Data(); outFile << " " << (*msrParamList)[i].fName.Data();
} }
for (unsigned int i(0); i < fNumSpecParam; ++i) { for (unsigned int i(0); i < fNumSpecParam; ++i) {
if (InParameterList(i, paramList)) {
tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data(); tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
string::size_type loc = tempName.rfind(curRunNumber.str()); string::size_type loc = tempName.rfind(curRunNumber.str());
if (loc == tempName.length() - fRunNumberDigits) { if (loc == tempName.length() - fRunNumberDigits) {
@ -2086,8 +2102,10 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
cerr << endl; cerr << endl;
} }
} }
}
} else { } else {
for (unsigned int i(0); i < msrNoOfParams; ++i) { for (unsigned int i(0); i < msrNoOfParams; ++i) {
if (InParameterList(i, paramList))
outFile << " " << (*msrParamList)[i].fName.Data(); outFile << " " << (*msrParamList)[i].fName.Data();
} }
} }
@ -2132,6 +2150,7 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
string tempName; string tempName;
unsigned int idx; unsigned int idx;
for (unsigned int i(0); i < fNumGlobalParam; ++i) { for (unsigned int i(0); i < fNumGlobalParam; ++i) {
if (InParameterList(i, paramList)) {
outFile << (*msrParamList)[i].fName.Data() << " = "; outFile << (*msrParamList)[i].fName.Data() << " = ";
if ((*msrParamList)[i].fPosErrorPresent) { if ((*msrParamList)[i].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db); WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
@ -2146,8 +2165,10 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
outFile << fabs((*msrParamList)[i].fStep) << ", "; outFile << fabs((*msrParamList)[i].fStep) << ", ";
outFile << fabs((*msrParamList)[i].fStep) << ",\\" << endl; outFile << fabs((*msrParamList)[i].fStep) << ",\\" << endl;
} }
}
for (unsigned int i(0); i < fNumSpecParam; ++i) { for (unsigned int i(0); i < fNumSpecParam; ++i) {
idx = fNumGlobalParam + fNumSpecParam*counter + i; idx = fNumGlobalParam + fNumSpecParam*counter + i;
if (InParameterList(idx, paramList)) {
tempName = (*msrParamList)[idx].fName.Data(); tempName = (*msrParamList)[idx].fName.Data();
string::size_type loc = tempName.rfind(curRunNumber.str()); string::size_type loc = tempName.rfind(curRunNumber.str());
if (loc == tempName.length() - fRunNumberDigits) { if (loc == tempName.length() - fRunNumberDigits) {
@ -2169,8 +2190,10 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
outFile << ",\\" << endl; outFile << ",\\" << endl;
} }
} }
}
} else { } else {
for (unsigned int i(0); i < msrNoOfParams; ++i) { for (unsigned int i(0); i < msrNoOfParams; ++i) {
if (InParameterList(i, paramList)) {
outFile << (*msrParamList)[i].fName.Data() << " = "; outFile << (*msrParamList)[i].fName.Data() << " = ";
if ((*msrParamList)[i].fPosErrorPresent) { if ((*msrParamList)[i].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db); WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
@ -2189,6 +2212,7 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
outFile << ",\\" << endl; outFile << ",\\" << endl;
} }
} }
}
if (msrStatistic->fChisq) if (msrStatistic->fChisq)
outFile << "CHISQ = " << msrStatistic->fMin << ", 0, 0,\\" << endl; outFile << "CHISQ = " << msrStatistic->fMin << ", 0, 0,\\" << endl;
@ -2221,13 +2245,18 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
string s; string s;
if (global) { if (global) {
for (unsigned int i(0); i < fNumGlobalParam; ++i) { for (unsigned int i(0); i < fNumGlobalParam; ++i) {
if (InParameterList(i, paramList)) {
s = (*msrParamList)[i].fName.Data(); s = (*msrParamList)[i].fName.Data();
length = s.length(); length = s.length();
if (length > maxlength) if (length > maxlength)
maxlength = length; maxlength = length;
} }
}
unsigned int idx;
for (unsigned int i(0); i < fNumSpecParam; ++i) { for (unsigned int i(0); i < fNumSpecParam; ++i) {
s = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data(); idx = fNumGlobalParam + fNumSpecParam*counter + i;
if (InParameterList(idx, paramList)) {
s = (*msrParamList)[idx].fName.Data();
string::size_type loc = s.rfind(curRunNumber.str()); string::size_type loc = s.rfind(curRunNumber.str());
if (loc == s.length() - fRunNumberDigits) { if (loc == s.length() - fRunNumberDigits) {
length = s.length() - fRunNumberDigits; length = s.length() - fRunNumberDigits;
@ -2239,14 +2268,17 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
cerr << endl; cerr << endl;
} }
} }
}
} else { } else {
for (unsigned int i(0); i < msrNoOfParams; ++i) { for (unsigned int i(0); i < msrNoOfParams; ++i) {
if (InParameterList(i, paramList)) {
s = (*msrParamList)[i].fName.Data(); s = (*msrParamList)[i].fName.Data();
length = s.length(); length = s.length();
if (length > maxlength) if (length > maxlength)
maxlength = length; maxlength = length;
} }
} }
}
if (maxlength < 13) if (maxlength < 13)
maxlength = 13; // will use a minimum field width of 13 which corresponds to: -1.23456e-07 + ' ' maxlength = 13; // will use a minimum field width of 13 which corresponds to: -1.23456e-07 + ' '
else else
@ -2274,13 +2306,18 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
// in the GLOBAL mode write only global parameters and those which belong to the actual run - in the NORMAL mode write all parameters // in the GLOBAL mode write only global parameters and those which belong to the actual run - in the NORMAL mode write all parameters
if (global) { if (global) {
for (unsigned int i(0); i < fNumGlobalParam; ++i) { for (unsigned int i(0); i < fNumGlobalParam; ++i) {
if (InParameterList(i, paramList)) {
s = (*msrParamList)[i].fName.Data(); s = (*msrParamList)[i].fName.Data();
outFile << setw(maxlength) << left << s \ outFile << setw(maxlength) << left << s \
<< setw(maxlength + 6) << left << s + "PosErr" \ << setw(maxlength + 6) << left << s + "PosErr" \
<< setw(maxlength + 6) << left << s + "NegErr"; << setw(maxlength + 6) << left << s + "NegErr";
} }
}
unsigned int idx;
for (unsigned int i(0); i < fNumSpecParam; ++i) { for (unsigned int i(0); i < fNumSpecParam; ++i) {
s = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data(); idx = fNumGlobalParam + fNumSpecParam*counter + i;
if (InParameterList(idx, paramList)) {
s = (*msrParamList)[idx].fName.Data();
string::size_type loc = s.rfind(curRunNumber.str()); string::size_type loc = s.rfind(curRunNumber.str());
if (loc == s.length() - fRunNumberDigits) { if (loc == s.length() - fRunNumberDigits) {
s = s.substr(0, loc); s = s.substr(0, loc);
@ -2293,14 +2330,17 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
cerr << endl; cerr << endl;
} }
} }
}
} else { } else {
for (unsigned int i(0); i < msrNoOfParams; ++i) { for (unsigned int i(0); i < msrNoOfParams; ++i) {
if (InParameterList(i, paramList)) {
s = (*msrParamList)[i].fName.Data(); s = (*msrParamList)[i].fName.Data();
outFile << setw(maxlength) << left << s \ outFile << setw(maxlength) << left << s \
<< setw(maxlength + 6) << left << s + "PosErr" \ << setw(maxlength + 6) << left << s + "PosErr" \
<< setw(maxlength + 6) << left << s + "NegErr"; << setw(maxlength + 6) << left << s + "NegErr";
} }
} }
}
s.clear(); s.clear();
if (msrStatistic->fChisq) if (msrStatistic->fChisq)
@ -2340,6 +2380,7 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
// in the GLOBAL mode write only global parameters and those which belong to the actual run - in the NORMAL mode write all parameters // in the GLOBAL mode write only global parameters and those which belong to the actual run - in the NORMAL mode write all parameters
if (global) { if (global) {
for (unsigned int i(0); i < fNumGlobalParam; ++i) { for (unsigned int i(0); i < fNumGlobalParam; ++i) {
if (InParameterList(i, paramList)) {
if ((*msrParamList)[i].fPosErrorPresent) if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db); WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
else else
@ -2352,9 +2393,11 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
WriteValue(outFile, fabs((*msrParamList)[i].fStep), (*msrParamList)[i].fStep, maxlength, db); WriteValue(outFile, fabs((*msrParamList)[i].fStep), (*msrParamList)[i].fStep, maxlength, db);
} }
}
unsigned int idx; unsigned int idx;
for (unsigned int i(0); i < fNumSpecParam; ++i) { for (unsigned int i(0); i < fNumSpecParam; ++i) {
idx = fNumGlobalParam + fNumSpecParam*counter + i; idx = fNumGlobalParam + fNumSpecParam*counter + i;
if (InParameterList(idx, paramList)) {
if ((*msrParamList)[idx].fPosErrorPresent) if ((*msrParamList)[idx].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, maxlength, db); WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, maxlength, db);
else else
@ -2367,8 +2410,10 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, maxlength, db); WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, maxlength, db);
} }
}
} else { } else {
for (unsigned int i(0); i < msrNoOfParams; ++i) { for (unsigned int i(0); i < msrNoOfParams; ++i) {
if (InParameterList(i, paramList)) {
if ((*msrParamList)[i].fPosErrorPresent) if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db); WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
else else
@ -2382,6 +2427,7 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
WriteValue(outFile, fabs((*msrParamList)[i].fStep), fabs((*msrParamList)[i].fStep), maxlength, db); WriteValue(outFile, fabs((*msrParamList)[i].fStep), fabs((*msrParamList)[i].fStep), maxlength, db);
} }
} }
}
WriteValue(outFile, msrStatistic->fMin, maxlength); WriteValue(outFile, msrStatistic->fMin, maxlength);
@ -2505,6 +2551,24 @@ int PMsr2Data::GetFirstSignificantDigit(const double &value) const
return prec+1; return prec+1;
} }
//-------------------------------------------------------------
/**
*
*/
bool PMsr2Data::InParameterList(const unsigned int &paramValue, const vector<unsigned int> &paramList) const
{
// if paramList.size() == 0, i.e. use ALL parameters
if (paramList.size() == 0)
return true;
for (unsigned int i=0; i<paramList.size(); i++) {
if (paramValue+1 == paramList[i])
return true;
}
return false;
}
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------
// end // end
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------

View File

@ -71,7 +71,7 @@ class PMsr2Data
bool PrepareNewInputFile(unsigned int, bool) const; // template bool PrepareNewInputFile(unsigned int, bool) const; // template
bool PrepareGlobalInputFile(unsigned int, const string&, unsigned int) const; // generate msr-input file for a global fit bool PrepareGlobalInputFile(unsigned int, const string&, unsigned int) const; // generate msr-input file for a global fit
int WriteOutput(const string&, bool, unsigned int, bool global = false, unsigned int counter = 0) const; int WriteOutput(const string&, const vector<unsigned int>&, bool, unsigned int, bool global = false, unsigned int counter = 0) const;
private: private:
bool PrepareNewSortedInputFile(unsigned int) const; // template bool PrepareNewSortedInputFile(unsigned int) const; // template
@ -80,6 +80,7 @@ class PMsr2Data
void WriteValue(fstream &outFile, const double &value, const unsigned int &width) const; void WriteValue(fstream &outFile, const double &value, const unsigned int &width) const;
void WriteValue(fstream &outFile, const double &value, const double &errValue, const unsigned int &width, const bool &db) const; void WriteValue(fstream &outFile, const double &value, const double &errValue, const unsigned int &width, const bool &db) const;
int GetFirstSignificantDigit(const double &value) const; int GetFirstSignificantDigit(const double &value) const;
bool InParameterList(const unsigned int &paramValue, const vector<unsigned int>&) const;
string fFileExtension; string fFileExtension;
vector<unsigned int> fRunVector; vector<unsigned int> fRunVector;

View File

@ -49,6 +49,7 @@
using namespace std; using namespace std;
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/case_conv.hpp> // for to_lower() in std::string #include <boost/algorithm/string/case_conv.hpp> // for to_lower() in std::string
using namespace boost::algorithm; using namespace boost::algorithm;
@ -84,14 +85,10 @@ bool isNumber(const string &s)
void msr2data_syntax() void msr2data_syntax()
{ {
cout << endl << "usage 0: msr2data [--version] | [--help]"; cout << endl << "usage 0: msr2data [--version] | [--help]";
cout << endl << "usage 1: msr2data <run> <extension> [-o<outputfile>] [new] [data] [[no]header] [nosummary] [global[+[!]]]"; cout << endl << "usage 1: msr2data <run> <extension> options";
cout << endl << " [fit [-k] [-t] | fit-<template>[!] [-k] [-t] | msr-<template>]"; cout << endl << "usage 2: msr2data <run1> <run2> <extension> options";
cout << endl << "usage 2: msr2data <run1> <run2> <extension> [-o<outputfile>] [new] [data] [[no]header] [nosummary] [global[+[!]]]"; cout << endl << "usage 3: msr2data \\[<runList>\\] <extension> options";
cout << endl << " [fit [-k] [-t] | fit-<template>[!] [-k] [-t] | msr-<template>]"; cout << endl << "usage 4: msr2data <runListFileName> <extension> options";
cout << endl << "usage 3: msr2data \\[<runList>\\] <extension> [-o<outputfile> ] [new] [data] [[no]header] [nosummary] [global[+[!]]]";
cout << endl << " [fit [-k] [-t] | fit-<template>[!] [-k] [-t] | msr-<template>]";
cout << endl << "usage 4: msr2data <runlist> <extension> [-o<outputfile>] [new] [data] [[no]header] [nosummary] [global[+[!]]]";
cout << endl << " [fit [-k] [-t] | fit-<template>[!] [-k] [-t] | msr-<template>]";
cout << endl; cout << endl;
cout << endl << " <runList> can be:"; cout << endl << " <runList> can be:";
cout << endl << " (i) <run0>, <run1>, <run2>, ... <runN> : run numbers, e.g. 123 124"; cout << endl << " (i) <run0>, <run1>, <run2>, ... <runN> : run numbers, e.g. 123 124";
@ -99,7 +96,12 @@ void msr2data_syntax()
cout << endl << " (iii) <run0>:<runN>:<step> : a sequence, e.g. 123:127:2 -> 123 125 127"; cout << endl << " (iii) <run0>:<runN>:<step> : a sequence, e.g. 123:127:2 -> 123 125 127";
cout << endl << " <step> will give the step width and has to be a positive number!"; cout << endl << " <step> will give the step width and has to be a positive number!";
cout << endl << " a <runList> can also combine (i)-(iii), e.g. 123 128-130 133, etc."; cout << endl << " a <runList> can also combine (i)-(iii), e.g. 123 128-130 133, etc.";
cout << endl << " <runListFileName> : an ASCII file containing a list of run numbers and optional";
cout << endl << " external parameters is passed to msr2data. For details see";
cout << endl << " the online documentation: http://lmu.web.psi.ch/musrfit/user/MUSR/Msr2Data.html";
cout << endl << " <extension> : msr-file extension, e.g. _tf_h13 for the file name 8472_tf_h13.msr"; cout << endl << " <extension> : msr-file extension, e.g. _tf_h13 for the file name 8472_tf_h13.msr";
cout << endl;
cout << endl << "options:";
cout << endl << " -o<outputfile> : specify the name of the DB or column-data output file; default: out.db/out.dat"; cout << endl << " -o<outputfile> : specify the name of the DB or column-data output file; default: out.db/out.dat";
cout << endl << " if the option '-o none' is used, no output file will be written."; cout << endl << " if the option '-o none' is used, no output file will be written.";
cout << endl << " new : before writing a new output file, delete the contents of any existing file with the same name"; cout << endl << " new : before writing a new output file, delete the contents of any existing file with the same name";
@ -109,6 +111,10 @@ void msr2data_syntax()
cout << endl << " If either none or both of the header options are given, the file header will be written"; cout << endl << " If either none or both of the header options are given, the file header will be written";
cout << endl << " if a new file is created, but not if the output file exists already!"; cout << endl << " if a new file is created, but not if the output file exists already!";
cout << endl << " nosummary : no additional data from the run data file is written to the output file"; cout << endl << " nosummary : no additional data from the run data file is written to the output file";
cout << endl << " paramList <param> : option used to select the parameters which shall be exported.";
cout << endl << " <param> is a list of parameter numbers to be exported. Allowed lists are:";
cout << endl << " 1-16 will export parameters 1 to 16. 1 3 5 will export parameters 1 3 5.";
cout << endl << " A combination of both is possible, e.g. 1-16 19 31 62, and so on.";
cout << endl << " fit : invoke musrfit to fit the specified runs"; cout << endl << " fit : invoke musrfit to fit the specified runs";
cout << endl << " All msr input files are assumed to be present, none is newly generated!"; cout << endl << " All msr input files are assumed to be present, none is newly generated!";
cout << endl << " fit-<template>! : generate msr files for the runs to be processed from the <template> run"; cout << endl << " fit-<template>! : generate msr files for the runs to be processed from the <template> run";
@ -149,6 +155,10 @@ void msr2data_syntax()
cout << endl << " will use 2045_tf_histo.msr as templete, and subsequently generating msr-files from the run-list:"; cout << endl << " will use 2045_tf_histo.msr as templete, and subsequently generating msr-files from the run-list:";
cout << endl << " 2047 2049 2051 2053 2056 (2047_tf_histo.msr etc.) and fit them."; cout << endl << " 2047 2049 2051 2053 2056 (2047_tf_histo.msr etc.) and fit them.";
cout << endl; cout << endl;
cout << endl << " msr2data 2046 2058 _tf_histo paramList 1-12 data -o fitParam.dat";
cout << endl << " will export the parameters number 1 trough 12 in a column like fashion of the runs 2046 to 2058,";
cout << endl << " collected form the msr-files 2046_tf_histo.msr and so on.";
cout << endl;
cout << endl << " For further information please refer to"; cout << endl << " For further information please refer to";
cout << endl << " http://lmu.web.psi.ch/musrfit/user/MUSR/Msr2Data.html"; cout << endl << " http://lmu.web.psi.ch/musrfit/user/MUSR/Msr2Data.html";
cout << endl << " https://intranet.psi.ch/MUSR/Msr2Data"; cout << endl << " https://intranet.psi.ch/MUSR/Msr2Data";
@ -208,7 +218,8 @@ string msr2data_validArguments(const vector<string> &arg)
if ( (!iter->compare("header")) || (!iter->compare("noheader")) || (!iter->compare("nosummary")) \ if ( (!iter->compare("header")) || (!iter->compare("noheader")) || (!iter->compare("nosummary")) \
|| (!iter->substr(0,3).compare("fit")) || (!iter->compare("-k")) || (!iter->compare("-t")) \ || (!iter->substr(0,3).compare("fit")) || (!iter->compare("-k")) || (!iter->compare("-t")) \
|| (!iter->compare("data")) || (!iter->substr(0,4).compare("msr-")) || (!iter->compare("global")) \ || (!iter->compare("data")) || (!iter->substr(0,4).compare("msr-")) || (!iter->compare("global")) \
|| (!iter->compare("global+")) || (!iter->compare("global+!")) || (!iter->compare("new")) ) || (!iter->compare("global+")) || (!iter->compare("global+!")) || (!iter->compare("new")) \
|| !iter->compare("paramList") )
word.clear(); word.clear();
else if (!iter->substr(0,2).compare("-o")) { else if (!iter->substr(0,2).compare("-o")) {
word.clear(); word.clear();
@ -393,6 +404,92 @@ int msr2data_doInputCreation(vector<string> &arg, bool &inputOnly)
return temp; return temp;
} }
//--------------------------------------------------------------------------
/**
* <p>
*
*/
int msr2data_paramList(vector<string> &arg, vector<unsigned int> &paramList)
{
paramList.clear(); // make sure paramList is empty
unsigned int idx=0;
// check if paramList tag is present
for (unsigned int i=0; i<arg.size(); i++) {
if (!arg[i].compare("paramList")) {
idx = i+1;
break;
}
}
if (idx == 0) { // paramList tag NOT present
return 0;
}
// make sure there are parameter list elements to follow
if (idx == arg.size()) {
cerr << endl << "**ERROR** found paramList without any arguments!" << endl;
msr2data_syntax();
return -1;
}
// paramList tag present and further elements present: collect them
vector<string> str;
unsigned int idx_end=0;
size_t pos=string::npos;
for (unsigned int i=idx; i<arg.size(); i++) {
cout << i << ": " << arg[i] << endl;
pos = arg[i].find("-");
if (pos == 0) { // likely something like -o, -k, etc.
idx_end = i;
break;
} else if (pos != string::npos) { // looks like a parameter list like n0-n1
boost::split(str, arg[i], boost::is_any_of("-"));
if (str.size() != 2) { // something is wrong, since the structure n0-n1 is expected
cerr << endl << "**ERROR** found token " << arg[i] << " in paramList command which cannot be handled." << endl;
msr2data_syntax();
return -1;
}
if (!str[0].compare("fit") || !str[0].compare("msr")) {
idx_end = i;
break;
}
if (!isNumber(str[0]) || !isNumber(str[1])) {
cerr << endl << "**ERROR** found token " << arg[i] << " in paramList command which cannot be handled." << endl;
msr2data_syntax();
return -1;
}
unsigned int start=boost::lexical_cast<unsigned int>(str[0]);
unsigned int end=boost::lexical_cast<unsigned int>(str[1]);
for (unsigned int j=start; j<=end; j++)
paramList.push_back(j);
} else if (isNumber(arg[i])) { // a single number
paramList.push_back(boost::lexical_cast<unsigned int>(arg[i]));
} else { // likely the next argument not related to paramList
idx_end = i;
break;
}
}
if (idx_end == 0)
idx_end = arg.size();
// remove all the paramList arguments for arg
arg.erase(arg.begin()+idx-1, arg.begin()+idx_end);
// go through the parameter list and make sure the values are unique
for (unsigned int i=0; i<paramList.size(); i++) {
for (unsigned int j=i+1; j<paramList.size(); j++) {
if (paramList[i] == paramList[j]) {
cerr << endl << "**ERROR** the parameter list numbers have to be unique. Found " << paramList[i] << " at least 2 times." << endl;
msr2data_syntax();
return -1;
}
}
}
return paramList.size();
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>msr2data is used to generate msr-files based on template msr-files, automatically fit these new msr-files, * <p>msr2data is used to generate msr-files based on template msr-files, automatically fit these new msr-files,
@ -441,6 +538,7 @@ int main(int argc, char *argv[])
vector<unsigned int> run_vec; vector<unsigned int> run_vec;
string run_list; string run_list;
string msrExtension; string msrExtension;
vector<unsigned int> param_vec;
try { try {
if (arg[0].at(0) == '[') { // In case a list of runs is given by [...] if (arg[0].at(0) == '[') { // In case a list of runs is given by [...]
@ -557,6 +655,13 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
// check if parameter list is given
int noParamList(msr2data_paramList(arg, param_vec));
if (noParamList == -1) {
arg.clear();
return -1;
}
// check the validity of the command line given command line arguments // check the validity of the command line given command line arguments
string wrongArgument(msr2data_validArguments(arg)); string wrongArgument(msr2data_validArguments(arg));
if (!wrongArgument.empty()) { if (!wrongArgument.empty()) {
@ -644,7 +749,6 @@ int main(int argc, char *argv[])
} }
// if no fitting should be done, check if only the input files should be created // if no fitting should be done, check if only the input files should be created
if (!temp) { if (!temp) {
temp = msr2data_doInputCreation(arg, onlyInputCreation); temp = msr2data_doInputCreation(arg, onlyInputCreation);
if (onlyInputCreation) { if (onlyInputCreation) {
@ -798,7 +902,7 @@ int main(int argc, char *argv[])
while (msr2dataHandler->GetPresentRun()) { while (msr2dataHandler->GetPresentRun()) {
// write DB or dat file // write DB or dat file
status = msr2dataHandler->WriteOutput(outputFile, db, writeHeader, !setNormalMode, counter); status = msr2dataHandler->WriteOutput(outputFile, param_vec, db, writeHeader, !setNormalMode, counter);
if (status == -1) { if (status == -1) {
msr2data_cleanup(msr2dataHandler, arg); msr2data_cleanup(msr2dataHandler, arg);
return status; return status;
@ -871,7 +975,7 @@ int main(int argc, char *argv[])
status = msr2dataHandler->ReadMsrFile(strInfile.str()); status = msr2dataHandler->ReadMsrFile(strInfile.str());
if (status != PMUSR_SUCCESS) { if (status != PMUSR_SUCCESS) {
// if the msr-file cannot be read, write no output but proceed to the next run // if the msr-file cannot be read, write no output but proceed to the next run
status = msr2dataHandler->WriteOutput("none", db, writeHeader); status = msr2dataHandler->WriteOutput("none", param_vec, db, writeHeader);
if (status == -1) { if (status == -1) {
msr2data_cleanup(msr2dataHandler, arg); msr2data_cleanup(msr2dataHandler, arg);
return status; return status;
@ -886,7 +990,7 @@ int main(int argc, char *argv[])
status = msr2dataHandler->ReadRunDataFile(); status = msr2dataHandler->ReadRunDataFile();
// write DB or dat file // write DB or dat file
status = msr2dataHandler->WriteOutput(outputFile, db, writeHeader); status = msr2dataHandler->WriteOutput(outputFile, param_vec, db, writeHeader);
if (status == -1) { if (status == -1) {
msr2data_cleanup(msr2dataHandler, arg); msr2data_cleanup(msr2dataHandler, arg);
return status; return status;