[go: up one dir, main page]

Menu

[e59016]: / modules / MyModule.h  Maximize  Restore  History

Download this file

237 lines (208 with data), 6.1 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
/* -*- mode: c++ -*- */
#ifndef __MyModule_h__
#define __MyModule_h__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <vector>
#include <DAQ++/ObserverModel.h>
#include <daq/GenModule.h>
#include "TAmanager.h"
class Analysis;
template<typename T>
class MyParameter;
class MyModule : public GenModule {
private:
double _delay;
public:
enum ROmode { Off=0, On=1, Serial=2, Sparse=4, SparseAdj=8, FORoff=16 };
MyModule(const DAQpp::DAQid &id,unsigned long add);
~MyModule();
bool hasData();
char *getData(int &size);
int PrepareForRun ();
int Start (int = 0);
int Stop (int = 0) { return 0; };
int Pause () { return 0; };
int Continue () { return 0; };
int Reset ();
int GetReady ();
int Trigger ();
void flush () {};
void SoftStart();
void set_threshold(int x, bool nt=false);
void set_rout( int x, bool nt=false);
void set_nchip( int x, bool nt=false);
void set_adj( int x, bool nt=false);
void set_ta( TAmanager &x, bool nt=false);
int get_threshold() const;
int get_rout() const;
int get_nchip() const;
int get_adj() const;
TAmanager &get_ta() const;
TAmanager &get_ta();
void set_delay(double x) { _delay=x; }
double get_delay() const { return _delay; }
void step_advance(int chan);
private:
enum Registers {
RW_FIFO = 0x0,
WCHAN = 0x4,
WADJCHAN = 0x8,
R_WC = 0xc,
RST = 0x10,
WDAC = 0x14,
PULSE = 0x18,
WCNTREG = 0x1c, // Write data to Control Reg (Xilinx) 5 bits
TROUT = 0x20,
TEVENT = 0x2c,
SOFTSTART = 0x24,
RWREG = 0x28, // Read data from Control Reg of chip (line 31)
SOFTCLK = 0x30,
REGCLK = 0x34, // Clock for register. No data
SHIFTIN_CPU = 0x38
};
enum CRAM {
// These variables for CRAM
MEMCH0 =0x00002000,
MEMCH1 =0x00004000,
FIFOCH0 =0x00000008,
FIFOCH1 =0x0000000c,
CHANNUM =0x00000004,
STATREG =0x00000002,
RESMOD =0x00000006,
WCCH1 =0x00000012,
WCCH0 =0x00000010,
TESTPA0 =0x00000014,
TESTPA1 =0x00000016
};
// Parameters
DAQpp::Par<int> *threshold;
DAQpp::Par<int> *nchip;
DAQpp::Par<int> *adj;
DAQpp::Par<int> *rout;
DAQpp::Par<TAmanager> *ta;
MyParameter<int> *threshold_p;
MyParameter<int> *nchip_p;
MyParameter<int> *adj_p;
MyParameter<int> *rout_p;
MyParameter<TAmanager> *ta_p;
// Callbacks
void change_threshold(int &x);
void change_nchip(int &x);
void change_adj(int &x);
void change_rout(int &x);
void change_ta(TAmanager &x);
void change_ped( std::vector<double> &) {}
int channel;
// This variables are used with dummy VME drivers to
// simulate the data
double _gain;
double _mean;
double _noise;
double _ped;
double _cmmd;
int _theChannel;
double _thePulse;
double _theGain;
double _theThreshold;
double _theThresholdGain;
double _theValue;
public:
//---------------------------------------------------------------------
// TA functions
//---------------------------------------------------------------------
// maks all the channels
void mask_all();
// masks a given channel
void mask_channel(int ch);
// selects one channel for triggering
void select_channel(int ch);
// enable all channels for triggering
void select_all();
// sets the gain
void set_gain(int ichip, int gain);
// send the TA mask to the chip
void load_register();
// sets the trim of a given channel
void trim_channel(int ch, int tr);
void set_scan_point(ScanPoint &);
void set_header_description(unsigned long &data);
unsigned long *write_pedestals(int &);
void test_channel(int);
};
template<class T>
class MyParameter : public Observer {
private:
MyModule *module;
void (MyModule::*func)(T &);
DAQpp::Par< T > *par;
public:
MyParameter(MyModule *m, void (MyModule::*f)(T &), DAQpp::Par< T > *p=0)
: module(m),func(f), par(0)
{
if (p)
set_par(p);
}
~MyParameter() {
par->deleteObserver( *dynamic_cast<Observer *>(this) );
}
void set_par( DAQpp::Par< T > *p) {
if (par)
par->deleteObserver( *dynamic_cast<Observer *>(this) );
par = p;
par->addObserver( *dynamic_cast<Observer *>(this) );
}
const MyModule *get_module() const { return module; }
void update(Observable *o, Argument *arg) {
Arg<T> *v = static_cast< Arg<T> * >(arg);
(module->*func)( v->get_value() );
}
};
/*
template<class T>
class MyParameter : public Observer, public DAQpp::Par<T> {
private:
MyModule *module;
void (MyModule::*func)(T &);
public:
MyParameter(MyModule *m,
void (MyModule::*f)(T &),
const char *s, const T &x = T())
: DAQpp::Par<T>(x),module(m),func(f)
{
DAQpp::Par<T>::addObserver( *dynamic_cast<Observer *>(this) );
module->add_par(s,dynamic_cast<DAQpp::Parameter *>(this));
}
~MyParameter() {
DAQpp::Par<T>::deleteObserver( *dynamic_cast<Observer *>(this) );
}
const MyModule *get_module() const { return module; }
void update(Observable *o, Argument *arg) {
Arg<T> *v = static_cast< Arg<T> * >(arg);
(module->*func)( v->get_value() );
}
};
*/
inline MyModule::~MyModule() {
std::cout << "...destroying Module " << get_id() << std::endl;
}
inline int MyModule::get_threshold() const {
return threshold->get_value();
}
inline int MyModule::get_rout() const {
return rout->get_value();
}
inline int MyModule::get_nchip() const {
return nchip->get_value();
}
inline int MyModule::get_adj() const {
return adj->get_value();
}
inline TAmanager &MyModule::get_ta() const {
return ta->get_value();
}
inline TAmanager &MyModule::get_ta() {
return ta->get_value();
}
#endif