MIDAS
Loading...
Searching...
No Matches
feoV1740.cxx
Go to the documentation of this file.
1/****************************************************************************/
45#include <stdio.h>
46#include <stdlib.h>
47
48#include <vector>
49using std::vector;
50
51#include "midas.h"
52#include "mvmestd.h"
53
54extern "C" {
55#include "CAENComm.h"
56}
57
58#include "v1740CONET2.hxx"
59
60using namespace std;
61
62#define Nv1740 1
63#define EQ_EVID 4
64#define EQ_TRGMSK 0
65
66#if SIMULATION
67#define FE_NAME "feoV1740_SIM"
68#else
69#define FE_NAME "feoV1740"
70#endif
71
72#define UNUSED(x) ((void)(x))
73
74/* Globals */
75/* Hardware */
76extern HNDLE hDB;
77extern BOOL debug;
78
79/* make frontend functions callable from the C framework */
80#ifdef __cplusplus
81extern "C" {
82#endif
83
84/*-- Globals -------------------------------------------------------*/
85
87char *frontend_name = (char*)FE_NAME;
95INT max_event_size = 32 * 34000;
97INT max_event_size_frag = 5 * 1024 * 1024;
100
101bool runInProgress = false;
102bool runOver = false;
103bool runStopRequested = false;
104
105/*-- Function declarations -----------------------------------------*/
108INT begin_of_run(INT run_number, char *error);
109INT end_of_run(INT run_number, char *error);
110INT pause_run(INT run_number, char *error);
111INT resume_run(INT run_number, char *error);
113extern void interrupt_routine(void);
114
115INT read_trigger_event(char *pevent, INT off);
116INT read_scaler_event(char *pevent, INT off);
117
118/*-- Equipment list ------------------------------------------------*/
119#undef USE_INT
122{
123 {
124#if SIMULATION
125 "FEv1740_SIM", /* equipment name */
126#else
127 "FEv1740", /* equipment name */
128#endif
129 {
130 EQ_EVID, EQ_TRGMSK, /* event ID, trigger mask */
131 "SYSTEM", /* event buffer */
132
133#ifdef USE_INT
134 EQ_INTERRUPT, /* equipment type */
135#else
136 EQ_POLLED, /* equipment type */
137#endif
138
139 LAM_SOURCE(0, 0x0), /* event source crate 0, all stations */
140 "MIDAS", /* format */
141 TRUE, /* enabled */
142 RO_RUNNING, /* read only when running */
143 500, /* poll for 500ms */
144 0, /* stop run after this event limit */
145 0, /* number of sub events */
146 0, /* don't log history */
147 "", "", ""
148 },
149 read_trigger_event, /* readout routine */
150 },
151 {""}
152};
153
154#ifdef __cplusplus
155}
156#endif
157
158// v1740 object
160vector<v1740CONET2>::iterator itv1740;
161
162
163/********************************************************************/
164/********************************************************************/
165/********************************************************************/
166
177{
178 KEY key;
179
180 for (itv1740 = ov1740.begin(); itv1740 != ov1740.end(); ++itv1740) {
181 if (hseq == itv1740->GetODBHandle()) {
183 itv1740->SetSettingsTouched(true);
184 printf("Settings %s touched. Changes will take effect at start of next run.\n", key.name);
185 }
186 }
187}
188
199{
200 set_equipment_status(equipment[0].name, "Initializing...", "#FFFF00");
201
202 // Suppress watchdog for PCIe for now
204
205 // --- Get the frontend index. Derive the Optical link number
207
208 int tNActivev1740=0; //Number of v1740 boards activated at the end of frontend_init
209
210 for (int iBoard=0; iBoard < Nv1740; iBoard++)
211 {
212 printf("<<< Init board %i\n", iBoard);
213
214 //If no index supplied, use link 0, else use index as link number
215 if(feIndex == -1)
216 ov1740.push_back(v1740CONET2(0, iBoard, iBoard));
217 else
218 ov1740.push_back(v1740CONET2(feIndex, iBoard, iBoard));
219
220 ov1740.back().verbose = 1;
221
222 //load ODB settings
223 ov1740.back().SetODBRecord(hDB,seq_callback);
224
225 // Open Optical interface
227 sCAEN = ov1740.back().Connect();
228 if (sCAEN != CAENComm_Success) {
229 cm_msg(MERROR, "fe", "Could not connect to board; error:%d", sCAEN);
230 }
231 else {
233 printf("Board#:%d Module_Handle[%d]:%d (active:%d)\n",
234 iBoard, iBoard, ov1740.back().GetHandle(), tNActivev1740);
235
236 ov1740.back().CheckBoardType();
237 }
238 }
239
240 printf(">>> End of Init. %d active v1740. Expected %d\n\n", tNActivev1740, Nv1740);
241
242 set_equipment_status(equipment[0].name, "Initialized", "#00ff00");
243 printf("end of Init: %d\n", SUCCESS);
244
245#if SIMULATION
246 printf("*** RUNNING SIMULATION ***\n");
247#endif
248
249 return SUCCESS;
250}
251
260{
261 set_equipment_status(equipment[0].name, "Exiting...", "#FFFF00");
262 cout << "frontend_exit";
263
264 for (itv1740 = ov1740.begin(); itv1740 != ov1740.end(); ++itv1740) {
265 if (itv1740->IsConnected()){
266 cm_msg(MINFO,"exit", "Closing handle %d", itv1740->GetHandle());
267 itv1740->Disconnect();
268 }
269 }
270
271 set_equipment_status(equipment[0].name, "Exited", "#00ff00");
272 printf("End of exit\n");
273 return SUCCESS;
274}
275
286{
287
288 set_equipment_status(equipment[0].name, "Starting run...", "#FFFF00");
289
290 printf("<<< Begin of begin_of_run\n");
291
292 CAENComm_ErrorCode sCAEN = CAENComm_Success; //hardcoded for now
293
294 for (itv1740 = ov1740.begin(); itv1740 != ov1740.end(); ++itv1740) {
295 if (! itv1740->IsConnected()) continue; // Skip unconnected board
296
297 // //Done at SetOdbRecord (frontend_init)
298 // size = sizeof(V1740_CONFIG_SETTINGS);
299 // if ((status = db_get_record (hDB, hSet, &tsvc, &size, 0)) != DB_SUCCESS)
300 // return status;
301
302 itv1740->InitializeForAcq();
303 itv1740->StartRun();
304 }
305
306 runInProgress = true;
307
308 //------ FINAL ACTIONS before BOR -----------
309 set_equipment_status(equipment[0].name, "Started run", "#00ff00");
310 printf(">>> End of begin_of_run\n\n");
311 return (sCAEN == CAENComm_Success ? SUCCESS : sCAEN);
312}
313
324{
325 set_equipment_status(equipment[0].name, "Ending run...", "#FFFF00");
326
327 printf("<<< Begin of end_of_run \n");
328 // Stop run
331
332 for (itv1740 = ov1740.begin(); itv1740 != ov1740.end(); ++itv1740) {
333 if (itv1740->IsConnected()) { // Skip unconnected board
334 sCAEN = itv1740->StopRun();
335
338
339 cout << "End of EOR. handle=" << itv1740->GetHandle() << " link=" << itv1740->GetLink()
340 << " ACQ_STATUS=" << status << " EV_STORED=" << eStored << " sCAEN=" << sCAEN << endl;
341 }
342 }
343
344 // Stop DAQ for seting up the parameters
345 runOver = false;
346 runStopRequested = false;
347 runInProgress = false;
348
349 printf(">>> End Of end_of_run\n\n");
350 set_equipment_status(equipment[0].name, "Ended run", "#00ff00");
351
352 return (sCAEN == CAENComm_Success ? SUCCESS : sCAEN);
353}
354
366{
367 cout << "pause";
368
369 runInProgress = false;
370 return SUCCESS;
371}
372
384{
385 cout << "resume";
386 runInProgress = true;
387 return SUCCESS;
388}
389
399{
400 cout << "frontend_lopp";
401 /* if frontend_call_loop is true, this routine gets called when
402 the frontend is idle or once between every event */
403 char str[128];
404 static DWORD evlimit;
405
406 if (runStopRequested && !runOver) {
407 db_set_value(hDB,0,"/logger/channels/0/Settings/Event limit", &evlimit, sizeof(evlimit), 1, TID_DWORD);
408 if (cm_transition(TR_STOP, 0, str, sizeof(str), ASYNC, FALSE) != CM_SUCCESS) {
409 cm_msg(MERROR, "feodeap", "cannot stop run: %s", str);
410 }
411 runInProgress = false;
412 runOver = true;
413 cm_msg(MERROR, "feodeap","feodeap Stop requested");
414 }
415 return SUCCESS;
416}
417
418/*------------------------------------------------------------------*/
419/********************************************************************\
420 Readout routines for different events
421\********************************************************************/
422int Nloop;
424
425// ___________________________________________________________________
426/*-- Trigger event routines ----------------------------------------*/
436extern "C" INT poll_event(INT source, INT count, BOOL test)
437/* Polling routine for events. Returns TRUE if event
438 is available. If test equals TRUE, don't return. The test
439 flag is used to time the polling */
440{
441
442 register int i; // , mod=-1;
443 register uint32_t lam = 0;
444 // register uint32_t event_size = 0;
446
447 for (i=0; i<count; i++)
448 {
450 UNUSED(sCAEN);
451 lam &= 0x8;
452
453 if (lam) {
454 Nloop = i; Ncount = count;
455 if (!test)
456 return lam;
457 }
458 }
459
460 return 0;
461}
462
475extern "C" INT interrupt_configure(INT cmd, INT source, POINTER_T adr)
476{
477 cout << "interrupt_configure";
478 switch (cmd) {
480 break;
482 break;
484 break;
486 break;
487 }
488 return SUCCESS;
489}
490
503{
504 if (!runInProgress) return 0;
505
506 DWORD *pdata;
508 int dwords_read;
509 // int sLoop, eEvent;
510
511 sn = SERIAL_NUMBER(pevent);
512 bk_init32(pevent);
513
515
516 for (itv1740 = ov1740.begin(); itv1740 != ov1740.end(); ++itv1740) {
517 if (!itv1740->IsConnected()) continue; // Skip unconnected board
518
520 if (event_size > 0)
521 {
522
523 char bankName[5];
524 sprintf(bankName,"W4%02d",itv1740->GetLink());
525 bk_create(pevent, bankName, TID_DWORD, &pdata);
526
527 sCAEN = itv1740->ReadEvent(pdata, &dwords_read);
528
529 //(eStored > 1) ? sLoop = 2 : sLoop = eStored;
530 // for (eEvent=0; eEvent < sLoop; eEvent++) {
531 //sCAEN = CAENComm_Read32(v1740->GetHandle(), V1740_EVENT_SIZE, &eSize);
532
533 bk_close(pevent, pdata + dwords_read);
534 }
535 }
536
537 //primitive progress bar
538 if (sn % 100 == 0) printf(".");
539
540 UNUSED(sCAEN);
541 return bk_size(pevent);
542}
543
555{
556 /* init bank structure */
557 bk_init(pevent);
558 return 0; // bk_size(pevent);
559}
#define FALSE
Definition cfortran.h:309
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
Definition feoV1740.cxx:91
bool runOver
run is over
Definition feoV1740.cxx:102
int Nloop
Number of loops executed in event polling.
Definition feoV1740.cxx:422
void seq_callback(INT hDB, INT hseq, void *info)
Sequencer callback info.
Definition feoV1740.cxx:176
INT max_event_size
maximum event size produced by this frontend
Definition feoV1740.cxx:95
INT frontend_exit()
Frontend exit.
Definition feoV1740.cxx:259
bool runStopRequested
stop run requested
Definition feoV1740.cxx:103
INT frontend_init()
Frontend initialization.
Definition feoV1740.cxx:198
INT event_buffer_size
buffer size to hold events
Definition feoV1740.cxx:99
bool runInProgress
run is in progress
Definition feoV1740.cxx:101
#define EQ_TRGMSK
Trigger mask.
Definition feoV1740.cxx:64
INT max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
Definition feoV1740.cxx:97
INT interrupt_configure(INT cmd, INT source, POINTER_T adr)
Interrupt configuration (not implemented)
Definition feoV1740.cxx:475
int Ncount
Loop count for event polling timeout.
Definition feoV1740.cxx:423
BOOL debug
debug printouts
Definition mana.cxx:254
#define UNUSED(x)
Suppress compiler warnings.
Definition feoV1740.cxx:72
void interrupt_routine(void)
Interrupt Service Routine.
INT poll_event(INT source, INT count, BOOL test)
Polling routine for events.
Definition feoV1740.cxx:436
#define FE_NAME
Frontend name.
Definition feoV1740.cxx:69
INT read_trigger_event(char *pevent, INT off)
Trigger event readout.
Definition feoV1740.cxx:502
EQUIPMENT equipment[]
Main structure for midas equipment.
Definition feoV1740.cxx:121
HNDLE hDB
main ODB handle
Definition mana.cxx:207
INT display_period
a frontend status page is displayed with this frequency in ms
Definition feoV1740.cxx:93
char * frontend_name
The frontend name (client name) as seen by other MIDAS clients.
Definition feoV1740.cxx:87
char * frontend_file_name
The frontend file name, don't change it.
Definition feoV1740.cxx:89
#define EQ_EVID
Event ID.
Definition feoV1740.cxx:63
INT begin_of_run(INT run_number, char *error)
Begin of Run.
Definition feoV1740.cxx:285
INT frontend_loop()
Frontend loop.
Definition feoV1740.cxx:398
INT end_of_run(INT run_number, char *error)
End of Run.
Definition feoV1740.cxx:323
INT read_scaler_event(char *pevent, INT off)
Scaler event readout.
Definition feoV1740.cxx:554
vector< v1740CONET2 > ov1740
objects for the v1740 modules controlled by this frontend
Definition feoV1740.cxx:159
vector< v1740CONET2 >::iterator itv1740
iterator
Definition feoV1740.cxx:160
#define Nv1740
Set the number of v1720 modules to be used.
Definition feoV1740.cxx:62
DWORD evlimit
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
void bk_init(void *event)
Definition midas.cxx:16406
void bk_init32(void *event)
Definition midas.cxx:16469
void bk_create(void *event, const char *name, WORD type, void **pdata)
Definition midas.cxx:16561
INT bk_size(const void *event)
Definition midas.cxx:16495
INT cm_transition(INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag)
Definition midas.cxx:5286
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
Definition midas.cxx:3283
#define CM_SUCCESS
Definition midas.h:582
#define CMD_INTERRUPT_ATTACH
Definition midas.h:822
#define CMD_INTERRUPT_DISABLE
Definition midas.h:821
#define CMD_INTERRUPT_ENABLE
Definition midas.h:820
#define CMD_INTERRUPT_DETACH
Definition midas.h:823
unsigned int DWORD
Definition mcstd.h:51
#define SUCCESS
Definition mcstd.h:54
#define EQ_POLLED
Definition midas.h:415
#define MINFO
Definition midas.h:560
#define MERROR
Definition midas.h:559
#define EQ_INTERRUPT
Definition midas.h:416
#define TR_STOP
Definition midas.h:406
#define RO_RUNNING
Definition midas.h:426
#define TID_DWORD
Definition midas.h:336
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6019
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
Definition odb.cxx:5261
void ** info
Definition fesimdaq.cxx:41
INT run_number[2]
Definition mana.cxx:246
double count
Definition mdump.cxx:33
KEY key
Definition mdump.cxx:34
INT i
Definition mdump.cxx:32
INT get_frontend_index()
Definition mfe.cxx:2391
int set_equipment_status(const char *name, const char *equipment_status, const char *status_class)
Definition mfe.cxx:884
INT HNDLE
Definition midas.h:132
DWORD BOOL
Definition midas.h:105
int INT
Definition midas.h:129
#define LAM_SOURCE(c, s)
Definition midas.h:469
#define TRUE
Definition midas.h:182
#define POINTER_T
Definition midas.h:166
#define SERIAL_NUMBER(e)
Definition midas.h:880
#define resume_run
#define name(x)
Definition midas_macro.h:24
#define pause_run
program test
Definition miniana.f:6
int event_size
Definition msysmon.cxx:527
char str[256]
Definition odbhist.cxx:33
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
Definition midas.h:1026
char name[NAME_LENGTH]
Definition midas.h:1029