]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Adding main class for the mchview program
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 25 Jan 2008 13:49:38 +0000 (13:49 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 25 Jan 2008 13:49:38 +0000 (13:49 +0000)
(Laurent)

MUON/AliMUONMchViewApplication.cxx [new file with mode: 0644]
MUON/AliMUONMchViewApplication.h [new file with mode: 0644]
MUON/MUONgraphicsLinkDef.h
MUON/libMUONgraphics.pkg
MUON/mchview.cxx

diff --git a/MUON/AliMUONMchViewApplication.cxx b/MUON/AliMUONMchViewApplication.cxx
new file mode 100644 (file)
index 0000000..65596bd
--- /dev/null
@@ -0,0 +1,225 @@
+#include "AliMUONMchViewApplication.h"
+
+#include "AliCDBManager.h"
+#include "AliCodeTimer.h"
+#include "AliLog.h"
+#include "AliMUONPainterDataSourceFrame.h"
+#include "AliMUONPainterHelper.h"
+#include "AliMUONPainterMasterFrame.h"
+#include "AliMUONPainterRegistry.h"
+#include "AliMUONVTrackerData.h"
+#include <Riostream.h>
+#include <TCanvas.h>
+#include <TEnv.h>
+#include <TFile.h>
+#include <TGClient.h>
+#include <TGFileDialog.h>
+#include <TGMenu.h>
+#include <TGTab.h>
+#include <TKey.h>
+#include <TList.h>
+#include <TString.h>
+#include <TSystem.h>
+
+/// \class AliMUONMchViewApplication
+///
+/// Main class for the mchview program
+///
+///\author Laurent Aphecetche, Subatech
+
+/// \cond CLASSIMP
+ClassImp(AliMUONMchViewApplication)
+/// \endcond CLASSIMP
+
+const Int_t AliMUONMchViewApplication::fgkFILESAVEAS(1);
+const Int_t AliMUONMchViewApplication::fgkFILEOPEN(2);
+const Int_t AliMUONMchViewApplication::fgkFILEEXIT(3);
+
+//______________________________________________________________________________
+AliMUONMchViewApplication::AliMUONMchViewApplication(const char* name,
+                                                     int* argc, char** argv,
+                                                     Float_t wfraction,
+                                                     Float_t hfraction) 
+: TRint(name,argc,argv),
+  fMainFrame(0x0)
+{
+
+  /// ctor
+  /// wfraction,hfraction are the fractions of display width and height
+  /// we want to draw on
+  
+  UInt_t dw = gClient->GetDisplayWidth(); 
+  UInt_t dh = gClient->GetDisplayHeight(); 
+                   
+  UInt_t w = (UInt_t)(wfraction*dw);
+  UInt_t h = (UInt_t)(hfraction*dh);
+
+  fMainFrame = new TGMainFrame(gClient->GetRoot(),w,h);
+  
+  CreateMenuBar(w);
+
+  const Int_t kbs = 2;
+  
+//  h -= 60; // menubar
+  
+  TGTab* tabs = new TGTab(fMainFrame,w,h);
+  
+  TGCompositeFrame* t = tabs->AddTab("Painter Master Frame");
+
+  AliMUONPainterMasterFrame* pf = 
+    new AliMUONPainterMasterFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
+  
+  t->AddFrame(pf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
+
+  t = tabs->AddTab("Data Sources");
+  
+  AliMUONPainterDataSourceFrame* dsf = 
+    new AliMUONPainterDataSourceFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
+  
+  t->AddFrame(dsf,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
+  
+  fMainFrame->AddFrame(tabs,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,0,0,0,0));
+
+  fMainFrame->SetWindowName("mchview - Visualization of MUON Tracker detector");
+
+  fMainFrame->MapSubwindows();
+  fMainFrame->Resize();
+  fMainFrame->MapWindow();
+  
+  fMainFrame->Connect("CloseWindow()","AliMUONMchViewApplication",this,"Terminate()");
+  
+  UInt_t x = dw/2 - w/2;
+  UInt_t y = 0;
+  
+  fMainFrame->MoveResize(x, y, w, h); 
+  fMainFrame->SetWMPosition(x, y);
+  
+  fMainFrame->SetWMSizeHints(w,h,w,h,0,0);
+}
+
+//______________________________________________________________________________
+AliMUONMchViewApplication::~AliMUONMchViewApplication()
+{
+  /// dtor
+}
+
+//______________________________________________________________________________
+void
+AliMUONMchViewApplication::CreateMenuBar(UInt_t w)
+{
+  /// Create the application menu bar
+  
+  TGPopupMenu* file = new TGPopupMenu(gClient->GetRoot());
+  
+  file->AddEntry("&Open...",fgkFILEOPEN);
+  file->AddEntry("&Save As...",fgkFILESAVEAS);
+  file->AddEntry("&Exit",fgkFILEEXIT);
+  
+  file->Connect("Activated(Int_t)","AliMUONMchViewApplication",this,"HandleMenu(Int_t)");
+  
+  TGMenuBar* bar = new TGMenuBar(fMainFrame,w);
+  
+  bar->AddPopup("&File",file,new TGLayoutHints(kLHintsLeft|kLHintsTop));
+  
+  fMainFrame->AddFrame(bar,new TGLayoutHints(kLHintsLeft|kLHintsExpandX));
+  
+  AliMUONPainterRegistry::Instance()->SetMenuBar(bar);
+}
+
+//______________________________________________________________________________
+void
+AliMUONMchViewApplication::HandleMenu(Int_t i)
+{
+  /// Handle the click of one menu item
+
+  switch (i)
+    {
+    case fgkFILEEXIT:
+      Terminate(1);
+      break;
+    case fgkFILEOPEN:
+      Open();
+      break;
+    case fgkFILESAVEAS:
+      Save();
+      break;
+    default:
+      break;
+    }
+}
+
+//______________________________________________________________________________
+void
+AliMUONMchViewApplication::Open()
+{
+  /// Open file dialog
+  
+  TGFileInfo fileInfo;
+  
+  new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
+                   kFDOpen,&fileInfo);
+  
+  Open(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
+}  
+
+//______________________________________________________________________________
+void
+AliMUONMchViewApplication::Open(const char* filename)
+{
+  /// Open a given file containing saved VTrackerData objects
+  
+  TFile f(filename);
+  
+  TList* keys = f.GetListOfKeys();
+  TIter next(keys);
+  
+  TKey* k;
+  
+  while ( ( k = static_cast<TKey*>(next()) ) )
+  {
+    TObject* object = k->ReadObj();
+    
+    if ( object->InheritsFrom("AliMUONVTrackerData") )
+    {
+      AliMUONVTrackerData* data = static_cast<AliMUONVTrackerData*>(object);
+      if ( data ) 
+      {
+        AliMUONPainterRegistry::Instance()->Register(data);
+      }
+    }
+  }
+} 
+
+
+//______________________________________________________________________________
+void
+AliMUONMchViewApplication::Save()
+{
+  /// Open "Save VTrackerData objects to file" dialog
+  
+  TGFileInfo fileInfo;
+  
+  new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
+                   kFDSave,&fileInfo);
+  
+  Save(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
+}  
+
+//______________________________________________________________________________
+void
+AliMUONMchViewApplication::Save(const char* filename)
+{
+  /// Save VTrackerData objects into file of given name
+  
+  AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
+
+  TFile f(filename,"RECREATE");
+  
+  for ( Int_t i = 0; i < reg->NumberOfDataSources(); ++i )
+  {
+    AliMUONVTrackerData* data = reg->DataSource(i);
+    data->Write();
+  }
+  
+  f.Close();
+}  
diff --git a/MUON/AliMUONMchViewApplication.h b/MUON/AliMUONMchViewApplication.h
new file mode 100644 (file)
index 0000000..9fc4f55
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef ALIMUONMCHVIEWAPPLICATION_H
+#define ALIMUONMCHVIEWAPPLICATION_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+* See cxx source for full Copyright notice                               */
+
+// $Id$
+
+/// \ingroup graphics
+/// \class AliMUONMchViewApplication
+/// \brief Main class for the mchview program
+///
+// Author Laurent Aphecetche, Subatech
+
+#ifndef ROOT_TRint
+#   include <TRint.h>
+#endif
+#ifndef ROOT_RQ_OBJECT
+#   include <RQ_OBJECT.h>
+#endif
+
+class TGMainFrame;
+
+class AliMUONMchViewApplication : public TRint
+{
+  RQ_OBJECT("AliMUONMchViewApplication")
+
+public:
+  AliMUONMchViewApplication(const char* name, int* argc, char** argv, 
+                            Float_t wfraction, Float_t hfraction);
+  virtual ~AliMUONMchViewApplication();
+
+  void HandleMenu(Int_t i);
+
+  /// Return the version number of the mchview application
+  static const char* Version() { return "0.8"; }
+  
+private:
+  /// Not implemented
+  AliMUONMchViewApplication(const AliMUONMchViewApplication& rhs);
+  /// Not implemented
+  AliMUONMchViewApplication& operator=(const AliMUONMchViewApplication& rhs);
+  
+  void CreateMenuBar(UInt_t w);
+  void Save();
+  void Save(const char* filename);
+  void Open();
+  void Open(const char* filename);
+  
+private:
+  TGMainFrame* fMainFrame; ///< pointer to our mainframe
+
+  static const Int_t fgkFILESAVEAS; ///< File/Save As... menu
+  static const Int_t fgkFILEOPEN; ///< File/Open... menu
+  static const Int_t fgkFILEEXIT; ///< File/Exit menu
+
+  ClassDef(AliMUONMchViewApplication,1) // mchview application
+};
+
+#endif
index df32bb40fe834511b799ad8ec3db0857eb55fc72..25b322efce4d0fdecfd9167fa70a5fd25cb80954 100644 (file)
@@ -39,5 +39,6 @@
 #pragma link C++ class AliMUONVTrackerDataMaker+;
 #pragma link C++ class AliMUONTrackerData+;
 #pragma link C++ class AliMUONTrackerRawDataMaker+;
+#pragma link C++ class AliMUONMchViewApplication+;
 
 #endif
index 0c6572b19b2506e129ae42d1cf34e10de115283e..4fc021d5e2ac11881f21788773ab18742e45fa43 100644 (file)
@@ -30,6 +30,7 @@ SRCS:=  AliMUONVPainter.cxx \
   AliMUONVTrackerDataMaker.cxx \
   AliMUONTrackerData.cxx \
   AliMUONTrackerRawDataMaker.cxx \
+  AliMUONMchViewApplication.cxx
     
 HDRS:= $(SRCS:.cxx=.h) 
 
index fef433588cf599de129dd806c7c2ba1fab609803..528790d2403c18d1a793d3707c431b0bcf5b87b9 100644 (file)
 /// \author Laurent Aphecetche, Subatech
 
 
-#include "AliMUONPainterDataSourceFrame.h"
+#include "AliMUONMchViewApplication.h"
 #include "AliMUONPainterHelper.h"
-#include "AliMUONPainterMasterFrame.h"
-#include "AliMUONPainterRegistry.h"
 #include "AliCDBManager.h"
 #include "AliCodeTimer.h"
 #include "AliLog.h"
-#include <Riostream.h>
-#include <TCanvas.h>
-#include <TEnv.h>
-#include <TGMenu.h>
-#include <TGTab.h>
 #include <TROOT.h>
-#include <TRint.h>
-#include <TString.h>
 #include <TStyle.h>
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <Riostream.h>
 
-//_____________________________________________________________________________
-void CreateMenuBar(TRint* app, TGMainFrame* mainFrame, UInt_t w)
+//______________________________________________________________________________
+Int_t Usage()
 {
-  /// Create the menu bar of the program
+  /// Printout available options of the program
+  cout << "mchview " << endl;
+  cout << "  --version : shows the current version of the program" << endl;
+  return -1;
+}
 
-  TGPopupMenu* file = new TGPopupMenu(gClient->GetRoot());
+//______________________________________________________________________________
+int main(int argc, char** argv)
+{
+  /// Main function for the program
+  TObjArray args;
   
-  file->AddEntry("&Exit",1);
+  for ( int i = 1; i < argc; ++i ) 
+  {
+    args.Add(new TObjString(argv[i]));
+  }
   
-  file->Connect("Activated(Int_t)","TRint",app,"Terminate()");
-
-  TGMenuBar* bar = new TGMenuBar(mainFrame,w);
+  Int_t nok(0);
   
-  bar->AddPopup("&File",file,new TGLayoutHints(kLHintsLeft|kLHintsTop));
+  for ( Int_t i = 0; i <= args.GetLast(); ++i ) 
+  {
+    TString a(static_cast<TObjString*>(args.At(i))->String());
+    if ( a == "--version" ) 
+    {
+      cout << "mchview Version " << AliMUONMchViewApplication::Version() << " ($Id$)" << endl;
+      ++nok;
+      return 0;
+    }
+  }
   
-  mainFrame->AddFrame(bar,new TGLayoutHints(kLHintsLeft|kLHintsExpandX));
+  if ( nok < args.GetLast() )
+  {
+    return Usage();
+  }
   
-  AliMUONPainterRegistry::Instance()->SetMenuBar(bar);
-}
-
-
-int main(int argc, char** argv)
-{
-  /// Main function for the program
-
   AliWarningGeneral("main","Remove default storage and run number from here...");
   
   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
   AliCDBManager::Instance()->SetRun(0);
-  
-  TRint *theApp = new TRint("mchview", &argc, argv);
-
-  gROOT->SetStyle("Plain");
-  
+  gROOT->SetStyle("Plain");  
   gStyle->SetPalette(1);
-  
   Int_t n = gStyle->GetNumberOfColors();
-  
   Int_t* colors = new Int_t[n+2];
-  
   for ( Int_t i = 1; i <= n; ++i )
   {
     colors[i] = gStyle->GetColorPalette(i-1);
   }
-  
   colors[0] = 0;
   colors[n+1] = 1;
-  
   gStyle->SetPalette(n+2,colors);
-  
   delete[] colors;
   
-  UInt_t dw = gClient->GetDisplayWidth(); 
-  UInt_t dh = gClient->GetDisplayHeight(); 
-  
-  UInt_t w = (UInt_t)(0.7*dw);
-  UInt_t h = (UInt_t)(0.90*dh);
-    
-  TGMainFrame* mainFrame = new TGMainFrame(gClient->GetRoot(),w,h);
-  
-  const Int_t kbs = 2;
-  
-  CreateMenuBar(theApp,mainFrame,w);
-
-//  h -= 60; // menubar
-  
-  TGTab* tabs = new TGTab(mainFrame,w,h);
-  
-  TGCompositeFrame* t = tabs->AddTab("Painter Master Frame");
-
-  AliMUONPainterMasterFrame* pf = 
-    new AliMUONPainterMasterFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
-  
-  t->AddFrame(pf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
-
-  t = tabs->AddTab("Data Sources");
-  
-  AliMUONPainterDataSourceFrame* dsf = 
-    new AliMUONPainterDataSourceFrame(t,t->GetWidth()-kbs*2,t->GetHeight()-kbs*2);
-  
-  t->AddFrame(dsf,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,kbs,kbs,kbs,kbs));
-  
-  mainFrame->AddFrame(tabs,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,0,0,0,0));
-
-  mainFrame->SetWindowName("mchview - Visualization of MUON Tracker detector");
-
-  mainFrame->MapSubwindows();
-  mainFrame->Resize();
-  mainFrame->MapWindow();
-  
-  mainFrame->Connect("CloseWindow()","TRint",theApp,"Terminate()");
-  
-  UInt_t x = dw/2 - w/2;
-  UInt_t y = 0;
-  
-  mainFrame->MoveResize(x, y, w, h); 
-  mainFrame->SetWMPosition(x, y);
-  
-  mainFrame->SetWMSizeHints(w,h,w,h,0,0);
-
+  TRint* theApp = new AliMUONMchViewApplication("mchview", &argc, argv, 0.7, 0.9);
+   
   AliCodeTimer::Instance()->Print();
 
   // --- Start the event loop ---