Midas Code and Libraries

previous.gif Midas build options and operation considerations - Top - Frequently Asked Questions next.gif

This section covers several aspect of the Midas system.


State Codes & Transition Codes


Midas Data Types

Midas defined its own data type for OS compatibility. It is suggested to use them in order to insure a proper compilation when moving code from one OS to another. float and double retain OS definition.

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):


Midas bank examples

There are several examples under the Midas source code that you can check. Please have a look at


YBOS Bank Types

YBOS defines several type but all types should be 4 bytes aligned. Distinction of signed and unsigned is not done. When mixing MIDAS and YBOS in the frontend for RO_ODB see The Equipment structure make sure the bank types are compatible (see also YBOS Define)


YBOS bank examples

Basic examples using YBOS banks are available in the midas tree under examples/ybosexpt.

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);
    }
    ...
    ... ...
}


Midas Code and Libraries

The Midas libraries are composed of 5 main source code and their corresponding header files.

  1. The midas.h & midas.c : Midas abstract layer.
  2. The msystem.h & system.c : Midas function implementation.
  3. The mrpc.h & mrpc.c : Midas RPC functions.
  4. The odb.c : Online Database functions.
  5. The ybos.h & ybos.c : YBOS specific functions.

Within these files, all the functions have been categorized depending on their scope.


MIDAS Macros

Several group of MACROs are available for simplifying user job on setting or getting Midas information. They are also listed in the Midas Code and Libraries. All of them are defined in the Midas Macros, System Macros, YBOS Macros header files.


YBOS library

Exportable ybos functions through inclusion of ybos.h

previous.gif Midas build options and operation considerations - Top - Frequently Asked Questions next.gif


Midas DOC Version 1.9.5 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk