[go: up one dir, main page]

Menu

[0a098c]: / daq / ScanPoint.h  Maximize  Restore  History

Download this file

319 lines (289 with data), 7.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/* -*- mode: c++ -*- */
#ifndef __ScanPoint_h__
#define __ScanPoint_h__
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
//////////////////////////////////////////////////////////////////////////
// class ScanVar
//
// Author: Carlos Lacasta
// Purpose:
// This class represents a scan variable. It contains
// information on the scan range, step and default value.
// It also defines the different types of scan variables.
//
//////////////////////////////////////////////////////////////////////////
class ScanVar
{
public:
enum ScanType
{ channel, pulse, threshold, trim, xposition, yposition, zposition,
angle1, angle2, angle3, user1, user2, user3, user4, thrs_trim, cal_dac};
private:
ScanType _type;
int _npoints;
double _first;
double _step;
double _default;
double _value;
// List of names
static std::vector<std::string> names;
void cpy(const ScanVar &s);
public:
ScanVar(ScanVar::ScanType tp, double frst = 0., double last = 1.,
double stp = 1., double dflt = 0.);
ScanVar(const ScanVar &s)
{
cpy(s);
}
ScanVar &operator=(const ScanVar &s)
{
if (this != &s)
cpy(s);
return *this;
}
ScanType type() const
{
return _type;
}
int n_points() const
{
return _npoints;
}
double first() const
{
return _first;
}
double last() const
{
return _first + (_npoints - 1)*_step;
}
double step() const
{
return _step;
}
double get_default() const
{
return _default;
}
double value() const
{
return _value;
}
void set_value(double x)
{
_value = x;
}
void set_n_points(int x)
{
_npoints = x;
}
void set_type(ScanType x)
{
_type = x;
}
void set_first(double x)
{
_first = x;
}
void set_step(double x)
{
_step = x;
}
void adjust(double first, double last, double step);
// I/O
std::ostream &dump(std::ostream &os);
std::istream &load(std::istream &is);
// global names
static int get_n_names()
{
return names.size();
}
static const std::string get_name(int x)
{
return names[x];
}
friend std::ostream &operator<<(std::ostream &, const ScanVar &);
};
inline std::ostream &operator<<(std::ostream &os, const ScanVar &v)
{
os << "Type "<< v._type<< " n. points "<< v._npoints<< " from "<< v._first
<< " step "<< v._step;
return os;
}
//////////////////////////////////////////////////////////////////////////
// ScanPoint
//
// Author: Carlos Lacasta
// Purpose:
// Represents a point in the scan. It is a collection of ScanVar
//
//////////////////////////////////////////////////////////////////////////
class ScanPoint
{
private:
std::string name;
std::vector<ScanVar> vvar;
void cpy(const ScanPoint &sc)
{
name = sc.name;
vvar.clear();
vvar = sc.vvar;
}
// Predicate used to find a ScanVar of a given type
class ftype
{
private:
ScanVar::ScanType type;
public:
ftype(ScanVar::ScanType tp) :
type(tp)
{
}
bool operator()(ScanVar &var)
{
return var.type() == type;
}
};
public:
ScanPoint() :
name("")
{
}
ScanPoint(std::string s) :
name(s)
{
}
ScanPoint(const ScanPoint &sc)
{
cpy(sc);
}
ScanPoint(const std::vector<ScanVar> &v) :
vvar(v)
{
}
void operator=(const ScanPoint &sc)
{
if ( this != &sc)
cpy(sc);
}
~ScanPoint()
{
vvar.clear();
}
void reset()
{
vvar.clear();
}
// I/O
std::ostream &dump(std::ostream &os);
std::istream &load(std::istream &is);
std::string get_name() const
{
return name;
}
void set_name(const std::string &s)
{
name = s;
}
std::vector<ScanVar>::iterator find_type(ScanVar::ScanType tp)
{
return find_if(vvar.begin(), vvar.end(), ftype(tp));
}
void remove_var(ScanVar::ScanType tp)
{
std::vector<ScanVar>::iterator ip = find_type(tp);
if (ip != vvar.end() )
vvar.erase(ip);
}
// Adds or modifies a variable
void add_var(ScanVar &v)
{
std::vector<ScanVar>::iterator ip = find_type(v.type() );
if (ip == vvar.end() )
vvar.push_back(v);
else
*ip = v;
}
int nvar() const
{
return vvar.size();
}
int npoints() const;
std::vector<ScanVar>::iterator end()
{
return vvar.end();
}
std::vector<ScanVar>::iterator begin()
{
return vvar.begin();
}
std::vector<ScanVar>::const_iterator end() const
{
return vvar.end();
}
std::vector<ScanVar>::const_iterator begin() const
{
return vvar.begin();
}
const std::vector<ScanVar> &operator()() const
{
return vvar;
}
friend std::ostream &operator<<(std::ostream &, const ScanPoint &);
static int FillList(std::vector<ScanVar>::iterator from,
std::vector<ScanVar>::iterator to, ScanPoint &sc,
std::vector<ScanPoint> &lst);
};
typedef std::map<std::string, ScanPoint> ScanListType;
class ScanList : protected ScanListType
{
private:
void cpy(const ScanList &s);
public:
using ScanListType::iterator;
using ScanListType::const_iterator;
using ScanListType::begin;
using ScanListType::end;
using ScanListType::find;
using ScanListType::empty;
using ScanListType::erase;
using ScanListType::size;
ScanList()
{
}
ScanList(const ScanList &s)
{
cpy(s);
}
void operator=(const ScanList &s)
{
if (this != &s)
cpy(s);
}
void remove_point(const std::string &name)
{
ScanList::iterator ip = find(name);
if (ip!=end())
erase(ip);
}
void add_point(const std::string &name, const ScanPoint &pt)
{
remove_point(name);
(*this)[name] = pt;
}
// I/O
std::ostream &dump(std::ostream &os);
std::istream &load(std::istream &is);
};
inline std::ostream &operator<<(std::ostream &os, const ScanPoint &sc)
{
std::vector<ScanVar>::const_iterator ip;
for (ip = sc.vvar.begin(); ip != sc.vvar.end(); ++ip)
os << (*ip)<< std::endl;
return os;
}
#endif