MIDAS
Loading...
Searching...
No Matches
feoV1740.cxx File Reference
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "midas.h"
#include "mvmestd.h"
#include "CAENComm.h"
#include "v1740CONET2.hxx"
Include dependency graph for feoV1740.cxx:

Go to the source code of this file.

Macros

#define Nv1740   1
 Set the number of v1720 modules to be used.
 
#define EQ_EVID   4
 Event ID.
 
#define EQ_TRGMSK   0
 Trigger mask.
 
#define FE_NAME   "feoV1740"
 Frontend name.
 
#define UNUSED(x)   ((void)(x))
 Suppress compiler warnings.
 

Functions

INT frontend_init ()
 Frontend initialization.
 
INT frontend_exit ()
 Frontend exit.
 
INT begin_of_run (INT run_number, char *error)
 Begin of Run.
 
INT end_of_run (INT run_number, char *error)
 End of Run.
 
INT pause_run (INT run_number, char *error)
 Pause Run.
 
INT resume_run (INT run_number, char *error)
 Resume Run.
 
INT frontend_loop ()
 Frontend loop.
 
void interrupt_routine (void)
 Interrupt Service Routine.
 
INT read_trigger_event (char *pevent, INT off)
 Trigger event readout.
 
INT read_scaler_event (char *pevent, INT off)
 Scaler event readout.
 
void seq_callback (INT hDB, INT hseq, void *info)
 Sequencer callback info.
 
INT poll_event (INT source, INT count, BOOL test)
 Polling routine for events.
 
INT interrupt_configure (INT cmd, INT source, POINTER_T adr)
 Interrupt configuration (not implemented)
 

Variables

HNDLE hDB
 main ODB handle
 
BOOL debug
 debug printouts
 
charfrontend_name = (char*)FE_NAME
 The frontend name (client name) as seen by other MIDAS clients.
 
charfrontend_file_name = (char*)__FILE__
 The frontend file name, don't change it.
 
BOOL frontend_call_loop = FALSE
 frontend_loop is called periodically if this variable is TRUE
 
INT display_period = 000
 a frontend status page is displayed with this frequency in ms
 
INT max_event_size = 32 * 34000
 maximum event size produced by this frontend
 
INT max_event_size_frag = 5 * 1024 * 1024
 maximum event size for fragmented events (EQ_FRAGMENTED)
 
INT event_buffer_size = 200 * max_event_size
 buffer size to hold events
 
bool runInProgress = false
 run is in progress
 
bool runOver = false
 run is over
 
bool runStopRequested = false
 stop run requested
 
EQUIPMENT equipment []
 Main structure for midas equipment.
 
vector< v1740CONET2ov1740
 objects for the v1740 modules controlled by this frontend
 
vector< v1740CONET2 >::iterator itv1740
 iterator
 
int Nloop
 Number of loops executed in event polling.
 
int Ncount
 Loop count for event polling timeout.
 

Macro Definition Documentation

◆ EQ_EVID

#define EQ_EVID   4

Event ID.

Definition at line 63 of file feoV1740.cxx.

◆ EQ_TRGMSK

#define EQ_TRGMSK   0

Trigger mask.

Definition at line 64 of file feoV1740.cxx.

◆ FE_NAME

#define FE_NAME   "feoV1740"

Frontend name.

Definition at line 69 of file feoV1740.cxx.

◆ Nv1740

#define Nv1740   1

Set the number of v1720 modules to be used.

Definition at line 62 of file feoV1740.cxx.

◆ UNUSED

#define UNUSED (   x)    ((void)(x))

Suppress compiler warnings.

Definition at line 72 of file feoV1740.cxx.

Function Documentation

◆ begin_of_run()

INT begin_of_run ( INT  run_number,
char error 
)

Begin of Run.

Called every run start transition. Set equipment status in ODB, start acquisition on the modules.

Parameters
[in]run_numberNumber of the run being started
[out]errorCan be used to write a message string to midas.log

Definition at line 285 of file feoV1740.cxx.

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}
bool runInProgress
run is in progress
Definition feoV1740.cxx:101
EQUIPMENT equipment[]
Main structure for midas equipment.
Definition feoV1740.cxx:121
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 SUCCESS
Definition mcstd.h:54
int set_equipment_status(const char *name, const char *equipment_status, const char *status_class)
Definition mfe.cxx:884
#define name(x)
Definition midas_macro.h:24
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

◆ end_of_run()

INT end_of_run ( INT  run_number,
char error 
)

End of Run.

Called every stop run transition. Set equipment status in ODB, stop acquisition on the modules.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log

Definition at line 323 of file feoV1740.cxx.

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}
bool runOver
run is over
Definition feoV1740.cxx:102
bool runStopRequested
stop run requested
Definition feoV1740.cxx:103
DWORD status
Definition odbhist.cxx:39
Here is the call graph for this function:

◆ frontend_exit()

INT frontend_exit ( void  )

Frontend exit.

Runs at frontend shutdown. Disconnect hardware and set equipment status in ODB

Returns
Midas status code

Definition at line 259 of file feoV1740.cxx.

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}
#define MINFO
Definition midas.h:560
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
Here is the call graph for this function:

◆ frontend_init()

INT frontend_init ( void  )

Frontend initialization.

Runs once at application startup. We initialize the hardware and optical interfaces and set the equipment status in ODB. We also lock the frontend to once physical cpu core.

Returns
Midas status code

Definition at line 198 of file feoV1740.cxx.

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}
#define FALSE
Definition cfortran.h:309
void seq_callback(INT hDB, INT hseq, void *info)
Sequencer callback info.
Definition feoV1740.cxx:176
HNDLE hDB
main ODB handle
Definition mana.cxx:207
#define Nv1740
Set the number of v1720 modules to be used.
Definition feoV1740.cxx:62
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
Definition midas.cxx:3283
#define MERROR
Definition midas.h:559
INT get_frontend_index()
Definition mfe.cxx:2391
Here is the call graph for this function:

◆ frontend_loop()

INT frontend_loop ( void  )

Frontend loop.

If frontend_call_loop is true, this routine gets called when the frontend is idle or once between every event.

Returns
Midas status code

Definition at line 398 of file feoV1740.cxx.

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}
DWORD evlimit
INT cm_transition(INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag)
Definition midas.cxx:5286
#define CM_SUCCESS
Definition midas.h:582
unsigned int DWORD
Definition mcstd.h:51
#define TR_STOP
Definition midas.h:406
#define TID_DWORD
Definition midas.h:336
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
char str[256]
Definition odbhist.cxx:33
Here is the call graph for this function:

◆ interrupt_configure()

INT interrupt_configure ( INT  cmd,
INT  source,
POINTER_T  adr 
)

Interrupt configuration (not implemented)

Routine for interrupt configuration if equipment is set in EQ_INTERRUPT mode. Not implemented right now, returns SUCCESS.

Parameters
[in]cmdCommand for interrupt events (see midas.h)
[in]sourceEquipment index number
[in]adrInterrupt routine (see mfe.c)
Returns
Midas status code

Definition at line 475 of file feoV1740.cxx.

476{
477 cout << "interrupt_configure";
478 switch (cmd) {
480 break;
482 break;
484 break;
486 break;
487 }
488 return SUCCESS;
489}
#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
Here is the call graph for this function:

◆ interrupt_routine()

void interrupt_routine ( void  )
extern

Interrupt Service Routine.

◆ pause_run()

INT pause_run ( INT  run_number,
char error 
)

Pause Run.

Called every pause run transition.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log
Returns
Midas status code

Definition at line 365 of file feoV1740.cxx.

366{
367 cout << "pause";
368
369 runInProgress = false;
370 return SUCCESS;
371}
Here is the call graph for this function:

◆ poll_event()

INT poll_event ( INT  source,
INT  count,
BOOL  test 
)

Polling routine for events.

Parameters
[in]sourceEvent source (LAM/IRQ)
[in]countLoop count for event polling timeout
[in]testflag used to time the polling
Returns
1 if event is available, 0 if done polling (no event). If test equals TRUE, don't return.

Definition at line 436 of file feoV1740.cxx.

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}
int Nloop
Number of loops executed in event polling.
Definition feoV1740.cxx:422
int Ncount
Loop count for event polling timeout.
Definition feoV1740.cxx:423
#define UNUSED(x)
Suppress compiler warnings.
Definition feoV1740.cxx:72
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
program test
Definition miniana.f:6
Here is the call graph for this function:

◆ read_scaler_event()

INT read_scaler_event ( char pevent,
INT  off 
)

Scaler event readout.

Placeholder.

Scaler event readout routine. Not used in this example.

Parameters
[in]peventPointer to event buffer
[in]offCaller info (unused here), see mfe.c
Returns
Size of the event

Definition at line 554 of file feoV1740.cxx.

555{
556 /* init bank structure */
557 bk_init(pevent);
558 return 0; // bk_size(pevent);
559}
void bk_init(void *event)
Definition midas.cxx:16406
Here is the call graph for this function:

◆ read_trigger_event()

INT read_trigger_event ( char pevent,
INT  off 
)

Trigger event readout.

Main trigger event readout routine. This is called by the polling or interrupt routines. (see mfe.c). For each module, read the event buffer into a midas data bank.

Parameters
[in]peventPointer to event buffer
[in]offCaller info (unused here), see mfe.c
Returns
Size of the event

Definition at line 502 of file feoV1740.cxx.

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}
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
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
#define SERIAL_NUMBER(e)
Definition midas.h:880
int event_size
Definition msysmon.cxx:527
Here is the call graph for this function:

◆ resume_run()

INT resume_run ( INT  run_number,
char error 
)

Resume Run.

Called every resume run transition.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log
Returns
Midas status code

Definition at line 383 of file feoV1740.cxx.

384{
385 cout << "resume";
386 runInProgress = true;
387 return SUCCESS;
388}
Here is the call graph for this function:

◆ seq_callback()

void seq_callback ( INT  hDB,
INT  hseq,
void info 
)

Sequencer callback info.

Function which gets called when record is updated

Parameters
[in]hDBmain ODB handle
[in]hseqHandle for key where search starts in ODB, zero for root.
[in]infoRecord descriptor additional info

Definition at line 176 of file feoV1740.cxx.

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}
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6019
KEY key
Definition mdump.cxx:34
Definition midas.h:1026
char name[NAME_LENGTH]
Definition midas.h:1029
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ debug

BOOL debug
extern

debug printouts

Definition at line 254 of file mana.cxx.

◆ display_period

INT display_period = 000

a frontend status page is displayed with this frequency in ms

Definition at line 93 of file feoV1740.cxx.

◆ equipment

EQUIPMENT equipment[]

Main structure for midas equipment.

Definition at line 121 of file feoV1740.cxx.

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};
#define EQ_TRGMSK
Trigger mask.
Definition feoV1740.cxx:64
INT read_trigger_event(char *pevent, INT off)
Trigger event readout.
Definition feoV1740.cxx:502
#define EQ_EVID
Event ID.
Definition feoV1740.cxx:63
#define EQ_POLLED
Definition midas.h:415
#define EQ_INTERRUPT
Definition midas.h:416
#define RO_RUNNING
Definition midas.h:426
#define LAM_SOURCE(c, s)
Definition midas.h:469
#define TRUE
Definition midas.h:182

◆ event_buffer_size

INT event_buffer_size = 200 * max_event_size

buffer size to hold events

Definition at line 99 of file feoV1740.cxx.

◆ frontend_call_loop

BOOL frontend_call_loop = FALSE

frontend_loop is called periodically if this variable is TRUE

Definition at line 91 of file feoV1740.cxx.

◆ frontend_file_name

char* frontend_file_name = (char*)__FILE__

The frontend file name, don't change it.

Definition at line 89 of file feoV1740.cxx.

◆ frontend_name

char* frontend_name = (char*)FE_NAME

The frontend name (client name) as seen by other MIDAS clients.

Definition at line 87 of file feoV1740.cxx.

◆ hDB

HNDLE hDB
extern

main ODB handle

Definition at line 207 of file mana.cxx.

◆ itv1740

vector<v1740CONET2>::iterator itv1740

iterator

Definition at line 160 of file feoV1740.cxx.

◆ max_event_size

INT max_event_size = 32 * 34000

maximum event size produced by this frontend

Definition at line 95 of file feoV1740.cxx.

◆ max_event_size_frag

INT max_event_size_frag = 5 * 1024 * 1024

maximum event size for fragmented events (EQ_FRAGMENTED)

Definition at line 97 of file feoV1740.cxx.

◆ Ncount

int Ncount

Loop count for event polling timeout.

Definition at line 423 of file feoV1740.cxx.

◆ Nloop

int Nloop

Number of loops executed in event polling.

Definition at line 422 of file feoV1740.cxx.

◆ ov1740

vector<v1740CONET2> ov1740

objects for the v1740 modules controlled by this frontend

Definition at line 159 of file feoV1740.cxx.

◆ runInProgress

bool runInProgress = false

run is in progress

Definition at line 101 of file feoV1740.cxx.

◆ runOver

bool runOver = false

run is over

Definition at line 102 of file feoV1740.cxx.

◆ runStopRequested

bool runStopRequested = false

stop run requested

Definition at line 103 of file feoV1740.cxx.