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
===================================
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-02-23 It is now possible to export the averaged data/Fourier
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)
*
* \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 withHeader write output file header 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
*/
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")) {
fRunVectorIter++;
return PMUSR_SUCCESS;
@ -2008,7 +2018,7 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
if (fDataHandler) {
for (unsigned int i(0); i < dataParamLabels.size(); ++i) {
outFile << dataParamLabels[i] << endl;
outFile << dataParamLabels[i] << endl;
}
}
@ -2022,22 +2032,26 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
if (global) {
string tempName;
for (unsigned int i(0); i < fNumGlobalParam; ++i) {
outFile << (*msrParamList)[i].fName.Data() << endl;
if (InParameterList(i, paramList))
outFile << (*msrParamList)[i].fName.Data() << endl;
}
for (unsigned int i(0); i < fNumSpecParam; ++i) {
tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
string::size_type loc = tempName.rfind(curRunNumber.str());
if (loc == tempName.length() - fRunNumberDigits) {
outFile << tempName.substr(0, loc) << endl;
} else {
cerr << endl << ">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
cerr << endl << ">> msr2data: **ERROR** The output will be flawed!";
cerr << endl;
if (InParameterList(fNumGlobalParam + fNumSpecParam*counter + i, paramList)) {
tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
string::size_type loc = tempName.rfind(curRunNumber.str());
if (loc == tempName.length() - fRunNumberDigits) {
outFile << tempName.substr(0, loc) << endl;
} else {
cerr << endl << ">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
cerr << endl << ">> msr2data: **ERROR** The output will be flawed!";
cerr << endl;
}
}
}
} else {
for (unsigned int i(0); i < msrNoOfParams; ++i) {
outFile << (*msrParamList)[i].fName.Data() << endl;
if (InParameterList(i, paramList))
outFile << (*msrParamList)[i].fName.Data() << endl;
}
}
@ -2073,22 +2087,26 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
if (global) {
string tempName;
for (unsigned int i(0); i < fNumGlobalParam; ++i) {
outFile << " " << (*msrParamList)[i].fName.Data();
if (InParameterList(i, paramList))
outFile << " " << (*msrParamList)[i].fName.Data();
}
for (unsigned int i(0); i < fNumSpecParam; ++i) {
tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
string::size_type loc = tempName.rfind(curRunNumber.str());
if (loc == tempName.length() - fRunNumberDigits) {
outFile << " " << tempName.substr(0, loc);
} else {
cerr << endl << ">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
cerr << endl << ">> msr2data: **ERROR** The output will be flawed!";
cerr << endl;
if (InParameterList(i, paramList)) {
tempName = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
string::size_type loc = tempName.rfind(curRunNumber.str());
if (loc == tempName.length() - fRunNumberDigits) {
outFile << " " << tempName.substr(0, loc);
} else {
cerr << endl << ">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
cerr << endl << ">> msr2data: **ERROR** The output will be flawed!";
cerr << endl;
}
}
}
} else {
for (unsigned int i(0); i < msrNoOfParams; ++i) {
outFile << " " << (*msrParamList)[i].fName.Data();
if (InParameterList(i, paramList))
outFile << " " << (*msrParamList)[i].fName.Data();
}
}
@ -2132,61 +2150,67 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
string tempName;
unsigned int idx;
for (unsigned int i(0); i < fNumGlobalParam; ++i) {
outFile << (*msrParamList)[i].fName.Data() << " = ";
if ((*msrParamList)[i].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
outFile << ", ";
} else {
outFile << (*msrParamList)[i].fValue << ", ";
}
if (InParameterList(i, paramList)) {
outFile << (*msrParamList)[i].fName.Data() << " = ";
if ((*msrParamList)[i].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
outFile << ", ";
} else {
outFile << (*msrParamList)[i].fValue << ", ";
}
if ((*msrParamList)[i].fPosErrorPresent)
outFile << (*msrParamList)[i].fPosError << ", ";
else
outFile << fabs((*msrParamList)[i].fStep) << ", ";
outFile << fabs((*msrParamList)[i].fStep) << ",\\" << endl;
if ((*msrParamList)[i].fPosErrorPresent)
outFile << (*msrParamList)[i].fPosError << ", ";
else
outFile << fabs((*msrParamList)[i].fStep) << ", ";
outFile << fabs((*msrParamList)[i].fStep) << ",\\" << endl;
}
}
for (unsigned int i(0); i < fNumSpecParam; ++i) {
idx = fNumGlobalParam + fNumSpecParam*counter + i;
tempName = (*msrParamList)[idx].fName.Data();
string::size_type loc = tempName.rfind(curRunNumber.str());
if (loc == tempName.length() - fRunNumberDigits) {
outFile << tempName.substr(0, loc) << " = ";
if ((*msrParamList)[idx].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, outFile.width(), db);
outFile << ", ";
} else {
outFile << (*msrParamList)[idx].fValue << ", ";
}
if ((*msrParamList)[idx].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[idx].fPosError, (*msrParamList)[idx].fPosError, outFile.width(), db);
outFile << ", ";
} else {
if (InParameterList(idx, paramList)) {
tempName = (*msrParamList)[idx].fName.Data();
string::size_type loc = tempName.rfind(curRunNumber.str());
if (loc == tempName.length() - fRunNumberDigits) {
outFile << tempName.substr(0, loc) << " = ";
if ((*msrParamList)[idx].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, outFile.width(), db);
outFile << ", ";
} else {
outFile << (*msrParamList)[idx].fValue << ", ";
}
if ((*msrParamList)[idx].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[idx].fPosError, (*msrParamList)[idx].fPosError, outFile.width(), db);
outFile << ", ";
} else {
WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, outFile.width(), db);
outFile << ", ";
}
WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, outFile.width(), db);
outFile << ", ";
outFile << ",\\" << endl;
}
WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, outFile.width(), db);
outFile << ",\\" << endl;
}
}
} else {
for (unsigned int i(0); i < msrNoOfParams; ++i) {
outFile << (*msrParamList)[i].fName.Data() << " = ";
if ((*msrParamList)[i].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
outFile << ", ";
} else {
outFile << (*msrParamList)[i].fValue << ", ";
}
if ((*msrParamList)[i].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, outFile.width(), db);
outFile << ", ";
} else {
if (InParameterList(i, paramList)) {
outFile << (*msrParamList)[i].fName.Data() << " = ";
if ((*msrParamList)[i].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
outFile << ", ";
} else {
outFile << (*msrParamList)[i].fValue << ", ";
}
if ((*msrParamList)[i].fPosErrorPresent) {
WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, outFile.width(), db);
outFile << ", ";
} else {
WriteValue(outFile, (*msrParamList)[i].fStep, (*msrParamList)[i].fStep, outFile.width(), db);
outFile << ", ";
}
WriteValue(outFile, (*msrParamList)[i].fStep, (*msrParamList)[i].fStep, outFile.width(), db);
outFile << ", ";
outFile << ",\\" << endl;
}
WriteValue(outFile, (*msrParamList)[i].fStep, (*msrParamList)[i].fStep, outFile.width(), db);
outFile << ",\\" << endl;
}
}
@ -2221,30 +2245,38 @@ int PMsr2Data::WriteOutput(const string &outfile, bool db, unsigned int withHead
string s;
if (global) {
for (unsigned int i(0); i < fNumGlobalParam; ++i) {
s = (*msrParamList)[i].fName.Data();
length = s.length();
if (length > maxlength)
maxlength = length;
}
for (unsigned int i(0); i < fNumSpecParam; ++i) {
s = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
string::size_type loc = s.rfind(curRunNumber.str());
if (loc == s.length() - fRunNumberDigits) {
length = s.length() - fRunNumberDigits;
if (InParameterList(i, paramList)) {
s = (*msrParamList)[i].fName.Data();
length = s.length();
if (length > maxlength)
maxlength = length;
} else {
cerr << endl << ">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
cerr << endl << ">> msr2data: **ERROR** The output will be flawed!";
cerr << endl;
}
}
unsigned int idx;
for (unsigned int i(0); i < fNumSpecParam; ++i) {
idx = fNumGlobalParam + fNumSpecParam*counter + i;
if (InParameterList(idx, paramList)) {
s = (*msrParamList)[idx].fName.Data();
string::size_type loc = s.rfind(curRunNumber.str());
if (loc == s.length() - fRunNumberDigits) {
length = s.length() - fRunNumberDigits;
if (length > maxlength)
maxlength = length;
} else {
cerr << endl << ">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
cerr << endl << ">> msr2data: **ERROR** The output will be flawed!";
cerr << endl;
}
}
}
} else {
for (unsigned int i(0); i < msrNoOfParams; ++i) {
s = (*msrParamList)[i].fName.Data();
length = s.length();
if (length > maxlength)
maxlength = length;
if (InParameterList(i, paramList)) {
s = (*msrParamList)[i].fName.Data();
length = s.length();
if (length > maxlength)
maxlength = length;
}
}
}
if (maxlength < 13)
@ -2274,31 +2306,39 @@ 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
if (global) {
for (unsigned int i(0); i < fNumGlobalParam; ++i) {
s = (*msrParamList)[i].fName.Data();
outFile << setw(maxlength) << left << s \
<< setw(maxlength + 6) << left << s + "PosErr" \
<< setw(maxlength + 6) << left << s + "NegErr";
}
for (unsigned int i(0); i < fNumSpecParam; ++i) {
s = (*msrParamList)[fNumGlobalParam + fNumSpecParam*counter + i].fName.Data();
string::size_type loc = s.rfind(curRunNumber.str());
if (loc == s.length() - fRunNumberDigits) {
s = s.substr(0, loc);
if (InParameterList(i, paramList)) {
s = (*msrParamList)[i].fName.Data();
outFile << setw(maxlength) << left << s \
<< setw(maxlength + 6) << left << s + "PosErr" \
<< setw(maxlength + 6) << left << s + "NegErr";
} else {
cerr << endl << ">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
cerr << endl << ">> msr2data: **ERROR** The output will be flawed!";
cerr << endl;
}
}
unsigned int idx;
for (unsigned int i(0); i < fNumSpecParam; ++i) {
idx = fNumGlobalParam + fNumSpecParam*counter + i;
if (InParameterList(idx, paramList)) {
s = (*msrParamList)[idx].fName.Data();
string::size_type loc = s.rfind(curRunNumber.str());
if (loc == s.length() - fRunNumberDigits) {
s = s.substr(0, loc);
outFile << setw(maxlength) << left << s \
<< setw(maxlength + 6) << left << s + "PosErr" \
<< setw(maxlength + 6) << left << s + "NegErr";
} else {
cerr << endl << ">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
cerr << endl << ">> msr2data: **ERROR** The output will be flawed!";
cerr << endl;
}
}
}
} else {
for (unsigned int i(0); i < msrNoOfParams; ++i) {
s = (*msrParamList)[i].fName.Data();
outFile << setw(maxlength) << left << s \
<< setw(maxlength + 6) << left << s + "PosErr" \
<< setw(maxlength + 6) << left << s + "NegErr";
if (InParameterList(i, paramList)) {
s = (*msrParamList)[i].fName.Data();
outFile << setw(maxlength) << left << s \
<< setw(maxlength + 6) << left << s + "PosErr" \
<< setw(maxlength + 6) << left << s + "NegErr";
}
}
}
s.clear();
@ -2340,46 +2380,52 @@ 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
if (global) {
for (unsigned int i(0); i < fNumGlobalParam; ++i) {
if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
else
WriteValue(outFile, (*msrParamList)[i].fValue, maxlength);
if (InParameterList(i, paramList)) {
if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
else
WriteValue(outFile, (*msrParamList)[i].fValue, maxlength);
if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, maxlength, db);
else
WriteValue(outFile, fabs((*msrParamList)[i].fStep), (*msrParamList)[i].fStep, maxlength, db);
if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, maxlength, db);
else
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;
for (unsigned int i(0); i < fNumSpecParam; ++i) {
idx = fNumGlobalParam + fNumSpecParam*counter + i;
if ((*msrParamList)[idx].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, maxlength, db);
else
WriteValue(outFile, (*msrParamList)[idx].fValue, maxlength);
if (InParameterList(idx, paramList)) {
if ((*msrParamList)[idx].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, maxlength, db);
else
WriteValue(outFile, (*msrParamList)[idx].fValue, maxlength);
if ((*msrParamList)[idx].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[idx].fPosError, (*msrParamList)[idx].fPosError, maxlength, db);
else
WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, maxlength, db);
if ((*msrParamList)[idx].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[idx].fPosError, (*msrParamList)[idx].fPosError, maxlength, db);
else
WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, maxlength, db);
WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, maxlength, db);
}
}
} else {
for (unsigned int i(0); i < msrNoOfParams; ++i) {
if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
else
WriteValue(outFile, (*msrParamList)[i].fValue, maxlength);
if (InParameterList(i, paramList)) {
if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
else
WriteValue(outFile, (*msrParamList)[i].fValue, maxlength);
if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, maxlength, db);
else
WriteValue(outFile, fabs((*msrParamList)[i].fStep), fabs((*msrParamList)[i].fStep), maxlength, db);
if ((*msrParamList)[i].fPosErrorPresent)
WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, maxlength, db);
else
WriteValue(outFile, fabs((*msrParamList)[i].fStep), fabs((*msrParamList)[i].fStep), maxlength, db);
WriteValue(outFile, fabs((*msrParamList)[i].fStep), fabs((*msrParamList)[i].fStep), maxlength, db);
}
}
}
@ -2505,6 +2551,24 @@ int PMsr2Data::GetFirstSignificantDigit(const double &value) const
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
//-------------------------------------------------------------------------------------------------------

View File

@ -71,7 +71,7 @@ class PMsr2Data
bool PrepareNewInputFile(unsigned int, bool) const; // template
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:
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 double &errValue, const unsigned int &width, const bool &db) const;
int GetFirstSignificantDigit(const double &value) const;
bool InParameterList(const unsigned int &paramValue, const vector<unsigned int>&) const;
string fFileExtension;
vector<unsigned int> fRunVector;

View File

@ -49,6 +49,7 @@
using namespace std;
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/case_conv.hpp> // for to_lower() in std::string
using namespace boost::algorithm;
@ -84,14 +85,10 @@ bool isNumber(const string &s)
void msr2data_syntax()
{
cout << endl << "usage 0: msr2data [--version] | [--help]";
cout << endl << "usage 1: msr2data <run> <extension> [-o<outputfile>] [new] [data] [[no]header] [nosummary] [global[+[!]]]";
cout << endl << " [fit [-k] [-t] | fit-<template>[!] [-k] [-t] | msr-<template>]";
cout << endl << "usage 2: msr2data <run1> <run2> <extension> [-o<outputfile>] [new] [data] [[no]header] [nosummary] [global[+[!]]]";
cout << endl << " [fit [-k] [-t] | fit-<template>[!] [-k] [-t] | msr-<template>]";
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 << "usage 1: msr2data <run> <extension> options";
cout << endl << "usage 2: msr2data <run1> <run2> <extension> options";
cout << endl << "usage 3: msr2data \\[<runList>\\] <extension> options";
cout << endl << "usage 4: msr2data <runListFileName> <extension> options";
cout << endl;
cout << endl << " <runList> can be:";
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 << " <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 << " <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;
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 << " 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";
@ -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 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 << " 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 << " 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";
@ -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 << " 2047 2049 2051 2053 2056 (2047_tf_histo.msr etc.) and fit them.";
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 << " http://lmu.web.psi.ch/musrfit/user/MUSR/Msr2Data.html";
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")) \
|| (!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("global+")) || (!iter->compare("global+!")) || (!iter->compare("new")) )
|| (!iter->compare("global+")) || (!iter->compare("global+!")) || (!iter->compare("new")) \
|| !iter->compare("paramList") )
word.clear();
else if (!iter->substr(0,2).compare("-o")) {
word.clear();
@ -393,6 +404,92 @@ int msr2data_doInputCreation(vector<string> &arg, bool &inputOnly)
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,
@ -441,6 +538,7 @@ int main(int argc, char *argv[])
vector<unsigned int> run_vec;
string run_list;
string msrExtension;
vector<unsigned int> param_vec;
try {
if (arg[0].at(0) == '[') { // In case a list of runs is given by [...]
@ -557,7 +655,14 @@ int main(int argc, char *argv[])
return -1;
}
// check the validity of the command line given command line arguments
// 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
string wrongArgument(msr2data_validArguments(arg));
if (!wrongArgument.empty()) {
cerr << endl;
@ -567,18 +672,18 @@ int main(int argc, char *argv[])
return -1;
}
// check if the output format is DB or data
// check if the output format is DB or data
bool db(msr2data_useOption(arg, "data"));
// check the arguments for the "-o" option and set the output filename
// check the arguments for the "-o" option and set the output filename
string outputFile(msr2data_outputfile(arg, db));
// introduce check, if no output should be generated - in that case we do not need msrfile and rundata handlers later
// introduce check, if no output should be generated - in that case we do not need msrfile and rundata handlers later
bool realOutput(true);
if (!to_lower_copy(outputFile).compare("none"))
realOutput = false;
// create the msr2data-object and set the run numbers according to the runTAG above
// create the msr2data-object and set the run numbers according to the runTAG above
PMsr2Data *msr2dataHandler = new PMsr2Data(msrExtension);
int status;
@ -615,7 +720,7 @@ int main(int argc, char *argv[])
run_vec.clear();
// check if fitting should be done and in case, which template run number to use
// check if fitting should be done and in case, which template run number to use
int temp(0);
bool chainfit(true), onlyInputCreation(false);
string musrfitOptions;
@ -635,7 +740,7 @@ int main(int argc, char *argv[])
}
// check if any options should be passed to musrfit
// check if any options should be passed to musrfit
if (temp) {
if (!msr2data_useOption(arg, "-k"))
musrfitOptions.append("-k ");
@ -643,9 +748,8 @@ int main(int argc, char *argv[])
musrfitOptions.append("-t ");
}
// if no fitting should be done, check if only the input files should be created
if(!temp) {
// if no fitting should be done, check if only the input files should be created
if (!temp) {
temp = msr2data_doInputCreation(arg, onlyInputCreation);
if (onlyInputCreation) {
// if only input files should be created, do not write data to an output file (no matter, what has been determined earlier)
@ -672,8 +776,8 @@ int main(int argc, char *argv[])
globalMode = 2;
}
// At this point it should be clear if any template for input-file generation is given or not.
// Therefore, the number of digits in the run number format is determined only here.
// At this point it should be clear if any template for input-file generation is given or not.
// Therefore, the number of digits in the run number format is determined only here.
if(temp > 0) {
status = msr2dataHandler->DetermineRunNumberDigits(temp, setNormalMode);
} else {
@ -685,7 +789,7 @@ int main(int argc, char *argv[])
return status;
}
// Check if all given run numbers are covered by the formatting of the data file name
// Check if all given run numbers are covered by the formatting of the data file name
status = msr2dataHandler->CheckRunNumbersInRange();
if(status) {
cerr << endl;
@ -736,7 +840,7 @@ int main(int argc, char *argv[])
}
}
// GLOBAL MODE
// GLOBAL MODE
if (!setNormalMode) {
ostringstream strInfile;
strInfile << msr2dataHandler->GetPresentRun() << "+global" << msrExtension << ".msr";
@ -798,7 +902,7 @@ int main(int argc, char *argv[])
while (msr2dataHandler->GetPresentRun()) {
// 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) {
msr2data_cleanup(msr2dataHandler, arg);
return status;
@ -842,7 +946,7 @@ int main(int argc, char *argv[])
}
}
// and do the fitting
// and do the fitting
if (!onlyInputCreation) {
// check if MUSRFITPATH is set, if not issue a warning
string path("");
@ -866,12 +970,12 @@ int main(int argc, char *argv[])
}
}
// read msr-file
// read msr-file
if (realOutput) {
status = msr2dataHandler->ReadMsrFile(strInfile.str());
if (status != PMUSR_SUCCESS) {
// 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) {
msr2data_cleanup(msr2dataHandler, arg);
return status;
@ -881,12 +985,12 @@ int main(int argc, char *argv[])
}
}
// read data files
// read data files
if (writeSummary)
status = msr2dataHandler->ReadRunDataFile();
// write DB or dat file
status = msr2dataHandler->WriteOutput(outputFile, db, writeHeader);
// write DB or dat file
status = msr2dataHandler->WriteOutput(outputFile, param_vec, db, writeHeader);
if (status == -1) {
msr2data_cleanup(msr2dataHandler, arg);
return status;
@ -899,7 +1003,7 @@ int main(int argc, char *argv[])
// Unfortunately, this can be done in a coherent way only on that level
// Unfortunately, there are also problems with boost::filesystem::exists(outputFile)
// Therefore, first try to open the file for reading and if this works, write to it - not clean but it works
if(realOutput) {
if (realOutput) {
fileOutput = new fstream;
fileOutput->open(outputFile.c_str(), ios::in);
if (fileOutput->is_open()) {