more flexible handling of startup XML's
This commit is contained in:
parent
df7f36de2f
commit
b38e8beffc
@ -30,6 +30,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include <TObjArray.h>
|
#include <TObjArray.h>
|
||||||
@ -48,6 +49,34 @@ ClassImpQ(PStartupHandler)
|
|||||||
*/
|
*/
|
||||||
PStartupHandler::PStartupHandler()
|
PStartupHandler::PStartupHandler()
|
||||||
{
|
{
|
||||||
|
fStartupFileFound = false;
|
||||||
|
fStartupFilePath = "";
|
||||||
|
|
||||||
|
// get default path (for the moment only linux like)
|
||||||
|
char *pmusrpath;
|
||||||
|
char musrpath[128];
|
||||||
|
char startup_path_name[128];
|
||||||
|
|
||||||
|
// check if the startup file is found in the current directory
|
||||||
|
strcpy(startup_path_name, "./musrfit_startup.xml");
|
||||||
|
if (StartupFileExists(startup_path_name)) {
|
||||||
|
fStartupFileFound = true;
|
||||||
|
fStartupFilePath = TString(startup_path_name);
|
||||||
|
} else { // startup file is not found in the current directory
|
||||||
|
// check if the MUSRFITPATH system variable is set
|
||||||
|
pmusrpath = getenv("MUSRFITPATH");
|
||||||
|
if (pmusrpath == 0) { // not set, will try default one
|
||||||
|
strcpy(musrpath, "/home/nemu/analysis/bin");
|
||||||
|
cout << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl;
|
||||||
|
} else {
|
||||||
|
strncpy(musrpath, pmusrpath, sizeof(musrpath));
|
||||||
|
}
|
||||||
|
sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath);
|
||||||
|
if (StartupFileExists(startup_path_name)) {
|
||||||
|
fStartupFileFound = true;
|
||||||
|
fStartupFilePath = TString(startup_path_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -440,5 +469,30 @@ void PStartupHandler::CheckLists()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// end ---------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
// StartupFileExists
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool PStartupHandler::StartupFileExists(char *fln)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
ifstream ifile(fln);
|
||||||
|
|
||||||
|
if (ifile.fail()) {
|
||||||
|
result = false;
|
||||||
|
} else {
|
||||||
|
result = true;
|
||||||
|
ifile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// end
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -56,6 +56,9 @@ class PStartupHandler : public TObject, public TQObject
|
|||||||
virtual void OnFatalError(const char*); // SLOT
|
virtual void OnFatalError(const char*); // SLOT
|
||||||
virtual void OnCdataBlock(const char*, Int_t); // SLOT
|
virtual void OnCdataBlock(const char*, Int_t); // SLOT
|
||||||
|
|
||||||
|
virtual bool StartupFileFound() { return fStartupFileFound; }
|
||||||
|
virtual TString GetStartupFilePath() { return fStartupFilePath; }
|
||||||
|
|
||||||
virtual void CheckLists();
|
virtual void CheckLists();
|
||||||
|
|
||||||
virtual PMsrFourierStructure GetFourierDefaults() { return fFourierDefaults; }
|
virtual PMsrFourierStructure GetFourierDefaults() { return fFourierDefaults; }
|
||||||
@ -70,11 +73,15 @@ class PStartupHandler : public TObject, public TQObject
|
|||||||
eColorList, eColor};
|
eColorList, eColor};
|
||||||
EKeyWords fKey;
|
EKeyWords fKey;
|
||||||
|
|
||||||
|
bool fStartupFileFound;
|
||||||
|
TString fStartupFilePath;
|
||||||
PMsrFourierStructure fFourierDefaults;
|
PMsrFourierStructure fFourierDefaults;
|
||||||
PStringVector fDataPathList;
|
PStringVector fDataPathList;
|
||||||
PIntVector fMarkerList;
|
PIntVector fMarkerList;
|
||||||
PIntVector fColorList;
|
PIntVector fColorList;
|
||||||
|
|
||||||
|
bool StartupFileExists(char *fln);
|
||||||
|
|
||||||
ClassDef(PStartupHandler, 1)
|
ClassDef(PStartupHandler, 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -554,22 +554,11 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// get default path (for the moment only linux like)
|
|
||||||
char *pmusrpath;
|
|
||||||
char musrpath[128];
|
|
||||||
pmusrpath = getenv("MUSRFITPATH");
|
|
||||||
if (pmusrpath == 0) { // not set, will try default one
|
|
||||||
strcpy(musrpath, "/home/nemu/analysis/bin");
|
|
||||||
cout << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl;
|
|
||||||
} else {
|
|
||||||
strncpy(musrpath, pmusrpath, sizeof(musrpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
// read startup file
|
// read startup file
|
||||||
char startup_path_name[128];
|
char startup_path_name[128];
|
||||||
sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath);
|
|
||||||
TSAXParser *saxParser = new TSAXParser();
|
TSAXParser *saxParser = new TSAXParser();
|
||||||
PStartupHandler *startupHandler = new PStartupHandler();
|
PStartupHandler *startupHandler = new PStartupHandler();
|
||||||
|
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
|
||||||
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
|
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
|
||||||
status = saxParser->ParseFile(startup_path_name);
|
status = saxParser->ParseFile(startup_path_name);
|
||||||
// check for parse errors
|
// check for parse errors
|
||||||
|
@ -235,10 +235,13 @@ PAdmin::PAdmin()
|
|||||||
fHelpMain = QString("");
|
fHelpMain = QString("");
|
||||||
|
|
||||||
// XML Parser part
|
// XML Parser part
|
||||||
|
QString fln = "./musrgui_startup.xml";
|
||||||
|
if (!QFile::exists(fln)) {
|
||||||
QString path = getenv("MUSRFITPATH");
|
QString path = getenv("MUSRFITPATH");
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
path = "/home/nemu/analysis/bin";
|
path = "/home/nemu/analysis/bin";
|
||||||
QString fln = path + "/musrgui_startup.xml";
|
fln = path + "/musrgui_startup.xml";
|
||||||
|
}
|
||||||
if (QFile::exists(fln)) { // administration file present
|
if (QFile::exists(fln)) { // administration file present
|
||||||
PAdminXMLParser handler(this);
|
PAdminXMLParser handler(this);
|
||||||
QFile xmlFile(fln);
|
QFile xmlFile(fln);
|
||||||
|
@ -97,22 +97,11 @@ int main(int argc, char *argv[])
|
|||||||
return PMUSR_WRONG_STARTUP_SYNTAX;
|
return PMUSR_WRONG_STARTUP_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get default path (for the moment only linux like)
|
|
||||||
char *pmusrpath;
|
|
||||||
char musrpath[128];
|
|
||||||
pmusrpath = getenv("MUSRFITPATH");
|
|
||||||
if (pmusrpath == 0) { // not set, will try default one
|
|
||||||
strcpy(musrpath, "/home/nemu/analysis/bin");
|
|
||||||
cout << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl;
|
|
||||||
} else {
|
|
||||||
strncpy(musrpath, pmusrpath, sizeof(musrpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
// read startup file
|
// read startup file
|
||||||
char startup_path_name[128];
|
char startup_path_name[128];
|
||||||
sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath);
|
|
||||||
TSAXParser *saxParser = new TSAXParser();
|
TSAXParser *saxParser = new TSAXParser();
|
||||||
PStartupHandler *startupHandler = new PStartupHandler();
|
PStartupHandler *startupHandler = new PStartupHandler();
|
||||||
|
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
|
||||||
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
|
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
|
||||||
status = saxParser->ParseFile(startup_path_name);
|
status = saxParser->ParseFile(startup_path_name);
|
||||||
// check for parse errors
|
// check for parse errors
|
||||||
|
@ -98,23 +98,12 @@ int main(int argc, char *argv[])
|
|||||||
return PMUSR_WRONG_STARTUP_SYNTAX;
|
return PMUSR_WRONG_STARTUP_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get default path (for the moment only linux like)
|
|
||||||
char *pmusrpath;
|
|
||||||
char musrpath[128];
|
|
||||||
pmusrpath = getenv("MUSRFITPATH");
|
|
||||||
if (pmusrpath == 0) { // not set, will try default one
|
|
||||||
strcpy(musrpath, "/home/nemu/analysis/bin");
|
|
||||||
cout << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl;
|
|
||||||
} else {
|
|
||||||
strncpy(musrpath, pmusrpath, sizeof(musrpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
// read startup file
|
// read startup file
|
||||||
char startup_path_name[128];
|
char startup_path_name[128];
|
||||||
sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath);
|
|
||||||
TSAXParser *saxParser = new TSAXParser();
|
TSAXParser *saxParser = new TSAXParser();
|
||||||
PStartupHandler *startupHandler = new PStartupHandler();
|
PStartupHandler *startupHandler = new PStartupHandler();
|
||||||
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
|
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
|
||||||
|
strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data());
|
||||||
status = saxParser->ParseFile(startup_path_name);
|
status = saxParser->ParseFile(startup_path_name);
|
||||||
// check for parse errors
|
// check for parse errors
|
||||||
if (status) { // error
|
if (status) { // error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user