This section covers several aspect of the Midas system.
When defining a data type either in the frontend code for bank definition or in user code to define ODB variables, Midas requires the use of its own data type declaration. The list below shows the main Type IDentification to be used (refers to Midas Define for complete listing):
-------- example 1 -------- Simple 16 bits bank construction void read_cft (DWORD *pevent) { DWORD *pbkdat, slot; ybk_create((DWORD *)pevent, "TDCP", I2_BKTYPE, &pbkdat); for (slot=FIRST_CFT;slot<=LAST_CFT;slot++) { cami(3,slot,1,6,(WORD *)pbkdat); ((WORD *)pbkdat)++; cam16i_rq(3,slot,0,4,(WORD **)&pbkdat,16); } ybk_close((DWORD *)pevent, I2_BKTYPE, pbkdat); return; } -------- example 2 -------- Simple 32bit bank construction { DWORD *pbkdat; ybk_create((DWORD *)pevent, "TICS", I4_BKTYPE, &pbkdat); camo(2,22,0,17,ZERO); cam24i_r(2,22,0,0,(DWORD **) &pbkdat,10); cam24i_r(2,22,0,0,(DWORD **) &pbkdat,10); cam24i_r(2,22,0,0,(DWORD **) &pbkdat,10); cam24i_r(2,22,0,0,(DWORD **) &pbkdat,10); cam24i_r(2,22,0,0,(DWORD **) &pbkdat,9); ybk_close((DWORD *)pevent, I4_BKTYPE, pbkdat); return 0; }
Example 3 shows a creation of an EVID bank containg a duplicate of the midas header. As the Midas header is stripped out of the event when data are logger, it is necessary to compose such event to retain event information for off-line analysis. Uses of predefined macros (see Midas Code and Libraries) are available in order to extract from a pre-composed Midas event the internal header fields i.e. Event ID, Trigger mask, Serial number, Time stamp. In this EVID bank we added the current run number which is retrieve by the frontend at the begin of a run.
-------- example 3 -------- Full equipment readout function INT read_cum_scaler_event(char *pevent, INT off) { INT i; DWORD *pbkdat, *pbktop, *podbvar; ybk_init((DWORD *) pevent); // collect user hardware SCALER data ybk_create((DWORD *)pevent, "EVID", I4_BKTYPE, (DWORD *)(&pbkdat)); *(pbkdat)++ = gbl_tgt_counter++; // event counter *((WORD *)pbkdat) = EVENT_ID(pevent); ((WORD *)pbkdat)++; *((WORD *)pbkdat) = TRIGGER_MASK(pevent); ((WORD *)pbkdat)++; *(pbkdat)++ = SERIAL_NUMBER(pevent); *(pbkdat)++ = TIME_STAMP(pevent); *(pbkdat)++ = gbl_run_number; // run number ybk_close((DWORD *)pevent, pbkdat); // BEGIN OF CUMULATIVE SCALER EVENT ybk_create((DWORD *)pevent, "CUSC", I4_BKTYPE, (DWORD *)(&pbkdat)); for (i=0 ; i<NSCALERS ; i++){ *pbkdat++ = scaler[i].cuval[0]; *pbkdat++ = scaler[i].cuval[1]; } ybk_close(DWORD *)pevent, I4_BKTYPE, pbkdat); // END OF CUMULATIVE SCALER EVENT // event in bytes for Midas return (ybk_size ((DWORD *)pevent)); }
--- Example of YBOS bank extraction ---- void process_event(HNDLE hBuf, HNDLE request_id, EVENT_HEADER *pheader, void *pevent) { INT status; DWORD *plrl, *pybk, *pdata, bklen, bktyp; char banklist[YB_STRING_BANKLIST_MAX]; // pointer to data section plrl = (DWORD *) pevent; // Swap event yb_any_event_swap(FORMAT_YBOS,plrl); // bank name given through argument list if ((status = ybk_find (plrl, sbank_name, &bklen, &bktyp, (void *)&pybk)) == YB_SUCCESS) { // given bank found in list status = ybk_list (plrl, banklist); printf("#banks:%i Bank list:-%s-\n",status,banklist); printf("Bank:%s - Length (I*4):%i - Type:%i - pBk:0x%p\n",sbank_name, bklen, bktyp, pybk); // check id EVID found in event for id and msk selection if ((status = ybk_find (plrl, "EVID", &bklen, &bktyp, (void *)&pybk)) == YB_SUCCESS) { pdata = (DWORD *)((YBOS_BANK_HEADER *)pybk + 1); ... } // iterate through the event pybk = NULL; while ((bklen = ybk_iterate(plrl, &pybk, (void *)&pdata)) && (pybk != NULL)) printf("bank length in 4 bytes unit: %d\n",bklen); } else { status = ybk_list (plrl, banklist); printf("Bank -%s- not found (%i) in ",sbank_name, status); printf("#banks:%i Bank list:-%s-\n",status,banklist); } ... ... ... }
Within these files, all the functions have been categorized depending on their scope.
INT adc_calib(EVENT_HEADER *pheader, void *pevent) { INT i, n_adc; WORD *pdata; float *cadc; // look for ADC0 bank, return if not present n_adc = bk_locate(pevent, "ADC0", &pdata); if (n_adc == 0 || n_adc > N_ADC) return 1; // create calibrated ADC bank bk_create(pevent, "CADC", TID_FLOAT, &cadc); ... }
INT read_trigger_event(char *pevent, INT off) { WORD *pdata, a; INT q, timeout; // init bank structure bk_init(pevent); ... }
INT read_ge_event(char *pevent, INT offset) { static WORD *pdata; INT i, x, q; WORD temp; // Change the time stamp in millisecond for the Super event TIME_STAMP(pevent) = ss_millitime(); bk_init(pevent); bk_create(pevent, "GERM", TID_WORD, &pdata); ... }
... lam = *((DWORD *)pevent); if (lam & LAM_STATION(JW_N)) { ... // compose event header TRIGGER_MASK(pevent) = JW_MASK; EVENT_ID(pevent) = JW_ID; SERIAL_NUMBER(pevent)= eq->serial_number++; // read MCS event size = read_mcs_event(pevent); // Correct serial in case event is empty if (size == 0) SERIAL_NUMBER(pevent) = eq->serial_number--; ... } ...
Midas build options and operation considerations - Top - Frequently Asked Questions