diff --git a/ChangeLog b/ChangeLog index 1bf8c76c..70a8d0dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 --getT0FromPromptPeak, -g with : will, in non-interactive mode estimate the t0's from 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. (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) diff --git a/src/classes/PMsr2Data.cpp b/src/classes/PMsr2Data.cpp index 92fc89ab..9358d565 100644 --- a/src/classes/PMsr2Data.cpp +++ b/src/classes/PMsr2Data.cpp @@ -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; + // 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 string tempParamName; 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 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 unsigned int oldTempRun(0); bool firstrun(true); @@ -1319,7 +1331,7 @@ bool PMsr2Data::PrepareGlobalInputFile(unsigned int tempRun, const string &msrOu //cout << "Number of run specific parameters: " << fNumSpecParam << endl; 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) singleRunMsrFile = GetSingleRunMsrFile(); diff --git a/src/msr2data.cpp b/src/msr2data.cpp index a2044218..98304e49 100644 --- a/src/msr2data.cpp +++ b/src/msr2data.cpp @@ -121,6 +121,45 @@ void msr2data_syntax() cout << endl << endl; } +//-------------------------------------------------------------------------- +/** + *

Checks if only valid options appear in the argument list + * + *

return: + * - 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 &arg) +{ + string word; + + for (vector::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; + +} + //-------------------------------------------------------------------------- /** *

filters out the output file name from at argument string @@ -141,7 +180,7 @@ string msr2data_outputfile(vector &arg, bool db = true) outputFile = "out.dat"; vector::iterator iterNext(arg.begin()); - for (vector::iterator iter(arg.begin()); iter != arg.end(); iter++) { + for (vector::iterator iter(arg.begin()); iter != arg.end(); ++iter) { iterNext = iter + 1; if (!iter->substr(0,2).compare("-o")) { if (!iter->compare("-o")) { @@ -204,6 +243,7 @@ bool msr2data_useOption(vector &arg, const string &s) * - template runNo if everything is OK * - -1 : tag: fit only, do not prepare input files * - -2 : fatal error - more than one fit-<temp> options are specified + * - -3 : fit-<temp> option found, but <temp> is not a valid number * * \param arg list of arguments * \param chainfit if true @@ -214,7 +254,6 @@ int msr2data_doFitting(vector &arg, bool &chainfit) int temp(0); string s; - istringstream iss; vector::iterator iter(arg.begin()); while (iter != arg.end()) { if (!iter->compare("fit")) { // fit found @@ -231,15 +270,21 @@ int msr2data_doFitting(vector &arg, bool &chainfit) } s = iter->substr(4); string::size_type loc = s.rfind('!'); - if (loc != string::npos) + if (loc != string::npos) { chainfit = false; + s.erase(loc); + } else chainfit = true; - iss.str(s); - iss >> temp; - iter = arg.erase(iter); + try { + temp = boost::lexical_cast(s); + arg.erase(iter); + } + catch(boost::bad_lexical_cast &) { + return -3; // the specified template is no number + } } else { - iter++; + ++iter; } } @@ -262,13 +307,16 @@ unsigned int msr2data_doInputCreation(vector &arg, bool &inputOnly) unsigned int temp(0); string s; - istringstream iss; - for (vector::iterator iter(arg.begin()); iter != arg.end(); iter++) { + for (vector::iterator iter(arg.begin()); iter != arg.end(); ++iter) { if (!iter->substr(0,4).compare("msr-")) { s = iter->substr(4); - iss.str(s); - iss >> temp; - arg.erase(iter); + try { + temp = boost::lexical_cast(s); + arg.erase(iter); + } + catch(boost::bad_lexical_cast &) { + temp = 0; // the specified template is no number + } inputOnly = true; 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... vector arg; - for (int i(1); i::max()) { - cout << endl; - cout << ">> msr2data: **ERROR** You used the list specification without closing bracket (])! Quitting now." << endl; + cerr << endl; + cerr << ">> msr2data: **ERROR** You used the list specification without closing bracket (])! Quitting now." << endl; return 0; } @@ -345,7 +393,7 @@ int main(int argc, char *argv[]) msrExtension = arg[rightbracket + 1]; vector::iterator iter(arg.begin()); - for (unsigned int i(0); i> msr2data: **ERROR** No msr-file extension specified! Quitting now..." << endl; + cerr << endl; + cerr << ">> msr2data: **ERROR** No msr-file extension specified! Quitting now..." << endl; run_vec.clear(); arg.clear(); return 0; @@ -398,8 +446,18 @@ int main(int argc, char *argv[]) } } catch(boost::bad_lexical_cast &) { - cout << endl; - cout << ">> msr2data: **ERROR** At least one given run number is out of range! Quitting..." << endl; + cerr << 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(); arg.clear(); return -1; @@ -435,16 +493,16 @@ int main(int argc, char *argv[]) status = msr2dataHandler.SetRunNumbers(run_list); break; default: - cout << endl; - cout << ">> msr2data: **ERROR** None of the possible run list specifications has been detected! Quitting now..." << endl; + cerr << endl; + cerr << ">> msr2data: **ERROR** None of the possible run list specifications has been detected! Quitting now..." << endl; run_vec.clear(); arg.clear(); return 0; } if (status == 1) { - cout << endl; - cout << ">> msr2data: **ERROR** The run numbers are out of range! Quitting..." << endl; + cerr << endl; + cerr << ">> msr2data: **ERROR** The run numbers are out of range! Quitting..." << endl; run_vec.clear(); arg.clear(); return status; @@ -460,13 +518,20 @@ int main(int argc, char *argv[]) temp = msr2data_doFitting(arg, chainfit); if (temp == -2) { - cout << endl; - cout << ">> msr2data: **ERROR** More than one fitting options are specified! Quitting..." << endl; + cerr << endl; + cerr << ">> msr2data: **ERROR** More than one fitting options are specified! Quitting..." << endl; run_vec.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 if (temp) { if (!msr2data_useOption(arg, "-k")) @@ -484,6 +549,13 @@ int main(int argc, char *argv[]) realOutput = false; 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 @@ -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 status = msr2dataHandler.CheckRunNumbersInRange(); if(status) { - cout << endl; - cout << ">> msr2data: **ERROR** At least one given run number is out of range! Quitting..." << endl; + cerr << endl; + cerr << ">> msr2data: **ERROR** At least one given run number is out of range! Quitting..." << endl; run_vec.clear(); arg.clear(); return status; @@ -543,7 +615,7 @@ int main(int argc, char *argv[]) bool success(msr2dataHandler.PrepareGlobalInputFile(temp, strInfile.str(), globalMode)); 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(); return -1; } @@ -626,7 +698,7 @@ int main(int argc, char *argv[]) oldtemp = msr2dataHandler.GetPresentRun(); 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(); return -1; }