ROOTANA
TRootanaDisplay.hxx
Go to the documentation of this file.
1 #ifndef TRootanaDisplay_hxx_seen
2 #define TRootanaDisplay_hxx_seen
3 
4 
5 #include "TRootanaEventLoop.hxx"
6 
7 #include "TCanvasHandleBase.hxx"
8 
9 #include <TRootEmbeddedCanvas.h>
10 #include "TMainDisplayWindow.hxx"
11 
12 #include "TCanvasHandleBase.hxx"
14 
15 class TCanvasHandleBase;
16 
17 /// This is an abstract base class for event displays.
18 /// Users need to define a class that derives from this class in order to
19 /// make an event display. The only method that users must implement
20 /// is the method AddAllCanvas(), where the user defines which tabs to use.
21 ///
22 /// The user then needs to define how they what to update and plot histograms.
23 /// The updating of histograms happens for each event.
24 /// In online mode, the plotting of histograms only happens for each XX events;
25 /// for offline mode the plotting happens for each event.
26 ///
27 /// There are two ways that users can decide to update and plot histograms:
28 ///
29 /// 1) They can create histograms in their event display class and then fill
30 /// the methods UpdateHistograms(TDataContainer) and PlotCanvas(TDataContainer).
31 /// This histograms can then file in the canvases that are added using
32 /// AddSingleCanvas(std::string name).
33 ///
34 /// 2) They can create classes that are derived from TCanvasHandleBase. The derived
35 /// classes are then added using the method AddSingleCanvas(TCanvasHandleBase* handleClass).
36 ///
37 /// There is no substantial difference between the two methods. The second method
38 /// is mainly meant to allow the user to separate the methods into separate files
39 /// for code cleaniness.
40 ///
41 /// Examples of both these methods are available in examples/display_example.cxx
42 ///
43 /// The actual ROOT GUI is encapsulated in a separate class TMainDisplayWindow.
44 /// The TRootanaDisplay has an instance of this TMainDisplayWindow class.
45 /// Users will be need to access the TMainDisplayWindow by calling
46 ///
47 /// TRootanaDisplay::GetDisplayWindow()
48 ///
49 /// in order to grab the particular canvas that we want plot on.
50 ///
51 /// There is also the functionality to add sub-tab groups to a
52 /// particular tab, so that you can have a set of tabs of tabs.
53 /// To use this functionality you use the syntax
54 ///
55 /// AddSingleCanvas(..., <tab name string>)
56 ///
57 /// to add a new tab to the top level tab named 'tab name string'.
59 
60 
61 public:
62 
64 
65  virtual ~TRootanaDisplay();
66 
67  /// User must
68  virtual void AddAllCanvases() = 0;
69 
70  /// Add a new canvas; user will interactively fill it.
71  void AddSingleCanvas(std::string name, std::string subtab_name = std::string("")){
72  fMainWindow->AddCanvas(name,subtab_name);
73  }
74 
75  /// Add a new canvas, using a TCanvasHandleBase class.
76  /// TRootanaDisplay will take ownership of pointer
77  /// and delete memory it points to.
78  void AddSingleCanvas(TCanvasHandleBase* handleClass, std::string subtab_name = std::string(""));
79 
80 
81  /// Retrieve the main display window, so that users can
82  /// do things like grab the canvases and update them.
84 
85  /// This method can be implemented by users to update user histograms.
86  virtual void UpdateHistograms(TDataContainer& dataContainer){};
87 
88  /// This method can be implemented by users to plotting of current canvas
89  virtual void PlotCanvas(TDataContainer& dataContainer){};
90 
91  /// This method can be implemented by users to plotting of current canvas
92  virtual void ResetHistograms(){};
93 
94  /// Method for when next button is pushed
96  waitingForNextButton = false;
98  }
99 
100  /// Method for when next interesting button is pushed
102  std::cout << "Looking for next interesting event " << std::endl;
104  waitingForNextButton = true;
105  }
106 
107  /// Method for when skip event button is pushed (online mode)
109  //fNumberSkipEventsOnline = fMainWindow->GetSkipEventButton()->GetNumberEntry()->GetIntNumber();
110 
112  fSecondsBeforeUpdating = (double)fMainWindow->GetSkipEventButton()->GetNumberEntry()->GetIntNumber();
113  }else{
114  fNumberSkipEventsOnline = fMainWindow->GetSkipEventButton()->GetNumberEntry()->GetIntNumber();
115  }
116  }
117 
118  /// This method calls a couple other methods for resets the histograms.
119  /// This method is attached using the ROOT signal/input system to the reset
120  /// button on the canvas.
121  void Reset();
122 
123  /// This is a generic action to call when some button gets pushed.
124  /// Also called in regular event handling loop
125  void UpdatePlotsAction();
126 
127  /// Method to call when 'quit' button is pressed.
128  void QuitButtonAction();
129 
130  /// Function so that user can specify at outset how many events to skip before
131  /// refreshing display (in online mode).
132  void SetNumberSkipEvent(int number){
133  fNumberSkipEventsOnline = number;
134  // check that window has been created; window will not have been created if
135  // this function in called in constructor.
137  fMainWindow->GetSkipEventButton()->GetNumberEntry()->SetIntNumber(number);
138  }
139 
140  /// Function so that user can skip how many seconds to wait in free-running mode
141  void SetSecondsBeforeUpdating(double SecondsBeforeUpdating){
142  fSecondsBeforeUpdating = SecondsBeforeUpdating;
143  }
144 
145  /// Function so user can chose to update display after X seconds, rather than
146  /// X events in online mode. Must be called in constructor of the display program.
147  void SetOnlineUpdatingBasedSeconds(bool updateBasedSeconds = true){
148  fUpdatingBasedSeconds = updateBasedSeconds;
149  }
150 
151  /// Get Display name
152  std::string GetDisplayName(){return fDisplayName;}
153  /// Set Display name
154  void SetDisplayName(std::string name){fDisplayName = name;}
155 
158  }
159 
160  bool CheckOptionRAD(std::string option){
161  if(option.find("-s") != std::string::npos){
162  std::string sub = option.substr(2);
163  fNumberSkipEventsOffline = atoi(sub.c_str());
164  printf("Will process %i events before plotting first event.\n",fNumberSkipEventsOffline);
165  return true;
166  } else if(option == "-S"){
168  return true;
169  }
170 
171  return false;
172  }
173  void UsageRAD(){
174  printf("\t-sYYY: will process YYY events before displaying (for display programs)\n");
175  printf("\t-S: will process all events of a run before displaying (for display programs)\n");
176  }
177 
178 private:
179 
180  /// Method to initialize the Main display window.
181  void InitializeMainWindow();
182 
183  // Variable to keep track of waiting for next event button
185 
186  // Variable to keep track of waiting for next interesting event button
188 
189  /// Variable to keep track of how many events to skip before updating display;
190  /// we have separate variable for online and offline modes.
192 
193  /// Variable to keep track of how many events to skip when running offline;
194  /// defined by command line argument.
196 
197  /// Flag to keep track of whether user wants to update (online) based on time passed
198  /// (rather than based on number of events
200 
202 
203  // Variable to keep track of number of processed events.
205 
206  // Seconds to wait in free-running mode before updating
208 
209  /// Flag to keep track of if quite button has been pushed.
211 
212  /// The pointer to our display window
214 
215  /// Process each midas event
216  bool ProcessMidasEvent(TDataContainer& dataContainer);
217 
218  /// Process each online midas event
219  bool ProcessMidasEventOnline(TDataContainer& dataContainer);
220 
221  /// Process each offline midas event
222  bool ProcessMidasEventOffline(TDataContainer& dataContainer);
223 
224  /// Called before the first event of a file is read, but you should prefer
225  /// Initialize() for general initialization. This method will be called
226  /// once for each input file.
227  void BeginRunRAD(int transition,int run,int time);
228 
229  /// Called after the last event of a file is read, but you should prefer
230  /// Finalize() for general finalization. This method will be called once
231  /// for each input file.
232  void EndRunRAD(int transition,int run,int time);
233 
234 
235  /// We keep a cached copy of the midas event (so that it can used for callback).
237 
238  /// Set the cached copy of midas dataContainer.
239  /// !!! This is very questionable! Caching each dataContainer might add a considerable overhead
240  /// to the processing!
243  fCachedDataContainer = new TDataContainer(dataContainer);
244  }
245 
246  /// Display name
247  std::string fDisplayName;
248 
249  /// This is a vector of user-defined canvas handler classes.
250  /// The first part of pair is the tab number.
251  std::vector< std::pair<std::pair<int,int> ,TCanvasHandleBase*> > fCanvasHandlers;
252 
253 #ifndef NO_CINT
254  ClassDef(TRootanaDisplay,1)
255 #endif
256 };
257 
258 
259 
260 
261 
262 #endif
263 
std::pair< int, int > AddCanvas(std::string subtabname, std::string tabname=std::string(""))
TGNumberEntry * GetSkipEventButton()
void AddSingleCanvas(std::string name, std::string subtab_name=std::string(""))
Add a new canvas; user will interactively fill it.
virtual void ResetHistograms()
This method can be implemented by users to plotting of current canvas.
std::string GetDisplayName()
Get Display name.
void NextButtonPushed()
Method for when next button is pushed.
void SetNumberSkipEvent(int number)
bool fQuitPushed
Flag to keep track of if quite button has been pushed.
TMainDisplayWindow * fMainWindow
The pointer to our display window.
virtual ~TRootanaDisplay()
void QuitButtonAction()
Method to call when 'quit' button is pressed.
void SetDisplayName(std::string name)
Set Display name.
void EndRunRAD(int transition, int run, int time)
void SetOnlineUpdatingBasedSeconds(bool updateBasedSeconds=true)
std::string fDisplayName
Display name.
void SetSecondsBeforeUpdating(double SecondsBeforeUpdating)
Function so that user can skip how many seconds to wait in free-running mode.
virtual void PlotCanvas(TDataContainer &dataContainer)
This method can be implemented by users to plotting of current canvas.
bool CheckOptionRAD(std::string option)
virtual void UpdateHistograms(TDataContainer &dataContainer)
This method can be implemented by users to update user histograms.
void NextInterestingButtonPushed()
Method for when next interesting button is pushed.
bool ProcessMidasEvent(TDataContainer &dataContainer)
Process each midas event.
virtual void AddAllCanvases()=0
User must.
void InitializeRAD()
Special version of Init method, to be used only by TRootanaDisplay.
TMainDisplayWindow * GetDisplayWindow()
void SetCachedDataContainer(TDataContainer &dataContainer)
std::vector< std::pair< std::pair< int, int >,TCanvasHandleBase * > > fCanvasHandlers
void InitializeMainWindow()
Method to initialize the Main display window.
bool ProcessMidasEventOnline(TDataContainer &dataContainer)
Process each online midas event.
bool waitingForNextInterestingButton
bool ProcessMidasEventOffline(TDataContainer &dataContainer)
Process each offline midas event.
void BeginRunRAD(int transition, int run, int time)
void UsageRAD()
Also a special version of usage for TRootanaDisplay. See CheckOptionRAD.
TDataContainer * fCachedDataContainer
We keep a cached copy of the midas event (so that it can used for callback).
void EventSkipButtonPushed()
Method for when skip event button is pushed (online mode)