fixed some 'uninitialized' stuff. Add canvas graphic dump feature, and fixed crash described in MUSR-53
This commit is contained in:
parent
addc2f5b91
commit
ea0800b4fe
@ -132,7 +132,7 @@ PMusrCanvas::PMusrCanvas(const int number, const char* title,
|
||||
*/
|
||||
PMusrCanvas::~PMusrCanvas()
|
||||
{
|
||||
cout << "~PMusrCanvas() called. fMainCanvas name=" << fMainCanvas->GetName() << endl;
|
||||
//cout << "~PMusrCanvas() called. fMainCanvas name=" << fMainCanvas->GetName() << endl;
|
||||
// cleanup
|
||||
if (fStyle) {
|
||||
delete fStyle;
|
||||
@ -180,10 +180,8 @@ cout << "~PMusrCanvas() called. fMainCanvas name=" << fMainCanvas->GetName() <<
|
||||
fMultiGraphDiff = 0;
|
||||
}
|
||||
if (fNonMusrData.size() > 0) {
|
||||
/*
|
||||
for (unsigned int i=0; i<fNonMusrData.size(); i++)
|
||||
CleanupDataSet(fNonMusrData[i]);
|
||||
*/
|
||||
fNonMusrData.clear();
|
||||
}
|
||||
if (fCurrentFourierPhaseText) {
|
||||
@ -247,8 +245,8 @@ void PMusrCanvas::UpdateParamTheoryPad()
|
||||
TString str;
|
||||
char cnum[128];
|
||||
int maxLength = 0;
|
||||
Double_t ypos, yoffset;
|
||||
int idx;
|
||||
Double_t ypos = 0.0, yoffset = 0.0;
|
||||
int idx = -1;
|
||||
|
||||
// add parameters ------------------------------------------------------------
|
||||
PMsrParamList param = *fMsrHandler->GetMsrParamList();
|
||||
@ -344,6 +342,7 @@ void PMusrCanvas::UpdateParamTheoryPad()
|
||||
fTheoryPad->AddText(0.03, ypos, functions[i].fLine.Data());
|
||||
}
|
||||
|
||||
|
||||
fParameterPad->Draw();
|
||||
fTheoryPad->Draw();
|
||||
fMainCanvas->cd();
|
||||
@ -900,6 +899,52 @@ void PMusrCanvas::LastCanvasClosed()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// SaveGraphicsAndQuit
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \param graphicsFormat One of the supported graphics formats.
|
||||
*/
|
||||
void PMusrCanvas::SaveGraphicsAndQuit(char *fileName, char *graphicsFormat)
|
||||
{
|
||||
cout << endl << ">> SaveGraphicsAndQuit: will dump the canvas into a graphics output file (" << graphicsFormat << ") ..."<< endl;
|
||||
|
||||
TString str(fileName);
|
||||
Int_t idx = -1;
|
||||
Int_t size = 0;
|
||||
char ext[32];
|
||||
|
||||
if (str.Contains(".msr")) {
|
||||
idx = str.Index(".msr");
|
||||
size = 4;
|
||||
}
|
||||
if (str.Contains(".mlog")) {
|
||||
idx = str.Index(".mlog");
|
||||
size = 5;
|
||||
}
|
||||
|
||||
if (idx == -1) {
|
||||
cout << endl << "PMusrCanvas::SaveGraphicsAndQuit **ERROR**: fileName (" << fileName << ") is invalid." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf(ext, "_%d", fPlotNumber);
|
||||
str.Replace(idx, size, ext, strlen(ext));
|
||||
idx += strlen(ext);
|
||||
size = strlen(ext);
|
||||
sprintf(ext, ".%s", graphicsFormat);
|
||||
str.Replace(idx, size, ext, strlen(ext));
|
||||
|
||||
cout << endl << ">> SaveGraphicsAndQuit: " << str.Data() << endl;
|
||||
|
||||
fMainCanvas->SaveAs(str.Data());
|
||||
|
||||
if (fPlotNumber == static_cast<int>(fMsrHandler->GetMsrPlotList()->size()) - 1)
|
||||
Done(0);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// CreateStyle (private)
|
||||
//--------------------------------------------------------------------------
|
||||
@ -908,7 +953,9 @@ void PMusrCanvas::LastCanvasClosed()
|
||||
*/
|
||||
void PMusrCanvas::CreateStyle()
|
||||
{
|
||||
fStyle = new TStyle("musrStyle", "musrStyle");
|
||||
TString musrStyle("musrStyle");
|
||||
musrStyle += fPlotNumber;
|
||||
fStyle = new TStyle(musrStyle, musrStyle);
|
||||
fStyle->SetOptStat(0); // no statistics options
|
||||
fStyle->SetOptTitle(0); // no title
|
||||
fStyle->cd();
|
||||
@ -1073,6 +1120,7 @@ void PMusrCanvas::InitMusrCanvas(const char* title, Int_t wtopx, Int_t wtopy, In
|
||||
|
||||
fMainCanvas->cd();
|
||||
fMainCanvas->Show();
|
||||
|
||||
fMainCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "PMusrCanvas",
|
||||
this, "HandleCmdKey(Int_t,Int_t,Int_t,TObject*)");
|
||||
|
||||
@ -1308,6 +1356,8 @@ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunDat
|
||||
// create histo specific infos
|
||||
name = fMsrHandler->GetMsrRunList()->at(runNo).fRunName[0] + "_DataRunNo";
|
||||
name += (int)runNo;
|
||||
name += "_";
|
||||
name += fPlotNumber;
|
||||
start = data->fDataTimeStart - data->fDataTimeStep/2.0;
|
||||
end = data->fDataTimeStart + data->fValue.size()*data->fDataTimeStep + data->fDataTimeStep/2.0;
|
||||
|
||||
@ -1344,6 +1394,8 @@ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunDat
|
||||
// create histo specific infos
|
||||
name = fMsrHandler->GetMsrRunList()->at(runNo).fRunName[0] + "_TheoRunNo";
|
||||
name += (int)runNo;
|
||||
name += "_";
|
||||
name += fPlotNumber;
|
||||
start = data->fTheoryTimeStart - data->fTheoryTimeStep/2.0;
|
||||
end = data->fTheoryTimeStart + data->fTheory.size()*data->fTheoryTimeStep + data->fTheoryTimeStep/2.0;
|
||||
|
||||
@ -1833,14 +1885,14 @@ cout << endl << ">> data scale = " << scale;
|
||||
*/
|
||||
double PMusrCanvas::FindOptimalFourierPhase()
|
||||
{
|
||||
cout << endl << ">> in FindOptimalFourierPhase ... ";
|
||||
//cout << endl << ">> in FindOptimalFourierPhase ... ";
|
||||
|
||||
// check that Fourier is really present
|
||||
if ((fData[0].dataFourierRe == 0) || (fData[0].dataFourierIm == 0))
|
||||
return 0.0;
|
||||
|
||||
double minPhase, x, valIm, val_xMin, val_xMax;
|
||||
double minIm, maxIm, asymmetry;
|
||||
Double_t minPhase, x, valIm, val_xMin = 0.0, val_xMax = 0.0;
|
||||
Double_t minIm = 0.0, maxIm = 0.0, asymmetry;
|
||||
// get min/max of the imaginary part for phase = 0.0 as a starting point
|
||||
minPhase = 0.0;
|
||||
bool first = true;
|
||||
@ -2873,22 +2925,22 @@ void PMusrCanvas::PlotFourierPhaseValue()
|
||||
double x, y;
|
||||
TString str;
|
||||
|
||||
// plot Fourier phase
|
||||
str = TString("phase = ");
|
||||
str += fCurrentFourierPhase;
|
||||
x = 0.7;
|
||||
y = 0.85;
|
||||
fCurrentFourierPhaseText = new TLatex();
|
||||
fCurrentFourierPhaseText->SetNDC(kTRUE);
|
||||
fCurrentFourierPhaseText->SetText(x, y, str.Data());
|
||||
fCurrentFourierPhaseText->SetTextFont(62);
|
||||
fCurrentFourierPhaseText->SetTextSize(0.03);
|
||||
// plot Fourier phase
|
||||
str = TString("phase = ");
|
||||
str += fCurrentFourierPhase;
|
||||
x = 0.7;
|
||||
y = 0.85;
|
||||
fCurrentFourierPhaseText = new TLatex();
|
||||
fCurrentFourierPhaseText->SetNDC(kTRUE);
|
||||
fCurrentFourierPhaseText->SetText(x, y, str.Data());
|
||||
fCurrentFourierPhaseText->SetTextFont(62);
|
||||
fCurrentFourierPhaseText->SetTextSize(0.03);
|
||||
|
||||
fDataTheoryPad->cd();
|
||||
fDataTheoryPad->cd();
|
||||
|
||||
fCurrentFourierPhaseText->Draw();
|
||||
fCurrentFourierPhaseText->Draw();
|
||||
|
||||
fDataTheoryPad->Update();
|
||||
fDataTheoryPad->Update();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
@ -324,7 +324,7 @@ void PMusrT0::InitDataAndBkg()
|
||||
|
||||
// add lines
|
||||
// t0 line
|
||||
int t0Bin;
|
||||
Int_t t0Bin = 0;
|
||||
switch (fDetectorTag) {
|
||||
case DETECTOR_TAG_FORWARD:
|
||||
t0Bin = fMsrHandler->GetMsrRunList()->at(fRunNo).fT0[0 + fAddRunNo * fAddRunOffset/2];
|
||||
|
@ -302,8 +302,8 @@ bool PRunNonMusr::PrepareViewData()
|
||||
// followed: the smallest x-interval found will be used to for the fXTheory resolution
|
||||
// which is 1000 function points. The function will be calculated from the smallest
|
||||
// xmin found up to the largest xmax found.
|
||||
double xMin, xMax;
|
||||
double xAbsMin, xAbsMax;
|
||||
Double_t xMin = 0.0, xMax = 0.0;
|
||||
Double_t xAbsMin = 0.0, xAbsMax = 0.0;
|
||||
bool first = true;
|
||||
// cout << endl << ">> plotList->size()=" << plotList->size();
|
||||
for (unsigned int i=0; i<plotList->size(); i++) {
|
||||
|
@ -172,6 +172,8 @@ class PMusrCanvas : public TObject, public TQObject
|
||||
virtual void HandleMenuPopup(Int_t id); // SLOT
|
||||
virtual void LastCanvasClosed(); // SLOT
|
||||
|
||||
virtual void SaveGraphicsAndQuit(char *fileName, char *graphicsFormat);
|
||||
|
||||
private:
|
||||
Bool_t fValid;
|
||||
Bool_t fDifferenceView; /// tag showing that the shown data, fourier, are the difference between data and theory
|
||||
|
@ -58,14 +58,13 @@ void musrview_syntax()
|
||||
cout << endl << "usage: musrview <msr-file> [--<graphic-format-extension>] | --version | --help";
|
||||
cout << endl << " <msr-file>: msr/mlog input file";
|
||||
cout << endl << " 'musrview <msr-file>' will execute musrview";
|
||||
cout << endl << ">> ----- NOT YET IMPLEMENTED ----- << ";
|
||||
cout << endl << " --<graphic-format-extension>: ";
|
||||
cout << endl << " will produce a graphics-output-file without starting a root session.";
|
||||
cout << endl << " the name is based on the <msr-file>, e.g. 3310.msr -> 3310.png";
|
||||
cout << endl << " the name is based on the <msr-file>, e.g. 3310.msr -> 3310_0.png";
|
||||
cout << endl << " supported graphic-format-extension:";
|
||||
cout << endl << " eps, pdf, gif, jpg, png, svg, xpm, root";
|
||||
cout << endl << " example: musrview 3310.msr --png, will produce a file 3310.png";
|
||||
cout << endl << ">> ----- NOT YET IMPLEMENTED ----- << ";
|
||||
cout << endl << " example: musrview 3310.msr --png, will produce a files 3310_X.png";
|
||||
cout << endl << " where 'X' stands for the plot number (starting form 0)";
|
||||
cout << endl << " 'musrview' or 'musrview --help' will show this help";
|
||||
cout << endl << " 'musrview --version' will print the musrview version";
|
||||
cout << endl << endl;
|
||||
@ -79,8 +78,10 @@ int main(int argc, char *argv[])
|
||||
bool success = true;
|
||||
char fileName[128];
|
||||
bool graphicsOutput = false;
|
||||
char graphicsExtension[32];
|
||||
char graphicsExtension[128];
|
||||
|
||||
|
||||
// check input arguments
|
||||
switch (argc) {
|
||||
case 1:
|
||||
show_syntax = true;
|
||||
@ -291,6 +292,10 @@ cout << endl;
|
||||
|
||||
musrCanvas->Connect("Done(Int_t)", "TApplication", &app, "Terminate(Int_t)");
|
||||
|
||||
if (graphicsOutput) {
|
||||
musrCanvas->SaveGraphicsAndQuit(fileName, graphicsExtension);
|
||||
}
|
||||
|
||||
// keep musrCanvas objects
|
||||
canvasVector.push_back(musrCanvas);
|
||||
}
|
||||
@ -300,24 +305,24 @@ cout << endl;
|
||||
app.Run(true); // true needed that Run will return after quit so that cleanup works
|
||||
|
||||
// clean up
|
||||
cout << endl << "clean up canvas vector ...";
|
||||
//cout << endl << "clean up canvas vector ...";
|
||||
char canvasName[32];
|
||||
for (unsigned int i=0; i<canvasVector.size(); i++) {
|
||||
// check if canvas is still there before calling the destructor **TO BE DONE**
|
||||
sprintf(canvasName, "fMainCanvas%d", i);
|
||||
cout << endl << ">> canvasName=" << canvasName << ", canvasVector[" << i << "]=" << canvasVector[i];
|
||||
//cout << endl << ">> canvasName=" << canvasName << ", canvasVector[" << i << "]=" << canvasVector[i];
|
||||
if (gROOT->GetListOfCanvases()->FindObject(canvasName) != 0) {
|
||||
cout << endl << ">> canvasName=" << canvasName << ", found ...";
|
||||
cout << endl;
|
||||
//cout << endl << ">> canvasName=" << canvasName << ", found ...";
|
||||
//cout << endl;
|
||||
canvasVector[i]->~PMusrCanvas();
|
||||
} else {
|
||||
cout << endl << ">> canvasName=" << canvasName << ", NOT found ...";
|
||||
cout << endl;
|
||||
//cout << endl << ">> canvasName=" << canvasName << ", NOT found ...";
|
||||
//cout << endl;
|
||||
}
|
||||
}
|
||||
canvasVector.empty();
|
||||
}
|
||||
cout << endl;
|
||||
//cout << endl;
|
||||
|
||||
// clean up
|
||||
plotList.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user