make sure that multiple instances of mupp can run simultaneously.
This commit is contained in:
parent
a3ddd07a9e
commit
294eaa8fb1
@ -205,6 +205,7 @@ PmuppGui::PmuppGui( QStringList fln, QWidget *parent, Qt::WindowFlags f )
|
||||
{
|
||||
QDateTime dt = QDateTime::currentDateTime();
|
||||
fDatime = dt.toTime_t();
|
||||
fMuppInstance = -1;
|
||||
|
||||
fMuppPlot = 0;
|
||||
|
||||
@ -414,8 +415,12 @@ void PmuppGui::aboutToQuit()
|
||||
|
||||
// clean up temporary plot files
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
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"));
|
||||
if (fMuppInstance != -1) {
|
||||
QString pathName = QString("%1/.musrfit/mupp/_mupp_%2.dat").arg(env.value("HOME")).arg(fDatime);
|
||||
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
|
||||
writeCmdHistory();
|
||||
@ -584,7 +589,7 @@ void PmuppGui::fileOpen()
|
||||
*/
|
||||
void PmuppGui::fileExit()
|
||||
{
|
||||
qApp->quit();
|
||||
aboutToQuit();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -1616,13 +1621,16 @@ void PmuppGui::plot()
|
||||
|
||||
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
|
||||
key_t key;
|
||||
struct mbuf msg;
|
||||
int flags, msqid;
|
||||
|
||||
// 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);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QMessageBox::critical(this, "ERROR", "Couldn't write necessary temporary file!");
|
||||
@ -1632,7 +1640,7 @@ void PmuppGui::plot()
|
||||
fout << QCoreApplication::applicationFilePath().toLatin1().data() << endl;
|
||||
file.close();
|
||||
|
||||
key = ftok(QCoreApplication::applicationFilePath().toLatin1().data(), 1);
|
||||
key = ftok(QCoreApplication::applicationFilePath().toLatin1().data(), fMuppInstance);
|
||||
if (key == -1) {
|
||||
QMessageBox::critical(this, "ERROR", "Couldn't obtain necessary key to install the IPC message queue.");
|
||||
return;
|
||||
@ -1677,11 +1685,14 @@ void PmuppGui::startMuppPlot()
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
QString cmd = QString("%1/bin/mupp_plot").arg(MUPP_PREFIX);
|
||||
#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
|
||||
QString workDir = QString("./");
|
||||
QStringList arg;
|
||||
|
||||
// feed the mupp instance
|
||||
arg << QString("%1").arg(fMuppInstance);
|
||||
|
||||
fMuppPlot = new QProcess(this);
|
||||
if (fMuppPlot == nullptr) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -129,6 +129,7 @@ private:
|
||||
bool fDarkToolBarIcon;
|
||||
|
||||
uint fDatime;
|
||||
uint fMuppInstance;
|
||||
|
||||
PParamDataHandler *fParamDataHandler;
|
||||
QVector<PmuppXY> fXY;
|
||||
@ -181,6 +182,7 @@ private:
|
||||
void getMinMax(QVector<double> &data, double &min, double &max);
|
||||
QString substituteDefaultLabels(QString label);
|
||||
void selectCollection(QString cmd);
|
||||
uint getFirstAvailableMuppInstance();
|
||||
|
||||
private slots:
|
||||
void refresh();
|
||||
|
@ -88,7 +88,9 @@ PMuppCanvas::PMuppCanvas()
|
||||
*/
|
||||
PMuppCanvas::PMuppCanvas(const Char_t *title, Int_t wtopx, Int_t wtopy,
|
||||
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),
|
||||
fMarkerSizeList(markerSizeList),
|
||||
fColorList(colorList)
|
||||
@ -303,7 +305,8 @@ void PMuppCanvas::CheckIPCMsgQueue()
|
||||
cerr << "**ERROR** couldn't get value of the environment variable HOME." << endl << endl;
|
||||
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);
|
||||
if (!fin.is_open()) {
|
||||
cerr << endl;
|
||||
@ -315,7 +318,7 @@ void PMuppCanvas::CheckIPCMsgQueue()
|
||||
fFtokName = str;
|
||||
}
|
||||
|
||||
key = ftok(fFtokName.Data(), 1);
|
||||
key = ftok(fFtokName.Data(), fMuppInstance);
|
||||
flags = IPC_CREAT;
|
||||
msqid = msgget(key, flags | S_IRUSR | S_IWUSR);
|
||||
if (msqid == -1) {
|
||||
|
@ -74,7 +74,8 @@ public:
|
||||
PMuppCanvas(const Char_t* title,
|
||||
Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh,
|
||||
const PIntVector markerSytleList, const PDoubleVector markerSizeList,
|
||||
const PIntVector colorList);
|
||||
const PIntVector colorList,
|
||||
const int mupp_instance);
|
||||
virtual ~PMuppCanvas();
|
||||
|
||||
virtual Bool_t IsValid() { return fValid; }
|
||||
@ -89,6 +90,7 @@ public:
|
||||
|
||||
private:
|
||||
Bool_t fValid;
|
||||
Int_t fMuppInstance;
|
||||
|
||||
TString fFtokName;
|
||||
TTimer *fCheckMsgQueue; ///< timer needed to check if a message in the IPC message queue is pending
|
||||
|
@ -46,6 +46,14 @@ using namespace std;
|
||||
*/
|
||||
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
|
||||
char startup_path_name[128];
|
||||
TSAXParser *saxParser = new TSAXParser();
|
||||
@ -93,7 +101,8 @@ int main(int argc, char *argv[])
|
||||
PMuppCanvas *muppCanvas = new PMuppCanvas("mupp", 10, 10, 600, 800,
|
||||
startupHandler->GetMarkerStyleList(),
|
||||
startupHandler->GetMarkerSizeList(),
|
||||
startupHandler->GetColorList());
|
||||
startupHandler->GetColorList(),
|
||||
mupp_instance);
|
||||
|
||||
if (muppCanvas != 0) {
|
||||
if (muppCanvas->IsValid()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user