CMS 3D CMS Logo

TSqueueConsumer< X, C > Class Template Reference

the user class More...

#include <Utilities/Threads/interface/TSqueue.h>

Inheritance diagram for TSqueueConsumer< X, C >:

Thread

List of all members.

Public Types

typedef TSqueueConsumer< X, C > self
typedef TSqueue< X > Xqueue

Public Member Functions

void interactive ()
void push (const X &x)
void reset ()
size_t size () const
 TSqueueConsumer (size_t imax=1000, size_t imin=900)
void wait ()
 ~TSqueueConsumer ()

Protected Attributes

Xqueue inqueue
bool interactive_

Private Member Functions

virtual void abort ()
 called if exception trapped;
void run ()
 body (in its own thread)
virtual void terminate ()
 called if Terminate trapped


Detailed Description

template<class X, class C>
class TSqueueConsumer< X, C >

the user class

Definition at line 131 of file TSqueue.h.


Member Typedef Documentation

template<class X, class C>
typedef TSqueueConsumer<X,C> TSqueueConsumer< X, C >::self

Definition at line 135 of file TSqueue.h.

template<class X, class C>
typedef TSqueue<X> TSqueueConsumer< X, C >::Xqueue

Definition at line 139 of file TSqueue.h.


Constructor & Destructor Documentation

template<class X, class C>
TSqueueConsumer< X, C >::TSqueueConsumer ( size_t  imax = 1000,
size_t  imin = 900 
) [inline, explicit]

Definition at line 234 of file TSqueue.h.

References Thread::initialize().

00234                                                              :
00235     inqueue(imax,imin),  interactive_(false) {
00236     initialize();
00237   }
  

template<class X, class C>
TSqueueConsumer< X, C >::~TSqueueConsumer (  )  [inline]

Definition at line 239 of file TSqueue.h.

References Thread::finalize(), TSqueueConsumer< X, C >::inqueue, and TSqueue< X >::terminate().

00239                      {
00240     inqueue.terminate();
00241     finalize();
00242   }


Member Function Documentation

template<class X, class C>
virtual void TSqueueConsumer< X, C >::abort ( void   )  [inline, private, virtual]

called if exception trapped;

Implements Thread.

Definition at line 226 of file TSqueue.h.

References TSqueue< X >::abort(), GeneralUtilities::cout, lat::endl(), TSqueueConsumer< X, C >::inqueue, ClassName< T >::name(), EnvVerbosity< Tag >::silent(), and thread_self_tid().

Referenced by TSqueueConsumer< X, C >::run().

00226                        { 
00227     if (!GeneralVerbosity::silent())
00228       GeneralUtilities::cout << ">>>>> consumer " << ClassName<C>::name()
00229                     << " thread aborts.." << thread_self_tid() <<  std::endl;
00230     inqueue.abort(); 
00231   }

template<class X, class C>
void TSqueueConsumer< X, C >::interactive (  )  [inline]

Definition at line 246 of file TSqueue.h.

References TSqueueConsumer< X, C >::interactive_.

00246 { interactive_=true;}

template<class X, class C>
void TSqueueConsumer< X, C >::push ( const X &  x  )  [inline]

Definition at line 255 of file TSqueue.h.

References TSqueueConsumer< X, C >::inqueue, and TSqueue< X >::push().

00255 { inqueue.push(x); }

template<class X, class C>
void TSqueueConsumer< X, C >::reset ( void   )  [inline]

Definition at line 244 of file TSqueue.h.

References TSqueueConsumer< X, C >::inqueue, and TSqueue< X >::reset().

00244 {  inqueue.reset();}

template<class X, class C>
void TSqueueConsumer< X, C >::run (  )  [inline, private, virtual]

body (in its own thread)

Implements Thread.

Definition at line 143 of file TSqueue.h.

References TSqueueConsumer< X, C >::abort(), funct::C, ce, className(), GeneralUtilities::cout, Genexception::dump(), lat::endl(), TSqueueConsumer< X, C >::inqueue, TSqueueConsumer< X, C >::interactive_, ClassName< T >::name(), TSqueue< X >::pop(), Thread::self_tid(), EnvVerbosity< Tag >::silent(), TSqueue< X >::size(), thread_self_tid(), and cms::Exception::what().

00143              {
00144       if (!GeneralVerbosity::silent())
00145           GeneralUtilities::cout << ">>>>> consumer " << ClassName<C>::name()
00146                     << " thread starts.." << thread_self_tid() <<  std::endl;
00147     
00148 #ifdef __linux__
00149     // now outside...
00150     //    string mess("Thread "); mess += boost::lexical_cast<string>(thread_self_tid());
00151     //    LinuxElapsedTime totaltime(mess,cout); 
00152 #endif // __linux__
00153     
00154     if (!GeneralVerbosity::silent())
00155       GeneralUtilities::cout << thread_self_tid() << " queue size is "<< inqueue.size() <<  std::endl;
00156     
00157     C consumer;
00158     
00159     try{  // this try logic is here to avoid double throw from consumer destructor...
00160       for(;;) {
00161         try {
00162           consumer(inqueue.pop());
00163         }
00164         catch ( Thread::Terminate ) {
00165           throw;
00166         }
00167         catch ( GenTerminate ) {
00168           if (!interactive_) throw;
00169           abort();
00170         }
00171         catch (...) {
00172           if (!interactive_) throw;
00173           if (!GeneralVerbosity::silent()) {
00174             GeneralUtilities::cout << "thread " 
00175                           << self_tid() << " caught exception " << std::endl;
00176           } 
00177           abort();
00178         } 
00179       }
00180     }
00181     catch ( Thread::Terminate ) {
00182       throw;
00183     }
00184     catch ( GenTerminate ) {
00185       throw;
00186     }
00187     catch ( cms::Exception & cexp) {
00188       if (!GeneralVerbosity::silent()) {
00189         GeneralUtilities::cout << "thread " 
00190                       << self_tid() << " caught  CMS/SEAL exception (" 
00191                       << className(cexp) 
00192                       << ") :" <<  std::endl;
00193         Genexception * ce = dynamic_cast<Genexception *>(&cexp);
00194         if (ce) ce->dump(GeneralUtilities::cout, true);
00195         else  GeneralUtilities::cout << cexp.what() <<  std::endl;
00196         GeneralUtilities::cout << " inform producer...." << std::endl;
00197       }
00198       UncatchedException uce(cexp);
00199       assert(&uce != 0); // Avoids warning message for unused variable uce.
00200       abort();
00201     }
00202     catch (...) {
00203       if (!GeneralVerbosity::silent()) {
00204         GeneralUtilities::cout << "thread " 
00205                       << self_tid() << " caught unknown exception " <<  std::endl;    
00206         GeneralUtilities::cout << " inform producer...." <<  std::endl;
00207       }
00208       UncatchedException uce;
00209       assert(&uce != 0); // Avoids warning message for unused variable uce.
00210       abort();
00211     }
00212     
00213     if (!GeneralVerbosity::silent())
00214       GeneralUtilities::cout << ">>>>> consumer " << ClassName<C>::name()
00215                     << " thread ends.." << thread_self_tid() << std::endl;
00216   }

template<class X, class C>
size_t TSqueueConsumer< X, C >::size ( void   )  const [inline]

Definition at line 257 of file TSqueue.h.

References TSqueueConsumer< X, C >::inqueue, and TSqueue< X >::size().

00257 { return inqueue.size();}

template<class X, class C>
virtual void TSqueueConsumer< X, C >::terminate ( void   )  [inline, private, virtual]

called if Terminate trapped

Implements Thread.

Definition at line 219 of file TSqueue.h.

References GeneralUtilities::cout, lat::endl(), ClassName< T >::name(), EnvVerbosity< Tag >::silent(), and thread_self_tid().

00219                           {
00220     if (!GeneralVerbosity::silent())
00221       GeneralUtilities::cout << ">>>>> consumer " << ClassName<C>::name()
00222                     << " thread terminate.." << thread_self_tid() << std:: endl;
00223   }

template<class X, class C>
void TSqueueConsumer< X, C >::wait ( void   )  [inline]

Definition at line 249 of file TSqueue.h.

References GeneralUtilities::cout, TSqueue< X >::drain(), lat::endl(), TSqueueConsumer< X, C >::inqueue, and EnvVerbosity< Tag >::silent().

00249               { 
00250     if (!GeneralVerbosity::silent())
00251       GeneralUtilities::cout << "wait queue to drain" << std::endl;
00252     inqueue.drain();
00253   }


Member Data Documentation

template<class X, class C>
Xqueue TSqueueConsumer< X, C >::inqueue [protected]

Definition at line 263 of file TSqueue.h.

Referenced by TSqueueConsumer< X, C >::abort(), TSqueueConsumer< X, C >::push(), TSqueueConsumer< X, C >::reset(), TSqueueConsumer< X, C >::run(), TSqueueConsumer< X, C >::size(), TSqueueConsumer< X, C >::wait(), and TSqueueConsumer< X, C >::~TSqueueConsumer().

template<class X, class C>
bool TSqueueConsumer< X, C >::interactive_ [protected]

Definition at line 264 of file TSqueue.h.

Referenced by TSqueueConsumer< X, C >::interactive(), and TSqueueConsumer< X, C >::run().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:34:39 2009 for CMSSW by  doxygen 1.5.4