Skip to content
Snippets Groups Projects
Commit 109a744f authored by pospelov's avatar pospelov
Browse files

new canvas names, correction in DrawHelper singleton to prevent dead reference

parent f43c9687
No related branches found
No related tags found
No related merge requests found
......@@ -10,33 +10,55 @@
// * mollis quis. Mauris commodo rhoncus porttitor. *
// ********************************************************************
//! @file DrawHelper.h
//! @brief Helper class definition for sophisticated data drawing
//! @brief Helper class for graphics in ROOT
//! @author Scientific Computing Group at FRM II
//! @date 01.04.2012
#include "TObject.h"
class TCanvas;
//- -------------------------------------------------------------------
//! @class DrawHelper
//! @brief Several usefull utilities for graphics in ROOT
//!
//! Provides magnification of pads in canvas, common style for drawing,
//! saving of all opened canvases from memory to pdf file
//- -------------------------------------------------------------------
class DrawHelper : public TObject
{
public:
~DrawHelper();
static DrawHelper *instance();
static DrawHelper &instance();
//! set own drawing style
static void SetStyle();
//! saving canvases from memory into multipage pdf file
static void SaveReport();
/// connect user canvas with magnifier function
//! connect user canvas with magnifier function
void SetMagnifier(TCanvas *c);
/// process double click in canvas to magnify given pad
//! process double click in canvas to magnify given pad
void ExecuteMagnifier(Int_t event, Int_t px, Int_t py, TObject *sel);
private:
/// prevents client from creating a copy of the singleton
DrawHelper();
DrawHelper(const DrawHelper &);
DrawHelper &operator=(const DrawHelper &);
/// reaction on too early destroyed object
static void onDeadReference();
/// create single copy of manager
static void create();
static DrawHelper *m_instance;
static bool m_destroyed;
ClassDef(DrawHelper,1)
};
......
#include "DrawHelper.h"
#include "Exceptions.h"
#include <iostream>
#include "TROOT.h"
#include "TCanvas.h"
......@@ -8,6 +10,8 @@
DrawHelper *DrawHelper::m_instance = 0;
bool DrawHelper::m_destroyed = false;
DrawHelper::DrawHelper()
......@@ -18,19 +22,53 @@ DrawHelper::DrawHelper()
DrawHelper::~DrawHelper()
{
std::cout << "DrawHelper::~DrawHelper() -> Info. Deleting material manager" << std::endl;
m_instance = 0;
m_destroyed = true;
}
DrawHelper *DrawHelper::instance()
/* ************************************************************************* */
// access to material manager
/* ************************************************************************* */
DrawHelper &DrawHelper::instance()
{
if( m_instance == 0) {
m_instance = new DrawHelper();
}
return m_instance;
// check if exists, if not, then initialise
if( !m_instance) {
// check for dead reference (i.e. object has been initialised but then somebody managed to delete it)
if( m_destroyed ) {
onDeadReference();
} else {
// first call initalise
create();
}
}
std::cout << "DrawHelper::Instance() -> Info. Accesing instance... " << m_instance << std::endl;
return *m_instance;
}
/* ************************************************************************* */
// create single instance
/* ************************************************************************* */
void DrawHelper::create() {
std::cout << "MaterialManager::Create() -> Info. Creating material manager" << std::endl;
static DrawHelper theInstance;
m_instance = &theInstance;
}
/* ************************************************************************* */
// Action for abnormal situation when object has been occasionally deleted.
// The possibility to rise object again should be still implemented.
/* ************************************************************************* */
void DrawHelper::onDeadReference() {
throw DeadReferenceException("Dead reference detected.");
}
/* ************************************************************************* */
// assign function to handle mouse events inside canvas
/* ************************************************************************* */
......
......@@ -58,7 +58,7 @@ void TestDWBAFormFactor::execute()
void TestDWBAFormFactor::draw()
{
// creation of 2D histogram from calculated intensities
TCanvas *c1 = new TCanvas("c1", "Cylinder Formfactor", 0, 0, 1024, 768);
TCanvas *c1 = new TCanvas("c1_test_dwba_formfactor", "Cylinder Formfactor", 0, 0, 1024, 768);
(void)c1;
MultiIndex& index = mp_intensity_output->getIndex();
......
......@@ -49,7 +49,7 @@ void TestFormFactor::execute()
void TestFormFactor::draw()
{
// creation of 2D histogram from calculated intensities
TCanvas *c1 = new TCanvas("c1", "Cylinder Formfactor", 0, 0, 1024, 768);
TCanvas *c1 = new TCanvas("c1_test_formfactor", "Cylinder Formfactor", 0, 0, 1024, 768);
(void)c1;
MultiIndex& index = mp_intensity_output->getIndex();
......
......@@ -122,9 +122,9 @@ void TestFresnelCoeff::Draw(const MultiLayer &sample, const MyDataSet_t &data)
gr_absSum->SetPoint(i_point, alpha_i*180./M_PI, sum);
}
TCanvas *c1 = new TCanvas("cf1","cf1",1024,768);
DrawHelper *drawHelper = DrawHelper::instance();
drawHelper->SetMagnifier(c1);
TCanvas *c1 = new TCanvas("c1_test_fresnel","Fresnel Coefficients in Multilayer",1024,768);
DrawHelper &drawHelper = DrawHelper::instance();
drawHelper.SetMagnifier(c1);
int ndivy = sqrt(nlayers);
int ndivx = nlayers/ndivy + 1;
......
......@@ -31,7 +31,7 @@ void TestRoughness::execute()
{
//test_FFT();
// draw possible surface profile using different methods for calculation of correlated random numbers
// draw surface profile using different methods for calculation of correlated random numbers
m_TestMethods.push_back( &TestRoughness::GetProfileXZ_MatrixMethod );
m_TestMethods.push_back( &TestRoughness::GetProfileXZ_FFTMethod );
DrawProfile();
......@@ -74,7 +74,7 @@ void TestRoughness::DrawProfile()
m_vzuncorr[i] = mr.Gaus(0,sigma);
}
// run through different sets of roughnes parameters and calculation models
// run through different sets of roughnes parameters and calculation methods
// and calculate z-profile of surface
size_t nsets = int(sizeof(roughnessSet)/sizeof(RoughnessData));
size_t nmethods = m_TestMethods.size();
......@@ -96,7 +96,7 @@ void TestRoughness::DrawProfile()
}
// making drawing
TCanvas *c1 = new TCanvas("c1","c1",1024, 768);
TCanvas *c1 = new TCanvas("c1_test_roughness","Surface Roughness Profile",1024, 768);
c1->Divide(2,3);
TH1F *href = new TH1F("h1","h1",npx, xmin, xmax);
......@@ -130,7 +130,7 @@ void TestRoughness::DrawProfile()
c1->cd(2+(i_set-3)*2); // i_set=3,4,5 will be on the right side of canvas
}
if(i_method==0) { // draw reference histogram only once per set
if(i_method==0) { // draw reference histogram per set only once
std::ostringstream out;
out << "#sigma: " << std::setprecision(3) << roughnessSet[i_set].sigma
<< " H: " << std::setprecision(3) << roughnessSet[i_set].hurst
......@@ -201,6 +201,7 @@ void TestRoughness::GetProfileXZ_MatrixMethod()
/* ************************************************************************* */
void TestRoughness::GetProfileXZ_FFTMethod()
{
// preparing array for rezults
size_t npx = m_vx.size();
m_vzcorr.clear();
m_vzcorr.resize(npx, 0);
......@@ -232,12 +233,6 @@ void TestRoughness::GetProfileXZ_FFTMethod()
for(size_t i=0; i<npx; i++){
m_vzcorr[i] = ift_result[i].real();
// std::cout << i << "C:" << cov[i] << "ftC:" << ft_cov[i]
// << " z:" << m_vzuncorr[i] << " ftZ" << ft_z[i]
// << " ft_R:" << ft_result[i]
// << " ift_R:" << ift_result[i]
// << " Zc:" << m_vzcorr[i]
// << std::endl;
}
}
......
......@@ -32,31 +32,31 @@
class MaterialManager
{
public:
/// access to material manager
//! access to material manager
static MaterialManager &instance();
/// return material from database
//! return material from database
const IMaterial *getMaterial(const std::string &name);
/// add material to the database
//! add material to the database
const IMaterial *addHomogeneousMaterial(const std::string &name, complex_t refractive_index);
/// clean collection of material
//! clean collection of material
void clear();
/// print material database
//! print material database
void print() const;
private:
/// prevents client from creating a copy of the singleton
//! prevents client from creating a copy of the singleton
MaterialManager();
MaterialManager(const MaterialManager &);
MaterialManager &operator=(const MaterialManager &);
/// reaction on too early destroyed object
//! reaction on too early destroyed object
static void onDeadReference();
/// create single copy of manager
//! create single copy of manager
static void create();
virtual ~MaterialManager();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment