13#define UNUSED(x) ((void)(x))
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] :",\
59 _link(link), _board(board), _moduleID(moduleID)
111 if (
verbose) cout <<
"Opening device (l,b) = (" <<
_link <<
"," <<
_board <<
")" << endl;
112 CAENComm_ErrorCode sCAEN;
115 sCAEN = CAENComm_Success;
121 if (sCAEN != CAENComm_Success)
_handle = -1;
131 if (
verbose) cout <<
"Closing device (l,b) = (" <<
_link <<
"," <<
_board <<
")" << endl;
132 CAENComm_ErrorCode sCAEN;
135 sCAEN = CAENComm_Success;
137 sCAEN = CAENComm_CloseDevice(
_handle);
157 cout <<
"Error: trying to start already started board" << endl;
158 return (CAENComm_ErrorCode)1;
161 cout <<
"Error: trying to start disconnected board" << endl;
162 return (CAENComm_ErrorCode)1;
166 cm_msg(
MINFO,
"feoV1740",
"Note: settings on board %s touched. Re-initializing board.",
168 cout <<
"reinitializing" << endl;
172 CAENComm_ErrorCode
e = ov1740_AcqCtl(
_handle, V1740_RUN_START);
173 if (
e == CAENComm_Success)
_running=
true;
186 CAENComm_ErrorCode
e = ov1740_AcqCtl(
_handle, V1740_RUN_STOP);
187 if (
e == CAENComm_Success)
_running=
false;
204 return CAENComm_Success;
206 return ov1740_Setup(
_handle, mode);
220 return CAENComm_Success;
222 return ov1740_AcqCtl(
_handle, operation);
234 if (
verbose >= 2) cout <<
GetName() <<
"::ReadReg(" << hex << address <<
")" << endl;
236 return CAENComm_Success;
238 return CAENComm_Read32(
_handle, address, val);
250 if (
verbose >= 2) cout <<
GetName() <<
"::WriteReg(" << hex << address <<
"," << val <<
")" << endl;
252 return CAENComm_Success;
254 return CAENComm_Write32(
_handle, address, val);
259#define MAX_BLT_READ_SIZE 10000
272 DWORD size_remaining, *data_pos =
data, to_read;
277 CAENComm_ErrorCode sCAEN = CAENComm_Success;
280 CAENComm_ErrorCode sCAEN =
ReadReg(V1740_EVENT_SIZE, &size_remaining);
283 if (
verbose>=2) cout <<
"Start of ReadEvent... "
284 <<
"size_rem = " << size_remaining <<
" " << sCAEN << endl;
286 while (size_remaining > 0 && sCAEN == CAENComm_Success)
290 for (
WORD i = 0;
i < to_read;
i++)
291 *data_pos++ = rand();
292 sCAEN = CAENComm_Success;
296 sCAEN = CAENComm_BLTRead(
_handle, V1740_EVENT_READOUT_BUFFER, data_pos, to_read, &tempnw);
300 <<
", addr=" << V1740_EVENT_READOUT_BUFFER
301 <<
", data_pos=" << data_pos
302 <<
", to_read=" << to_read
303 <<
", tempnw returned " << tempnw <<
");" << endl;
304 *dwords_read += tempnw;
305 size_remaining -= tempnw;
308 if (
verbose>=2) cout <<
"End of ReadEvent... "
309 <<
"dwords_read = " << *dwords_read << endl;;
323 if (
verbose) cout <<
"Sending Trigger (l,b) = (" <<
_link <<
"," <<
_board <<
")" << endl;
324 return WriteReg(V1740_SOFTWARE_TRIGGER, 0x1);
349 sprintf(set_str,
"/Equipment/FEv1740_SIM/Settings/Board%d",
_board);
351 sprintf(set_str,
"/Equipment/FEv1740/Settings/Board%d",
_board);
354 if (
verbose) cout <<
GetName() <<
"::SetODBRecord(" << h <<
"," << set_str <<
",...)" << endl;
385 cout <<
"Error: cannot call InitializeForAcq() without settings loaded properly" << endl;
388 cout <<
"Error: trying to call InitializeForAcq() to unconnected board" << endl;
391 cout <<
"Error: trying to call InitializeForAcq() to already running board" << endl;
396 CAENComm_ErrorCode sCAEN;
412 AcqCtl(V1740_COUNT_ACCEPTED_TRIGGER);
416 ReadReg(V1740_GROUP_CONFIG, &temp);
418 printf(
"group config 0x%x\n", temp);
421 WriteReg(V1740_VME_CONTROL, V1740_ALIGN64);
424 for (
int i=0;
i<8;
i++) {
427 sCAEN = ov1740_GroupGet(
GetHandle(),
i, V1740_GROUP_THRESHOLD, &temp);
428 printf(
"Threshold[%i] = %d \n",
i, temp);
431 printf(
"DAC[%i] = %d \n",
i, temp);
433 WriteReg(V1740_GROUP_CH_TRG_MASK + (
i<<8), 0);
456 uint32_t version = 0;
457 const uint32_t v1740_board_type = 0x04;
458 CAENComm_ErrorCode sCAEN =
ReadReg(V1740_BOARD_INFO, &version);
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!");
472 CAENComm_ErrorCode sCAEN;
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);
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.
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.
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
INT db_open_record(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info)
INT db_get_record(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT align)
char * strcomb(const char **list)
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
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]
INT acq_mode
0x8100@[ 1.. 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]
INT custom_size
0x8020@[31.. 0]
DWORD threshold[8]
0x1n80@[11.. 0]
DWORD group_mask
0x8120@[ 7.. 0]
#define MAX_BLT_READ_SIZE
Maximum size of data to read using BLT (32-bit) cycle.