CFEL - ASG Software Suite  2.5.0
CASS
input_base.h
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file input_base.h contains the base class for all input modules
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _INPUTBASE_H_
10 #define _INPUTBASE_H_
11 
12 #include <string>
13 #include <tr1/memory>
14 
15 #include "pausablethread.h"
16 
17 #include "cass.h"
18 #include "cass_event.h"
19 #include "ringbuffer.hpp"
20 
21 namespace cass
22 {
23 class Ratemeter;
24 
25 /** Input base class
26  *
27  * This class acts as base class for all input modules.
28  *
29  * @author Lutz Foucar
30  */
32 {
33 public:
34  /** shared pointer of this type */
35  typedef std::tr1::shared_ptr<InputBase> shared_pointer;
36 
37  /** destructor */
38  virtual ~InputBase(){}
39 
40  /** function with the main loop
41  *
42  * the implementation of this function needs to start by setting the _status
43  * variable of the PausableThread to running.like follows:
44  * _status = lmf::PausableThread::running;
45  */
46  virtual void runthis()=0;
47 
48  /** load the settings of the input module from ini file
49  *
50  * @note before calling this the caller has to make sure that the input has
51  * paused. And resume it afterwards.
52  */
53  virtual void load()=0;
54 
55  /** retrieve the fraction of how much of the input has been processed
56  *
57  * needs to be implemented by the individual inputs, defaults to 0 in case
58  * it has not been implemented
59  */
60  virtual double progress();
61 
62  /** retrieve the number of events that have been input so far
63  *
64  * needs to be implemented by the individual imputs, defaults to 0 otherwise
65  */
66  virtual uint64_t eventcounter();
67 
68  /** retrieve the number of skipped events that have been input so far
69  *
70  * needs to be implemented by the individual imputs, defaults to 0 otherwise
71  */
72  virtual uint64_t skippedeventcounter();
73 
74  /** increment the numer of events received in the ratemeter
75  *
76  * To indicate that we are done processing an event this signal is emitted.
77  * This is used for by the ratemeter to evaluate how fast we get events.
78  *
79  * @param eventsize size of the event in bytes
80  */
81  void newEventAdded(const size_t eventsize);
82 
83  /** retrieve a reference to the the ringbuffer
84  *
85  * @return reference to the ringbuffer
86  */
88 
89  /** get the signelton instance
90  *
91  * throws logic error when instance does not exist yet
92  *
93  * @return the singleton instance
94  */
95  static shared_pointer instance();
96 
97  /** get reference to the singelton instance
98  *
99  * throws logic error when instance does not exist yet
100  *
101  * @return reference to the singleton
102  */
103  static shared_pointer::element_type& reference();
104 
105  /** a mutex so that external program can lock access to this */
107 
108  /** define an item in the ringbuffer */
110 
111  /** retrieve an iterator to the next fillable event
112  *
113  * try to get an event to be filled from the buffer. Do this until either an
114  * event could be retrieved or the thread has been told to quit.
115  *
116  * @return iterator to the next fillable event, when the end of the ringbuffer
117  * has been returned, the thread should quit
118  */
119  rbItem_t getNextFillable(unsigned timeout=500);
120 
121 protected:
122  /** protected constructor since it should be a singelton
123  *
124  * @param ringbuffer reference to the ringbuffer containing the CASSEvents
125  * @param ratemeter reference to the ratemeter to measure the rate of the input
126  * @param loadmeter reference to the ratemeter to measure the load of the input
127  * @param parent The parent QT Object of this class
128  */
130  Ratemeter & ratemeter,
131  Ratemeter & loadmeter,
132  QObject *parent=0)
134  _ringbuffer(ringbuffer),
135  _ratemeter(ratemeter),
136  _loadmeter(loadmeter)
137  {}
138 
139  /** reference to the ringbuffer */
141 
142  /** ratemeter to measure the rate */
144 
145  /** meter to measure the data load */
147 
148  /** singelton instance */
149  static shared_pointer _instance;
150 
151 private:
152  /** a mutex to lock operations */
153  static QMutex _mutex;
154 };
155 
156 }//end namespace cass
157 
158 #endif
RingBuffer< CASSEvent >::iter_type rbItem_t
define an item in the ringbuffer
Definition: input_base.h:109
declaration of a pausable QThread
class calculating a rate in Hz.
Definition: ratemeter.h:28
virtual uint64_t eventcounter()
retrieve the number of events that have been input so far
Definition: input_base.cpp:62
file contains declaration of the CASSEvent
Input base class.
Definition: input_base.h:31
virtual void load()=0
load the settings of the input module from ini file
PausableThread(control_t control=_run, QObject *parent=0)
constructor
virtual double progress()
retrieve the fraction of how much of the input has been processed
Definition: input_base.cpp:57
virtual uint64_t skippedeventcounter()
retrieve the number of skipped events that have been input so far
Definition: input_base.cpp:67
InputBase(RingBuffer< CASSEvent > &ringbuffer, Ratemeter &ratemeter, Ratemeter &loadmeter, QObject *parent=0)
protected constructor since it should be a singelton
Definition: input_base.h:129
RingBuffer< CASSEvent > & ringbuffer()
retrieve a reference to the the ringbuffer
Definition: input_base.cpp:43
A Ringbuffer, handles communication between Input and Worker Threads.
Definition: ringbuffer.hpp:52
static shared_pointer _instance
singelton instance
Definition: input_base.h:149
Ratemeter & _ratemeter
ratemeter to measure the rate
Definition: input_base.h:143
buffer_t::iterator iter_type
type of the interator over the elements of the container
Definition: ringbuffer.hpp:93
file contains the ringbuffer class
Ratemeter & _loadmeter
meter to measure the data load
Definition: input_base.h:146
file contains global definitions for project cass
static QMutex _mutex
a mutex to lock operations
Definition: input_base.h:153
static shared_pointer instance()
get the signelton instance
Definition: input_base.cpp:20
RingBuffer< CASSEvent > & _ringbuffer
reference to the ringbuffer
Definition: input_base.h:140
std::tr1::shared_ptr< InputBase > shared_pointer
shared pointer of this type
Definition: input_base.h:35
QMutex lock
a mutex so that external program can lock access to this
Definition: input_base.h:106
rbItem_t getNextFillable(unsigned timeout=500)
retrieve an iterator to the next fillable event
Definition: input_base.cpp:48
static shared_pointer::element_type & reference()
get reference to the singelton instance
Definition: input_base.cpp:28
virtual ~InputBase()
destructor
Definition: input_base.h:38
void newEventAdded(const size_t eventsize)
increment the numer of events received in the ratemeter
Definition: input_base.cpp:37
virtual void runthis()=0
function with the main loop
A QThread that has the ability to be paused and resumed.