From daea7545a688395b5e9e8327c2907e0c044eb9ad Mon Sep 17 00:00:00 2001 From: nemu Date: Fri, 25 May 2012 14:40:41 +0000 Subject: [PATCH] added muSR data run header information dump to musrgui --- ChangeLog | 2 +- src/musredit/PTextEdit.cpp | 2 + src/musrgui/PDumpOutputHandler.cpp | 138 +++++++++++++++++++++++++++++ src/musrgui/PDumpOutputHandler.h | 68 ++++++++++++++ src/musrgui/PTextEdit.cpp | 37 ++++++++ src/musrgui/PTextEdit.h | 1 + src/musrgui/images/musrdump.xpm | 28 ++++++ src/musrgui/musrgui.pro | 5 +- 8 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 src/musrgui/PDumpOutputHandler.cpp create mode 100644 src/musrgui/PDumpOutputHandler.h create mode 100644 src/musrgui/images/musrdump.xpm diff --git a/ChangeLog b/ChangeLog index 1de586ae..325147c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,7 +6,7 @@ changes since 0.11.0 =================================== -NEW 2012-05-25 musredit: added a dump muSR data header file information. +NEW 2012-05-25 musredit/musrgui: added a dump muSR data header file information. NEW 2012-05-22 added spin rotation angle to the LEM MusrRoot file. NEW 2012-05-12 added dump_header. This is a little program which dumps the header information of a given muSR data file onto the standard diff --git a/src/musredit/PTextEdit.cpp b/src/musredit/PTextEdit.cpp index ac477386..cdd1a7ae 100644 --- a/src/musredit/PTextEdit.cpp +++ b/src/musredit/PTextEdit.cpp @@ -2225,6 +2225,8 @@ void PTextEdit::musrDump() { // select a muSR data filename QString fileName = QFileDialog::getOpenFileName(this, tr("Select muSR Data File"), "./", tr("muSR Data Files (*.root *.bin *.msr *.nxs)")); + if (fileName.isEmpty()) + return; QVector cmd; QString str = fAdmin->getExecPath() + "/dump_header"; diff --git a/src/musrgui/PDumpOutputHandler.cpp b/src/musrgui/PDumpOutputHandler.cpp new file mode 100644 index 00000000..d62cd7e8 --- /dev/null +++ b/src/musrgui/PDumpOutputHandler.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** + + PDumpOutputHandler.cpp + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + + $Id$ + +*****************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2012 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include + +#include "PDumpOutputHandler.h" + +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +PDumpOutputHandler::PDumpOutputHandler(QValueVector &cmd) +{ + if (cmd.empty()) + return; + + // Layout + fVbox = new QVBox( this ); + fVbox->resize(600, 800); + fOutput = new QTextEdit( fVbox ); + fOutput->setMinimumSize(600, 755); + fOutput->setReadOnly(true); + connect( fOutput, SIGNAL( destroyed() ), this, SLOT(quitButtonPressed() ) ); + fQuitButton = new QPushButton( tr("Close"), fVbox ); + connect( fQuitButton, SIGNAL( clicked() ), this, SLOT( quitButtonPressed() ) ); + resize( 600, 800 ); + fQuitButton->setFocus(); + + // QProcess related code + fProc = new QProcess( this ); + + // Set up the command and arguments. + for (unsigned int i=0; iaddArgument(cmd[i]); + + connect( fProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdOut() ) ); + connect( fProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStdErr() ) ); + + if ( !fProc->start() ) { + // error handling + QMessageBox::critical( 0, + tr("Fatal error"), + tr("Could not execute the output command: "+cmd[0]), + tr("Quit") ); + done(0); + } + fProcPID = fProc->processIdentifier(); +} + +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +PDumpOutputHandler::~PDumpOutputHandler() +{ + if (fProc->isRunning()) { + fProc->tryTerminate(); + QTimer::singleShot( 3000, fProc, SLOT( kill() ) ); + } + if (fProc->isRunning()) { // try low level kill + char cmd[128]; + sprintf(cmd, "kill -9 %ld", fProcPID); + system(cmd); + } + if (fProc) { + delete fProc; + fProc = 0; + } +} + +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +void PDumpOutputHandler::readFromStdOut() +{ + // Read and process the data. + // Bear in mind that the data might be output in chunks. + fOutput->append( fProc->readStdout() ); +} + +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +void PDumpOutputHandler::readFromStdErr() +{ + // Read and process the data. + // Bear in mind that the data might be output in chunks. + fOutput->append( fProc->readStderr() ); +} + +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +void PDumpOutputHandler::quitButtonPressed() +{ + // if the fitting is still taking place, kill it + if (fProc->isRunning()) { + fProc->tryTerminate(); + QTimer::singleShot( 1000, fProc, SLOT( kill() ) ); + } + + accept(); +} + +//---------------------------------------------------------------------------------------------------- +// END +//---------------------------------------------------------------------------------------------------- diff --git a/src/musrgui/PDumpOutputHandler.h b/src/musrgui/PDumpOutputHandler.h new file mode 100644 index 00000000..bc0c6df7 --- /dev/null +++ b/src/musrgui/PDumpOutputHandler.h @@ -0,0 +1,68 @@ +/**************************************************************************** + + PDumpOutputHandler.h + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + + $Id$ + +*****************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2012 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _PDUMPOUTPUTHANDLER_H_ +#define _PDUMPOUTPUTHANDLER_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +class PDumpOutputHandler : public QDialog +{ + Q_OBJECT + + public: + PDumpOutputHandler(QValueVector &cmd); + virtual ~PDumpOutputHandler(); + + private slots: + virtual void readFromStdOut(); + virtual void readFromStdErr(); + virtual void quitButtonPressed(); + +private: + Q_LONG fProcPID; + QProcess *fProc; + + QVBox *fVbox; + QTextEdit *fOutput; + QPushButton *fQuitButton; +}; + +#endif // _PDUMPOUTPUTHANDLER_H_ diff --git a/src/musrgui/PTextEdit.cpp b/src/musrgui/PTextEdit.cpp index 3929bb26..25d25d04 100644 --- a/src/musrgui/PTextEdit.cpp +++ b/src/musrgui/PTextEdit.cpp @@ -65,6 +65,7 @@ using namespace std; #include "PReplaceDialog.h" #include "forms/PReplaceConfirmationDialog.h" #include "PFitOutputHandler.h" +#include "PDumpOutputHandler.h" #include "PPrefsDialog.h" #include "PGetDefaultDialog.h" #include "forms/PMusrGuiAbout.h" @@ -397,6 +398,15 @@ void PTextEdit::setupMusrActions() connect( a, SIGNAL( activated() ), this, SLOT( musrPrefs() ) ); a->addTo( tb ); a->addTo( menu ); + + menu->insertSeparator(); + tb->addSeparator(); + + a = new QAction( QPixmap::fromMimeSource( "musrdump.xpm" ), tr( "&Dump Header" ), 0, this, "musrDump" ); + connect( a, SIGNAL( activated() ), this, SLOT( musrDump() ) ); + a->addTo( tb ); + a->addTo( menu ); + } //---------------------------------------------------------------------------------------------------- @@ -1920,6 +1930,33 @@ void PTextEdit::musrSwapMsrMlog() } } +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +void PTextEdit::musrDump() +{ + QString fileName = QFileDialog::getOpenFileName( + "./", + "muSR Data Files (*.root *.bin *.msr *.nxs)", + this, + "Select muSR Data File", + "Select muSR Data File" ); + + if (fileName.isNull()) + return; + + QValueVector cmd; + QString str; + str = fAdmin->getExecPath() + "/dump_header"; + cmd.append(str); + cmd.append(fileName); + + PDumpOutputHandler dumpOutputHandler(cmd); + dumpOutputHandler.setModal(false); + dumpOutputHandler.exec(); +} + //---------------------------------------------------------------------------------------------------- /** *

diff --git a/src/musrgui/PTextEdit.h b/src/musrgui/PTextEdit.h index 4c98e0ab..408165ae 100644 --- a/src/musrgui/PTextEdit.h +++ b/src/musrgui/PTextEdit.h @@ -105,6 +105,7 @@ private slots: void musrT0(); void musrPrefs(); void musrSwapMsrMlog(); + void musrDump(); void helpContents(); void helpAboutQt(); diff --git a/src/musrgui/images/musrdump.xpm b/src/musrgui/images/musrdump.xpm new file mode 100644 index 00000000..f6d401f0 --- /dev/null +++ b/src/musrgui/images/musrdump.xpm @@ -0,0 +1,28 @@ +/* XPM */ +static char * musrdump_xpm[] = { +"22 22 3 1", +" c None", +". c #0000FF", +"+ c #000000", +"... . . . . ... ", +". . . . .. .. . .", +". . . . . . . . .", +". . . . . . . . .", +". . . . . . ... ", +". . . . . . . ", +"... ... . . . ", +" ", +" ", +"+++ ", +" ++++ ", +" + ", +" ++++ ", +" + ", +" ++++ ", +" + + ", +" + +++++ ", +" + +++ ", +" ++++ + ", +" +++ +++ ", +" + ++++ ", +" +++ + "}; diff --git a/src/musrgui/musrgui.pro b/src/musrgui/musrgui.pro index 3e98cc8d..043f3c6a 100644 --- a/src/musrgui/musrgui.pro +++ b/src/musrgui/musrgui.pro @@ -69,6 +69,7 @@ HEADERS = musrgui.h \ PFindDialog.h \ PReplaceDialog.h \ PFitOutputHandler.h \ + PDumpOutputHandler.h \ PPrefsDialog.h \ PGetDefaultDialog.h \ PGetParameterDialog.h \ @@ -88,6 +89,7 @@ SOURCES = PFileWatcher.cpp \ PFindDialog.cpp \ PReplaceDialog.cpp \ PFitOutputHandler.cpp \ + PDumpOutputHandler.cpp \ PPrefsDialog.cpp \ PGetDefaultDialog.cpp \ PGetParameterDialog.cpp \ @@ -139,4 +141,5 @@ IMAGES = images/editcopy.xpm \ images/musrview.xpm \ images/musrt0.xpm \ images/musrprefs.xpm \ - images/musrswap.xpm + images/musrswap.xpm \ + images/musrdump.xpm