MIDAS
Loading...
Searching...
No Matches
v1740CONET2.cxx
Go to the documentation of this file.
1/*****************************************************************************/
10#include "v1740CONET2.hxx"
11#include <stdlib.h>
12
13#define UNUSED(x) ((void)(x))
14
15using namespace std;
16
18const char * v1740CONET2::config_str[] = {\
19 "setup = INT : 0",\
20 "Acq mode = INT : 1",\
21 "Group Configuration = DWORD : 0",\
22 "Buffer organization = INT : 8",\
23 "Custom size = INT : 0",\
24 "Group Mask = DWORD : 0xFF",\
25 "Trigger Source = DWORD : 0x40000000",\
26 "Trigger Output = DWORD : 0x40000000",\
27 "Post Trigger = DWORD : 200",\
28 "Threshold = DWORD[8] :",\
29 "[0] 2080",\
30 "[1] 1900",\
31 "[2] 2080",\
32 "[3] 9",\
33 "[4] 9",\
34 "[5] 9",\
35 "[6] 9",\
36 "[7] 9",\
37 "DAC = DWORD[8] :",\
38 "[0] 35000",\
39 "[1] 35000",\
40 "[2] 35000",\
41 "[3] 35000",\
42 "[4] 35000",\
43 "[5] 35000",\
44 "[6] 9190",\
45 "[7] 9190",\
46 NULL
47};
48
59 _link(link), _board(board), _moduleID(moduleID)
60{
61 _handle = -1;
62 _odb_handle = 0;
63 verbose = 0;
64 _settings_loaded=false;
66 _running = false;
67}
74
81{
82 stringstream txt;
83 txt << "B" << _board;
84 return txt.str();
85}
92{
93 return (_handle >= 0);
94}
101{
102 return _running;
103}
110{
111 if (verbose) cout << "Opening device (l,b) = (" << _link << "," << _board << ")" << endl;
113
114#if SIMULATION //Simulate success opening device
116 _handle = 1; //random
117#else
119#endif
120
121 if (sCAEN != CAENComm_Success) _handle = -1;
122 return sCAEN;
123}
130{
131 if (verbose) cout << "Closing device (l,b) = (" << _link << "," << _board << ")" << endl;
133
134#if SIMULATION //Simulate success closing device
136#else
138#endif
139
140
141 _handle = -1;
142 return sCAEN;
143}
154{
155 if (verbose) cout << GetName() << "::StartRun()\n";
156 if (IsRunning()) {
157 cout << "Error: trying to start already started board" << endl;
158 return (CAENComm_ErrorCode)1;
159 }
160 if (!IsConnected()) {
161 cout << "Error: trying to start disconnected board" << endl;
162 return (CAENComm_ErrorCode)1;
163 }
165 {
166 cm_msg(MINFO, "feoV1740", "Note: settings on board %s touched. Re-initializing board.",
167 GetName().c_str());
168 cout << "reinitializing" << endl;
170 }
171
173 if (e == CAENComm_Success) _running=true;
174 return e;
175}
202{
203#if SIMULATION
204 return CAENComm_Success;
205#else
206 return ov1740_Setup(_handle, mode);
207#endif
208}
218{
219#if SIMULATION
220 return CAENComm_Success;
221#else
223#endif
224}
233{
234 if (verbose >= 2) cout << GetName() << "::ReadReg(" << hex << address << ")" << endl;
235#if SIMULATION
236 return CAENComm_Success;
237#else
238 return CAENComm_Read32(_handle, address, val);
239#endif
240}
249{
250 if (verbose >= 2) cout << GetName() << "::WriteReg(" << hex << address << "," << val << ")" << endl;
251#if SIMULATION
252 return CAENComm_Success;
253#else
254 return CAENComm_Write32(_handle, address, val);
255#endif
256}
257
259#define MAX_BLT_READ_SIZE 10000
271{
273 int tempnw = 0;
274 *dwords_read = 0;
275
276#if SIMULATION //read maximum size allowed
279#else
281#endif
282
283 if (verbose>=2) cout << "Start of ReadEvent... "
284 << "size_rem = " << size_remaining << " " << sCAEN << endl;
285
286 while (size_remaining > 0 && sCAEN == CAENComm_Success)
287 {
288#if SIMULATION //read random 32-bit integers
290 for (WORD i = 0; i < to_read; i++)
291 *data_pos++ = rand();
293 tempnw = to_read; //simulate success reading all data
294#else
297#endif
298
299 if (verbose>=2) cout << sCAEN << " = BLTRead(handle=" << _handle
300 << ", addr=" << V1740_EVENT_READOUT_BUFFER
301 << ", data_pos=" << data_pos
302 << ", to_read=" << to_read
303 << ", tempnw returned " << tempnw << ");" << endl;
306 data_pos += tempnw;
307 }
308 if (verbose>=2) cout << "End of ReadEvent... "
309 << "dwords_read = " << *dwords_read << endl;;
310
311 return sCAEN;
312}
322{
323 if (verbose) cout << "Sending Trigger (l,b) = (" << _link << "," << _board << ")" << endl;
324 return WriteReg(V1740_SOFTWARE_TRIGGER, 0x1);
325}
344{
345 char set_str[80];
346 int status,size;
347
348#if SIMULATION
349 sprintf(set_str, "/Equipment/FEv1740_SIM/Settings/Board%d", _board);
350#else
351 sprintf(set_str, "/Equipment/FEv1740/Settings/Board%d", _board);
352#endif
353
354 if (verbose) cout << GetName() << "::SetODBRecord(" << h << "," << set_str << ",...)" << endl;
355
356 //create record if doesn't exist and find key
359 if (status != DB_SUCCESS) cm_msg(MINFO,"FE","Key %s not found", set_str);
360
361 //hotlink
362 // size = sizeof(config_type);
363 size = sizeof(V1740_CONFIG_SETTINGS);
365
366 //get actual record
367 status = db_get_record(h, _odb_handle, &config, &size, 0);
368
369 if (status == DB_SUCCESS) _settings_loaded = true;
370 _settings_touched = true;
371
372 return status; //== DB_SUCCESS for success
373}
383{
384 if (!_settings_loaded) {
385 cout << "Error: cannot call InitializeForAcq() without settings loaded properly" << endl;
386 return -1; }
387 if (!IsConnected()) {
388 cout << "Error: trying to call InitializeForAcq() to unconnected board" << endl;
389 return -1; }
390 if (IsRunning()) {
391 cout << "Error: trying to call InitializeForAcq() to already running board" << endl;
392 return -1; }
393
394 if (_settings_loaded && !_settings_touched) return 0; //don't do anything if settings haven't been changed
395
398
399 //use preset setting if enabled
400 if (config.setup != 0) {
402 //else use odb values
403 } else {
404
406 printf("group config 0x%x\n", config.group_config);
417 WriteReg(V1740_MONITOR_MODE, 0x3); // buffer occupancy
418 printf("group config 0x%x\n", temp);
419 /*sCAEN = ov1740_GroupConfig(GetHandle()
420 , config.trigger_positive_pulse == 1 ? V1740_TRIGGER_OVERTH : V1740_TRIGGER_UNDERTH);*/
422
423 // Set individual channel stuff
424 for (int i=0;i<8;i++) {
425 //group threshold
428 printf("Threshold[%i] = %d \n", i, temp);
429 //set DAC
431 printf("DAC[%i] = %d \n", i, temp);
432 //disable channel triggers
434 }
435
436 // Doesn't set the ID in the data stream!
439 }
440
441 _settings_touched = false;
442 UNUSED(sCAEN);
443
444 //ready to do startrun
445
446 return 0;
447}
454{
455 // Verify Board Type
456 uint32_t version = 0;
457 const uint32_t v1740_board_type = 0x04;
459 if((version & 0xFF) != v1740_board_type)
460 cm_msg(MINFO,"feoV1740","*** WARNING *** Trying to use a v1740 frontend with another"
461 " type of board. Results will be unexpected!");
462
463 UNUSED(sCAEN);
464}
469{
470#if !SIMULATION
471 DWORD temp;
473 cout << " *** regs: ";
474 sCAEN = CAENComm_Read32(_handle, V1740_EVENT_SIZE, &temp); cout << "E_SIZE=0x" << hex << temp << " ";
475 sCAEN = CAENComm_Read32(_handle, V1740_EVENT_STORED, &temp); cout << "E_STORED=0x" << hex << temp << " ";
476 sCAEN = CAENComm_Read32(_handle, V1740_GROUP_BUFFER_OCCUPANCY, &temp); cout << "GRP_BUFF_OCC[0]=0x" << temp << " ";
477 sCAEN = CAENComm_Read32(_handle, V1740_ACQUISITION_STATUS, &temp); cout << "ACQ_STATUS=0x" << temp << " lam=" << (temp & 0x4);
478 //sCAEN = CAENComm_Read32(_handle, V1740_BLT_EVENT_NB, &temp); cout << "BLT_EVENT_NB=0x" << temp << " ";
479 //sCAEN = CAENComm_Read32(_handle, V1740_GROUP_CONFIG, &temp); cout << "GROUP_CONFIG= " << temp << " ";
480 //sCAEN = CAENComm_Read32(_handle, V1740_GROUP_EN_MASK, &temp); cout << "GROUP_EN_MASK= " << temp << " ";
481 cout << dec << endl;
482 UNUSED(sCAEN);
483#endif
484}
v1740CONET2(int link, int board, int moduleID)
Constructor for the module object.
bool _settings_touched
ODB settings touched.
bool IsRunning()
Get run status.
int GetHandle()
returns device handler
static const char * config_str[]
Configuration string for this module. (ODB: /Equipment/[eq_name]/Settings/[board_name]/)
struct v1740CONET2::V1740_CONFIG_SETTINGS config
instance of config structure
~v1740CONET2()
Destructor for the module object.
CAENComm_ErrorCode ReadEvent(DWORD *, int *)
Read event buffer.
int SetODBRecord(HNDLE h, void(*cb_func)(INT, INT, void *))
Set the ODB record for this module.
bool IsConnected()
Get connected status.
CAENComm_ErrorCode SendTrigger()
Send a software trigger to the board.
CAENComm_ErrorCode StartRun()
Start data acquisition.
int _handle
Device handler.
void CheckBoardType()
Check board type.
CAENComm_ErrorCode Connect()
Connect the board through the optical link.
CAENComm_ErrorCode ReadReg(DWORD, DWORD *)
Read 32-bit register.
CAENComm_ErrorCode SetupPreset(int)
Setup board registers using preset (see ov1720.c:ov1720_Setup())
CAENComm_ErrorCode Disconnect()
Disconnect the board through the optical link.
CAENComm_ErrorCode StopRun()
Start data acquisition.
std::string GetName()
Get short string identifying the module's board number.
int InitializeForAcq()
Initialize the hardware for data acquisition.
CAENComm_ErrorCode WriteReg(DWORD, DWORD)
Write to 32-bit register.
HNDLE _odb_handle
CAENComm_ErrorCode AcqCtl(uint32_t)
Control data acquisition.
int _link
Optical link number.
bool _settings_loaded
ODB settings loaded.
void ShowRegs()
Misc reg printout, for debug purposes.
int _board
Module/Board number.
bool _running
Run in progress.
#define DB_SUCCESS
Definition midas.h:631
unsigned short int WORD
Definition mcstd.h:49
unsigned int DWORD
Definition mcstd.h:51
#define MINFO
Definition midas.h:560
#define MODE_READ
Definition midas.h:370
#define UNUSED
Definition mongoose6.h:113
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
INT db_open_record(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info)
Definition odb.cxx:13291
INT db_get_record(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT align)
Definition odb.cxx:11709
char * strcomb(const char **list)
Definition odb.cxx:571
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
Definition odb.cxx:12800
void * data
Definition mana.cxx:268
INT i
Definition mdump.cxx:32
INT HNDLE
Definition midas.h:132
int INT
Definition midas.h:129
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Settings structure for this v1740 module.
INT setup
Initial board setup mode number.
DWORD post_trigger
0x8114@[31.. 0]
DWORD group_config
0x8000@[19.. 0]
DWORD trigger_output
0x8110@[31.. 0]
INT buffer_organization
0x800C@[ 3.. 0]
DWORD dac[8]
0x1n98@[15.. 0]
DWORD trigger_source
0x810C@[31.. 0]
DWORD threshold[8]
0x1n80@[11.. 0]
static double e(void)
Definition tinyexpr.c:136
#define MAX_BLT_READ_SIZE
Maximum size of data to read using BLT (32-bit) cycle.