/*************************************************************************** * Copyright (C) 2004-2006 by Olivier Stezowski & Christian Finck * * stezow(AT)ipnl.in2p3.fr, cfinck(AT)ires.in2p3.fr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ /** \file RMTEmulator.h header file for RMTEmulator.cpp */ #ifndef Gw_RMTEmulator #define Gw_RMTEmulator #include "DEmulator.h" #include "TMath.h" #include "TThread.h" #include "TMutex.h" using namespace ADF; namespace Gw { class RMTActorConnection : public DActorConnection { protected: //! FrameBlock *fBlockLeft, *fBlockRight; protected: //! means the contain of the first block is moved to the second one and then the first block is reset. Bool_t Switch(FrameBlock *, FrameBlock *); public: RMTActorConnection(ALoadedActor *producer, ALoadedActor *consumer, Int_t size) : DActorConnection(producer,consumer,size), fBlockLeft(0x0), fBlockRight(0x0) { fBlockLeft = new OneBlock(size); fBlockRight = new OneBlock(size); } virtual ~RMTActorConnection() { if ( fBlockLeft ) delete fBlockLeft ; if ( fBlockRight ) delete fBlockRight ; } //! test if some data are ready to be sent to the consumer (right part of the connection) virtual Bool_t IsReadyforConsumer() ; //! Prepare the connection so that data can be consumed by the right actor: return false if someting wrong virtual Bool_t SetReadyforConsumer(); //! test if some data can be collected be the producer (left part of the connection) virtual Bool_t IsReadyforProducer() ; //! Prepare the connection so that data can be produced by the left actor : return false if someting wrong virtual Bool_t SetReadyforProducer(); virtual FrameBlock *GetBlock(const Char_t opt) { if ( opt == 'p' ) return fBlockLeft; if ( opt == 'c' ) return fBlockRight; return 0x0; } }; //! Root Multi-threaded Actor's Loader /*! */ class RMTActor : public ALoadedActor { private: TThread *fThread; private: TCondition *fCondition; public: RMTActor(const Char_t *name); virtual ~RMTActor(); void SetCondition(TCondition *cond) { fCondition = cond; } TCondition *GetCondition() const { return fCondition; } TThread *GetThread() const { return fThread; } Short_t IsToBeRun(); virtual void ProcessActor () ; //! /*! */ static void ProcessAsThread (void *); //! //virtual void Process (); }; //! An general emulator, could run or not in multi-threading environement /*! */ class RMTEmulator : public BaseEmulator { private: TMutex *fMutex; TCondition *fCondition; protected: //! link left and right ... depends on the emulator's implementation virtual void LinkActors(ALoadedActor *left, ALoadedActor *middle, ALoadedActor *right); public: RMTEmulator(std::string name = "RMTEmulator"); virtual ~RMTEmulator(); //! to wait for all the actors to finish their job. void Join(); template RMTActor *Add(const Char_t *name_left, const Char_t *name_new_actor, const Char_t *name_right = "-", const Char_t *conf_dir = "./") { return BaseEmulator::AddLoader(name_left,name_new_actor,name_right,conf_dir,T_actor::process_config); } template RMTActor *Add(const Char_t *name_left, const Char_t *name_new_actor, const Char_t *name_right = "-", const Char_t *conf_dir = "./") { return BaseEmulator::AddLoader(name_left,name_new_actor,name_right,conf_dir,T_Configurator::process_config); } //! Init the emulator virtual void Init( const NamedItem &init_sequence = NamedItem("InitSequence","config load init") ); //! Run max loop virtual void Run(Int_t max_loop = -1); virtual void Draw(); }; } // end namespace #endif /// boost /* # include # include # include class BOOSTActorConnection : public DActorConnection { protected: //! FrameBlock *fBlockLeft, *fBlockRight; protected: void Switch(FrameBlock *, FrameBlock *); public: BOOSTActorConnection(ALoadedActor *producer, ALoadedActor *consumer, Int_t size) : DActorConnection(producer,consumer,size), fBlockLeft(0x0), fBlockRight(0x0) { fBlockLeft = new FrameBlock("",size); fBlockRight = new FrameBlock("",size); ; } virtual ~BOOSTActorConnection() { if ( fBlockLeft ) delete fBlockLeft ; if ( fBlockRight ) delete fBlockRight ;} //! test if some data are ready to be sent to the consumer (right part of the connection) virtual Bool_t IsReadyforConsumer() const ; //! Prepare the connection so that data can be consumed by the right actor: return false if someting wrong virtual Bool_t SetReadyforConsumer(); //! test if some data can be collected be the producer (left part of the connection) virtual Bool_t IsReadyforProducer() const; //! Prepare the connection so that data can be produced by the left actor : return false if someting wrong virtual Bool_t SetReadyforProducer(); virtual FrameBlock *GetBlock(const Char_t opt) { if ( opt == 'p' ) return fBlockLeft; if ( opt == 'c' ) return fBlockRight; return 0x0; } }; //! Root Multi-threaded Actor's Loader class BOOSTActor : public ALoadedActor { private: TThread *fThread; private: TCondition *fCondition; public: BOOSTActor(const Char_t *name, NarvalInterface *narval_actor); virtual ~BOOSTActor(); void SetCondition(TCondition *cond) { fCondition = cond; } TCondition *GetCondition() const { return fCondition; } TThread *GetThread() const { return fThread; } virtual void ProcessBlock () ; //! static void *ProcessAsThread (void *); //! //virtual void Process (); }; //! An general emulator, could run or not in multi-threading environement class BOOSTEmulator : public Emulator { private: TMutex *fMutex; TCondition *fCondition; protected: //! link left and right ... depends on the emulator's implementation void LinkActors(ALoadedActor *left, ALoadedActor *right, Int_t); public: BOOSTEmulator(); virtual ~BOOSTEmulator(); //! to wait for all the actors to finish their job. void Join(); template T_actor *Add(const Char_t *name_left, const Char_t *name_new_actor, const Char_t *name_right = "-", const Char_t *conf_path = "./", UInt_t buffer_size_left = 100u, UInt_t buffer_size_right = 100u) { return Emulator::Add(name_left,name_new_actor,name_right,conf_path,buffer_size_left,buffer_size_right); } //! Init the emulator virtual Bool_t Init(); //! Run max loop virtual Bool_t Run(UInt_t max_loop); virtual void Draw(); }; */