MIDAS
Loading...
Searching...
No Matches
fesimdaq.cxx File Reference
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include "midas.h"
#include "mfe.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)
 
INT interrupt_configure (INT cmd, INT source, POINTER_T adr)
 
double sampleNormal ()
 

Variables

const charfrontend_name = "fesimdaq"
 
const charfrontend_file_name = __FILE__
 
BOOL frontend_call_loop = TRUE
 
INT display_period = 0
 
INT max_event_size = 3 * 1024 * 1024
 
INT max_event_size_frag = 2 * 1024 * 1024
 
INT event_buffer_size = 20 * 1000000
 
void ** info
 
char strin [256]
 
HNDLE hSet
 
EQUIPMENT 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 140 of file fesimdaq.cxx.

140 {\
141"[.]",\
142"Descrip = STRING : [256] ",\
143"Parameter AAA = INT : 0",\
144"Parameter BB2 = INT : 0", \
145"Parameter CC22 = INT : 0",\
146"",\
147NULL }

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

182{
183
184 nremaining = -1;
186 return SUCCESS;
187}
#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 191 of file fesimdaq.cxx.

192{
193 return SUCCESS;
194}

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

174{
175 printf("Exiting fedcrc!\n");
176 return SUCCESS;
177}
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 152 of file fesimdaq.cxx.

153{
154
155
156 int status = db_check_record(hDB, 0, "/Equipment/SIMDAQ/Settings", strcomb1(simdaqsettings_str).c_str(), TRUE);
157 printf("Status %i\n",status);
158 if (status == DB_STRUCT_MISMATCH) {
159 cm_msg(MERROR, "init_simdaqsettings", "Aborting on mismatching /Equipment/SIMDAQ/Settings");
161 abort();
162 }
163
165 return SUCCESS;
166}
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 212 of file fesimdaq.cxx.

213{
214 /* if frontend_call_loop is true, this routine gets called when
215 the frontend is idle or once between every event */
216 usleep(10000);
217 return SUCCESS;
218}
Here is the call graph for this function:

◆ interrupt_configure()

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

Definition at line 251 of file fesimdaq.cxx.

252{
253 switch (cmd) {
255 break;
257 break;
259 break;
261 break;
262 }
263 return SUCCESS;
264}
#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 caller 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 198 of file fesimdaq.cxx.

199{
200 return SUCCESS;
201}

◆ poll_event()

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

Definition at line 230 of file fesimdaq.cxx.

234{
235 int i;
236
237 for (i = 0; i < count; i++) {
238// cam_lam_read(LAM_SOURCE_CRATE(source), &lam);
239
240// if (lam & LAM_SOURCE_STATION(source))
241 if (!test)
242 return 1;
243 }
244
245 usleep(1000);
246 return 0;
247}
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:
Here is the caller graph for this function:

◆ read_scaler_event()

INT read_scaler_event ( char pevent,
INT  off 
)

Scaler event readout.

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

◆ read_trigger_event()

INT read_trigger_event ( char pevent,
INT  off 
)

Definition at line 277 of file fesimdaq.cxx.

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

206{
207 return SUCCESS;
208}

◆ sampleNormal()

double sampleNormal ( )

Definition at line 267 of file fesimdaq.cxx.

267 {
268 double u = ((double) rand() / (RAND_MAX)) * 2 - 1;
269 double v = ((double) rand() / (RAND_MAX)) * 2 - 1;
270 double r = u * u + v * v;
271 if (r == 0 || r > 1) return sampleNormal();
272 double c = sqrt(-2 * log(r) / r);
273 return u * c;
274}
char c
Definition system.cxx:1310
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SIMDAQSETTINGS_STR()

SIMDAQSETTINGS_STR ( simdaqsettings_str  )

◆ wait_end_cycle()

BOOL wait_end_cycle ( int  transition,
BOOL  first 
)

Definition at line 123 of file fesimdaq.cxx.

124 {
125 //printf("wait_end_cycle: transition %d, first %d\n", transition, first);
126
127 if(first){
128 std::cout << "Starting deferred transition" << std::endl;
129 nremaining = 10;
130 }
131
132 if (finished_readout) {
133 return TRUE;
134 }
135
136 return FALSE;
137 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ display_period

INT display_period = 0

Definition at line 31 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

Definition at line 69 of file fesimdaq.cxx.

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

◆ event_buffer_size

INT event_buffer_size = 20 * 1000000

Definition at line 40 of file fesimdaq.cxx.

◆ finished_readout

BOOL finished_readout =FALSE

Definition at line 119 of file fesimdaq.cxx.

◆ frontend_call_loop

BOOL frontend_call_loop = TRUE

Definition at line 28 of file fesimdaq.cxx.

◆ frontend_file_name

const char* frontend_file_name = __FILE__

Definition at line 25 of file fesimdaq.cxx.

◆ frontend_name

const char* frontend_name = "fesimdaq"

Definition at line 23 of file fesimdaq.cxx.

◆ hSet

HNDLE hSet

Definition at line 44 of file fesimdaq.cxx.

◆ info

void** info

Definition at line 41 of file fesimdaq.cxx.

◆ max_event_size

INT max_event_size = 3 * 1024 * 1024

Definition at line 34 of file fesimdaq.cxx.

◆ max_event_size_frag

INT max_event_size_frag = 2 * 1024 * 1024

Definition at line 37 of file fesimdaq.cxx.

◆ nremaining

int nremaining = -1

Definition at line 121 of file fesimdaq.cxx.

◆ strin

char strin[256]

Definition at line 42 of file fesimdaq.cxx.