TRootanaDisplay.hxx

Go to the documentation of this file.
00001 #ifndef TRootanaDisplay_hxx_seen
00002 #define TRootanaDisplay_hxx_seen
00003 
00004 
00005 #include "TRootanaEventLoop.hxx"
00006 
00007 #include "TCanvasHandleBase.hxx"
00008 
00009 #include <TRootEmbeddedCanvas.h>
00010 #include "TMainDisplayWindow.hxx"
00011 
00012 #include "TCanvasHandleBase.hxx"
00013 
00014 class TCanvasHandleBase;
00015 
00016 /// This is an abstract base class for event displays.  
00017 /// Users need to define a class that derives from this class in order to 
00018 /// make an event display.  The only method that users must implement
00019 /// is the method AddAllCanvas(), where the user defines which tabs to use.
00020 /// 
00021 /// The user then needs to define how they what to update and plot histograms.
00022 /// The updating of histograms happens for each event.
00023 /// In online mode, the plotting of histograms only happens for each XX events;
00024 /// for offline mode the plotting happens for each event.
00025 ///
00026 /// There are two ways that users can decide to update and plot histograms:
00027 ///
00028 /// 1) They can create histograms in their event display class and then fill 
00029 ///    the methods UpdateHistograms(TDataContainer) and PlotCanvas(TDataContainer).
00030 ///    This histograms can then file in the canvases that are added using 
00031 ///    AddSingleCanvas(std::string name).
00032 ///
00033 /// 2) They can create classes that are derived from TCanvasHandleBase.  The derived
00034 ///    classes are then added using the method AddSingleCanvas(TCanvasHandleBase* handleClass).
00035 ///    
00036 /// There is no substantial difference between the two methods.  The second method
00037 /// is mainly meant to allow the user to separate the methods into separate files
00038 /// for code cleaniness.
00039 ///
00040 /// Examples of both these methods are available in examples/display_example.cxx
00041 ///
00042 /// The actual ROOT GUI is encapsulated in a separate class TMainDisplayWindow.
00043 /// The TRootanaDisplay has an instance of this TMainDisplayWindow class.
00044 /// Users will be need to access the TMainDisplayWindow by calling
00045 ///
00046 /// TRootanaDisplay::GetDisplayWindow()
00047 /// 
00048 /// in order to grab the particular canvas that we want plot on.
00049 ///
00050 /// There is also the functionality to add sub-tab groups to a 
00051 /// particular tab, so that you can have a set of tabs of tabs.
00052 /// To use this functionality you use the syntax
00053 ///
00054 /// AddSingleCanvas(..., <tab name string>) 
00055 /// 
00056 /// to add a new tab to the top level tab named 'tab name string'.
00057 class TRootanaDisplay: public TRootanaEventLoop {
00058 
00059 
00060 public:
00061 
00062   TRootanaDisplay();
00063 
00064   virtual ~TRootanaDisplay();
00065 
00066   /// User must 
00067   virtual void AddAllCanvases() = 0;
00068 
00069   /// Add a new canvas; user will interactively fill it.
00070   void AddSingleCanvas(std::string name, std::string subtab_name = std::string("")){
00071     fMainWindow->AddCanvas(name,subtab_name);
00072   }
00073 
00074   /// Add a new canvas, using a TCanvasHandleBase class.
00075   /// TRootanaDisplay will take ownership of pointer
00076   /// and delete memory it points to.
00077   void AddSingleCanvas(TCanvasHandleBase* handleClass, std::string subtab_name = std::string(""));
00078 
00079 
00080   /// Retrieve the main display window, so that users can 
00081   /// do things like grab the canvases and update them.
00082   TMainDisplayWindow* GetDisplayWindow(){ return fMainWindow;}
00083 
00084   /// This method can be implemented by users to update user histograms.
00085   virtual void UpdateHistograms(TDataContainer& dataContainer){};
00086   
00087   /// This method can be implemented by users to plotting of current canvas
00088   virtual void PlotCanvas(TDataContainer& dataContainer){};
00089 
00090   /// This method can be implemented by users to plotting of current canvas
00091   virtual void ResetHistograms(){};
00092 
00093   /// Method for when next button is pushed (offline mode)
00094   void NextButtonPushed(){
00095     waitingForNextButton = false;
00096   }
00097   /// Method for when skip event button is pushed (online mode)
00098   void EventSkipButtonPushed(){
00099     fNumberSkipEventsOnline = fMainWindow->GetSkipEventButton()->GetNumberEntry()->GetIntNumber();
00100   }
00101 
00102   /// This method calls a couple other methods for resets the histograms.
00103   /// This method is attached using the ROOT signal/input system to the reset
00104   /// button on the canvas.
00105   void Reset();
00106 
00107   /// This is a generic action to call when some button gets pushed.
00108   /// Also called in regular event handling loop
00109   void UpdatePlotsAction();
00110 
00111   /// Method to call when 'quit' button is pressed.
00112   void QuitButtonAction();
00113   
00114   /// Function so that user can specify at outset how many events to skip before
00115   /// refreshing display (in online mode).
00116   void SetNumberSkipEvent(int number){
00117     fNumberSkipEventsOnline = number;
00118     if(fMainWindow->GetSkipEventButton())
00119       fMainWindow->GetSkipEventButton()->GetNumberEntry()->SetIntNumber(number);
00120   }
00121 
00122   /// Get Display name
00123   std::string GetDisplayName(){return fDisplayName;}
00124   /// Set Display name
00125   void SetDisplayName(std::string name){fDisplayName = name;}
00126   
00127   void Initialize(){
00128     InitializeMainWindow();
00129   }
00130 
00131   bool CheckOptionRAD(std::string option){
00132     if(option.find("-s") != std::string::npos){
00133       std::string sub = option.substr(2);
00134       fNumberSkipEventsOffline = atoi(sub.c_str());
00135       printf("Will process %i events before plotting first event.\n",fNumberSkipEventsOffline);
00136       return true;
00137     }
00138     return false;
00139   }
00140   void UsageRAD(){
00141     printf("\t-s: will process specified number of events before displaying (for display programs)\n");
00142   }
00143 
00144 private:
00145 
00146   /// Method to initialize the Main display window.
00147   void InitializeMainWindow();
00148 
00149   // Variable to keep track of waiting for next event button (offline mode)
00150   bool waitingForNextButton; 
00151 
00152   /// Variable to keep track of how many events to skip before updating display;
00153   /// we have separate variable for online and offline modes.
00154   int fNumberSkipEventsOnline;
00155 
00156   /// Variable to keep track of how many events to skip when running offline;
00157   /// defined by command line argument.
00158   int fNumberSkipEventsOffline;
00159 
00160   // Variable to keep track of number of processed events.
00161   int fNumberProcessed;
00162 
00163         /// Flag to keep track of if quite button has been pushed.
00164         bool fQuitPushed;
00165 
00166   /// The pointer to our display window
00167   TMainDisplayWindow* fMainWindow;
00168 
00169   /// Process each midas event
00170   bool ProcessMidasEvent(TDataContainer& dataContainer);
00171 
00172   /// Called before the first event of a file is read, but you should prefer
00173   /// Initialize() for general initialization.  This method will be called
00174   /// once for each input file.  
00175   void BeginRun(int transition,int run,int time);
00176   
00177   /// Called after the last event of a file is read, but you should prefer
00178   /// Finalize() for general finalization.  This method will be called once
00179   /// for each input file.
00180   void EndRun(int transition,int run,int time);
00181   
00182 
00183   /// We keep a cached copy of the midas event (so that it can used for callback).
00184   TDataContainer* fCachedDataContainer;
00185 
00186   /// Set the cached copy of midas dataContainer.
00187   /// !!! This is very questionable!  Caching each dataContainer might add a considerable overhead
00188   /// to the processing!
00189   void SetCachedDataContainer(TDataContainer& dataContainer){
00190     if(fCachedDataContainer) delete fCachedDataContainer;
00191     fCachedDataContainer = new TDataContainer(dataContainer);
00192   }
00193 
00194   /// Display name
00195   std::string fDisplayName;
00196 
00197   /// This is a vector of user-defined canvas handler classes.
00198   /// The first part of pair is the tab number.
00199   std::vector< std::pair<std::pair<int,int> ,TCanvasHandleBase*> > fCanvasHandlers;
00200 
00201   ClassDef(TRootanaDisplay,1)
00202 }; 
00203 
00204 
00205 
00206 
00207 
00208 #endif
00209 

Generated on 12 Feb 2016 for ROOT Analyzer by  doxygen 1.6.1