msr2data: the number of threads to be used can now be injected to musrfit from the command line.
Build and Deploy Documentation / build-and-deploy (push) Canceled after 0s

This commit is contained in:
suter_a committed 2026-09-05 11:09:50 +02:00
1 parent 6222fa5573
commit 880dee9397
1 file changed
+74 -3
+74 -3
View File
@@ -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 <msr-file>.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 <number>: if fitting is used, pass the option --use-no-of-threads <number> to musrfit";
std::cout << std::endl << " <number>: 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<std::string> &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 <number>)
std::vector<std::string>::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()) // <number> is checked later in msr2data_noOfThreads
break;
else
continue;
} else {
word = *iter;
break;
@@ -239,6 +250,7 @@ std::string msr2data_outputfile(std::vector<std::string> &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<std::string> &arg, const std::string &s)
return option;
}
//--------------------------------------------------------------------------
/**
* <p>Checks if the option '-u, --use-no-of-threads <number>' is present in the
* argument input list. If present, the option and its <number> are removed from
* the argument list.
*
* <p><b>return:</b>
* - 0 if the option is not present
* - <number> (> 0) if the option is present and valid
* - -1 if the option is present but <number> is missing or not a positive integer
*
* \param arg list of arguments
*/
int msr2data_noOfThreads(std::vector<std::string> &arg)
{
std::vector<std::string>::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<std::string>::iterator iterNext(iter + 1);
if (iterNext == arg.end()) {
std::cerr << std::endl << ">> msr2data: **ERROR** found option --use-no-of-threads without <number>" << std::endl;
return -1;
}
if (!isNumber(*iterNext)) {
std::cerr << std::endl << ">> msr2data: **ERROR** found option --use-no-of-threads where <number> is not a number: '" << *iterNext << "'" << std::endl;
return -1;
}
int noOfThreads(0);
try {
noOfThreads = boost::lexical_cast<int>(*iterNext);
} catch (boost::bad_lexical_cast &) {
noOfThreads = 0;
}
if (noOfThreads <= 0) {
std::cerr << std::endl << ">> msr2data: **ERROR** found option --use-no-of-threads with <number> <= 0" << std::endl;
return -1;
}
// remove the option and its <number> from the argument list
arg.erase(iter, iterNext + 1);
return noOfThreads;
}
//--------------------------------------------------------------------------
/**
* <p>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 <number>)
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