add an option to musrfit which allows to replace to musrfit_startup.xml by the default one.
This commit is contained in:
parent
d6a3767040
commit
23ac67a443
@ -91,7 +91,7 @@ int parseXmlFile(TSAXParser *saxParser, const char *startup_path_name)
|
||||
/**
|
||||
* <p>Constructor. Check if the musrfit_startup.xml file is found in some standard search paths
|
||||
*/
|
||||
PStartupHandler::PStartupHandler()
|
||||
PStartupHandler::PStartupHandler(bool reset_startup_file)
|
||||
{
|
||||
fStartupFileFound = false;
|
||||
fStartupFilePath = "";
|
||||
@ -145,6 +145,17 @@ PStartupHandler::PStartupHandler()
|
||||
}
|
||||
}
|
||||
|
||||
// musrfit_startup.xml found. Check if it should be rewritten
|
||||
if (fStartupFileFound && reset_startup_file) {
|
||||
std::cout << std::endl;
|
||||
std::cout << ">> Will only reset the file: '" << fStartupFilePath.Data() << "'."<< std::endl;
|
||||
std::cout << std::endl;
|
||||
if (!WriteDefaultStartupFile(reset_startup_file)) {
|
||||
std::cerr << std::endl << "**ERROR** couldn't re-write " << fStartupFilePath.Data() << "." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// if musrfit_startup.xml is still not found, will create a default one
|
||||
if (!fStartupFileFound) {
|
||||
std::cout << std::endl << "**INFO** no musrfit_startup.xml file found, will write a default one." << std::endl;
|
||||
@ -606,33 +617,37 @@ Bool_t PStartupHandler::StartupFileExists(Char_t *fln)
|
||||
//--------------------------------------------------------------------------
|
||||
// WriteDefaultStartupFile
|
||||
//--------------------------------------------------------------------------
|
||||
Bool_t PStartupHandler::WriteDefaultStartupFile()
|
||||
Bool_t PStartupHandler::WriteDefaultStartupFile(bool reset_startup_file)
|
||||
{
|
||||
// get home
|
||||
Char_t startup_path_name[256];
|
||||
Char_t *home = nullptr;
|
||||
home = getenv("HOME");
|
||||
if (home == nullptr) {
|
||||
std::cerr << std::endl << "**ERROR** couldn't obtain $HOME." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// first check that $HOME/.musrfit exists and if NOT create it
|
||||
struct stat info;
|
||||
|
||||
snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit", home);
|
||||
if (!stat(startup_path_name, &info)) {
|
||||
if (!(info.st_mode & S_IFDIR))
|
||||
return false;
|
||||
} else {
|
||||
if (mkdir(startup_path_name, 0777)) {
|
||||
std::cerr << std::endl << "**ERROR** couldn't create '" << startup_path_name << "'" << std::endl;
|
||||
if (reset_startup_file) { // reset the found
|
||||
snprintf(startup_path_name, sizeof(startup_path_name), "%s", fStartupFilePath.Data());
|
||||
} else { // no musrfit_startup.xml found, hence write default under $HOME/.musrfit
|
||||
// get home
|
||||
Char_t *home = nullptr;
|
||||
home = getenv("HOME");
|
||||
if (home == nullptr) {
|
||||
std::cerr << std::endl << "**ERROR** couldn't obtain $HOME." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// set path-name for musrfit_startup.xml
|
||||
snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit/musrfit_startup.xml", home);
|
||||
// first check that $HOME/.musrfit exists and if NOT create it
|
||||
struct stat info;
|
||||
|
||||
snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit", home);
|
||||
if (!stat(startup_path_name, &info)) {
|
||||
if (!(info.st_mode & S_IFDIR))
|
||||
return false;
|
||||
} else {
|
||||
if (mkdir(startup_path_name, 0777)) {
|
||||
std::cerr << std::endl << "**ERROR** couldn't create '" << startup_path_name << "'" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// set path-name for musrfit_startup.xml
|
||||
snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit/musrfit_startup.xml", home);
|
||||
}
|
||||
|
||||
std::ofstream fout(startup_path_name, std::ofstream::out);
|
||||
if (!fout.is_open()) {
|
||||
|
@ -54,7 +54,7 @@ int parseXmlFile(TSAXParser*, const char*);
|
||||
class PStartupHandler : public TObject, public TQObject
|
||||
{
|
||||
public:
|
||||
PStartupHandler();
|
||||
PStartupHandler(bool reset_startup_file=false);
|
||||
virtual ~PStartupHandler();
|
||||
|
||||
virtual void OnStartDocument(); // SLOT
|
||||
@ -97,7 +97,7 @@ class PStartupHandler : public TObject, public TQObject
|
||||
PIntVector fColorList; ///< color list
|
||||
|
||||
Bool_t StartupFileExists(Char_t *fln);
|
||||
Bool_t WriteDefaultStartupFile();
|
||||
Bool_t WriteDefaultStartupFile(bool reset_startup_file=false);
|
||||
|
||||
ClassDef(PStartupHandler, 1)
|
||||
};
|
||||
|
@ -121,6 +121,12 @@ void musrfit_syntax()
|
||||
std::cout << std::endl << " -u, --use-no-of-threads <number>:";
|
||||
std::cout << std::endl << " <number>: number of threads to be used (OpenMP). Needs to be <= max. number of cores.";
|
||||
std::cout << std::endl << " If OpenMP is enable, the maximal number of cores is used, if it is not limited by this option.";
|
||||
std::cout << std::endl << " -r, --reset: reset startup musrfit_startup.xml, i.e. rewrite a default, and quit.";
|
||||
std::cout << std::endl << " The order of which musrfit_startup.xml is reset is:";
|
||||
std::cout << std::endl << " (i) if present in the current dir.";
|
||||
std::cout << std::endl << " (ii) if present under $HOME/.musrfit/";
|
||||
std::cout << std::endl << " (iii) if present under $MUSRFITPATH/";
|
||||
std::cout << std::endl << " (iv) if present under $ROOTSYS/";
|
||||
std::cout << std::endl << " --dump <type> is writing a data file with the fit data and the theory";
|
||||
std::cout << std::endl << " <type> can be 'ascii', 'root'";
|
||||
std::cout << std::endl << " --timeout <timeout_tag>: overwrites to predefined timeout of " << timeout << " (sec).";
|
||||
@ -442,6 +448,7 @@ int main(int argc, char *argv[])
|
||||
bool chisq_only = false;
|
||||
bool title_from_data_file = false;
|
||||
bool timeout_enabled = true;
|
||||
bool reset_startup_file = false;
|
||||
PStartupOptions startup_options;
|
||||
startup_options.writeExpectedChisq = false;
|
||||
startup_options.estimateN0 = false;
|
||||
@ -568,6 +575,8 @@ int main(int argc, char *argv[])
|
||||
show_syntax = true;
|
||||
break;
|
||||
}
|
||||
} else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--reset")) {
|
||||
reset_startup_file = true;
|
||||
} else if (!strcmp(argv[i], "--timeout")) {
|
||||
if (i<argc-1) {
|
||||
TString str(argv[i+1]);
|
||||
@ -595,7 +604,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// check if a filename is present
|
||||
if (strlen(filename) == 0) {
|
||||
if ((strlen(filename) == 0) && !reset_startup_file) {
|
||||
show_syntax = true;
|
||||
std::cout << std::endl << ">> musrfit **ERROR** no msr-file present!" << std::endl;
|
||||
}
|
||||
@ -618,7 +627,9 @@ int main(int argc, char *argv[])
|
||||
// read startup file
|
||||
char startup_path_name[128];
|
||||
std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>();
|
||||
std::unique_ptr<PStartupHandler> startupHandler = std::make_unique<PStartupHandler>();
|
||||
std::unique_ptr<PStartupHandler> startupHandler = std::make_unique<PStartupHandler>(reset_startup_file);
|
||||
if (reset_startup_file) // only rewrite musrfit_startup.xml has been requested
|
||||
return PMUSR_SUCCESS;
|
||||
if (!startupHandler->StartupFileFound()) {
|
||||
std::cerr << std::endl << ">> musrfit **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
|
||||
std::cerr << std::endl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user