Commit 09e3e3de authored by Jérémie Dudouet's avatar Jérémie Dudouet
Browse files

Merge branch 'FIPPS_Spy' into 'preprod'

Add Fipps spy

See merge request !44
parents 92c24888 9baa2e00
Pipeline #38414 passed with stages
in 5 minutes and 45 seconds
#include "TApplication.h"
#include "TGClient.h"
#include "TString.h"
#include "TEnv.h"
#include "TSysEvtHandler.h"
#include "FSMainWindow.h"
TApplication *theApp;
FSMainWindow *fFSMainWindow;
class TInterruptHandler : public TSignalHandler {
public:
TInterruptHandler() : TSignalHandler(kSigInterrupt, kFALSE) { }
virtual Bool_t Notify() {
// do anything
fFSMainWindow->CloseWindow();
return kTRUE;
}
};
int main(int argc, char **argv)
{
if(getenv("gammaSoftware_DIR") == nullptr) {
ERR_MESS<<"Environment variable: gammaSoftware_DIR needs to be define ==> EXIT"<<ENDL;
return 1;
}
if(getenv("FSRawDataDir") == nullptr) {
ERR_MESS<<"Environment variable: FSRawDataDir needs to be define ==> EXIT"<<ENDL;
return 1;
}
if(getenv("FSLUTFile") == nullptr) {
ERR_MESS<<"Environment variable: FSLUTFile needs to be define ==> EXIT"<<ENDL;
return 1;
}
if(getenv("FSShiftTrackDir") == nullptr) {
WARN_MESS<<"Environment variable FSShiftTrackDir not defined ==> not used"<<ENDL;
}
if(getenv("FSModeLastRun")) {
INFO_MESS<<"FSModeLastRun defined, Spy only on the last run, not online"<<ENDL;
}
gEnv->SetValue("Gui.IconPath",Form("%s/icons:%s/icons",getenv("ROOTSYS"),getenv("gammaSoftware_DIR")));
TString RunInit="";
if(argc > 1){
RunInit = argv[1];
}
TInterruptHandler *fxInterruptHandler = new TInterruptHandler();
fxInterruptHandler->Add();
char* FIPPSSpy_version = (char*) FIPPSSpy_VERSION;
cout << " *******************************************\n";
cout << " * HELLO -- You are Running FIPPSSpy *\n";
cout << " * FIPPSSpy Version : "<< left << setw(18) << FIPPSSpy_version << "*\n";
cout << " *******************************************\n";
theApp = new TApplication("App", &argc, argv);
// make sure that the Gpad and GUI libs are loaded
TApplication::NeedGraphicsLibs();
gApplication->InitializeGraphics();
fFSMainWindow = new FSMainWindow(gClient->GetRoot(), 800, 600, RunInit );
theApp->Run(false);
if (fFSMainWindow) {
delete (fFSMainWindow); // make sure that the Gpad and GUI libs are loaded
TApplication::NeedGraphicsLibs();
gApplication->InitializeGraphics();
fFSMainWindow = nullptr;
}
if (theApp) {
delete (theApp);
theApp = nullptr;
}
return 0;
}
#include "FSGlobalCanvas.h"
#include "TGButton.h"
#include "TGLabel.h"
#include "TImage.h"
#include "TCanvas.h"
#include "TFrame.h"
#include "TGIcon.h"
#include "TH1.h"
#include "TROOT.h"
#include "TError.h"
#include "FSMainWindow.h"
#include "FSPad.h"
#include "FSTab.h"
FSGlobalCanvas::FSGlobalCanvas(const TGWindow *w, const TGWindow *m, CanvasTypes type):
TGHorizontalFrame(w)
{
fMain = const_cast<FSMainWindow *>(static_cast < FSMainWindow const * >(m));
fDetType =type;
SetName(fNames[type]);
fListOfHists = new TList;
TGLabel *label= new TGLabel(this,GetName());
AddFrame(label, new TGLayoutHints( kLHintsCenterY | kLHintsCenterX, 5, 5, 2, 2));
const TGPicture *picbut = fClient->GetPicture("../icons/arrow-next-icone-7059-16.png");
fPictButton = new TGPictureButton(this,picbut,-1);
AddFrame(fPictButton, new TGLayoutHints( kLHintsCenterY | kLHintsRight, 5, 5, 2, 2));
fPictButton->Associate(this);
fPictButton->Connect("Released()", "FSGlobalCanvas", this, "PlotCanvas()");
}
FSGlobalCanvas::~FSGlobalCanvas()
{
delete fListOfHists;
}
void FSGlobalCanvas::Print()
{
cout<<fName<<" ; NPads = "<<fNPads<<"("<<fNPadsx<<"x"<<fNPadsy<<") ; NSpectra = "<<fListOfHists->GetEntries()<<endl;
}
void FSGlobalCanvas::AddSpectrum(TH1 *hist)
{
fListOfHists->Add(hist);
}
void FSGlobalCanvas::PlotCanvas()
{
Int_t NDets=fListOfHists->GetEntries();
Bool_t CheckTab = fMain->DoTab(GetName());
if(CheckTab == false){
fMain->GetTabPage()->ComputePadXY(NDets,&fNPadsx,&fNPadsy);
fNPads = fNPadsx*fNPadsy;
fMain->NewTab(GetName(),fNPadsx,fNPadsy);
}
TCanvas *c = fMain->GetTabPage()->GetCanvasAt(fMain->GetTabPage()->GetCurrent());
for(int i=0 ; i<fListOfHists->GetEntries() ; i++) {
gErrorIgnoreLevel = kFatal;
FSPad* pad = dynamic_cast<FSPad*>(fMain->GetTabPage()->GetPad(fMain->GetTabPage()->GetCurrent(),i+1));
pad->cd();
if(fListOfHists->At(i)->InheritsFrom(TH1::Class()) && ((TH1*)fListOfHists->At(i))->GetEntries()>0)
fListOfHists->At(i)->Draw("hist");
}
gROOT->SetSelectedPad(c->cd(1));
fMain->GetTabPage()->RefreshTab();
gErrorIgnoreLevel = kPrint;
}
#ifndef FSGLOBALCANVAS_H
#define FSGLOBALCANVAS_H
#include <map>
#include "TGFrame.h"
using namespace std;
class TGPictureButton;
class TH1;
class FSMainWindow;
enum CanvasTypes{ kFIPPS, kFIPPS_ACF, kFIPPS_ACS, kFIPPS_ACB, kIFIN, kIFIN_AC, kTAG, kUndef};
static const TString fNames[8] = {"FIPPS","FIPPS_AC_FRONT","FIPPS_AC_SIDE","FIPPS_AC_BACK","IFIN","IFIN_AC","TAG","Undef"};
class FSGlobalCanvas : public TGHorizontalFrame
{
public:
protected:
FSMainWindow *fMain = nullptr;
Int_t fCurrentPad = 1;
Int_t fNPadsx;
Int_t fNPadsy;
Int_t fNPads;
Int_t fDetType;
TString fDetName;
TGPictureButton *fPictButton = nullptr;
TList *fListOfHists = nullptr;
public:
FSGlobalCanvas(const TGWindow *w, const TGWindow *m, CanvasTypes type);
~FSGlobalCanvas();
virtual void AddSpectrum(TH1 *hist);
TList *GetListOfSpectra(){return fListOfHists;}
virtual void Print();
virtual void PlotCanvas();
};
#endif // FSGLOBALCANVAS_H
#ifndef FSGLOBALS_H
#define FSGLOBALS_H
///////////////////////////////////////////
/// ///
/// Include file for general define.... ///
/// ///
///////////////////////////////////////////
#define FIPPSSpy_VERSION "1.0";
using namespace std;
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include "GuiTypes.h"
/// Root includes
static Pixel_t FS_White = 0xFFFFFF;
static Pixel_t FS_Snow = 0xFFFAFA;
static Pixel_t FS_Azure = 0xF0FFFF;
static Pixel_t FS_Black = 0x000000 ;
static Pixel_t FS_LightBlue = 0xADD8E6;
static Pixel_t FS_LightRed = 0xF08080;
static Pixel_t FS_Red = 0xFF0000;
static Pixel_t FS_LightGreen = 0x90EE90;
static Pixel_t FS_Wheat = 0xF5DEB3;
#define ERR_MESS std::cout<<"\e[0;3;31m -- ERROR : "
#define WARN_MESS std::cout<<"\e[0;3;33m -- WARNNING: "
#define INFO_MESS std::cout<<"\e[0;3;32m -- INFO : "
#define END_MESS "\e[0;m"
#define ENDL END_MESS<<std::endl
#endif // FSGLOBALS_H
This diff is collapsed.
#ifndef FSMainWindow_H
#define FSMainWindow_H
/// ROOT includes
#include "TGFrame.h"
#include "GuiTypes.h"
#include "TGSplitter.h"
#include "TGTab.h"
#include "TH1D.h"
/// FS includes
#include "FSGlobals.h"
#include "FSMenuBar.h"
#include "FSToolBar.h"
#include "FSTab.h"
#include "FSShutter.h"
class TGPopupMenu;
class FSPad;
class FSSpectraList;
class FSSetRangeUser;
class DetDef
{
public:
UShort_t Type=0;
UShort_t CloverId=0;
UShort_t Ge_Id=0;
UShort_t AC_Id=0;
UShort_t GlobId=0;
UShort_t Id=0;
UShort_t adc=0;
public:
DetDef(){;}
Bool_t IsTAG(){return Type==4;}
Bool_t IsAC(){return (Type==3 || Type==5 || Type==6 || Type==7);}
Bool_t IsIFIN(){return Type==2;}
Bool_t IsFIPPS(){return Type==1;}
Bool_t IsClover(){return IsFIPPS() || IsIFIN();}
};
class FSMainWindow : public TGMainFrame
{
private:
TGHorizontalFrame *fMainFrame = nullptr;
TGVSplitter *fVSplitter = nullptr;
TGTab *fMainTabL = nullptr;
TGCompositeFrame *fLetfTab = nullptr;
TGVerticalFrame *fVFLeft = nullptr;
TGVerticalFrame *fVFRight = nullptr;
myTGCompositeFrame *fActiveTab = nullptr;
TGStatusBar *fStatusBar = nullptr;
map <Int_t, TH1D*> fListOfSpectra;
map <Int_t, Double_t[10]> fListOfCal;
map <Int_t, Double_t[2]> fListOfShiftTrack;
/// FIPPSSpy objects
FSMenuBar *fFSMenuBar = nullptr;
FSToolBar *fFSToolBar = nullptr;
FSSetRangeUser *fRangeUser = nullptr;
FSTab *fCanvasTab = nullptr;
TList *fListOfCanvases = nullptr;
FSShutter *fShutter = nullptr;
Int_t fLastEventX =-1;
Int_t fLastEventY =-1;
TString fSavedAs="";
map<Int_t, DetDef*> fDetectors;
TString fCurrentDate="";
Int_t fCalOrder = 0;
TString fLastRun="";
Int_t fLastShiftTrackRun = 0;
TString fCurrentCalFile = "";
TString fCurrentShiftTrackFile = "";
public:
FSMainWindow(const TGWindow *p, UInt_t w, UInt_t h, TString RunInit="");
~FSMainWindow();
void CloseWindow();
void ReadHistograms();
map <Int_t, TH1D*> GetListOfSpectra(){return fListOfSpectra;}
TH1 *GetNextHist(TH1 *hist_in, bool previous);
FSTab *GetTabPage(){return fCanvasTab;}
void NewTab(TString name ="", Int_t npx=2, Int_t npy=2);
TPad *GetSelectedPad();
Bool_t DoTab(TString TabName);
void ZoomOnPad(FSPad *origin, bool same = false);
void HandleZoom(Int_t EventType, Int_t EventX, Int_t EventY, TObject *selected);
FSMenuBar *GetMenuBar(){return fFSMenuBar;}
void SetGlobalZoomWindow(FSSetRangeUser *rangeuser ) {fRangeUser = rangeuser;}
FSSetRangeUser *GetGlobalZoomWindow(){return fRangeUser;}
TGStatusBar *GetStatusBar(){return fStatusBar;}
Bool_t IsFullMode(){return fFSToolBar->IsFullMode();}
TGCompositeFrame *GetLeftTab(){return fLetfTab;}
void RebuildShutter();
void SaveTabAs();
TCanvas *GetTCanvas();
void DoCalMode(Bool_t on);
void PrintShiftTrack();
void PrintCal();
protected:
private:
void InitParameters();
void ReadLUT();
void GetLastShiftTrack();
void ReadCal();
void LoadMainWindow();
void LoadMenuFile();
void LoadToolBar();
void LoadLeftSide();
void LoadRightSide();
TString GetStdoutFromCommand(string cmd);
ClassDef(FSMainWindow,0)
};
#endif
#include "FSMenuBar.h"
#include "FSMainWindow.h"
enum ETestCommandIdentifiers {
M_FILE_EXIT,
M_FILE_SAVE,
M_CALIB,
M_PRINTSHIFTTRACK,
M_PRINTCAL,
};
/*------------------------------------------------------*/
//constructor
FSMenuBar::FSMenuBar(const TGWindow *p, UInt_t w, UInt_t h, UInt_t option) :
TGMenuBar(p, w, h, option) {
fMain = const_cast<FSMainWindow *>(static_cast < FSMainWindow const * >(p));
const TGPicture* pict_exit = gClient->GetPicture("bld_exit.png");
const TGPicture* pict_saveas = gClient->GetPicture("bld_save.png");
TGLayoutHints *fFSMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
//////////////////////
///*** MenuFile ***///
//////////////////////
fMenuFile = new TGPopupMenu(gClient->GetRoot());
fMenuFile->Connect("Activated(Int_t)", "FSMenuBar", this, "HandleMenu(Int_t)");
fMenuFile->AddEntry("S&ave As", M_FILE_SAVE, 0, pict_saveas);
fMenuFile->AddEntry("E&xit", M_FILE_EXIT, 0, pict_exit);
AddPopup("&File", fMenuFile, fFSMenuBarItemLayout);
fMenuMode = new TGPopupMenu(gClient->GetRoot());
fMenuMode->Connect("Activated(Int_t)", "FSMenuBar", this, "HandleMenu(Int_t)");
fMenuMode->AddEntry("&Calibrated", M_CALIB);
AddPopup("&Mode", fMenuMode, fFSMenuBarItemLayout);
fToolsMode = new TGPopupMenu(gClient->GetRoot());
fToolsMode->Connect("Activated(Int_t)", "FSMenuBar", this, "HandleMenu(Int_t)");
fToolsMode->AddEntry("&Print shift track", M_PRINTSHIFTTRACK);
fToolsMode->AddEntry("&Print calibrations", M_PRINTCAL);
AddPopup("&Tools", fToolsMode, fFSMenuBarItemLayout);
}
FSMenuBar::~FSMenuBar() {
}
void FSMenuBar::HandleMenu(Int_t id) {
switch (id) {
case M_FILE_EXIT:
fMain->CloseWindow(); // terminate theApp no need to use SendCloseMessage()
break;
case M_FILE_SAVE:
fMain->SaveTabAs(); // terminate theApp no need to use SendCloseMessage()
break;
case M_CALIB:
if(fMenuMode->IsEntryChecked(M_CALIB)) fMenuMode->UnCheckEntry(M_CALIB);
else fMenuMode->CheckEntry(M_CALIB);
fMain->DoCalMode(IsCalMode());
break;
case M_PRINTSHIFTTRACK:
fMain->PrintShiftTrack();
break;
case M_PRINTCAL:
fMain->PrintCal();
break;
}
}
Bool_t FSMenuBar::IsCalMode()
{
return fMenuMode->IsEntryChecked(M_CALIB);
}
ClassImp(FSMenuBar)
#ifndef FSMenuBar_h
#define FSMenuBar_h
#include "TGMenu.h"
class FSMainWindow;
class FSMenuBar: public TGMenuBar
{
private:
FSMainWindow *fMain = nullptr;
TGPopupMenu *fMenuFile = nullptr;
TGPopupMenu *fMenuMode = nullptr;
TGPopupMenu *fToolsMode = nullptr;
public:
FSMenuBar(const TGWindow *p, UInt_t w, UInt_t h, UInt_t option);
virtual ~FSMenuBar();
Bool_t IsCalMode();
void HandleMenu(Int_t id);
ClassDef(FSMenuBar,0)
};
#endif
#include "FSPad.h"
#include "TGMsgBox.h"
#include "FSPad.h"
#include "TStyle.h"
#include "TROOT.h"
#include "TVirtualPad.h"
#include "TFrame.h"
#include "TCanvas.h"
#include "KeySymbols.h"
#include "FSMainWindow.h"
#include "FSTab.h"
FSPad::FSPad(TGMainFrame * main, const char* name, const char* title,
Double_t xlow, Double_t ylow, Double_t xup, Double_t yup,
Color_t color, Short_t bordersize, Short_t bordermode) :
TPad(name, title, xlow, ylow, xup, yup, color, bordersize, bordermode)
{
fMain = const_cast<FSMainWindow *>(static_cast < FSMainWindow const * >(main));
Initialization();
}
void FSPad::Initialization()
{
SetBit(kCannotMove, kTRUE);
SetBorderMode(1);
}
FSPad::~FSPad()
{
}
TH1 *FSPad::GetHisto()
{
TList *lop = GetListOfPrimitives();
TH1 *hist = nullptr;
for(int i=0 ; i<lop->GetEntries() ; i++) {
TObject *o = lop->At(i);
if(o->InheritsFrom("TH1")) {
hist = (TH1*)o;
break;
}
}
return hist;
}
void FSPad::RemoveLog(Bool_t logx, Bool_t logy, Bool_t logz)
{
if (logx) {
SetLogx(0);
}
if (logy) {
SetLogy(0);
}
if (logz) {
SetLogz(0);