Fixed a few more problems in msr2data.

That these did not surface earlier can only be due to the musrgui/musredit interface which has additional safeguards.
Obviously no one uses this program from the command line (my guess).
This commit is contained in:
Bastian M. Wojek
2011-01-22 12:39:34 +00:00
parent ebcd192509
commit 230586a2d4
3 changed files with 119 additions and 35 deletions

View File

@ -11,7 +11,7 @@ NEW any2many: an attempt to write the universial musr-data-file converter. Just
NEW musrt0: added the possibility to show the t0 saved in the data file 's'. Furthermore added the option NEW musrt0: added the possibility to show the t0 saved in the data file 's'. Furthermore added the option
--getT0FromPromptPeak, -g with <firstGoodBinOffset>: will, in non-interactive mode estimate the t0's from --getT0FromPromptPeak, -g with <firstGoodBinOffset>: will, in non-interactive mode estimate the t0's from
the prompt peak and write it into the msr-file (MUSR-133). the prompt peak and write it into the msr-file (MUSR-133).
FIXED a bug in the determination of the length of the run numbers in msr2data FIXED various bugs in msr2data
FIXED 2 little annoying problems: (i) now it is possible to zoom down to the single bin in musrview. FIXED 2 little annoying problems: (i) now it is possible to zoom down to the single bin in musrview.
(ii) when switching between data- and difference-view, the x-range doesn't change anymore. (ii) when switching between data- and difference-view, the x-range doesn't change anymore.
FIXED musrt0 crash for histogram number out of range (MUSR-157) FIXED musrt0 crash for histogram number out of range (MUSR-157)

View File

@ -703,6 +703,18 @@ bool PMsr2Data::PrepareGlobalInputFile(unsigned int tempRun, const string &msrOu
cout << endl << ">> msr2data: **INFO** Generating new global input msr file " << msrOutFile << endl; cout << endl << ">> msr2data: **INFO** Generating new global input msr file " << msrOutFile << endl;
// set some title for the msr-file
ostringstream titleStream;
titleStream << "Global msr file for the runs: ";
while (fRunVectorIter != fRunVector.end()) {
titleStream << *fRunVectorIter << " ";
++fRunVectorIter;
}
fRunVectorIter = fRunVector.begin();
fMsrHandler->SetMsrTitle(TString(titleStream.str()));
titleStream.clear();
titleStream.str("");
// search parameter list for run-specific parameters - the rest is assumed to be global // search parameter list for run-specific parameters - the rest is assumed to be global
string tempParamName; string tempParamName;
for (unsigned int i(0); i < msrParamList->size(); ++i) { for (unsigned int i(0); i < msrParamList->size(); ++i) {
@ -1257,7 +1269,7 @@ bool PMsr2Data::PrepareGlobalInputFile(unsigned int tempRun, const string &msrOu
// to obtain better starting parameter values for the global file // to obtain better starting parameter values for the global file
if (globalPlus) { if (globalPlus) {
// for the first file, prepare a sorted input from the internal data-structure // for the first file (or if the !-option is given), prepare a sorted input from the internal data-structure
// if chain-fitting is used, the successive files are copied from the first // if chain-fitting is used, the successive files are copied from the first
unsigned int oldTempRun(0); unsigned int oldTempRun(0);
bool firstrun(true); bool firstrun(true);
@ -1319,7 +1331,7 @@ bool PMsr2Data::PrepareGlobalInputFile(unsigned int tempRun, const string &msrOu
//cout << "Number of run specific parameters: " << fNumSpecParam << endl; //cout << "Number of run specific parameters: " << fNumSpecParam << endl;
if (newRunNumber.str().compare(tempRunNumber.str())) { // first run number does not match the template run number if (newRunNumber.str().compare(tempRunNumber.str())) { // first run number does not match the template run number
// in global+ mode, read in the single run msr-file // in global+ mode, read in the single run msr-file of the corresponding run
if (globalPlus) if (globalPlus)
singleRunMsrFile = GetSingleRunMsrFile(); singleRunMsrFile = GetSingleRunMsrFile();

View File

@ -121,6 +121,45 @@ void msr2data_syntax()
cout << endl << endl; cout << endl << endl;
} }
//--------------------------------------------------------------------------
/**
* <p>Checks if only valid options appear in the argument list
*
* <p><b>return:</b>
* - empty string if everything is fine
* - first found wrong argument in case of an error
*
* \param arg list of arguments
*
*/
string msr2data_validArguments(const vector<string> &arg)
{
string word;
for (vector<string>::const_iterator iter(arg.begin()); iter != arg.end(); ++iter) {
if ( (!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+!")) )
word.clear();
else if (!iter->substr(0,2).compare("-o")) {
word.clear();
if (!iter->compare("-o")) {
if (++iter == arg.end())
break;
else
continue;
}
} else {
word = *iter;
break;
}
}
return word;
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>filters out the output file name from at argument string * <p>filters out the output file name from at argument string
@ -141,7 +180,7 @@ string msr2data_outputfile(vector<string> &arg, bool db = true)
outputFile = "out.dat"; outputFile = "out.dat";
vector<string>::iterator iterNext(arg.begin()); vector<string>::iterator iterNext(arg.begin());
for (vector<string>::iterator iter(arg.begin()); iter != arg.end(); iter++) { for (vector<string>::iterator iter(arg.begin()); iter != arg.end(); ++iter) {
iterNext = iter + 1; iterNext = iter + 1;
if (!iter->substr(0,2).compare("-o")) { if (!iter->substr(0,2).compare("-o")) {
if (!iter->compare("-o")) { if (!iter->compare("-o")) {
@ -204,6 +243,7 @@ bool msr2data_useOption(vector<string> &arg, const string &s)
* - template runNo if everything is OK * - template runNo if everything is OK
* - -1 : tag: fit only, do not prepare input files * - -1 : tag: fit only, do not prepare input files
* - -2 : fatal error - more than one fit-&lt;temp&gt; options are specified * - -2 : fatal error - more than one fit-&lt;temp&gt; options are specified
* - -3 : fit-&lt;temp&gt; option found, but &lt;temp&gt; is not a valid number
* *
* \param arg list of arguments * \param arg list of arguments
* \param chainfit if true * \param chainfit if true
@ -214,7 +254,6 @@ int msr2data_doFitting(vector<string> &arg, bool &chainfit)
int temp(0); int temp(0);
string s; string s;
istringstream iss;
vector<string>::iterator iter(arg.begin()); vector<string>::iterator iter(arg.begin());
while (iter != arg.end()) { while (iter != arg.end()) {
if (!iter->compare("fit")) { // fit found if (!iter->compare("fit")) { // fit found
@ -231,15 +270,21 @@ int msr2data_doFitting(vector<string> &arg, bool &chainfit)
} }
s = iter->substr(4); s = iter->substr(4);
string::size_type loc = s.rfind('!'); string::size_type loc = s.rfind('!');
if (loc != string::npos) if (loc != string::npos) {
chainfit = false; chainfit = false;
s.erase(loc);
}
else else
chainfit = true; chainfit = true;
iss.str(s); try {
iss >> temp; temp = boost::lexical_cast<int>(s);
iter = arg.erase(iter); arg.erase(iter);
}
catch(boost::bad_lexical_cast &) {
return -3; // the specified template is no number
}
} else { } else {
iter++; ++iter;
} }
} }
@ -262,13 +307,16 @@ unsigned int msr2data_doInputCreation(vector<string> &arg, bool &inputOnly)
unsigned int temp(0); unsigned int temp(0);
string s; string s;
istringstream iss; for (vector<string>::iterator iter(arg.begin()); iter != arg.end(); ++iter) {
for (vector<string>::iterator iter(arg.begin()); iter != arg.end(); iter++) {
if (!iter->substr(0,4).compare("msr-")) { if (!iter->substr(0,4).compare("msr-")) {
s = iter->substr(4); s = iter->substr(4);
iss.str(s); try {
iss >> temp; temp = boost::lexical_cast<unsigned int>(s);
arg.erase(iter); arg.erase(iter);
}
catch(boost::bad_lexical_cast &) {
temp = 0; // the specified template is no number
}
inputOnly = true; inputOnly = true;
break; break;
} }
@ -299,7 +347,7 @@ int main(int argc, char *argv[])
// use a string-vector for the arguments to get rid of char* as far as possible... // use a string-vector for the arguments to get rid of char* as far as possible...
vector<string> arg; vector<string> arg;
for (int i(1); i<argc; i++) { for (int i(1); i<argc; ++i) {
arg.push_back(argv[i]); arg.push_back(argv[i]);
} }
@ -320,7 +368,7 @@ int main(int argc, char *argv[])
else else
arg[0]=arg[0].substr(1); arg[0]=arg[0].substr(1);
for (unsigned int i(firstRunNumberInArg); i<arg.size(); i++) { for (unsigned int i(firstRunNumberInArg); i<arg.size(); ++i) {
string::size_type loc = arg[i].rfind(']'); string::size_type loc = arg[i].rfind(']');
if ( loc != string::npos ) { if ( loc != string::npos ) {
rightbracket = i; rightbracket = i;
@ -334,8 +382,8 @@ int main(int argc, char *argv[])
} }
} }
if (rightbracket == numeric_limits<unsigned int>::max()) { if (rightbracket == numeric_limits<unsigned int>::max()) {
cout << endl; cerr << endl;
cout << ">> msr2data: **ERROR** You used the list specification without closing bracket (])! Quitting now." << endl; cerr << ">> msr2data: **ERROR** You used the list specification without closing bracket (])! Quitting now." << endl;
return 0; return 0;
} }
@ -345,7 +393,7 @@ int main(int argc, char *argv[])
msrExtension = arg[rightbracket + 1]; msrExtension = arg[rightbracket + 1];
vector<string>::iterator iter(arg.begin()); vector<string>::iterator iter(arg.begin());
for (unsigned int i(0); i<rightbracket + 2; i++) { for (unsigned int i(0); i<rightbracket + 2; ++i) {
arg.erase(iter); arg.erase(iter);
iter = arg.begin(); iter = arg.begin();
} }
@ -357,8 +405,8 @@ int main(int argc, char *argv[])
runTAG = 2; runTAG = 2;
if (arg.size() < 3) { if (arg.size() < 3) {
cout << endl; cerr << endl;
cout << ">> msr2data: **ERROR** No msr-file extension specified! Quitting now..." << endl; cerr << ">> msr2data: **ERROR** No msr-file extension specified! Quitting now..." << endl;
run_vec.clear(); run_vec.clear();
arg.clear(); arg.clear();
return 0; return 0;
@ -398,8 +446,18 @@ int main(int argc, char *argv[])
} }
} }
catch(boost::bad_lexical_cast &) { catch(boost::bad_lexical_cast &) {
cout << endl; cerr << endl;
cout << ">> msr2data: **ERROR** At least one given run number is out of range! Quitting..." << endl; cerr << ">> msr2data: **ERROR** At least one given run number is out of range! Quitting..." << endl;
run_vec.clear();
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;
cerr << ">> msr2data: **ERROR** Unknown argument: " << wrongArgument << ". Quitting..." << endl;
run_vec.clear(); run_vec.clear();
arg.clear(); arg.clear();
return -1; return -1;
@ -435,16 +493,16 @@ int main(int argc, char *argv[])
status = msr2dataHandler.SetRunNumbers(run_list); status = msr2dataHandler.SetRunNumbers(run_list);
break; break;
default: default:
cout << endl; cerr << endl;
cout << ">> msr2data: **ERROR** None of the possible run list specifications has been detected! Quitting now..." << endl; cerr << ">> msr2data: **ERROR** None of the possible run list specifications has been detected! Quitting now..." << endl;
run_vec.clear(); run_vec.clear();
arg.clear(); arg.clear();
return 0; return 0;
} }
if (status == 1) { if (status == 1) {
cout << endl; cerr << endl;
cout << ">> msr2data: **ERROR** The run numbers are out of range! Quitting..." << endl; cerr << ">> msr2data: **ERROR** The run numbers are out of range! Quitting..." << endl;
run_vec.clear(); run_vec.clear();
arg.clear(); arg.clear();
return status; return status;
@ -460,13 +518,20 @@ int main(int argc, char *argv[])
temp = msr2data_doFitting(arg, chainfit); temp = msr2data_doFitting(arg, chainfit);
if (temp == -2) { if (temp == -2) {
cout << endl; cerr << endl;
cout << ">> msr2data: **ERROR** More than one fitting options are specified! Quitting..." << endl; cerr << ">> msr2data: **ERROR** More than one fitting options are specified! Quitting..." << endl;
run_vec.clear(); run_vec.clear();
arg.clear(); arg.clear();
return status; return temp;
} else if (temp == -3) {
cerr << endl;
cerr << ">> msr2data: **ERROR** The given template has not a valid run number! Quitting..." << endl;
run_vec.clear();
arg.clear();
return temp;
} }
// check if any options should be passed to musrfit // check if any options should be passed to musrfit
if (temp) { if (temp) {
if (!msr2data_useOption(arg, "-k")) if (!msr2data_useOption(arg, "-k"))
@ -484,6 +549,13 @@ int main(int argc, char *argv[])
realOutput = false; realOutput = false;
outputFile = "none"; outputFile = "none";
} }
if (!temp) {
cerr << endl;
cerr << ">> msr2data: **ERROR** The given template has not a valid run number! Quitting..." << endl;
run_vec.clear();
arg.clear();
return temp;
}
} }
// check if msr2data should work in the global fit regime // check if msr2data should work in the global fit regime
@ -515,8 +587,8 @@ int main(int argc, char *argv[])
// 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(); status = msr2dataHandler.CheckRunNumbersInRange();
if(status) { if(status) {
cout << endl; cerr << endl;
cout << ">> msr2data: **ERROR** At least one given run number is out of range! Quitting..." << endl; cerr << ">> msr2data: **ERROR** At least one given run number is out of range! Quitting..." << endl;
run_vec.clear(); run_vec.clear();
arg.clear(); arg.clear();
return status; return status;
@ -543,7 +615,7 @@ int main(int argc, char *argv[])
bool success(msr2dataHandler.PrepareGlobalInputFile(temp, strInfile.str(), globalMode)); bool success(msr2dataHandler.PrepareGlobalInputFile(temp, strInfile.str(), globalMode));
if (!success) { if (!success) {
cout << endl << ">> msr2data: **ERROR** Input file generation has not been successful! Quitting..." << endl; cerr << endl << ">> msr2data: **ERROR** Input file generation has not been successful! Quitting..." << endl;
arg.clear(); arg.clear();
return -1; return -1;
} }
@ -626,7 +698,7 @@ int main(int argc, char *argv[])
oldtemp = msr2dataHandler.GetPresentRun(); oldtemp = msr2dataHandler.GetPresentRun();
if (!success) { if (!success) {
cout << endl << ">> msr2data: **ERROR** Input file generation has not been successful! Quitting..." << endl; cerr << endl << ">> msr2data: **ERROR** Input file generation has not been successful! Quitting..." << endl;
arg.clear(); arg.clear();
return -1; return -1;
} }