CFEL - ASG Software Suite  2.5.0
CASS
processor.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010, 2013 Lutz Foucar
2 
3 /** @file processor.cpp file contains processors baseclass definition
4  *
5  * @author Lutz Foucar
6  */
7 
8 
9 #include <algorithm>
10 #include <tr1/functional>
11 #include <tr1/memory>
12 
13 #include "processor.h"
14 
15 #include "cass_exceptions.hpp"
16 #include "cass_settings.h"
17 #include "processor_manager.h"
18 
19 #include "log.h"
20 
21 using namespace cass;
22 using namespace std;
23 using std::tr1::bind;
24 using std::tr1::placeholders::_1;
25 
27  : _name(name),
28  _hide(false)
29 {}
30 
32 {}
33 
35 {
36  try
37  {
39  if (_condition->result(evt.id()).isTrue())
40  {
41  result_t &result(*(pointer->second));
42  QWriteLocker lock(&(result.lock));
43  result.id(evt.id());
44  process(evt,result);
45  _resultList.latest(pointer);
46  }
47  }
48  catch (const InvalidData& error)
49  {
50  Log::add(Log::ERROR,"EventID '"+ toString(evt.id()) +"': "+ error.what());
51  }
52 }
53 
55 {
56  if (0 == eventid)
57  return _resultList.latest();
58  else
59  return _resultList.item(eventid);
60 }
61 
63 {
64  _resultList.release(event.id());
65 }
66 
68 {
69  const result_t &r(result(eventid));
70  QReadLocker lock(&r.lock);
71  return r.clone();
72 }
73 
75 {
77 }
78 
80 {
81  result->name(name());
83 }
84 
86 {
87  CASSSettings settings;
88  settings.beginGroup("Processor");
90  _hide = settings.value("Hide",false).toBool();
91  _comment = settings.value("Comment","").toString().toStdString();
92 }
93 
94 bool Processor::setupCondition(bool conditiontype)
95 {
96  CASSSettings settings;
97  settings.beginGroup("Processor");
99  if (settings.contains("ConditionName"))
100  {
101  _condition = setupDependency("ConditionName");
102  }
103  else
104  {
105  if (conditiontype)
106  _condition = setupDependency("ConditionName","DefaultTrueHist");
107  else
108  _condition = setupDependency("ConditionName","DefaultFalseHist");
109  }
110  return _condition;
111 }
112 
114 Processor::setupDependency(const string &depVarName, const name_t& depkey)
115 {
116  name_t dependkey(depkey);
117  shared_pointer dependency;
118  if (dependkey.empty())
119  {
120  CASSSettings s;
121  s.beginGroup("Processor");
123  dependkey = s.value(QString::fromStdString(depVarName),"Unknown").toString().toStdString();
124  }
125  if (QString::fromStdString(dependkey).toUpper() == QString::fromStdString(name()).toUpper())
126  {
127  throw invalid_argument("Processor::setupDependency(): Error: '" +
128  name() + "' looks for a dependency '" + dependkey +
129  "'. One cannot let a processor depend on itself." +
130  " Note that qsettings is not case sensitive, so on must provide" +
131  " names that differ not only in upper / lower case.");
132  }
133 
134  Log::add(Log::DEBUG0,"Processor::setupDependency(): '" + name() +
135  "' check if dependency key '" + depVarName + "' which is '" +
136  dependkey + "' is already on the dependency list");
137  if (_dependencies.end() == find(_dependencies.begin(),_dependencies.end(),dependkey))
138  {
139  Log::add(Log::DEBUG0,"Processor::setupDependency(): '" + name() +
140  "': '" + dependkey +"' is not on depend list, add it ");
141  _dependencies.push_back(dependkey);
142  }
143  else
144  {
145  Log::add(Log::DEBUG0,"Processor::setupDependency(): '" + name() +
146  "' Dependency is on list. Retrieve '"+dependkey +"' from the mananger");
147  dependency = ProcessorManager::reference().getProcessorSPointer(dependkey);
148  }
149  return dependency;
150 }
151 
153 {
154  CASSSettings settings;
155  settings.beginGroup("Processor");
157  _hide = settings.value("Hide",false).toBool();
158  _comment = settings.value("Comment","").toString().toStdString();
159  if (settings.contains("ConditionName"))
160  _condition = setupDependency("ConditionName");
161  else
162  _condition = setupDependency("ConditionName","DefaultTrueHist");
163 }
164 
166 {
167  Log::add(Log::DEBUG4,"ProcessorBackend::process(): '" + name() +
168  "' not implemented");
169 }
170 
172 {
173  Log::add(Log::DEBUG4,"Processor::loadSettings(): '" + name() +
174  "' not implemented");
175 }
176 
178 {
179  Log::add(Log::DEBUG4,"Processor::aboutToQuit(): '" + name() +
180  "' not implemented");
181 }
182 
183 void Processor::processCommand(std::string )
184 {
185  Log::add(Log::DEBUG4,"Processor::processCommand(): '" + name() +
186  "' not implemented");
187 }
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 item_type & latest() const
retrieve the latest item
Definition: cached_list.hpp:75
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
Settings for CASS.
Definition: cass_settings.h:30
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
void clearItems()
clear the items in the list
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
STL namespace.
uint64_t id() const
retrieve the id of the result
Definition: result.hpp:934
file contains custom exceptions used in cass
Exception thrown when there is a problem with the data.
virtual void processCommand(std::string command)
process command in pp
Definition: processor.cpp:183
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
iter_type newItem(const id_type &id)
get an item for processing
fromStdString(const std::string &str)
shared_pointer clone() const
create a copy of the result
Definition: result.hpp:890
virtual ~Processor()
virtual destructor
Definition: processor.cpp:31
virtual void processEvent(const CASSEvent &event)
process the event
Definition: processor.cpp:34
void setup(item_sp item, size_t size)
create the list of items
shared_pointer setupDependency(const std::string &depVarName, const name_t &name="")
setup the dependecy.
Definition: processor.cpp:114
contains(const QString &key)
virtual void process(const CASSEvent &event, result_t &result)
process the event
Definition: processor.cpp:165
void release(const id_type &id)
unlock the item with id
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
names_t _dependencies
the list of dependencies
Definition: processor.h:274
QReadWriteLock lock
lock for locking operations on the data of the container
Definition: result.hpp:954
contains the manager for the processors
id_t & id()
setters
Definition: cass_event.h:64
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
virtual void loadSettings(size_t unused)
Provide default implementation of loadSettings that does nothing.
Definition: processor.cpp:171
file contains processors baseclass declaration
value(const QString &key, const QVariant &defaultValue=QVariant()
Processor(const name_t &name)
constructor
Definition: processor.cpp:26
void setupGeneral()
general setup of the processor
Definition: processor.cpp:85
file contains specialized class that do the settings for cass
virtual void load()
load the general settings
Definition: processor.cpp:152
const size_t NbrOfWorkers
global variable to set the number of worker threads
Definition: cass.h:274
static shared_pointer::element_type & reference()
return a reference to this instance
list_type::iterator iter_type
define an iterator for the list
Definition: cached_list.hpp:56
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
const item_type & item(const id_type &id)
retrieve an item with the right id
Definition: cached_list.hpp:62
contains a logger for cass
std::tr1::shared_ptr< Processor > shared_pointer
a shared pointer of this
Definition: processor.h:43
beginGroup(const QString &prefix)
virtual const result_t & result(const CASSEvent::id_t eventid=0)
retrieve a result for a given id.
Definition: processor.cpp:54