From 676043cb81a9bf035f28e0ccaa02e7f65bb6410f Mon Sep 17 00:00:00 2001 From: nemu Date: Tue, 8 Apr 2008 11:35:36 +0000 Subject: [PATCH] some even more flexible startup handler scheme --- src/ToDo.txt | 4 +- src/classes/PMusrCanvas.cpp | 103 ++++++++++++++++++++------------ src/classes/PRunDataHandler.cpp | 21 ++++++- src/include/PMusrCanvas.h | 3 + src/include/PRunDataHandler.h | 1 + src/musrfit.cpp | 26 ++++---- src/musrview.cpp | 23 ++++--- 7 files changed, 121 insertions(+), 60 deletions(-) diff --git a/src/ToDo.txt b/src/ToDo.txt index a1b4dc8b..4d0e636b 100644 --- a/src/ToDo.txt +++ b/src/ToDo.txt @@ -46,9 +46,7 @@ short term: * at the moment that startup handler is looked for in the directory where musrfit/musrview is executed, this is stupid. Define a place where to look for it. - -* check concept to get bin data for musrview on single histo (fBinData in PRunBase). - If it is ok, implement it for the others. + **DONE** 08-04-08 * do I need to cleanup AddText() objects from TPaveText etc myself? **CHECK** diff --git a/src/classes/PMusrCanvas.cpp b/src/classes/PMusrCanvas.cpp index 9d697d1d..4362a34b 100644 --- a/src/classes/PMusrCanvas.cpp +++ b/src/classes/PMusrCanvas.cpp @@ -57,6 +57,19 @@ PMusrCanvas::PMusrCanvas() fKeyboardHandlerText = 0; } +//-------------------------------------------------------------------------- +// Constructor +//-------------------------------------------------------------------------- +/** + * + */ +PMusrCanvas::PMusrCanvas(const int number, const char* title, + Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh) : + fPlotNumber(number) +{ + InitMusrCanvas(title, wtopx, wtopy, ww, wh); +} + //-------------------------------------------------------------------------- // Constructor //-------------------------------------------------------------------------- @@ -67,6 +80,59 @@ PMusrCanvas::PMusrCanvas(const int number, const char* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh, const PIntVector markerList, const PIntVector colorList) : fPlotNumber(number), fMarkerList(markerList), fColorList(colorList) +{ + InitMusrCanvas(title, wtopx, wtopy, ww, wh); +} + +//-------------------------------------------------------------------------- +// Destructor +//-------------------------------------------------------------------------- +/** + * + */ +PMusrCanvas::~PMusrCanvas() +{ +cout << "~PMusrCanvas() called" << endl; + // cleanup + if (fKeyboardHandlerText) { + delete fKeyboardHandlerText; + fKeyboardHandlerText = 0; + } + if (fTitlePad) { + delete fTitlePad; + fTitlePad = 0; + } + if (fDataTheoryPad) { + delete fDataTheoryPad; + fDataTheoryPad = 0; + } + if (fParameterTheoryPad) { + delete fParameterTheoryPad; + fParameterTheoryPad = 0; + } + if (fInfoPad) { + delete fInfoPad; + fInfoPad = 0; + } + if (fMainCanvas) { + delete fMainCanvas; + fMainCanvas = 0; + } +} + +//-------------------------------------------------------------------------- +// InitMusrCanvas +//-------------------------------------------------------------------------- +/** + *

+ * + * \param title + * \param wtopx + * \param wtopy + * \param ww + * \param wh + */ +void PMusrCanvas::InitMusrCanvas(const char* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh) { fValid = false; @@ -158,43 +224,6 @@ cout << canvasName.Data() << " = " << fMainCanvas << endl; // cout << "fParameterTheoryPad " << fParameterTheoryPad << endl; // cout << "fInfoPad " << fInfoPad << endl; // cout << "fKeyboardHandlerText " << fKeyboardHandlerText << endl; - -} - -//-------------------------------------------------------------------------- -// Destructor -//-------------------------------------------------------------------------- -/** - * - */ -PMusrCanvas::~PMusrCanvas() -{ -cout << "~PMusrCanvas() called" << endl; - // cleanup - if (fKeyboardHandlerText) { - delete fKeyboardHandlerText; - fKeyboardHandlerText = 0; - } - if (fTitlePad) { - delete fTitlePad; - fTitlePad = 0; - } - if (fDataTheoryPad) { - delete fDataTheoryPad; - fDataTheoryPad = 0; - } - if (fParameterTheoryPad) { - delete fParameterTheoryPad; - fParameterTheoryPad = 0; - } - if (fInfoPad) { - delete fInfoPad; - fInfoPad = 0; - } - if (fMainCanvas) { - delete fMainCanvas; - fMainCanvas = 0; - } } //-------------------------------------------------------------------------- diff --git a/src/classes/PRunDataHandler.cpp b/src/classes/PRunDataHandler.cpp index 5a141c16..e5e0a867 100644 --- a/src/classes/PRunDataHandler.cpp +++ b/src/classes/PRunDataHandler.cpp @@ -52,11 +52,28 @@ using namespace std; *

* */ -PRunDataHandler::PRunDataHandler(PMsrHandler *msrInfo, const PStringVector dataPath) : fDataPath(dataPath) +PRunDataHandler::PRunDataHandler(PMsrHandler *msrInfo) : fMsrInfo(msrInfo) { // cout << endl << "in PRunDataHandler::PRunDataHandler()"; - fMsrInfo = msrInfo; + // read files + if (!ReadFile()) // couldn't read file + fAllDataAvailable = false; + else + fAllDataAvailable = true; +} + +//-------------------------------------------------------------------------- +// Constructor +//-------------------------------------------------------------------------- +/** + *

+ * + */ +PRunDataHandler::PRunDataHandler(PMsrHandler *msrInfo, const PStringVector dataPath) : + fMsrInfo(msrInfo), fDataPath(dataPath) +{ +// cout << endl << "in PRunDataHandler::PRunDataHandler()"; // read files if (!ReadFile()) // couldn't read file diff --git a/src/include/PMusrCanvas.h b/src/include/PMusrCanvas.h index eb7f1368..8b89f234 100644 --- a/src/include/PMusrCanvas.h +++ b/src/include/PMusrCanvas.h @@ -87,6 +87,8 @@ class PMusrCanvas : public TObject, public TQObject { public: PMusrCanvas(); + PMusrCanvas(const int number, const char* title, + Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh); PMusrCanvas(const int number, const char* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh, const PIntVector markerList, const PIntVector colorList); @@ -128,6 +130,7 @@ class PMusrCanvas : public TObject, public TQObject PIntVector fMarkerList; PIntVector fColorList; + virtual void InitMusrCanvas(const char* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh); virtual void InitDataSet(PMusrCanvasDataSet &dataSet); virtual void CleanupDataSet(PMusrCanvasDataSet &dataSet); virtual void HandleSingleHistoDataSet(unsigned int runNo, PRunData *data); diff --git a/src/include/PRunDataHandler.h b/src/include/PRunDataHandler.h index e390184b..8b4acff8 100644 --- a/src/include/PRunDataHandler.h +++ b/src/include/PRunDataHandler.h @@ -43,6 +43,7 @@ using namespace std; class PRunDataHandler { public: + PRunDataHandler(PMsrHandler *msrInfo); PRunDataHandler(PMsrHandler *msrInfo, const PStringVector dataPath); virtual ~PRunDataHandler(); diff --git a/src/musrfit.cpp b/src/musrfit.cpp index 473b3ab8..21ae29c6 100644 --- a/src/musrfit.cpp +++ b/src/musrfit.cpp @@ -527,7 +527,7 @@ int main(int argc, char *argv[]) status = saxParser->ParseFile(startup_path_name); // check for parse errors if (status) { // error - cout << endl << "**ERROR** reading/parsing musrfit_startup.xml. Fix it."; + cout << endl << "**WARNING** reading/parsing musrfit_startup.xml."; cout << endl; // clean up if (saxParser) { @@ -538,7 +538,6 @@ int main(int argc, char *argv[]) delete startupHandler; startupHandler = 0; } - return PMUSR_WRONG_STARTUP_SYNTAX; } // read msr-file @@ -547,12 +546,12 @@ int main(int argc, char *argv[]) if (status != PMUSR_SUCCESS) { switch (status) { case PMUSR_MSR_FILE_NOT_FOUND: - cout << endl << "couldn't find " << argv[1] << endl << endl; + cout << endl << "**ERROR** couldn't find " << argv[1] << endl << endl; break; case PMUSR_MSR_SYNTAX_ERROR: - cout << endl << "syntax error in file " << argv[1] << ", full stop here." << endl << endl; + cout << endl << "**SYNTAX ERROR** in file " << argv[1] << ", full stop here." << endl << endl; default: - cout << endl << "unkown error when trying to read the msr-file" << endl << endl; + cout << endl << "**UNKOWN ERROR** when trying to read the msr-file" << endl << endl; break; } return status; @@ -562,10 +561,15 @@ int main(int argc, char *argv[]) musrfit_debug_info(msrHandler); // read all the necessary runs (raw data) - PRunDataHandler *dataHandler = new PRunDataHandler(msrHandler, startupHandler->GetDataPathList()); + PRunDataHandler *dataHandler; + if (startupHandler) + dataHandler = new PRunDataHandler(msrHandler, startupHandler->GetDataPathList()); + else + dataHandler = new PRunDataHandler(msrHandler); + bool success = dataHandler->IsAllDataAvailable(); if (!success) { - cout << endl << "Couldn't read all data files, will quit ..." << endl; + cout << endl << "**ERROR** Couldn't read all data files, will quit ..." << endl; } // generate the necessary fit histogramms for the fit @@ -576,7 +580,7 @@ int main(int argc, char *argv[]) for (unsigned int i=0; i < msrHandler->GetMsrRunList()->size(); i++) { success = runListCollection->Add(i, kFit); if (!success) { - cout << endl << "Couldn't handle run no " << i << " "; + cout << endl << "**ERROR** Couldn't handle run no " << i << " "; cout << (*msrHandler->GetMsrRunList())[i].fRunName.Data(); break; } @@ -598,13 +602,13 @@ int main(int argc, char *argv[]) if (status != PMUSR_SUCCESS) { switch (status) { case PMUSR_MSR_LOG_FILE_WRITE_ERROR: - cout << endl << "couldn't write mlog-file" << endl << endl; + cout << endl << "**ERROR** couldn't write mlog-file" << endl << endl; break; case PMUSR_TOKENIZE_ERROR: - cout << endl << "couldn't generate mlog-file name" << endl << endl; + cout << endl << "**ERROR** couldn't generate mlog-file name" << endl << endl; break; default: - cout << endl << "unkown error when trying to write the mlog-file" << endl << endl; + cout << endl << "**UNKOWN ERROR** when trying to write the mlog-file" << endl << endl; break; } } diff --git a/src/musrview.cpp b/src/musrview.cpp index f2a84739..b2a48b55 100644 --- a/src/musrview.cpp +++ b/src/musrview.cpp @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) status = saxParser->ParseFile(startup_path_name); // check for parse errors if (status) { // error - cout << endl << "**ERROR** reading/parsing musrfit_startup.xml. Fix it."; + cout << endl << "**WARNING** reading/parsing musrfit_startup.xml."; cout << endl; // clean up if (saxParser) { @@ -128,7 +128,6 @@ int main(int argc, char *argv[]) delete startupHandler; startupHandler = 0; } - return PMUSR_WRONG_STARTUP_SYNTAX; } // read msr-file @@ -149,7 +148,12 @@ int main(int argc, char *argv[]) } // read all the necessary runs (raw data) - PRunDataHandler *dataHandler = new PRunDataHandler(msrHandler, startupHandler->GetDataPathList()); + PRunDataHandler *dataHandler; + if (startupHandler) + dataHandler = new PRunDataHandler(msrHandler, startupHandler->GetDataPathList()); + else + dataHandler = new PRunDataHandler(msrHandler); + success = dataHandler->IsAllDataAvailable(); if (!success) { cout << endl << "**ERROR** Couldn't read all data files, will quit ..." << endl; @@ -180,10 +184,15 @@ int main(int argc, char *argv[]) bool ok = true; for (unsigned int i=0; iGetMsrPlotList()->size(); i++) { - musrCanvas = new PMusrCanvas(i, msrHandler->GetMsrTitle()->Data(), - 10+i*100, 10+i*100, 800, 600, - startupHandler->GetMarkerList(), - startupHandler->GetColorList()); + if (startupHandler) + musrCanvas = new PMusrCanvas(i, msrHandler->GetMsrTitle()->Data(), + 10+i*100, 10+i*100, 800, 600, + startupHandler->GetMarkerList(), + startupHandler->GetColorList()); + else + musrCanvas = new PMusrCanvas(i, msrHandler->GetMsrTitle()->Data(), + 10+i*100, 10+i*100, 800, 600); + if (!musrCanvas->IsValid()) { cout << endl << "**SEVERE ERROR** Couldn't invoke all necessary objects, will quit."; cout << endl;