CFEL - ASG Software Suite  2.5.0
CASS
processor.h
Go to the documentation of this file.
1 // Copyright (C) 2010 Lutz Foucar
2 // Copyright (C) 2010 Jochen Küpper
3 
4 /** @file processor.h file contains processors baseclass declaration
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _PROCESSOR_H_
10 #define _PROCESSOR_H_
11 
12 #include <QtCore/QReadWriteLock>
13 
14 #include <list>
15 #include <string>
16 #include <stdint.h>
17 #include <utility>
18 #include <tr1/memory>
19 
20 #include "cass.h"
21 #include "result.hpp"
22 #include "cass_event.h"
23 #include "cached_list.hpp"
24 
25 namespace cass
26 {
27 /** base class for processors.
28  *
29  * This class handles most of the functionality of a processor. When
30  * creating a new processor the user has just the overwrite the process
31  * function. There it will retrieve the result from either other
32  * processors or from the cassevent itselve. All the rest is handled by
33  * the base class. Optionally, if one wants to have user interaction with the
34  * class, this can be implemented by overwriting loadSettings.
35  *
36  * @author Lutz Foucar
37  * @author Jochen Kuepper
38  */
39 class Processor
40 {
41 public:
42  /** a shared pointer of this */
43  typedef std::tr1::shared_ptr<Processor> shared_pointer;
44 
45  /** define the name type */
46  typedef std::string name_t;
47 
48  /** define the list of names */
49  typedef std::list<name_t> names_t;
50 
51  /** define the results */
53 
54  /** define the shared pointer to the result */
56 
57  /** constructor
58  *
59  * @param name the name of the processor
60  */
61  Processor(const name_t &name);
62 
63  /** virtual destructor */
64  virtual ~Processor();
65 
66  /** process the event
67  *
68  * @note this is the function that should only be called by the Processor
69  * Manager.
70  * @note only use this function if all dependencies have been processed before.
71  *
72  * It will retrieve the pointer to the last result in the list and call
73  * the process function to process the event, if the condition is true.
74  * The histlist is locked throughout the the operations on the list, but it
75  * will be unlocked after the result has been write lockend and before process
76  * is called.
77  *
78  * If the condition is not true, the pointer to the result will be put to the
79  * second to front position in the list.
80  *
81  * @param event the event to be processed
82  */
83  virtual void processEvent(const CASSEvent& event);
84 
85  /** retrieve a result for a given id.
86  *
87  * return a reference to the result for the given id or the most recent one
88  * in case of eventid beeing 0
89  *
90  * @return const reference to the requested histogram
91  * @param eventid the event id of the histogram that is requested.
92  * Default is 0
93  */
94  virtual const result_t& result(const CASSEvent::id_t eventid=0);
95 
96  /** tell the list that the result for event can be overwritten
97  *
98  * details
99  *
100  * @param event The event that can be released
101  */
102  virtual void releaseEvent(const CASSEvent &event);
103 
104  /** retrieve histogram for id
105  *
106  * same as getHist, but returns a copy of the histogram.
107  *
108  * Locks the histogram for read access before creating the copy.
109  *
110  * @return shared pointer of a copy of the histogram
111  * @param eventid the event id of the histogram that is requested.
112  * Default is 0
113  */
115 
116  /** Provide default implementation of loadSettings that does nothing
117  *
118  * @note the implementation of load settings should ensure that all
119  * dependencies should be known at the first time it is run
120  *
121  * @param unused not used
122  */
123  virtual void loadSettings(size_t unused);
124 
125  /** load the general settings
126  *
127  * loads the settings common to all procesors then calls loadSettings to
128  * get the specific settings of the processor
129  */
130  virtual void load();
131 
132  /** function that will be called when the processor is about to be deleted */
133  virtual void aboutToQuit();
134 
135  /** Define all processors keys a processor depends on
136  *
137  * If the dependencies are user choosable they must all be set in
138  * loadSettings before it makes sense to call this function.
139  *
140  * This function will be called by Processors::setup() when it creates
141  * the container with all activated processors.
142  */
143  const names_t& dependencies()
144  {
145  return _dependencies;
146  }
147 
148  /** clear the dependenies */
150 
151  /** clear the histograms
152  *
153  * this will lock for write access to the histograms before clearing them
154  */
155  void clearHistograms();
156 
157  /** process command in pp
158  *
159  * overwrite this function in pp. can do whatever it wants to do as a
160  * reaction on command.
161  *
162  * @param command the command string transmitted
163  */
164  virtual void processCommand(std::string command);
165 
166  /** retrieve the name of this processor */
167  const name_t name() const {return _name;}
168 
169  /** retrieve the hide flag of this processor */
170  bool hide()const {return _hide;}
171 
172  /** retrieve the comment of this processor */
173  const std::string& comment()const {return _comment;}
174 
175 protected:
176  /** process the event
177  *
178  * This will evaluate the event and fill the resulting histogram. It needs
179  * to be implemented in the processors. The result should be locked when
180  * calling this function so users can rely on the fact that they can savely
181  * use the result without locking it.
182  *
183  * The default implementation mimiks the behaviour of the operator(). It
184  * assings the result to the _result member and locks the list to ensure that
185  * noone can process this at the same time and therefore change the pointer to
186  * the _result member.
187  *
188  * @param event the cassevent to work on
189  * @param result this is where the result will be written to
190  */
191  virtual void process(const CASSEvent& event, result_t& result);
192 
193  /** create result list.
194  *
195  * uses cass::CachedList::setup to generate the result list. The size is
196  * 2+cass::nbrworkers.
197  *
198  * @param result shared pointer of the result that will be used in the cached
199  * result list
200  */
202 
203  /** general setup of the processor
204  *
205  * will setup the options that are available for all processors
206  *
207  * @cassttng Processor/\%name\%/{Hide} \n
208  * Flag that will hide this processor in cassview's combobox.
209  * Default is false
210  * @cassttng Processor/\%name\%/{Write} \n
211  * Flag that will tell a dumper to write this processor into
212  * the file. Default is true
213  * @cassttng Processor/\%name\%/{WriteSummary} \n
214  * Flag that will tell a dumper to write this processor into
215  * the summary. Useful for histograms that are only interesting
216  * per run. Default is true
217  * @cassttng Processor/\%name\%/{Comment} \n
218  * A comment with a short description of what this processor
219  * is doing. Will be added to the file, when its written.
220  * Default is "".
221  */
222  void setupGeneral();
223 
224  /** setup the condition.
225  *
226  * this will setup the condition with the default name ConditionList
227  *
228  * @cassttng Processor/\%name\%/{ConditionName} \n
229  * 0D Processor name that we check before filling image.
230  * if this setting is not defined, this processor is
231  * unconditional. Therefore its always true.
232  *
233  * @return true when condition is there, false otherwise
234  * @param defaultConditionType the type of condition that should be used when
235  * there is no ConditionName defined in cass.ini
236  */
237  bool setupCondition(bool defaultConditionType=true);
238 
239  /** setup the dependecy.
240  *
241  * this will look up the dependecy key in cass.ini and tries to get it from
242  * the processors. It will return the pointer to the dependecy
243  * processor when it is there. If it's not in the container it will
244  * return 0. When the depencendy key is not already in the list with all
245  * dependcies, it will be added.
246  *
247  * In case the second parameter is set, then it doesn't look up the key name
248  * in the cass.ini, but rather use the provided one.
249  *
250  * @return pointer to the dependency processor
251  * @param[in] depVarName the name of the setting that hold the dependcy key
252  * @param[in] name optional name of the key, without getting it from the
253  * settings file.
254  */
255  shared_pointer setupDependency(const std::string& depVarName, const name_t& name="");
256 
257 protected:
258  /** the processors name */
259  const name_t _name;
260 
261  /** flag to tell whether this pp should be hidden in the dropdown list */
262  bool _hide;
263 
264  /** optional comment that one can add to a processor.
265  *
266  * Will be used when writing this pp to file.
267  */
268  std::string _comment;
269 
270  /** the list of results */
272 
273  /** the list of dependencies */
274  names_t _dependencies;
275 
276  /** pointer to the processor that will contain the condition */
277  shared_pointer _condition;
278 };
279 
280 
281 
282 
283 
284 /** an accumulating processor
285  *
286  * instead of having a list of result, just uses one result.
287  * Overwrites functions to only use one result
288  */
290 {
291 public:
292  /** constructor
293  *
294  * @param name the name of the processor
295  */
297  : Processor(name),
299  {}
300 
301  /** virtual destructor */
303 
304  /** process the event
305  *
306  * @note this is the function that should only be called by the Processor
307  * Manager.
308  * @note only use this function if all dependencies have been processed before.
309  *
310  * retrieve the result from the list. Get the writelock on it and process it,
311  * if condition is true.
312  *
313  * @param evt the event to be processed
314  */
315  virtual void processEvent(const CASSEvent& evt)
316  {
317  if (_condition->result(evt.id()).isTrue())
318  {
319  QWriteLocker locker(&(_result->lock));
320  _result->id(evt.id());
321  process(evt,*_result);
322  }
323  }
324 
325  /** retrieve a result.
326  *
327  * return a reference to the latest result no matter what Id has been given,
328  * as it doesn't make any sense to differentiate between different events.
329  *
330  * @return const reference to the requested histogram
331  * @param eventid Ignored
332  */
333  virtual const result_t& result(const CASSEvent::id_t)
334  {
335  return *_result;
336  }
337 
338  /** overwrite default behaviour to do nothing */
339  virtual void releaseEvent(const CASSEvent&){}
340 
341  /** create the list of results
342  *
343  * Just sets up the one result that an accumulating processor manages
344  *
345  * @param result shared pointer of the result that will be used in the cached
346  * result list
347  */
349  {
350  result->name(name());
351  _result = result->clone();
352  }
353 
354 protected:
355  /** the result that accumulates the events */
357 
358  /** the number of events the processor has accumulated */
360 };
361 
362 } //end namespace cass
363 
364 #endif
CachedList::item_type result_t
define the results
Definition: processor.h:52
Event to store all LCLS Data.
Definition: cass_event.h:32
virtual void createHistList(result_t::shared_pointer result)
create result list.
Definition: processor.cpp:79
std::string _comment
optional comment that one can add to a processor.
Definition: processor.h:268
const name_t name() const
retrieve the name of this processor
Definition: processor.h:167
check if FEL is off by checking for bykick which is eventid
file contains declaration of the CASSEvent
virtual ~AccumulatingProcessor()
virtual destructor
Definition: processor.h:302
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
virtual void aboutToQuit()
function that will be called when the processor is about to be deleted
Definition: processor.cpp:177
result_t::shared_pointer resultCopy(const uint64_t eventid)
retrieve histogram for id
Definition: processor.cpp:67
virtual void processEvent(const CASSEvent &evt)
process the event
Definition: processor.h:315
uint64_t id_t
define the id type
Definition: cass_event.h:52
bool _hide
flag to tell whether this pp should be hidden in the dropdown list
Definition: processor.h:262
size_t _nbrEventsAccumulated
the number of events the processor has accumulated
Definition: processor.h:359
result classes
virtual void processCommand(std::string command)
process command in pp
Definition: processor.cpp:183
a list of results for caching
Definition: cached_list.hpp:34
std::list< name_t > names_t
define the list of names
Definition: processor.h:49
virtual ~Processor()
virtual destructor
Definition: processor.cpp:31
virtual const result_t & result(const CASSEvent::id_t)
retrieve a result.
Definition: processor.h:333
base class for processors.
Definition: processor.h:39
virtual void processEvent(const CASSEvent &event)
process the event
Definition: processor.cpp:34
shared_pointer setupDependency(const std::string &depVarName, const name_t &name="")
setup the dependecy.
Definition: processor.cpp:114
void clearDependencies()
clear the dependenies
Definition: processor.h:149
virtual void process(const CASSEvent &event, result_t &result)
process the event
Definition: processor.cpp:165
virtual void releaseEvent(const CASSEvent &event)
tell the list that the result for event can be overwritten
Definition: processor.cpp:62
CachedList _resultList
the list of results
Definition: processor.h:271
CachedList::item_sp resultsp_t
define the shared pointer to the result
Definition: processor.h:55
names_t _dependencies
the list of dependencies
Definition: processor.h:274
file contains global definitions for project cass
id_t & id()
setters
Definition: cass_event.h:64
const std::string & comment() const
retrieve the comment of this processor
Definition: processor.h:173
AccumulatingProcessor(const name_t &name)
constructor
Definition: processor.h:296
virtual void loadSettings(size_t unused)
Provide default implementation of loadSettings that does nothing.
Definition: processor.cpp:171
virtual void createHistList(result_t::shared_pointer result)
create the list of results
Definition: processor.h:348
Processor(const name_t &name)
constructor
Definition: processor.cpp:26
contains a list for caching results
virtual void releaseEvent(const CASSEvent &)
overwrite default behaviour to do nothing
Definition: processor.h:339
void setupGeneral()
general setup of the processor
Definition: processor.cpp:85
std::tr1::shared_ptr< item_type > item_sp
define a shared pointer of the item
Definition: cached_list.hpp:41
virtual void load()
load the general settings
Definition: processor.cpp:152
const name_t _name
the processors name
Definition: processor.h:259
an accumulating processor
Definition: processor.h:289
const names_t & dependencies()
Define all processors keys a processor depends on.
Definition: processor.h:143
result_t::shared_pointer _result
the result that accumulates the events
Definition: processor.h:356
bool hide() const
retrieve the hide flag of this processor
Definition: processor.h:170
shared_pointer _condition
pointer to the processor that will contain the condition
Definition: processor.h:277
void clearHistograms()
clear the histograms
Definition: processor.cpp:74
bool setupCondition(bool defaultConditionType=true)
setup the condition.
Definition: processor.cpp:94
std::string name_t
define the name type
Definition: processor.h:46
std::tr1::shared_ptr< Processor > shared_pointer
a shared pointer of this
Definition: processor.h:43
virtual const result_t & result(const CASSEvent::id_t eventid=0)
retrieve a result for a given id.
Definition: processor.cpp:54