CFEL - ASG Software Suite  2.5.0
CASS
table_operations.cpp
Go to the documentation of this file.
1 // Copyright (C) 2013 Lutz Foucar
2 
3 /**
4  * @file table_operations.cpp contains processors that will operate
5  * on table like histograms of other processors.
6  *
7  * @author Lutz Foucar
8  */
9 
10 #include "table_operations.h"
11 
12 #include "log.h"
13 #include "cass_settings.h"
14 #include "convenience_functions.h"
15 
16 using namespace cass;
17 using namespace std;
18 
19 
20 
21 // *** pp 72 returns column of a table ***
22 
23 pp72::pp72(const name_t &name)
24  : Processor(name)
25 {
26  loadSettings(0);
27 }
28 
29 void pp72::loadSettings(size_t)
30 {
31  CASSSettings s;
32  s.beginGroup("Processor");
34  setupGeneral();
35  _table = setupDependency("TableName");
36  bool ret (setupCondition());
37  if (!(ret && _table))
38  return;
39  _colIdx = s.value("ColumnIndex",0).toUInt();
40 
41  size_t maxIdx(_table->result().axis(result_t::xAxis).nBins);
42  if (_colIdx >= maxIdx)
43  throw runtime_error("pp72::loadSettings(): '" + name() + "' The requested " +
44  "column index '" + toString(_colIdx) + " 'exeeds the " +
45  "maximum possible index value '" + toString(maxIdx) + "'");
46 
48  Log::add(Log::INFO,"Processor '" + name() +
49  "' retrieves column with index '" + toString(_colIdx) +
50  "' from table " + _table->name() + "' .Condition on processor '" +
51  _condition->name() + "'");
52 }
53 
54 void pp72::process(const CASSEvent& evt, result_t &result)
55 {
56  const result_t& table(_table->result(evt.id()));
57  QReadLocker lock(&table.lock);
58 
59  result.reset();
60 
61  const size_t nCols(table.shape().first);
62  const size_t nRows(table.shape().second);
63 
64  for (size_t row=0; row < nRows; ++row)
65  result.append(table[row*nCols + _colIdx]);
66 
67 }
68 
69 
70 
71 
72 // *** pp 73 returns subset of table with condition on rows ***
73 
74 pp73::pp73(const name_t &name)
75  : Processor(name)
76 {
77  loadSettings(0);
78 }
79 
80 void pp73::loadSettings(size_t)
81 {
82  CASSSettings s;
83  s.beginGroup("Processor");
85  setupGeneral();
86  _table = setupDependency("TableName");
87  bool ret (setupCondition());
88  if (!(ret && _table))
89  return;
90  _colIdx = s.value("ColumnIndex",0).toUInt();
91  _bounds = make_pair(s.value("LowerBound",0.f).toFloat(),
92  s.value("UpperBound",1.f).toFloat());
93 
94  size_t tableSize(_table->result().axis(result_t::xAxis).nBins);
95  if (_colIdx >= tableSize)
96  throw runtime_error("pp73::loadSettings(): '" + name() + "' The requested " +
97  "column index '" + toString(_colIdx) + " 'exeeds the " +
98  "maximum possible index value '" + toString(tableSize) + "'");
99 
101  Log::add(Log::INFO,"Processor '" + name() +
102  "' retrieves subset of table in '" + _table->name() + "'. UpperBound '" +
103  toString(_bounds.first) + "' LowerBound '" + toString(_bounds.second) +
104  "' on values in column with index '" + toString(_colIdx) +
105  "'. Condition on processor '" + _condition->name() + "'");
106 }
107 
108 void pp73::process(const CASSEvent& evt, result_t &result)
109 {
110  const result_t& table(_table->result(evt.id()));
111  QReadLocker lock(&table.lock);
112 
113  result_t::const_iterator tableIt(table.begin());
114 
115  result.resetTable();
116 
117  const size_t nCols(table.shape().first);
118  const size_t nRows(table.shape().second);
119 
120  result_t::storage_t rows;
121  for (size_t rowIdx=0; rowIdx < nRows; ++rowIdx)
122  {
123  if(_bounds.first <= tableIt[_colIdx] && tableIt[_colIdx] < _bounds.second)
124  rows.insert(rows.end(),tableIt,tableIt+nCols);
125  tableIt += nCols;
126  }
127  result.appendRows(rows);
128 
129 }
130 
131 
132 
133 
134 // *** pp 74 retrieve a specific value of a specific row ***
135 
136 pp74::pp74(const name_t &name)
137  : Processor(name)
138 {
139  loadSettings(0);
140 }
141 
142 void pp74::loadSettings(size_t)
143 {
144  CASSSettings s;
145  s.beginGroup("Processor");
147  setupGeneral();
148  _table = setupDependency("TableName");
149  bool ret (setupCondition());
150  if (!(ret && _table))
151  return;
152  _colIdx = s.value("ColumnIndex",0).toUInt();
153  _rowIdx = s.value("RowIndex",0).toUInt();
154 
155  size_t tableSize(_table->result().shape().first);
156  if (_colIdx >= tableSize)
157  throw runtime_error("pp73::loadSettings(): '" + name() + "' The requested " +
158  "column index '" + toString(_colIdx) + " 'exeeds the " +
159  "maximum possible index value '" + toString(tableSize) + "'");
160 
162 
163  Log::add(Log::INFO,"Processor '" + name() +
164  "' retrieves the value of row '" + toString(_rowIdx) +
165  "' and column '" + toString(_colIdx) + "' from table '" +
166  _table->name() + "'. Condition on processor '" +
167  _condition->name() + "'");
168 }
169 
170 void pp74::process(const CASSEvent& evt, result_t &result)
171 {
172  const result_t& table(_table->result(evt.id()));
173  QReadLocker lock(&table.lock);
174 
175  const size_t nCols(table.shape().first);
176  const size_t nRows(table.shape().second);
177 
178  if (_rowIdx >= nRows)
179  throw invalid_argument("pp74::process(): '" + name() + "' The requested row index '" +
180  toString(_rowIdx) + "' is too big for a table with '" +
181  toString(nRows) + "' rows.");
182 
183  result.setValue(table[_rowIdx * nCols + _colIdx]);
184 }
185 
186 
187 
188 
189 
190 
191 
192 
193 // *** pp 79 generates a 2d histogram from 2 columns***
194 
195 pp79::pp79(const name_t &name)
196  : Processor(name)
197 {
198  loadSettings(0);
199 }
200 
201 void pp79::loadSettings(size_t)
202 {
203  CASSSettings s;
204  s.beginGroup("Processor");
206  setupGeneral();
207  _table = setupDependency("TableName");
208  bool ret (setupCondition());
209  if (!(ret && _table))
210  return;
211  _xcolIdx = s.value("XColumnIndex",0).toUInt();
212  _ycolIdx = s.value("YColumnIndex",0).toUInt();
213  _weightcolIdx = s.value("WeightColumnIndex",-1).toInt();
214 
215  size_t maxIdx(_table->result().shape().first);
216  if (_xcolIdx >= maxIdx)
217  throw runtime_error("pp79::loadSettings(): '" + name() + "' The requested " +
218  "x column index '" + toString(_xcolIdx) + " 'exeeds the " +
219  "maximum possible index value '" + toString(maxIdx) + "'");
220  if (_ycolIdx >= maxIdx)
221  throw runtime_error("pp79::loadSettings(): '" + name() + "' The requested " +
222  "y column index '" + toString(_ycolIdx) + " 'exeeds the " +
223  "maximum possible index value '" + toString(maxIdx) + "'");
224  if (!(_weightcolIdx < 0) && _weightcolIdx >= static_cast<int>(maxIdx))
225  throw runtime_error("pp79::loadSettings(): '" + name() + "' The requested " +
226  "weight column index '" + toString(_weightcolIdx) + " 'exeeds the " +
227  "maximum possible index value '" + toString(maxIdx) + "'");
228  if (_weightcolIdx < 0)
229  _getWeight = std::tr1::bind(&pp79::constantWeight, this, tr1::placeholders::_1);
230  else
231  {
232  _getWeight = std::tr1::bind(&pp79::weightFromTable, this, tr1::placeholders::_1);
233  }
234 
236  Log::add(Log::INFO,"Processor '" + name() +
237  "' X column index '" + toString(_xcolIdx) +
238  "' Y column index '" + toString(_ycolIdx) +
239  "' Table " + _table->name() + "' .Condition on processor '" +
240  _condition->name() + "'");
241 }
242 
243 pp79::func_t::result_type pp79::weightFromTable(func_t::argument_type tableIt)
244 {
245  return tableIt[_weightcolIdx];
246 }
247 
248 pp79::func_t::result_type pp79::constantWeight(func_t::argument_type)
249 {
250  return abs(_weightcolIdx);
251 }
252 
253 void pp79::process(const CASSEvent& evt, result_t &result)
254 {
255  const result_t& table(_table->result(evt.id()));
256  QReadLocker lock(&table.lock);
257 
258  const size_t nCols(table.shape().first);
259  const size_t nRows(table.shape().second);
260 
261  result_t::const_iterator tableIt(table.begin());
262  for (size_t row=0; row < nRows; ++row)
263  {
264  const int pixCol(tableIt[_xcolIdx]);
265  const int pixRow(tableIt[_ycolIdx]);
266  result.histogram(make_pair(pixCol,pixRow),_getWeight(tableIt));
267  tableIt += nCols;
268  }
269 }
270 
271 
272 
273 
274 
275 
276 
277 
278 // *** pp 500 retrieve a specific value of result and add to new column ***
279 
280 pp500::pp500(const name_t &name)
281  : Processor(name)
282 {
283  loadSettings(0);
284 }
285 
287 {
288  CASSSettings s;
289  s.beginGroup("Processor");
291  setupGeneral();
292  _table = setupDependency("TableName");
293  _inResult = setupDependency("InputName");
294  bool ret (setupCondition());
295  if (!(ret && _table && _inResult))
296  return;
297  _colIdx = s.value("IndexColumn",0).toUInt();
298 
299  size_t tableSize(_table->result().shape().first);
300  if (_colIdx >= tableSize)
301  throw runtime_error("pp500::loadSettings(): '" + name() + "' The requested " +
302  "column index '" + toString(_colIdx) + " 'exeeds the " +
303  "maximum possible index value '" + toString(tableSize) + "'");
304 
305  createHistList(result_t::shared_pointer(new result_t(tableSize+1,0)));
306 
307  Log::add(Log::INFO,"Processor '" + name() +
308  "' retrieves the value of '" + _table->result().name() +
309  "' that correponds to point in column '" + toString(_colIdx) +
310  "' from table '" + _table->name() + "'. Condition on processor '" +
311  _condition->name() + "'");
312 }
313 
314 void pp500::process(const CASSEvent& evt, result_t &result)
315 {
316  const result_t& table(_table->result(evt.id()));
317  QReadLocker lock1(&table.lock);
318  const result_t& inres(_inResult->result(evt.id()));
319  QReadLocker lock2(&inres.lock);
320 
321  /** reset the output table */
322  result.resetTable();
323  /** create a table row */
324  result_t::storage_t newRow;
325  /** go through all rows of the input table */
326  const size_t nTableRows(table.shape().first);
327  const size_t nTableCols(table.shape().second);
328  for (size_t iRow(0); iRow < nTableRows; ++iRow)
329  {
330  /** get the beginning and end of the row of the input table */
331  result_t::const_iterator rowStart(table.begin());
332  advance(rowStart,iRow*nTableCols);
333  result_t::const_iterator rowEnd(rowStart);
334  advance(rowEnd,nTableCols);
335  /** get the index that one should retrieve from the input result */
336  const size_t idx(rowStart[_colIdx]);
337  /** retrieve the value from the input result */
338  const result_t::value_t value(inres[idx]);
339  /** create a new row of the result from the input table */
340  newRow.assign(rowStart,rowEnd);
341  /** add the retrieved value in the last column */
342  newRow.push_back(value);
343  /** add the row to the output table */
344  result.appendRows(newRow);
345  }
346 }
CachedList::item_type result_t
define the results
Definition: processor.h:52
storage_t::const_iterator const_iterator
a const iterator on the storage
Definition: result.hpp:338
size_t _xcolIdx
index of the column with the x-values that needs to be extracted
void appendRows(const storage_t &rows)
add row(s) to the result
Definition: result.hpp:724
virtual void loadSettings(size_t)
load the settings of the pp
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
virtual void loadSettings(size_t)
load the settings of the pp
size_t _rowIdx
the index of the row
contains processors that will operate on table like histograms of other processors.
void reset()
clear the appendable 1d like result
Definition: result.hpp:771
std::vector< value_t > storage_t
the storage of this container
Definition: result.hpp:332
pp500(const name_t &)
constructor
std::pair< float, float > _bounds
the boundaries for the condition
func_t _getWeight
the function to return the weight
const name_t name() const
retrieve the name of this processor
Definition: processor.h:167
float value_t
the values of this container
Definition: result.hpp:326
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 loadSettings(size_t)
load the settings of the pp
Processor::result_t::shared_pointer set2DHist(const Processor::name_t &name)
function to set the 2d histogram properties from the ini file.
virtual void loadSettings(size_t)
load the settings of the pp
STL namespace.
virtual void process(const CASSEvent &, result_t &)
process event
void resetTable()
reset the table like result
Definition: result.hpp:740
pp74(const name_t &)
constructor
shared_pointer _table
pp containing input table
shared_pointer _table
pp containing input table
int _weightcolIdx
index of the column with the weights that needs to be exracted
size_t _colIdx
index of the column
virtual void loadSettings(size_t)
load the settings of the pp
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
void setValue(const_reference value)
assign the result container to a value
Definition: result.hpp:543
const_iterator begin() const
retrieve a iterator for read access to beginning
Definition: result.hpp:608
fromStdString(const std::string &str)
func_t::result_type constantWeight(func_t::argument_type unused)
returns a 1
base class for processors.
Definition: processor.h:39
pp73(const name_t &)
constructor
shared_pointer setupDependency(const std::string &depVarName, const name_t &name="")
setup the dependecy.
Definition: processor.cpp:114
virtual void process(const CASSEvent &, result_t &)
process event
virtual void process(const CASSEvent &, result_t &)
process event
func_t::result_type weightFromTable(func_t::argument_type tableIt)
returns the weight value from a table
size_t _colIdx
index of the column with the x-values that needs to be extracted
virtual void process(const CASSEvent &, result_t &)
process event
file contains declaration of classes and functions that help other processors to do their job...
QReadWriteLock lock
lock for locking operations on the data of the container
Definition: result.hpp:954
pp72(const name_t &)
constructor
shared_pointer _table
pp containing input table
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
void append(const value_t &val)
append a value to the end of the result
Definition: result.hpp:756
shared_pointer _inResult
pp containing input table
value(const QString &key, const QVariant &defaultValue=QVariant()
pp79(const name_t &)
constructor
size_t _ycolIdx
index of the column with the y-values that needs to be extracted
void setupGeneral()
general setup of the processor
Definition: processor.cpp:85
file contains specialized class that do the settings for cass
iterator histogram(const value_t &pos, const value_t &weight=1)
add the weight at the right bin for the value in the 1d array
Definition: result.hpp:651
shared_pointer _table
pp containing input table
shared_pointer _condition
pointer to the processor that will contain the condition
Definition: processor.h:277
size_t _colIdx
index of the column that will be checked for
virtual void process(const CASSEvent &, result_t &)
process event
shape_t shape() const
return the shape of the result
Definition: result.hpp:811
bool setupCondition(bool defaultConditionType=true)
setup the condition.
Definition: processor.cpp:94
std::string name_t
define the name type
Definition: processor.h:46
contains a logger for cass
check if there is some light in the chamber based upon the GMD value
size_t _colIdx
index of the column that needs to be extracted
shared_pointer _table
pp containing input table
beginGroup(const QString &prefix)