make sure that multiple instances of mupp can run simultaneously.

This commit is contained in:
suter_a 2018-07-02 18:55:02 +02:00
parent 360d4ec7ae
commit 61b3eafa0b
5 changed files with 62 additions and 11 deletions

View File

@ -205,6 +205,7 @@ PmuppGui::PmuppGui( QStringList fln, QWidget *parent, Qt::WindowFlags f )
{ {
QDateTime dt = QDateTime::currentDateTime(); QDateTime dt = QDateTime::currentDateTime();
fDatime = dt.toTime_t(); fDatime = dt.toTime_t();
fMuppInstance = -1;
fMuppPlot = 0; fMuppPlot = 0;
@ -414,8 +415,12 @@ void PmuppGui::aboutToQuit()
// clean up temporary plot files // clean up temporary plot files
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
if (fMuppInstance != -1) {
QString pathName = QString("%1/.musrfit/mupp/_mupp_%2.dat").arg(env.value("HOME")).arg(fDatime); QString pathName = QString("%1/.musrfit/mupp/_mupp_%2.dat").arg(env.value("HOME")).arg(fDatime);
pathName = QString("%1/.musrfit/mupp/_mupp_ftok.dat").arg(env.value("HOME")); QFile::remove(pathName);
pathName = QString("%1/.musrfit/mupp/_mupp_ftok_%2.dat").arg(env.value("HOME")).arg(fMuppInstance);
QFile::remove(pathName);
}
// needed for clean up and to save the cmd history // needed for clean up and to save the cmd history
writeCmdHistory(); writeCmdHistory();
@ -584,7 +589,7 @@ void PmuppGui::fileOpen()
*/ */
void PmuppGui::fileExit() void PmuppGui::fileExit()
{ {
qApp->quit(); aboutToQuit();
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -1616,13 +1621,16 @@ void PmuppGui::plot()
file.close(); file.close();
// get first free mupp instance
fMuppInstance = getFirstAvailableMuppInstance();
// issue a system message to inform to ROOT parameter plotter (rpp) that new data are available // issue a system message to inform to ROOT parameter plotter (rpp) that new data are available
key_t key; key_t key;
struct mbuf msg; struct mbuf msg;
int flags, msqid; int flags, msqid;
// generate the ICP message queue key // generate the ICP message queue key
QString tmpPathName = QString("%1/.musrfit/mupp/_mupp_ftok.dat").arg(env.value("HOME")); QString tmpPathName = QString("%1/.musrfit/mupp/_mupp_ftok_%2.dat").arg(env.value("HOME")).arg(fMuppInstance);
file.setFileName(tmpPathName); file.setFileName(tmpPathName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox::critical(this, "ERROR", "Couldn't write necessary temporary file!"); QMessageBox::critical(this, "ERROR", "Couldn't write necessary temporary file!");
@ -1632,7 +1640,7 @@ void PmuppGui::plot()
fout << QCoreApplication::applicationFilePath().toLatin1().data() << endl; fout << QCoreApplication::applicationFilePath().toLatin1().data() << endl;
file.close(); file.close();
key = ftok(QCoreApplication::applicationFilePath().toLatin1().data(), 1); key = ftok(QCoreApplication::applicationFilePath().toLatin1().data(), fMuppInstance);
if (key == -1) { if (key == -1) {
QMessageBox::critical(this, "ERROR", "Couldn't obtain necessary key to install the IPC message queue."); QMessageBox::critical(this, "ERROR", "Couldn't obtain necessary key to install the IPC message queue.");
return; return;
@ -1677,11 +1685,14 @@ void PmuppGui::startMuppPlot()
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString cmd = QString("%1/bin/mupp_plot").arg(MUPP_PREFIX); QString cmd = QString("%1/bin/mupp_plot").arg(MUPP_PREFIX);
#if defined(Q_OS_DARWIN) || defined(Q_OS_MAC) #if defined(Q_OS_DARWIN) || defined(Q_OS_MAC)
cmd = QString("/Applications/mupp.app/Contents/MacOS/mupp_plot"); // as35 not yet ready cmd = QString("/Applications/mupp.app/Contents/MacOS/mupp_plot");
#endif #endif
QString workDir = QString("./"); QString workDir = QString("./");
QStringList arg; QStringList arg;
// feed the mupp instance
arg << QString("%1").arg(fMuppInstance);
fMuppPlot = new QProcess(this); fMuppPlot = new QProcess(this);
if (fMuppPlot == nullptr) { if (fMuppPlot == nullptr) {
QMessageBox::critical(0, "**ERROR**", "Couldn't invoke QProcess for mupp_plot!"); QMessageBox::critical(0, "**ERROR**", "Couldn't invoke QProcess for mupp_plot!");
@ -1996,3 +2007,27 @@ void PmuppGui::selectCollection(QString cmd)
} }
} }
} }
//----------------------------------------------------------------------------------------------------
/**
* @brief PmuppGui::getFirstAvailableMuppInstance
* @return
*/
uint PmuppGui::getFirstAvailableMuppInstance()
{
// if fMuppInstance already set, i.e. != -1, do nothing
if (fMuppInstance != -1)
return fMuppInstance;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString fln("");
uint i=0;
for (i=0; i<256; i++) {
fln = QString("%1/.musrfit/mupp/_mupp_ftok_%2.dat").arg(env.value("HOME")).arg(i);
if (!QFile::exists(fln))
break;
}
return i;
}

View File

@ -129,6 +129,7 @@ private:
bool fDarkToolBarIcon; bool fDarkToolBarIcon;
uint fDatime; uint fDatime;
uint fMuppInstance;
PParamDataHandler *fParamDataHandler; PParamDataHandler *fParamDataHandler;
QVector<PmuppXY> fXY; QVector<PmuppXY> fXY;
@ -181,6 +182,7 @@ private:
void getMinMax(QVector<double> &data, double &min, double &max); void getMinMax(QVector<double> &data, double &min, double &max);
QString substituteDefaultLabels(QString label); QString substituteDefaultLabels(QString label);
void selectCollection(QString cmd); void selectCollection(QString cmd);
uint getFirstAvailableMuppInstance();
private slots: private slots:
void refresh(); void refresh();

View File

@ -88,7 +88,9 @@ PMuppCanvas::PMuppCanvas()
*/ */
PMuppCanvas::PMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy, PMuppCanvas::PMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
Int_t ww, Int_t wh, const PIntVector markerSytleList, Int_t ww, Int_t wh, const PIntVector markerSytleList,
const PDoubleVector markerSizeList, const PIntVector colorList) : const PDoubleVector markerSizeList, const PIntVector colorList,
const int mupp_instance) :
fMuppInstance(mupp_instance),
fMarkerStyleList(markerSytleList), fMarkerStyleList(markerSytleList),
fMarkerSizeList(markerSizeList), fMarkerSizeList(markerSizeList),
fColorList(colorList) fColorList(colorList)
@ -303,7 +305,8 @@ void PMuppCanvas::CheckIPCMsgQueue()
cerr << "**ERROR** couldn't get value of the environment variable HOME." << endl << endl; cerr << "**ERROR** couldn't get value of the environment variable HOME." << endl << endl;
return; return;
} }
strncat(str, "/.musrfit/mupp/_mupp_ftok.dat", sizeof(str)-1); memset(str, '\0', sizeof(str));
snprintf(str, sizeof(str), "%s/.musrfit/mupp/_mupp_ftok_%d.dat", getenv("HOME"), fMuppInstance);
ifstream fin(str, ifstream::in); ifstream fin(str, ifstream::in);
if (!fin.is_open()) { if (!fin.is_open()) {
cerr << endl; cerr << endl;
@ -315,7 +318,7 @@ void PMuppCanvas::CheckIPCMsgQueue()
fFtokName = str; fFtokName = str;
} }
key = ftok(fFtokName.Data(), 1); key = ftok(fFtokName.Data(), fMuppInstance);
flags = IPC_CREAT; flags = IPC_CREAT;
msqid = msgget(key, flags | S_IRUSR | S_IWUSR); msqid = msgget(key, flags | S_IRUSR | S_IWUSR);
if (msqid == -1) { if (msqid == -1) {

View File

@ -74,7 +74,8 @@ public:
PMuppCanvas(const Char_t* title, PMuppCanvas(const Char_t* title,
Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh,
const PIntVector markerSytleList, const PDoubleVector markerSizeList, const PIntVector markerSytleList, const PDoubleVector markerSizeList,
const PIntVector colorList); const PIntVector colorList,
const int mupp_instance);
virtual ~PMuppCanvas(); virtual ~PMuppCanvas();
virtual Bool_t IsValid() { return fValid; } virtual Bool_t IsValid() { return fValid; }
@ -89,6 +90,7 @@ public:
private: private:
Bool_t fValid; Bool_t fValid;
Int_t fMuppInstance;
TString fFtokName; TString fFtokName;
TTimer *fCheckMsgQueue; ///< timer needed to check if a message in the IPC message queue is pending TTimer *fCheckMsgQueue; ///< timer needed to check if a message in the IPC message queue is pending

View File

@ -46,6 +46,14 @@ using namespace std;
*/ */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc != 2) {
return -1;
}
int mupp_instance = (int)strtol(argv[1], NULL, 10);
if ((mupp_instance < 0) || (mupp_instance > 255)) {
return -2;
}
// read startup file // read startup file
char startup_path_name[128]; char startup_path_name[128];
TSAXParser *saxParser = new TSAXParser(); TSAXParser *saxParser = new TSAXParser();
@ -93,7 +101,8 @@ int main(int argc, char *argv[])
PMuppCanvas *muppCanvas = new PMuppCanvas("mupp", 10, 10, 600, 800, PMuppCanvas *muppCanvas = new PMuppCanvas("mupp", 10, 10, 600, 800,
startupHandler->GetMarkerStyleList(), startupHandler->GetMarkerStyleList(),
startupHandler->GetMarkerSizeList(), startupHandler->GetMarkerSizeList(),
startupHandler->GetColorList()); startupHandler->GetColorList(),
mupp_instance);
if (muppCanvas != 0) { if (muppCanvas != 0) {
if (muppCanvas->IsValid()) { if (muppCanvas->IsValid()) {