102#include <sys/resource.h>
111#include "ov1720drv.h"
122#define NBLINKSPERA3818 1
123#define NBLINKSPERFE 1
124#define NB1720PERLINK 2
125#define NBV1720TOTAL 2
131#define FE_NAME "feov1720_SIM"
133#define FE_NAME "feov1720"
136#define UNUSED(x) ((void)(x))
262 if (hseq ==
itv1720->GetODBHandle()){
264 itv1720->SetSettingsTouched(
true);
265 printf(
"Settings %s touched. Changes will take effect at start of next run.\n",
key.
name);
288 for (
int iBoard=0; iBoard < Nv1720; iBoard++)
290 printf(
"<<< Init board %i\n", iBoard);
292 ov1720[iBoard].verbose = 1;
298 CAENComm_ErrorCode sCAEN;
299 sCAEN =
ov1720[iBoard].Connect();
300 if (sCAEN != CAENComm_Success) {
301 cm_msg(
MERROR,
"fe",
"Could not connect to board; error:%d", sCAEN);
304 printf(
"Connected successfully to module; handle: %d\n",
ov1720[iBoard].GetHandle());
306 ov1720[iBoard].InitializeForAcq();
307 ov1720[iBoard].mZLE =
false;
315 if( sched_setaffinity(0,
sizeof(
mask), &
mask) < 0 ){
316 printf(
"ERROR: affinity not set\n");
318 printf(
">>> End of Init.\n\n");
329 printf(
"<<< No index supplied! Assuming only 1 frontend only and starting all boards on all links\n");
334 printf(
"<<< Begin of Init \n link:%i, board:%i\n", iLink, iBoard);
341 ov1720.back().verbose = 1;
347 printf(
"Opening optical interface Link %d, Board %d\n", iLink, iBoard);
348 CAENComm_ErrorCode sCAEN;
349 sCAEN =
ov1720.back().Connect();
350 if (sCAEN != CAENComm_Success) {
351 cm_msg(
MERROR,
"fe",
"Link#:%d iBoard#:%d error:%d", iLink, iBoard, sCAEN);
355 printf(
"Link#:%d Board#:%d Module_Handle[%d]:%d (active:%d)\n",
356 iLink, iBoard, moduleID,
ov1720.back().GetHandle(), tNActivev1720);
358 ov1720.back().InitializeForAcq();
367 printf(
"Incorrect setup: the number of boards controlled by each frontend"
368 " is not a fraction of the total number of boards.");
372 if(feIndex < 0 || feIndex > maxIndex){
373 printf(
"Front end index must be between 0 and %d\n", maxIndex);
379 for (
int iLink=firstLink; iLink <= lastLink; iLink++)
384 printf(
"<<< Begin of Init \n feIndex:%i, link:%i, board:%i\n",
385 feIndex, iLink, iBoard);
392 ov1720.back().verbose = 1;
398 printf(
"Opening optical interface Link %d, Board %d\n", iLink, iBoard);
399 CAENComm_ErrorCode sCAEN;
400 sCAEN =
ov1720.back().Connect();
401 if (sCAEN != CAENComm_Success) {
402 cm_msg(
MERROR,
"fe",
"Link#:%d iBoard#:%d error:%d", iLink, iBoard, sCAEN);
406 printf(
"Link#:%d Board#:%d Module_Handle[%d]:%d (active:%d)\n",
407 iLink, iBoard, moduleID,
ov1720.back().GetHandle(), tNActivev1720);
409 ov1720.back().InitializeForAcq();
419 if( sched_setaffinity(0,
sizeof(
mask), &
mask) < 0 ){
420 printf(
"ERROR: affinity not set\n");
424 printf(
">>> End of Init. %d active v1720. Expected %d\n\n",
427 printf(
">>> End of Init. %d active v1720. Expected %d\n\n",
435 printf(
"*** RUNNING SIMULATION ***\n");
475 printf(
"<<< Begin of begin_of_run\n");
477 CAENComm_ErrorCode sCAEN = CAENComm_Success;
483 if (!
itv1720->IsConnected())
continue;
484 printf(
"Starting module iBoard %d\n",
itv1720->GetModuleID());
494 printf(
">>> End of begin_of_run\n\n");
497 return (sCAEN == CAENComm_Success ?
SUCCESS : sCAEN);
515 printf(
"<<< Beging of end_of_run \n");
517 CAENComm_ErrorCode sCAEN = CAENComm_Success;
530 sCAEN =
ov1720[0].Poll(&buffLvl);
532 sCAEN =
ov1720[0].Poll(&buffLvl);
534 cm_msg(
MERROR,
"feov1720:EOR",
"Events left in the v1720: %d",buffLvl);
538 printf(
">>> End Of end_of_run\n\n");
541 return (sCAEN == CAENComm_Success ?
SUCCESS : sCAEN);
623 register DWORD buffLvl;
624 CAENComm_ErrorCode sCAEN;
628 sCAEN =
ov1720[0].Poll(&buffLvl);
630 if (
debugpolling) printf(
"loop: %d lam:%x, sCAEN:%d\n",
i, lam, sCAEN);
639 ov1720[0].ReadReg(v1720_ACQUISITION_STATUS, &acqStat);
640 ov1720[0].ReadReg(v1720_EVENT_STORED ,&buffLvl);
641 printf(
"vme %i | acq %i | buff lvl %i | count %i\n",lam, acqStat, buffLvl,
Nloop);
695 DWORD *pdata, eStored, eSize, eSizeTot, sn, buffLvl;
701 char statBankName[5];
702 CAENComm_ErrorCode sCAEN;
706 if (!
itv1720->IsConnected())
continue;
711 suseconds_t usStart =
tv.tv_usec;
714 sCAEN =
itv1720->ReadReg(V1720_EVENT_STORED, &eStored);
715 sCAEN =
itv1720->ReadReg(V1720_EVENT_SIZE, &eSize);
719 sCAEN =
itv1720->ReadReg(V1720_VME_STATUS, &lam);
723 printf(
"Module:%02d Hndle:%d S/N:%8.8d Nloop:%d/%d (%5.2f) sCAEN:%d Event Stored:0x%x Event Size:0x%x\n"
728 int module = itv1720->GetModuleID();
732 sprintf(bankName,
"ZL%02d", module);
735 sprintf(bankName,
"W2%02d", module);
741 sCAEN =
itv1720->ReadEvent(pdata, &dwords_read);
744 bk_close(pevent, pdata + dwords_read);
750 itv1720->fillQtBank(pevent, pdata, module);
754 sprintf(statBankName,
"ST%02d", module);
762 *pdata++ =
tv.tv_usec;
768 if (sn % 100 == 0) printf(
".");
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
int Nloop
Number of loops executed in event polling.
void seq_callback(INT hDB, INT hseq, void *info)
Sequencer callback info.
INT max_event_size
maximum event size produced by this frontend
INT frontend_exit()
Frontend exit.
BOOL debugpolling
debug msgs polling loop
bool runStopRequested
stop run requested
INT frontend_init()
Frontend initialization.
BOOL debugtrigger
debug msgs read trigger event
INT event_buffer_size
buffer size to hold events
bool runInProgress
run is in progress
#define EQ_TRGMSK
Trigger mask.
INT max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
#define NBV1720TOTAL
Number of v1720 boards in total.
INT interrupt_configure(INT cmd, INT source, POINTER_T adr)
Interrupt configuration (not implemented)
int Ncount
Loop count for event polling timeout.
BOOL debug
debug printouts
#define NB1720PERLINK
Number of daisy-chained v1720s per optical link.
void interrupt_routine(void)
Interrupt Service Routine.
#define NBLINKSPERFE
Number of optical links controlled by each frontend.
INT poll_event(INT source, INT count, BOOL test)
Polling routine for events.
#define FE_NAME
Frontend name.
INT read_trigger_event(char *pevent, INT off)
Event readout.
vector< v1720CONET2 > ov1720
objects for the v1720 modules controlled by this frontend
EQUIPMENT equipment[]
Main structure for midas equipment.
INT display_period
a frontend status page is displayed with this frequency in ms
char * frontend_name
The frontend name (client name) as seen by other MIDAS clients.
char * frontend_file_name
The frontend file name, don't change it.
INT begin_of_run(INT run_number, char *error)
Begin of Run.
INT frontend_loop()
Frontend loop.
#define NBLINKSPERA3818
Number of optical links used per A3818.
INT end_of_run(INT run_number, char *error)
End of Run.
INT read_scaler_event(char *pevent, INT off)
Placeholder.
vector< v1720CONET2 >::iterator itv1720
iterator
INT bk_close(void *event, void *pdata)
void bk_init32(void *event)
void bk_create(void *event, const char *name, WORD type, void **pdata)
INT bk_size(const void *event)
INT cm_transition(INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag)
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
#define CMD_INTERRUPT_ATTACH
#define CMD_INTERRUPT_DISABLE
#define CMD_INTERRUPT_ENABLE
#define CMD_INTERRUPT_DETACH
INT ss_sleep(INT millisec)
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
int set_equipment_status(const char *name, const char *equipment_status, const char *status_class)
int gettimeofday(struct timeval *tp, void *tzp)