Hi Chris,
You can use a Timer. eg at teh start of your program do:
TTimer timer(500);
timer.SetCommand("gSystem->ProcessEvents();");
and remove your current gSystem->ProcessEvents()
Rene Brun
Chris Jones wrote:
> Hi,
>
> Apologies if this is an FAQ, but I've been unable so far to find an answer in 
> the user guides etc.
>
> I have a root script (attached) which is designed to monitor a root file and 
> continuously update the histgrams in it on root canvases. To do this I have a 
> while loop with a sleep statement
>
>    gSystem->Sleep ( sleepTime );
>
> which pauses for a fixed time (60 secs or whatever). 
>
> The problem is during this sleep time, ROOT is unresponsive. I cannot 
> interactive with the canvases. I would like to be able to do this, to 
> printout figures, quite ROOT etc. Not, outside the sleep, which the rest of 
> the scrtipt is running, I can interactive with ROOT.
>
> Is there a way I can do this, to get the root script to allow interaction 
> whilst the sleep is running ?
>
> cheers Chris 
>   
> ------------------------------------------------------------------------
>
>
> #include <iostream>
> #include <string.h>
> #include <map>
> #include <vector>
>
> #include "TROOT.h"
> #include "TKey.h"
> #include "TFile.h"
> #include "TCanvas.h"
> #include "TH1D.h"
> #include "TH2D.h"
> #include "TSystem.h"
>
> using std::cout;
> using std::cerr;
> using std::endl;
>
> namespace RichTB
> {
>
>   // sleep time in ms
>   const int sleepTime = 5000 ;
>
>   typedef std::map<std::string,TCanvas*> CanvasMap;
>   static CanvasMap canvasMap;
>
>   void plotObject( TObject * obj )
>   {
>     // get canvas for this object
>     TCanvas * canvas = canvasMap[ obj->GetName() ];
>     if ( NULL == canvas )
>     {
>       canvasMap[ obj->GetName() ] = canvas = new TCanvas(obj->GetTitle(),obj->GetName());
>     }
>     canvas->cd();
>     TH1 * th1Obj = (TH1*)obj;
>     th1Obj->Draw("zcol");
>     canvas->Modified();
>     canvas->Update();
>     gSystem->ProcessEvents();
>  
>   }
>
>   void dirScan(TDirectory* dir1)
>   {
>
>     dir1->cd(); // change searching directory
>     TList * olist = dir1->GetListOfKeys();
>     for ( int oidx = 0; oidx<olist->GetSize(); ++oidx )
>     {
>       // get objects in this directory
>       TKey* key = (TKey*)olist->At(oidx);
>
>       // read object from key
>       TObject* obj = key->ReadObj();
>       cout << "Found " << obj->ClassName() << " object, id = " << obj->GetName() << endl;
>
>       // Plot this object on its own canvas
>       plotObject( obj );
>
>     }
>
>
>   }
>
>   void runMoni( const std::string moniFile )
>   {
>  
>     bool OK ( true );
>     int maxRuns(100), nRuns(0);
>     while ( OK && nRuns < maxRuns )
>     {
>       ++nRuns;
>
>       // try to open input file
>       TFile * fin = new TFile( moniFile.c_str() );
>       if ( fin->IsOpen() )
>       {
>         cout << "Processing input file : " << fin->GetName() << endl;
>         dirScan(gDirectory);
>       }
>       else
>       {
>         cout << "WARNING : input file " << fin->GetName() << " does not exist yet" << endl;
>       }
>       delete fin;
>
>       //break;
>       cout << "Sleeping for " << sleepTime << " ms" << endl;
>       // sleep ( sleepTime );
>       gSystem->Sleep ( sleepTime );
>
>     }
>
>     // delete canvas
>     for ( CanvasMap::iterator i = canvasMap.begin(); i != canvasMap.end(); ++i )
>     {
>       delete (*i).second;
>     }
>     canvasMap.clear();
>
>   }
>
>
> }
>   
Received on Fri Jul 07 2006 - 15:20:33 MEST
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET