diff --git a/src/classes/PMusrCanvas.cpp b/src/classes/PMusrCanvas.cpp index f3f62bb5..f58e0b2e 100644 --- a/src/classes/PMusrCanvas.cpp +++ b/src/classes/PMusrCanvas.cpp @@ -92,12 +92,11 @@ cout << "fMainCanvas = " << fMainCanvas << endl; } fTitlePad->SetFillColor(TColor::GetColor(255,255,255)); fTitlePad->SetTextAlign(12); // middle, left - fTitlePad->AddText("This is a title, this is a title, this is a title, this is a title, ..."); + fTitlePad->AddText(title); fTitlePad->Draw(); // data/theory pad - fDataTheoryPad = new TPad("dataTheoryPad", "dataTheoryPad", 0.0, YINFO, XTHEO-0.02, YTITLE); - fDataTheoryPad = new TPad("dataTheoryPad", "dataTheoryPad", 0.0, YINFO, XTHEO, YTITLE); + fDataTheoryPad = new TPad("dataTheoryPad", "dataTheoryPad", 0.0, YINFO, XTHEO, YTITLE); if (fDataTheoryPad == 0) { cout << endl << "PMusrCanvas::PMusrCanvas: **PANIC ERROR**: Couldn't invoke fDataTheoryPad"; cout << endl; @@ -116,21 +115,6 @@ cout << "fMainCanvas = " << fMainCanvas << endl; fParameterTheoryPad->SetFillColor(TColor::GetColor(255,255,255)); fParameterTheoryPad->SetTextAlign(13); // top, left fParameterTheoryPad->SetTextFont(102); // courier bold, scalable so that greek parameters will be plotted properly - fParameterTheoryPad->AddText("parameter/theory pad ..."); - fParameterTheoryPad->AddText("1 alphaLR 0.9157 0.01075"); - fParameterTheoryPad->AddText("2 alphaTB 0.8777 0.007409"); - fParameterTheoryPad->AddText("3 asyS 0.1555 0.004631"); - fParameterTheoryPad->AddText("4 lambdaS 0.06726 0.01466"); - fParameterTheoryPad->AddText("5 field 7.444 0.1995"); - fParameterTheoryPad->AddText("6 phaseLR 18.3 4.1"); - fParameterTheoryPad->AddText("7 phaseTB -83.1 2.1"); - fParameterTheoryPad->AddText(" "); - fParameterTheoryPad->AddText("asymmetry 3"); - fParameterTheoryPad->AddText("simplExpo 4 (#lambda)"); - fParameterTheoryPad->AddText("TFieldCos map1 fun1 (#phi #nu)"); - fParameterTheoryPad->AddText(" "); - fParameterTheoryPad->AddText("fun1 = par5 * 0.01355"); - fParameterTheoryPad->Draw(); // info pad fInfoPad = new TPaveText(0.0, 0.0, 1.0, YINFO, "NDC"); @@ -257,3 +241,128 @@ void PMusrCanvas::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected) fMainCanvas->Update(); } } + +//-------------------------------------------------------------------------- +// SetParameterList +//-------------------------------------------------------------------------- +/** + *

+ * + * \param paramList + */ +void PMusrCanvas::SetParameterList(PMsrParamList ¶mList) +{ + fParamList = paramList; +} + +//-------------------------------------------------------------------------- +// SetTheoryList +//-------------------------------------------------------------------------- +/** + *

+ * + * \param theoryList + */ +void PMusrCanvas::SetTheoryList(PMsrLines &theoryList) +{ + fTheoryList = theoryList; +} + +//-------------------------------------------------------------------------- +// SetFunctionList +//-------------------------------------------------------------------------- +/** + *

+ * + * \param functionList + */ +void PMusrCanvas::SetFunctionList(PMsrLines &functionList) +{ + fFunctionList = functionList; +} + +//-------------------------------------------------------------------------- +// UpdateParamTheoryPad +//-------------------------------------------------------------------------- +/** + *

+ */ +void PMusrCanvas::UpdateParamTheoryPad() +{ + TString str; + char cnum[128]; + int maxLength = 0; + Double_t ypos; + int idx; + + // add parameters ------------------------------------------------------------ + // get maximal parameter name string length + for (unsigned int i=0; i maxLength) + maxLength = fParamList[i].fName.Length(); + } + maxLength += 2; + // add parameters to the pad + for (unsigned int i=0; iAddText(0.03, ypos, str.Data()); + } + + // add theory ------------------------------------------------------------ + ypos -= 0.025; + for (unsigned int i=1; i 0) { // comment present + str.Resize(idx-1); + str.Resize(str.Strip().Length()); + } + ypos -= 0.025; + fParameterTheoryPad->AddText(0.03, ypos, str.Data()); + } + + fParameterTheoryPad->Draw(); + fMainCanvas->cd(); + fMainCanvas->Update(); +} diff --git a/src/include/PMusrCanvas.h b/src/include/PMusrCanvas.h index c2c85cf1..4f0ad819 100644 --- a/src/include/PMusrCanvas.h +++ b/src/include/PMusrCanvas.h @@ -38,6 +38,8 @@ #include #include +#include "PMusr.h" + #define YINFO 0.1 #define YTITLE 0.95 #define XTHEO 0.75 @@ -55,6 +57,12 @@ class PMusrCanvas : public TObject, public TQObject virtual Bool_t IsValid() { return fValid; } + virtual void SetParameterList(PMsrParamList ¶mList); + virtual void SetTheoryList(PMsrLines &theoryList); + virtual void SetFunctionList(PMsrLines &functionList); + + virtual void UpdateParamTheoryPad(); + virtual void Done(Int_t status=0); // *SIGNAL* virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected); // SLOT @@ -69,6 +77,10 @@ class PMusrCanvas : public TObject, public TQObject TPaveText *fKeyboardHandlerText; + PMsrParamList fParamList; + PMsrLines fTheoryList; + PMsrLines fFunctionList; + ClassDef(PMusrCanvas, 1) }; diff --git a/src/musrview.cpp b/src/musrview.cpp index a9f730bf..a321d526 100644 --- a/src/musrview.cpp +++ b/src/musrview.cpp @@ -35,8 +35,13 @@ using namespace std; #include #include "PMusr.h" +#include "PStartupHandler.h" +#include "PMsrHandler.h" +#include "PRunDataHandler.h" +#include "PRunListCollection.h" #include "PMusrCanvas.h" + //-------------------------------------------------------------------------- /** *

@@ -56,6 +61,7 @@ void musrview_syntax() int main(int argc, char *argv[]) { bool show_syntax = false; + int status; switch (argc) { case 1: @@ -71,7 +77,7 @@ int main(int argc, char *argv[]) } else { // check if filename has extension msr if (!strstr(argv[1], ".msr")) { - cout << endl << "ERROR: " << argv[1] << " is not a msr-file!" << endl; + cout << endl << "**ERROR** " << argv[1] << " is not a msr-file!" << endl; show_syntax = true; } } @@ -85,23 +91,90 @@ int main(int argc, char *argv[]) return PMUSR_WRONG_STARTUP_SYNTAX; } - TApplication app("App", &argc, argv); + // read startup file + PStartupHandler *startupHandler = new PStartupHandler(); - PMusrCanvas *musrCanvas = new PMusrCanvas("musr canvas dummy", 10, 10, 800, 600); - if (!musrCanvas->IsValid()) { - cout << endl << "**SEVERE ERROR** Couldn't invoke all necessary objects, will quit."; - cout << endl; - return -1; + // read msr-file + PMsrHandler *msrHandler = new PMsrHandler(argv[1]); + status = msrHandler->ReadMsrFile(); + if (status != PMUSR_SUCCESS) { + switch (status) { + case PMUSR_MSR_FILE_NOT_FOUND: + 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; + default: + cout << endl << "**UNKNOWN ERROR** when trying to read the msr-file" << endl << endl; + break; + } + return status; } - musrCanvas->Connect("Done(Int_t)", "TApplication", &app, "Terminate(Int_t)"); + // read all the necessary runs (raw data) + PRunDataHandler *dataHandler = new PRunDataHandler(msrHandler); + bool success = dataHandler->IsAllDataAvailable(); + if (!success) { + cout << endl << "**ERROR** Couldn't read all data files, will quit ..." << endl; + } - app.Run(); + // generate the necessary fit histogramms for the view + PRunListCollection *runListCollection = 0; + if (success) { + // feed all the necessary histogramms for the view + runListCollection = new PRunListCollection(msrHandler, dataHandler); + for (unsigned int i=0; i < msrHandler->GetMsrRunList()->size(); i++) { + success = runListCollection->Add(i); + if (!success) { + cout << endl << "**ERROR** Couldn't handle run no " << i << " "; + cout << (*msrHandler->GetMsrRunList())[i].fRunName.Data(); + break; + } + } + } + + if (success) { + // generate Root application needed for PMusrCanvas + TApplication app("App", &argc, argv); + + PMusrCanvas *musrCanvas = new PMusrCanvas(msrHandler->GetMsrTitle()->Data(), 10, 10, 800, 600); + if (!musrCanvas->IsValid()) { + cout << endl << "**SEVERE ERROR** Couldn't invoke all necessary objects, will quit."; + cout << endl; + return -1; + } + musrCanvas->SetParameterList(*msrHandler->GetMsrParamList()); + musrCanvas->SetTheoryList(*msrHandler->GetMsrTheory()); + musrCanvas->SetFunctionList(*msrHandler->GetMsrFunctions()); + musrCanvas->UpdateParamTheoryPad(); + + musrCanvas->Connect("Done(Int_t)", "TApplication", &app, "Terminate(Int_t)"); + + app.Run(); + + // clean up + if (musrCanvas) { + delete musrCanvas; + musrCanvas = 0; + } + } // clean up - if (musrCanvas) { - delete musrCanvas; - musrCanvas = 0; + if (startupHandler) { + delete startupHandler; + startupHandler = 0; + } + if (msrHandler) { + delete msrHandler; + msrHandler = 0; + } + if (dataHandler) { + delete dataHandler; + dataHandler = 0; + } + if (runListCollection) { + delete runListCollection; + runListCollection = 0; } return 0;