////////////////////////////////////////////////////////////////////////////////
// //
// MIDTRCTab //
// //
// Begin_Html <!--
/*-->
<!--*/
// --> End_Html
// //
// //
////////////////////////////////////////////////////////////////////////////////
/* Generated header file containing necessary includes */
#include "generated/MIDTRCTabGeneratedIncludes.h"
////////////////////////////////////////////////////////////////////////////////
/* This header was generated by ROMEBuilder. Manual changes above the *
* following line will be lost next time ROMEBuilder is executed. */
/////////////////////////////////////----///////////////////////////////////////
#include "generated/MIDWindow.h"
#include "generated/MIDAnalyzer.h"
#include "tabs/MIDTRCTab.h"
#include "tasks/MIDTFillHistogramraw.h"
#include "TAxis.h"
#include "TLatex.h"
#include <TGClient.h>
#include <TCanvas.h>
#include <TRandom.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TRootEmbeddedCanvas.h>
#include <RQ_OBJECT.h>
#include<TString.h>
#include<TDatime.h>
// uncomment if you want to include headers of all folders
#include "MIDAllFolders.h"
ClassImp(MIDTRCTab)
using namespace std;
//______________________________________________________________________________
void MIDTRCTab::Init()
{
// Create style for this tab
TStyle *orgStyle = gStyle;
fStyle = new TStyle(*orgStyle); // copy the original style
fStyle->SetOptTitle(1);
fStyle->SetTitleOffset(0.38, "y");
fStyle->SetPadGridX(1);
fStyle->SetPadGridY(1);
fStyle->SetPadTickX(1);
fStyle->SetPadTickY(1);
fStyle->SetFrameBorderSize(0);
fStyle->SetFrameBorderMode(0);
fStyle->SetFrameFillStyle(0);
fStyle->SetTitleSize(0.06, "t");
fStyle->SetStatH(0.30);
fStyle->SetStatW(0.30);
fStyle->cd();
// Create a vertical frame containing buttons and canvas
fVert = new TGVerticalFrame(this, (UInt_t) (700 * gAnalyzer->GetWindow()->GetWindowScale()), (UInt_t) (700 * gAnalyzer->GetWindow()->GetWindowScale()));
// Create an embedded canvas and add to the main frame, centered in x and y
// set data member
fCanvasName = new TString ("Sample Canvas");
fCanvas = new TRootEmbeddedCanvas("Sample Canvas", fVert, (UInt_t) (600 * gAnalyzer->GetWindow()->GetWindowScale()), (UInt_t) (600 * gAnalyzer->GetWindow()->GetWindowScale()));
fCanvas->GetCanvas()->Divide(5, 11);
// Create "Update" button
ULong_t yellow;
gClient->GetColorByName("Yellow",yellow);
fBUpdate = new TGTextButton(fVert, "Update");
fBUpdate->ChangeBackground(yellow);
fBUpdate->Associate(this);
// fVert->AddFrame(fCanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 4, 4, 4, 4));
fVert->AddFrame(fBUpdate, new TGLayoutHints(kLHintsCenterX, 10, 10, 4, 4));
AddFrame(fVert, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 4, 4));
//create Exit button
ULong_t red;
gClient->GetColorByName("Red",red);
fExit = new TGTextButton(fVert, "&Exit", "gApplication->Terminate(0)");
fExit->ChangeBackground(red);
fExit->Associate(this);
fVert->AddFrame(fExit, new TGLayoutHints(kLHintsCenterX, 10, 10, 4, 4));
//create save button
ULong_t green;
gClient->GetColorByName("Green",green);
fSaveCanvas = new TGTextButton(fVert, "SaveCanvas");
fSaveCanvas->ChangeBackground(green);
fSaveCanvas->Associate(this);
fVert->AddFrame(fSaveCanvas, new TGLayoutHints(kLHintsCenterX, 10, 10, 4, 4));
fVert->AddFrame(fCanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 4, 4, 4, 4));
// AddFrame(fVert, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 4, 4, 4, 4));
ConnectAll();
orgStyle->cd();
}
//______________________________________________________________________________
void MIDTRCTab::EndInit()
{
}
//______________________________________________________________________________
void MIDTRCTab::EventHandler()
{
}
//______________________________________________________________________________
void MIDTRCTab::MenuClicked(TGPopupMenu * /* menu */, Long_t /* param */)
{
}
//______________________________________________________________________________
void MIDTRCTab::TabSelected()
{
}
//______________________________________________________________________________
void MIDTRCTab::TabUnSelected()
{
}
// Save Canvas:
// you'll need a function of the same signature in your .h -> also make sure that TString is included in your .h
void MIDTRCTab::SaveCanvas()
{
// if following doesn't work blame Sabato Leo
TString * fileName = new TString (fCanvasName->Data());
//replace all spaces in your canvas name
fileName->ReplaceAll(" ", "");
//generate data and time stamp -> Recall you'll have to make sure TDatime is included
TDatime dateTime; // time and date remain frozen when this function was called
TString dateAsString = Form("%d", dateTime.GetDate());
TString timeAsString = Form("%d", dateTime.GetTime());
// append time date etc to canvas name
(*fileName) += ".";
(*fileName) += dateAsString;
(*fileName) += ".";
(*fileName) += timeAsString;
(*fileName) += ".pdf"; // pdf for now maybe think about png and other options for user later ?
// debug
//cout << " This is the filename " << fileName->Data() << endl;
// now print it and hope it works ....
fCanvas->GetCanvas()->Print(fileName->Data());
// cout << " Already attempted to print this file " << fileName->Data() << endl;
}
void MIDTRCTab::Update()
{
TStyle *orgStyle = gStyle;
fStyle->cd();
TH1 *histo;
for (Int_t i = 0; i < 55; i++) { //loop over all 55 pads
fCanvas->GetCanvas()->cd(i + 1);
histo = (TH1F *) gAnalyzer->GetFillHistogramrawTask()->Geth1_wfAt(i);
if (!histo) {
cout << "Histo ADC not available." << endl;
} else {
histo->Draw();
}
}
fCanvas->GetCanvas()->cd(0);
fCanvas->GetCanvas()->Modified();
fCanvas->GetCanvas()->Update();
orgStyle->cd();
return;
}
//_____________________________________________________________________________\
_
void MIDTRCTab::ConnectAll()
{
fBUpdate->Connect("Pressed()", "MIDTRCTab", this, "Update()");
fExit->Connect("Pressed()", "MIDTRCTab", this, "&Exit()");
fSaveCanvas->Connect("Pressed()","MIDTRCTab", this, "SaveCanvas()");
}
//_____________________________________________________________________________\
_
void MIDTRCTab::DisconnectAll()
{
if (fBUpdate) { fBUpdate->Disconnect(this); }
if (fExit) { fExit->Disconnect(this); }
if(fSaveCanvas) { fSaveCanvas->Disconnect(this);}
}
|