TRootanaDisplay.cxx

Go to the documentation of this file.
00001 #include "TRootanaDisplay.hxx"
00002 #include "TPad.h"
00003 #include "TSystem.h"
00004 #include <stdlib.h>
00005 
00006 ClassImp(TRootanaDisplay)
00007 
00008 TRootanaDisplay::TRootanaDisplay() 
00009 {
00010   fNumberSkipEventsOnline = 1; 
00011   fNumberSkipEventsOffline = 0;
00012   fNumberProcessed = 0;
00013   fCachedDataContainer = 0;
00014   SetDisplayName("Rootana Display");
00015 
00016         fQuitPushed = false;
00017 
00018   // Don't create second main window.
00019   DisableAutoMainWindow();
00020 
00021   // Don't create output ROOT files;
00022   // Output ROOT files will kill histograms.
00023   DisableRootOutput(true);
00024 
00025 }
00026 
00027 TRootanaDisplay::~TRootanaDisplay() {
00028 
00029   for(unsigned int i = 0; i < fCanvasHandlers.size(); i++)
00030     delete fCanvasHandlers[i].second;
00031 
00032 };
00033 
00034 void TRootanaDisplay::InitializeMainWindow(){
00035 
00036   fMainWindow = new TMainDisplayWindow(gClient->GetRoot(),1200,800,IsOffline()); 
00037   
00038   // Link the a bunch of buttons in TMainWindowDisplay to functions in TRootanaDisplay.
00039   // This bit of ROOT magic requires that the TRootanaDisplay class get rootcint-ed.
00040   // It also requires that TRootanaDisplay methods be public (protected doesn't work).
00041 
00042   // The reset button
00043   fMainWindow->GetResetButton()->Connect("Clicked()", "TRootanaDisplay", this, "Reset()");
00044 
00045   // The tab buttons
00046   fMainWindow->GetTab()->Connect("Selected(Int_t)", "TRootanaDisplay", this, "UpdatePlotsAction()");
00047 
00048   // The quit button
00049   fMainWindow->GetQuitButton()->Connect("Clicked()", "TRootanaDisplay", this, "QuitButtonAction()");
00050 
00051 
00052   // The next button
00053   if(IsOffline())
00054     fMainWindow->GetNextButton()->Connect("Clicked()", "TRootanaDisplay", this, "NextButtonPushed()");
00055 
00056   // The event skip counter
00057   if(IsOnline()){
00058     TGNumberEntry *skipButton = fMainWindow->GetSkipEventButton();
00059     skipButton->Connect("ValueSet(Long_t)", "TRootanaDisplay",this, "EventSkipButtonPushed()");
00060     skipButton->GetNumberEntry()->Connect("ReturnPressed()", "TRootanaDisplay", this, "EventSkipButtonPushed()");
00061     fNumberSkipEventsOnline = skipButton->GetNumberEntry()->GetIntNumber();    
00062   }
00063 
00064   // Let the user add all the canvases they want.
00065   AddAllCanvases();
00066 
00067   // Now map out window.
00068   GetDisplayWindow()->BuildWindow();
00069 
00070 
00071 }
00072  
00073 
00074 void TRootanaDisplay::AddSingleCanvas(TCanvasHandleBase* handleClass, std::string subtab_name){
00075   
00076   std::pair<int,int> index = GetDisplayWindow()->AddCanvas(handleClass->GetTabName(),subtab_name);
00077 
00078   std::pair< std::pair<int,int>, TCanvasHandleBase*> tmp(index,handleClass);
00079   
00080   fCanvasHandlers.push_back(tmp);
00081   // Now set up the embedded canvas, if user so desires.
00082   TGCompositeFrame* embed = GetDisplayWindow()->GetCompositeFrame(index);//ssGetTab()->GetTabContainer(tab_index);
00083   handleClass->SetUpCompositeFrame(embed,this);
00084 
00085   // If we just created a new sub-tab, grab the tab and add
00086   // call-back to UpdatePlot
00087   if(index.second == 0){
00088     TGTab* tab = GetDisplayWindow()->GetSubTab(index.first);
00089     tab->Connect("Selected(Int_t)", "TRootanaDisplay", this, "UpdatePlotsAction()");
00090   }
00091 
00092 
00093 }
00094 
00095 
00096 bool TRootanaDisplay::ProcessMidasEvent(TDataContainer& dataContainer){
00097 
00098   fMainWindow->ResetSize();
00099   fNumberProcessed++;
00100 
00101   // Only update histograms if we are "offline" or "online and but paused".
00102   // This ensures that we don't update if the user pressed 'pause' since the 
00103   // last event.
00104   if(!IsOnline() || (IsOnline() && !fMainWindow->IsDisplayPaused())){
00105     SetCachedDataContainer(dataContainer);
00106     
00107     // Perform any histogram updating from user code.
00108     UpdateHistograms(*fCachedDataContainer);
00109     for(unsigned int i = 0; i < fCanvasHandlers.size(); i++)
00110       fCanvasHandlers[i].second->UpdateCanvasHistograms(*fCachedDataContainer);
00111   }  
00112 
00113   // If processing online and if processing is not paused, then just plot and return
00114   if(IsOnline() && !fMainWindow->IsDisplayPaused() ){
00115        
00116     // Do canvas plotting from user code; 
00117     // only do plot if we have processed enough events
00118     if(fNumberSkipEventsOnline == 1 || fNumberProcessed % fNumberSkipEventsOnline  == 1){      
00119       UpdatePlotsAction();
00120     }
00121     
00122     return true;
00123   }
00124 
00125   // If processing offline, make sure we have skipped the right number of events.
00126   if(!IsOnline() && fNumberSkipEventsOffline >= fNumberProcessed){
00127     return true;
00128   }
00129 
00130   UpdatePlotsAction();
00131 
00132   // If offline, then keep looping till the next event button is pushed.
00133   // If online, then keep looping till the resume button is pushed.
00134   waitingForNextButton = true;
00135   while(1){
00136     
00137     // Add some sleeps; otherwise program takes 100% of CPU...
00138     usleep(1000);
00139 
00140     // ROOT signal/slot trick; this variable will magically 
00141     // get changed to false once the next button is pushed.
00142     if(!waitingForNextButton) break;
00143 
00144     // Alternately, break out if in online mode and 
00145     // no longer in paused state.  Again, the state of variable
00146     // will be changed by ROOT signal/slot callback.
00147     if(IsOnline() && !fMainWindow->IsDisplayPaused()) break;    
00148       
00149                 // Check if quit button has been pushed.  See QuitButtonAction() for details
00150                 if(IsOnline() && fQuitPushed) break;
00151 
00152     // Resize windows, if needed.
00153     fMainWindow->ResetSize();
00154 
00155     // handle GUI events
00156     bool result = gSystem->ProcessEvents(); 
00157     
00158   }
00159   return true;
00160 
00161 }
00162 
00163 void TRootanaDisplay::BeginRun(int transition,int run,int time){
00164   
00165   std::cout << "Begin of run " << run << " at time " << time << std::endl;
00166   for(unsigned int i = 0; i < fCanvasHandlers.size(); i++)    
00167     fCanvasHandlers[i].second->BeginRun(transition,run,time);
00168   UpdatePlotsAction();
00169 }
00170 
00171 void TRootanaDisplay::EndRun(int transition,int run,int time){
00172 
00173   std::cout << "End of run " << run << " at time " << time << std::endl;
00174   for(unsigned int i = 0; i < fCanvasHandlers.size(); i++)
00175     fCanvasHandlers[i].second->EndRun(transition,run,time);
00176   UpdatePlotsAction();
00177 
00178 }
00179 
00180 
00181 
00182 void TRootanaDisplay::UpdatePlotsAction(){
00183 
00184   if(!fCachedDataContainer){
00185     char displayTitle[200];
00186     sprintf(displayTitle,"%s (): run %i (no events yet)",
00187             GetDisplayName().c_str(),GetCurrentRunNumber());
00188     GetDisplayWindow()->GetMain()->SetWindowName(displayTitle);
00189     return;
00190   }
00191     
00192   // Execute the plotting actions from user event loop.
00193   PlotCanvas(*fCachedDataContainer);
00194   
00195   // See if we find a user class that describes this tab.
00196   std::pair<int,int> tabdex = GetDisplayWindow()->GetCurrentTabIndex();
00197   for(unsigned int i = 0; i < fCanvasHandlers.size(); i++){
00198     if(tabdex == fCanvasHandlers[i].first){
00199       TRootEmbeddedCanvas* embed = GetDisplayWindow()->GetCurrentEmbeddedCanvas();
00200       fCanvasHandlers[i].second->PlotCanvas(*fCachedDataContainer,embed);
00201     }
00202   }
00203     
00204   
00205   // Set the display title
00206   char displayTitle[200];
00207   if(IsOnline())
00208     sprintf(displayTitle,"%s (online): run %i event %i",
00209             GetDisplayName().c_str(),GetCurrentRunNumber(),
00210             fCachedDataContainer->GetMidasData().GetSerialNumber());
00211   else
00212     sprintf(displayTitle,"%s (offline): run %i event %i",
00213             GetDisplayName().c_str(),GetCurrentRunNumber(),
00214             fCachedDataContainer->GetMidasData().GetSerialNumber());
00215     
00216   GetDisplayWindow()->GetMain()->SetWindowName(displayTitle);
00217 
00218 
00219   // Update canvas and window sizes    
00220   fMainWindow->ResetSize();
00221   
00222 }
00223 
00224 void TRootanaDisplay::Reset(){
00225   // Call the reset functions defined in user event loop.
00226   ResetHistograms();
00227   // Call the user defined canvas classes.
00228   for(unsigned int i = 0; i < fCanvasHandlers.size(); i++)
00229       fCanvasHandlers[i].second->ResetCanvasHistograms();
00230   UpdatePlotsAction();
00231 }
00232 
00233 
00234 void TRootanaDisplay::QuitButtonAction()
00235 {
00236   // If we are offline, then we close the ROOT file here.
00237   // If we are online then the control will return to TRootanaEventLoop::ProcessMidasOnline
00238   // which will take care of closing the file.
00239 
00240   if(!IsOnline()){
00241     EndRun(0,GetCurrentRunNumber(),0);
00242     CloseRootFile();  
00243   }
00244 
00245         // Set a flag so that we can breakout of loop if 
00246         // we are ONLINE and PAUSED.
00247         // It is odd that gApplication->Terminate(0) doesn't 
00248         // finish, but somehow it seems to wait for the the 
00249         // RootanaDisplay::ProcessMidasEvent() to finish.
00250         fQuitPushed = true;
00251   gApplication->Terminate(0);   
00252 }

Generated on 5 May 2014 for ROOT Analyzer by  doxygen 1.6.1