Stefano Argiro` wrote: > Return-Path: <owner-roottalk@pcroot.cern.ch> > Received: from sirius-b.ihep.su by altair.ihep.su (MX V4.2 AXP) with SMTP; Tue, > 13 Mar 2001 12:40:56 GMT+03:00 > Received: from pcroot.cern.ch (pcroot.cern.ch [137.138.213.102]) by > sirius-b.ihep.su (8.10.0/8.10.0) with ESMTP id f2D9eOA28914; Tue, 13 > Mar 2001 12:40:25 +0300 (MSK) > X-Sender: owner-roottalk@pcroot.cern.ch > Received: (from majordomo@localhost) by pcroot.cern.ch (8.8.7/8.8.7) id > JAA30054 for roottalk-outgoing; Tue, 13 Mar 2001 09:47:52 +0100 > X-Authentication-Warning: pcroot.cern.ch: majordomo set sender to > owner-roottalk@root.cern.ch using -f > Received: from newmint.cern.ch (newmint.cern.ch [137.138.26.94]) by > pcroot.cern.ch (8.8.7/8.8.7) with ESMTP id JAA30051 for > <roottalk@pcroot.cern.ch>; Tue, 13 Mar 2001 09:47:51 +0100 > Received: from carmen.to.infn.it (carmen.to.infn.it [192.84.137.1]) by > newmint.cern.ch (8.9.3/8.9.3) with ESMTP id JAA10232 for > <roottalk@pcroot.cern.ch>; Tue, 13 Mar 2001 09:47:51 +0100 (MET) > Received: from to01xd.to.infn.it (to01xd.to.infn.it [192.84.137.11]) by > carmen.to.infn.it (8.9.3/8.9.3) with ESMTP id JAA24815 for > <roottalk@pcroot.cern.ch>; Tue, 13 Mar 2001 09:47:50 +0100 (MET) > Received: from localhost (argiro@localhost) by to01xd.to.infn.it (8.8.8/8.8.8) > with ESMTP id JAA12842 for <roottalk@root.cern.ch>; Tue, 13 Mar 2001 > 09:47:50 +0100 (MET) > Date: Tue, 13 Mar 2001 09:47:50 +0100 (MET) > From: Stefano Argiro` <argiro@to.infn.it> > To: roottalk@pcroot.cern.ch > Subject: [ROOT] questions on TApplication's and TTimer's > Message-ID: <Pine.OSF.4.10.10103130921120.5325-100000@to01xd.to.infn.it> > MIME-Version: 1.0 > Content-Type: TEXT/PLAIN; charset=US-ASCII > Sender: owner-roottalk@pcroot.cern.ch > Precedence: bulk > > Hi, > > I would like to use a TTimer in a DAQ that has to read data every > 20 seconds. For this purpose I have implemented a class called, > say, Readout:public TObject{} with methods, Start() , Stop(), > ForceReadout() and overriding HandleTimer(). > > Class Readout has a TApplication as a data member, and upon Start() > TApplication::Run() is called. > Soon I realized that, after calling Start(), the event loop is started, > and I cannot communicate anymore with the class: I cannot tell it to > Stop() not to ForceReadout(). > > Is there a solution to this ? Will the signal/slot mechanism do it > (right now we are still using v2.25) ? > > Thanks > > I enclose an outline of the code. > > //////////////////////////////////////////// > class Readout:public TObject{ > private: > TApplication ftheApplication; > Int_t fEvents; // number of events > ... > > public: > Readout(); > void ForceReadout() > Bool_t HandleTimer(TTimer *timer); > void Start(); > void Stop(); > Int_t GetEvents() {return fEvents;}; > > }; > > Readout::Readout(){ > > ftheApplication = new TApplication("",&arc,argv,NULL,0); > ... > } > > void Readout::ForceReadout(){ > > // do the readout ... > > } > > void Readout::HandleTimer(TTimer *timer){ > // do the readout , save etc.... > } > > void Readout::Start(){ > TTimer * timer = new TTimer(this,20000); > timer->TurnOn(); > ftheApplication->Run(); > > return 0; > } > > Int_t CurrentMonitorRO::Stop(){ > > ftheApplication->Terminate(); > return 0; > } > ////////////////////////////////////////////////////////////////// > > int main(){ > > TROOT CMReadout("CMreadout","CM readout application"); > > Readout * readout = new CurrentMonitorRO(); > > readout->Start(); > > // of course it never gets here !! > if (readout->GetEvents() == 5) cout << "Done"<<endl; > return 0; > > } Hi Stefano, I modified your code which allows to work it with signal/slots - cut the text below and save it as Readout.C - compile it: $root -b -q >/dev/null tmp.C | echo '{gSystem->CompileMacro("Readout.C","kf");}' >tmp.C $g++ -o readout Readout.C `root-config --cflags --libs` -DSTANDALONE - run it $./readout Note: it's quick&dirty .. few mem.leaks exist (fix it by yourself). hth. Regards. Valeriy ---------------------------- Readout.C --------------------------------- #include <TApplication.h> #include <iostream> #include <TTimer.h> class Readout { private: TApplication* ftheApplication; Int_t fEvents; // number of events public: Readout(); void ForceReadout(); void HandleTimer(); void Start(); void Stop(); Int_t GetEvents() {return fEvents;}; }; Readout::Readout() { ftheApplication = new TApplication("",0,0); fEvents = 0; } void Readout::ForceReadout() { // do the readout ... } void Readout::HandleTimer() { // do the readout , save etc.... fEvents++; cout << "do the readout , save etc...." << fEvents << endl; ForceReadout(); if(fEvents>50) Stop(); } void Readout::Start() { TTimer * timer = new TTimer(200); timer->Connect("Timeout()","Readout",this,"HandleTimer()"); timer->TurnOn(); ftheApplication->Run(); return; } void Readout::Stop() { ftheApplication->Terminate(); return; } ////////////////////////////////////////////////////////////////// #ifdef STANDALONE #include <TROOT.h> #include <TSystem.h> int main(){ TROOT CMReadout("CMreadout","CM readout application"); gSystem->Load("./Readout_C"); Readout * readout = new Readout(); readout->Start(); return 0; } #endif //STANDALONE ---------------------------- Readout.C ---------------------------------
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:39 MET