diff --git a/src/msr2data.cpp b/src/msr2data.cpp index 8408f2c1..637bc4db 100644 --- a/src/msr2data.cpp +++ b/src/msr2data.cpp @@ -129,6 +129,8 @@ void msr2data_syntax() std::cout << std::endl << " -e, --estimateN0: estimate N0 for single histogram fits."; std::cout << std::endl << " -y, --yaml: write fit results (MINUIT2.OUTPUT) into a yaml-file. Output .yaml"; std::cout << std::endl << " -p, --per-run-block-chisq: will per run block chisq to the msr-file."; + std::cout << std::endl << " -u, --use-no-of-threads : if fitting is used, pass the option --use-no-of-threads to musrfit"; + std::cout << std::endl << " : number of threads to be used (OpenMP). Needs to be <= max. number of cores."; std::cout << std::endl; std::cout << std::endl << " global : switch on the global-fit mode"; std::cout << std::endl << " Within that mode all specified runs will be united in a single msr file!"; @@ -197,11 +199,20 @@ std::string msr2data_validArguments(const std::vector &arg) else if (!iter->substr(0,2).compare("-o")) { word.clear(); if (!iter->compare("-o")) { - if (++iter == arg.end()) + // the next argument is the output file name, unless it is the -u option (which takes its own ) + std::vector::const_iterator iterNext(iter + 1); + if (iterNext == arg.end()) break; - else - continue; + else if ((iterNext->compare("-u")) && (iterNext->compare("--use-no-of-threads"))) + ++iter; + continue; } + } else if ((!iter->compare("-u")) || (!iter->compare("--use-no-of-threads"))) { + word.clear(); + if (++iter == arg.end()) // is checked later in msr2data_noOfThreads + break; + else + continue; } else { word = *iter; break; @@ -239,6 +250,7 @@ std::string msr2data_outputfile(std::vector &arg, bool db = true) if ((iterNext != arg.end()) && (iterNext->compare("header")) && (iterNext->compare("noheader")) && (iterNext->compare("nosummary")) \ && (iterNext->substr(0,3).compare("fit")) && (iterNext->compare("-k")) && (iterNext->compare("-t")) \ && (iterNext->compare("-e")) && (iterNext->compare("-p")) \ + && (iterNext->compare("-u")) && (iterNext->compare("--use-no-of-threads")) \ && (iterNext->compare("data")) && (iterNext->substr(0,3).compare("msr")) && (iterNext->compare("global")) \ && (iterNext->compare("global+")) && (iterNext->compare("global+!")) && (iterNext->compare("new"))) { outputFile = *iterNext; @@ -287,6 +299,56 @@ bool msr2data_useOption(std::vector &arg, const std::string &s) return option; } +//-------------------------------------------------------------------------- +/** + *

Checks if the option '-u, --use-no-of-threads ' is present in the + * argument input list. If present, the option and its are removed from + * the argument list. + * + *

return: + * - 0 if the option is not present + * - (> 0) if the option is present and valid + * - -1 if the option is present but is missing or not a positive integer + * + * \param arg list of arguments + */ +int msr2data_noOfThreads(std::vector &arg) +{ + std::vector::iterator iter; + iter = find(arg.begin(), arg.end(), "-u"); + if (iter == arg.end()) + iter = find(arg.begin(), arg.end(), "--use-no-of-threads"); + if (iter == arg.end()) + return 0; + + std::vector::iterator iterNext(iter + 1); + if (iterNext == arg.end()) { + std::cerr << std::endl << ">> msr2data: **ERROR** found option --use-no-of-threads without " << std::endl; + return -1; + } + + if (!isNumber(*iterNext)) { + std::cerr << std::endl << ">> msr2data: **ERROR** found option --use-no-of-threads where is not a number: '" << *iterNext << "'" << std::endl; + return -1; + } + + int noOfThreads(0); + try { + noOfThreads = boost::lexical_cast(*iterNext); + } catch (boost::bad_lexical_cast &) { + noOfThreads = 0; + } + if (noOfThreads <= 0) { + std::cerr << std::endl << ">> msr2data: **ERROR** found option --use-no-of-threads with <= 0" << std::endl; + return -1; + } + + // remove the option and its from the argument list + arg.erase(iter, iterNext + 1); + + return noOfThreads; +} + //-------------------------------------------------------------------------- /** *

Filters out the template run number (if present) and check at the @@ -699,6 +761,13 @@ int main(int argc, char *argv[]) temp = msr2data_doFitting(arg, chainfit); + // check if the number of threads for musrfit is given (-u, --use-no-of-threads ) + int noOfThreads(msr2data_noOfThreads(arg)); + if (noOfThreads == -1) { + msr2data_syntax(); + return -1; + } + if (temp == -2) { std::cerr << std::endl; std::cerr << ">> msr2data: **ERROR** More than one fitting options are specified! Quitting..." << std::endl; @@ -722,6 +791,8 @@ int main(int argc, char *argv[]) musrfitOptions.append("-y "); if (!msr2data_useOption(arg, "-p") || !msr2data_useOption(arg, "--per-run-block-chisq")) musrfitOptions.append("-p "); + if (noOfThreads > 0) + musrfitOptions.append("-u " + std::to_string(noOfThreads) + " "); } // if no fitting should be done, check if only the input files should be created