MIDAS
Loading...
Searching...
No Matches
fesimdaq.cxx File Reference
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include "midas.h"
#include <stdint.h>
#include <iostream>
#include <sstream>
#include <unistd.h>
#include "math.h"
#include <sys/time.h>
Include dependency graph for fesimdaq.cxx:

Go to the source code of this file.

Macros

#define SIMDAQSETTINGS_STR(_name)
 

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.
 
INT read_trigger_event (char *pevent, INT off)
 
INT read_scaler_event (char *pevent, INT off)
 Scaler event readout.
 
BOOL wait_end_cycle (int transition, BOOL first)
 
 SIMDAQSETTINGS_STR (simdaqsettings_str)
 
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)
 
double sampleNormal ()
 

Variables

charfrontend_name = "fesimdaq"
 The frontend name (client name) as seen by other MIDAS clients.
 
charfrontend_file_name = __FILE__
 The frontend file name, don't change it.
 
BOOL frontend_call_loop = TRUE
 frontend_loop is called periodically if this variable is TRUE
 
INT display_period = 0
 a frontend status page is displayed with this frequency in ms
 
INT max_event_size = 3 * 1024 * 1024
 maximum event size produced by this frontend
 
INT max_event_size_frag = 2 * 1024 * 1024
 maximum event size for fragmented events (EQ_FRAGMENTED)
 
INT event_buffer_size = 20 * 1000000
 buffer size to hold events
 
void ** info
 
char strin [256]
 
HNDLE hDB
 main ODB handle
 
HNDLE hSet
 
EQUIPMENT equipment []
 Main structure for midas equipment.
 
BOOL finished_readout =FALSE
 
int nremaining = -1
 

Macro Definition Documentation

◆ SIMDAQSETTINGS_STR

#define SIMDAQSETTINGS_STR (   _name)
Value:
const char *_name[] = {\
"[.]",\
"Descrip = STRING : [256] ",\
"Parameter AAA = INT : 0",\
"Parameter BB2 = INT : 0", \
"Parameter CC22 = INT : 0",\
"",\
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24

Definition at line 145 of file fesimdaq.cxx.

145 {\
146"[.]",\
147"Descrip = STRING : [256] ",\
148"Parameter AAA = INT : 0",\
149"Parameter BB2 = INT : 0", \
150"Parameter CC22 = INT : 0",\
151"",\
152NULL }

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 186 of file fesimdaq.cxx.

187{
188
189 nremaining = -1;
191 return SUCCESS;
192}
#define FALSE
Definition cfortran.h:309
#define SUCCESS
Definition mcstd.h:54
int nremaining
Definition fesimdaq.cxx:121
BOOL finished_readout
Definition fesimdaq.cxx:119

◆ 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 196 of file fesimdaq.cxx.

197{
198 return SUCCESS;
199}

◆ 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 178 of file fesimdaq.cxx.

179{
180 printf("Exiting fedcrc!\n");
181 return SUCCESS;
182}
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 157 of file fesimdaq.cxx.

158{
159
160
161 int status = db_check_record(hDB, 0, "/Equipment/SIMDAQ/Settings", strcomb1(simdaqsettings_str).c_str(), TRUE);
162 printf("Status %i\n",status);
163 if (status == DB_STRUCT_MISMATCH) {
164 cm_msg(MERROR, "init_simdaqsettings", "Aborting on mismatching /Equipment/SIMDAQ/Settings");
166 abort();
167 }
168
170 return SUCCESS;
171}
INT cm_disconnect_experiment(void)
Definition midas.cxx:2846
INT cm_register_deferred_transition(INT transition, BOOL(*func)(INT, BOOL))
Definition midas.cxx:3837
#define DB_STRUCT_MISMATCH
Definition midas.h:654
#define MERROR
Definition midas.h:559
#define TR_STOP
Definition midas.h:406
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
std::string strcomb1(const char **list)
Definition odb.cxx:598
INT db_check_record(HNDLE hDB, HNDLE hKey, const char *keyname, const char *rec_str, BOOL correct)
Definition odb.cxx:12972
BOOL wait_end_cycle(int transition, BOOL first)
Definition fesimdaq.cxx:123
HNDLE hDB
main ODB handle
Definition mana.cxx:207
#define TRUE
Definition midas.h:182
DWORD status
Definition odbhist.cxx:39
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 217 of file fesimdaq.cxx.

218{
219 /* if frontend_call_loop is true, this routine gets called when
220 the frontend is idle or once between every event */
221 usleep(10000);
222 return SUCCESS;
223}
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 257 of file fesimdaq.cxx.

257 { INT interrupt_configure(INT cmd, INT source, POINTER_T adr)
258{
259 switch (cmd) {
261 break;
263 break;
265 break;
267 break;
268 }
269 return SUCCESS;
270}
#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
INT interrupt_configure(INT cmd, INT source, POINTER_T adr)
Definition fesimdaq.cxx:251
int INT
Definition midas.h:129
#define POINTER_T
Definition midas.h:166
Here is the call graph for this function:

◆ 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 203 of file fesimdaq.cxx.

204{
205 return SUCCESS;
206}

◆ 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 235 of file fesimdaq.cxx.

235 { INT poll_event(INT source, INT count, BOOL test)
236/* Polling routine for events. Returns TRUE if event
237 is available. If test equals TRUE, don't return. The test
238 flag is used to time the polling */
239{
240 int i;
241
242 for (i = 0; i < count; i++) {
243// cam_lam_read(LAM_SOURCE_CRATE(source), &lam);
244
245// if (lam & LAM_SOURCE_STATION(source))
246 if (!test)
247 return 1;
248 }
249
250 usleep(1000);
251 return 0;
252}
INT poll_event(INT source, INT count, BOOL test)
Definition fesimdaq.cxx:230
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
DWORD BOOL
Definition midas.h:105
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 295 of file ebfe.cxx.

296{
297 DWORD *pdata, a;
298
299 /* init bank structure */
300 bk_init(pevent);
301
302 /* create SCLR bank */
303 bk_create(pevent, Sclx, TID_DWORD, (void**)&pdata);
304
305 /* read scaler bank */
306 for (a = 0; a < N_SCLR; a++)
307 cam24i(CRATE, SLOT_SCLR, a, 0, pdata++);
308
309 bk_close(pevent, pdata);
310
311 return bk_size(pevent);
312}
#define SLOT_SCLR
Definition ebfe.cxx:63
char Sclx[5]
Definition ebfe.cxx:51
#define N_SCLR
Definition ebfe.cxx:56
#define CRATE
Definition ebfe.cxx:59
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
void bk_init(void *event)
Definition midas.cxx:16406
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
EXTERNAL void EXPRT cam24i(const int c, const int n, const int a, const int f, DWORD *d)
unsigned int DWORD
Definition mcstd.h:51
#define TID_DWORD
Definition midas.h:336
Here is the call graph for this function:

◆ read_trigger_event()

INT read_trigger_event ( char pevent,
INT  off 
)

Definition at line 284 of file fesimdaq.cxx.

285{
286
287 /* init bank structure */
288 bk_init32(pevent);
289
291 /* create structured ADC0 bank of double words (i.e. 4-byte words) */
292 bk_create(pevent, "ADC0", TID_DWORD, (void **)&pdata32);
293
294 // Add a header, with number of words in event.
295 // Use the top two bits to indicate different control words.
296 // 11 -> 0xcXXXXXXX : overall header
297 // 01 -> 0x4XXXXXXX : trigger header
298 // 00 -> 0x0XXXXXXX : channel header
299 // 10 -> 0x8XXXXXXX : trailer
300
301 // Write the bank header to the bank, containing the number of triggers
302 *pdata32++ = 0xfa000200;
303
304 int sample = floor(sampleNormal()*80)+1200;
305 if((rand() % 100) > 80) sample += 200;
306 *pdata32++ = 0xf800406b + sample;
307
308 int sample2 = floor(sampleNormal()*120)+1000;
309 *pdata32++ = 0xf801405e + sample2;
310
311 int sample3 = floor(sampleNormal()*100)+1000;
312 *pdata32++ = 0xf802405e + sample3;
313
314 int sample4 = floor(sampleNormal()*20)+950;
315 *pdata32++ = 0xf803405e + sample4;
316
317 int sample5 = floor(sampleNormal()*50)+1300;
318 *pdata32++ = 0xf804405e + sample5;
319
320 int sample6 = floor(sampleNormal()*200)+2000;
321 *pdata32++ = 0xf805405e + sample6;
322
323
324
325 *pdata32++ = 0xfcfd57e8;
326
327
328 int size2 = bk_close(pevent, pdata32);
329
330
332 bk_create(pevent, "ADC1", TID_DWORD, (void **)&pdata322);
333
334
335 //for(int i = 0; i < 100000; i++)
336 //*pdata322++ = i;
337
338 size2 = bk_close(pevent, pdata322);
339
341 bk_create(pevent, "W200", TID_DWORD, (void **)&pdata720);
342
343
344 *pdata720++ = 0xa00001f8;
345 *pdata720++ = 0xfff703;
346 *pdata720++ = 0x0;
347 *pdata720++ = 0x13132f;
348
349 int pulse_position = floor(sampleNormal()*80) + 200;
350 for(int j = 0; j < 2; j++){
351
352 if (j==1) pulse_position+= 5;
353 int pulse_height = floor(sampleNormal()*30) +200;
354 pulse_height = pulse_height * (1.0 - ((double)pulse_position)/600.0);
355
356 for(int i = 0; i < 504; i++){
357 uint32_t word = 0;
358 uint32_t sample = 400 + floor(sampleNormal()*2);
359 if(i == pulse_position) sample += 0.2 * pulse_height;
360 if(i == pulse_position+1) sample += 0.8 * pulse_height;
361 if(i == pulse_position+2) sample += 1.0 * pulse_height;
362 if(i == pulse_position+3) sample += 0.9 * pulse_height;
363 if(i == pulse_position+4) sample += 0.5 * pulse_height;
364 if(i == pulse_position+5) sample += 0.3 * pulse_height;
365 if(i == pulse_position+6) sample += 0.1 * pulse_height;
366 //std::cout << i << " " << pulse_position << " " << pulse_height << " " << sample << std::endl;
367 word = sample;
368 i++;
369 sample = 400 + floor(sampleNormal()*2);
370 if(i == pulse_position) sample += 0.2 * pulse_height;
371 if(i == pulse_position+1) sample += 0.8 * pulse_height;
372 if(i == pulse_position+2) sample += 1.0 * pulse_height;
373 if(i == pulse_position+3) sample += 0.9 * pulse_height;
374 if(i == pulse_position+4) sample += 0.5 * pulse_height;
375 if(i == pulse_position+5) sample += 0.3 * pulse_height;
376 if(i == pulse_position+6) sample += 0.1 * pulse_height;
377 //std::cout << j << " " << i << " " << pulse_position << " " << pulse_height << " " << sample << std::endl;
378 word += (sample << 16);
379 *pdata720++ = word;
380 }
381 }
382
383
384
385 size2 = bk_close(pevent, pdata720);
386
387
388
389 struct timeval start,end;
390 gettimeofday(&start,NULL);
391 if(0)printf ("simdaq request: %f\n",start.tv_sec
392 + 0.000001*start.tv_usec);
393 // close the bank
394
395 // handle the deferred transition
396 if(nremaining > 0){ std::cout << "deferring " << nremaining << std::endl; nremaining--;
397 };
398
399 if(nremaining == 0){
401 std::cout << "Finished readout... " << std::endl;
402 }
403
404 /*
405 printf("Start sleep\n");
406 bool done = false;
407 double time;
408 while(!done){
409 sleep(5);
410 gettimeofday(&end,NULL);
411 time = end.tv_sec - start.tv_sec + (end.tv_usec - start.tv_usec)*0.000001;
412 if(time > 10) done = true;
413 }
414
415 //}
416 printf("End sleep. time %f\n", time);
417 */
418
419 usleep(10000);
420 return bk_size(pevent);
421}
void bk_init32(void *event)
Definition midas.cxx:16469
double sampleNormal()
Definition fesimdaq.cxx:267
#define end
int gettimeofday(struct timeval *tp, void *tzp)
INT j
Definition odbhist.cxx:40
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 210 of file fesimdaq.cxx.

211{
212 return SUCCESS;
213}

◆ sampleNormal()

double sampleNormal ( )

Definition at line 274 of file fesimdaq.cxx.

274 {
275 double u = ((double) rand() / (RAND_MAX)) * 2 - 1;
276 double v = ((double) rand() / (RAND_MAX)) * 2 - 1;
277 double r = u * u + v * v;
278 if (r == 0 || r > 1) return sampleNormal();
279 double c = sqrt(-2 * log(r) / r);
280 return u * c;
281}
char c
Definition system.cxx:1310
Here is the call graph for this function:

◆ SIMDAQSETTINGS_STR()

SIMDAQSETTINGS_STR ( simdaqsettings_str  )

◆ wait_end_cycle()

BOOL wait_end_cycle ( int  transition,
BOOL  first 
)

Definition at line 130 of file fesimdaq.cxx.

131 {
132 if(first){
133 std::cout << "Starting deferred transition" << std::endl;
134 nremaining = 5;
135 }
136
137 if (finished_readout) {
138 return TRUE;
139 }
140
141 return FALSE;
142 }
Here is the call graph for this function:

Variable Documentation

◆ display_period

INT display_period = 0

a frontend status page is displayed with this frequency in ms

Definition at line 35 of file fesimdaq.cxx.

◆ equipment

EQUIPMENT equipment[]
Initial value:
= {
{"SIMDAQ",
{1, 0,
"SYSTEM",
LAM_SOURCE(0, 0xFFFFFF),
"MIDAS",
TRUE,
1000,
0,
0,
0,
"", "", "",},
},
{""}
}
#define EQ_PERIODIC
Definition midas.h:414
#define RO_RUNNING
Definition midas.h:426
INT read_trigger_event(char *pevent, INT off)
Definition fesimdaq.cxx:277
#define LAM_SOURCE(c, s)
Definition midas.h:469

Main structure for midas equipment.

Definition at line 72 of file fesimdaq.cxx.

72 {
73
74 {"SIMDAQ", /* equipment name */
75 {1, 0, /* event ID, trigger mask */
76 "SYSTEM", /* event buffer */
77#ifdef USE_INT
78 EQ_INTERRUPT, /* equipment type */
79#else
80 EQ_PERIODIC, /* equipment type */
81#endif
82 LAM_SOURCE(0, 0xFFFFFF), /* event source crate 0, all stations */
83 "MIDAS", /* format */
84 TRUE, /* enabled */
85 RO_RUNNING, /* read only when running */
86 1000, /* poll for 1000ms */
87 0, /* stop run after this event limit */
88 0, /* number of sub events */
89 0, /* don't log history */
90 "", "", "",},
91 read_trigger_event, /* readout routine */
92 },
93
94 {""}
95};
#define EQ_INTERRUPT
Definition midas.h:416

◆ event_buffer_size

INT event_buffer_size = 20 * 1000000

buffer size to hold events

Definition at line 44 of file fesimdaq.cxx.

◆ finished_readout

BOOL finished_readout =FALSE

Definition at line 126 of file fesimdaq.cxx.

◆ frontend_call_loop

BOOL frontend_call_loop = TRUE

frontend_loop is called periodically if this variable is TRUE

Definition at line 32 of file fesimdaq.cxx.

◆ frontend_file_name

char* frontend_file_name = __FILE__

The frontend file name, don't change it.

Definition at line 29 of file fesimdaq.cxx.

◆ frontend_name

char* frontend_name = "fesimdaq"

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

Definition at line 27 of file fesimdaq.cxx.

◆ hDB

HNDLE hDB

main ODB handle

Definition at line 47 of file fesimdaq.cxx.

◆ hSet

HNDLE hSet

Definition at line 47 of file fesimdaq.cxx.

◆ info

void** info

Definition at line 45 of file fesimdaq.cxx.

◆ max_event_size

INT max_event_size = 3 * 1024 * 1024

maximum event size produced by this frontend

Definition at line 38 of file fesimdaq.cxx.

◆ max_event_size_frag

INT max_event_size_frag = 2 * 1024 * 1024

maximum event size for fragmented events (EQ_FRAGMENTED)

Definition at line 41 of file fesimdaq.cxx.

◆ nremaining

int nremaining = -1

Definition at line 128 of file fesimdaq.cxx.

◆ strin

char strin[256]

Definition at line 46 of file fesimdaq.cxx.