Re: sleep in root scripts

From: Chris Jones <jonesc_at_hep.phy.cam.ac.uk>
Date: Fri, 7 Jul 2006 14:59:40 +0100

Hi,

Thanks for the suggestion. Unfortunately, it doesn't seem to work for me.

I've attached to this email an update script plus and example root file, so you can if you like run it yourself to see what I mean. simply place both in the same directory and

 root [0] .L moniRichTBRootFile.C+
 root [1] RichTB::runMoni()

what you will see is the while loop runs and each time two canvases are updated (in this test, the histos do not change, but that does not matter here). This does almost what I want, the only problem is that whilst the system is sleeping, I cannot interact with the canvas, which if possible I would like to do.

I tried altering the script to your suggestion - It didn't work, I still could not interact with the canvas. I tried a few variations but still found none that worked.

I would be very grateful if you could take a look and see if there is something which does what I want.

cheers Chris

On Friday 07 July 2006 2:20 pm, Rene Brun wrote:
> 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();
> >
> > }
> >
> >
> > }

-- 
+--------------------------------------------------------------+
| Dr Chris R Jones         work   : +44 (0)1223 337324         |
| HEP Group  (rm 882)      fax    : +44 (0)1223 353920         |
| Cavendish Laboratory,    home   : +44 (0)1223 510711         |
| Madingley Road,          mobile : +44 (0)7723 327477         |
| Cambridge, CB3 0HE       email  : jonesc_at_hep.phy.cam.ac.uk   |
+--------------------------------------------------------------+

Received on Fri Jul 07 2006 - 15:59:49 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET