mEmcFEMToDCM.c

Go to the documentation of this file.
00001 /*:>--------------------------------------------------------------------
00002 **: compile with cc
00003 **: FILE:       mEmcFEMToDCM.c.template
00004 **: HISTORY:
00005 **:             00jan93-v000a-hpl- Created by stic Version
00006 **:  Id: idl.y,v 1.3 1998/04/20 19:56:35 leitch Exp  
00007 **:<------------------------------------------------------------------*/
00008 #include "mEmcFEMToDCM.h"
00009 #include "emlLib.h"
00010 #include "packetConstants.h"
00011 
00012 long mEmcFEMToDCM_(
00013   TABLE_HEAD_ST    *dEmcFEMData_h,    DEMCFEMDATA_ST      *dEmcFEMData ,
00014   TABLE_HEAD_ST    *dEmcDCMData_h,    DEMCDCMDATA_ST      *dEmcDCMData )
00015 {
00016 /*:>--------------------------------------------------------------------
00017 **: ROUTINE:    mEmcFEMToDCM_
00018 **: DESCRIPTION: Physics Analysis Module ANSI C template.
00019 **:             This is an ANSI C Physics Analysis Module template
00020 **:             automatically generated by stic from mEmcFEMToDCM.idl.
00021 **:             Please edit comments and code.
00022 **: AUTHOR:     hpl - H.P. Lovecraft, hplovecraft@cthulhu.void
00023 **: ARGUMENTS:
00024 **:       IN:
00025 **:        dEmcFEMData    - PLEASE FILL IN DESCRIPTION HERE
00026 **:       dEmcFEMData_h   - header Structure for dEmcFEMData
00027 **:    INOUT:
00028 **:      OUT:
00029 **:        dEmcDCMData    - PLEASE FILL IN DESCRIPTION HERE
00030 **:       dEmcDCMData_h   - header Structure for dEmcDCMData
00031 **: RETURNS:    STAF Condition Value
00032 **:>------------------------------------------------------------------*/
00033 
00034   short i_DCMData;
00035   unsigned long iflag,imodule,ievno,iclock,idetid;
00036   unsigned long iparity = 0;
00037   unsigned long itrailer = 255;
00038   unsigned long itimecell,iprecell,ipostcell;
00039   
00040   long timecell,precell,postcell;
00041   long data[442];
00042   
00043   short i,j,k;
00044   long ichan;
00045   short ihit,icount;
00046   long itime,ihigain,ilogain;
00047   long ipre,ipost;
00048 
00049 #define i_minvalue 100
00050   
00051   if(dEmcFEMData_h->nok <= 0)
00052     {
00053       printf("Error in mEmcFEMToDCM: FEM data table empty \n");
00054       return ( STAFCV_BAD);
00055     }
00056 
00057   /* 
00058      Right now one FEM row goes to one DCM row.
00059      Set up an additional counter, anticipating that more than one
00060      FEM may end up in the same DCM
00061   */
00062   i_DCMData = 0;
00063 
00064   
00065   for ( i = 0; i < dEmcFEMData_h->nok; i++)
00066     {
00067       iflag = 
00068         dEmcFEMData[i].flag & 0x0000FFFF + 0x000F0000; /* Bits 19-16 = 15 */
00069 
00070       imodule = 
00071         dEmcFEMData[i].module & 0x0000FFFF + 0x00060000; /* Bits 19-16 = 6 */
00072       ievno = 
00073         dEmcFEMData[i].evno & 0x0000FFFF + 0x00060000; /* Bits 19-16 = 6 */
00074       iclock = 
00075         dEmcFEMData[i].clock & 0x0000FFFF + 0x00060000; /* Bits 19-16 = 6 */
00076       idetid = 
00077         dEmcFEMData[i].detid & 0x0000FFFF + 0x00060000; /* Bits 19-16 = 6 */
00078       
00079       itimecell = 
00080         dEmcFEMData[i].timecell & 0x0000FFFF + 0x00020000; /* Bits 19-16 = 2 */
00081       iprecell = 
00082         dEmcFEMData[i].precell & 0x0000FFFF + 0x00040000; /* Bits 19-16 = 4 */
00083       ipostcell = 
00084         dEmcFEMData[i].postcell & 0x0000FFFF + 0x00010000; /* Bits 19-16 = 1 */
00085 
00086       icount = 0;
00087 
00088       /* Add new header */
00089 
00090       /*      dEmcDCMData[i_DCMData].nWords = 453;  Hardwired: pass-through */
00091       dEmcDCMData[i_DCMData].nWords = 450; /* Hardwired: pass-through */
00092       /*      dEmcDCMData[i_DCMData].scheme = 0;  Hardwired: pass-through */
00093       dEmcDCMData[i_DCMData].scheme = IDPBSC_DCM0;
00094 
00095       /*      dEmcDCMData[i_DCMData].packetID = 0x80000000 + i_DCMData; */
00096       /* Packet ID form changed after Sep 98 computing meeting.
00097          Martin wants the first packet - 8000 - reserved.
00098          Also, right how we are not making any distinction between 
00099          PbSc and PbGl packets - maybe to be done later */
00100       dEmcDCMData[i_DCMData].packetID = 8001 + imodule;
00101 
00102 
00103 
00104       /*  Fill first part */
00105 
00106       dEmcDCMData[i_DCMData].DCM[0] = iflag;
00107       dEmcDCMData[i_DCMData].DCM[1] = imodule;
00108       dEmcDCMData[i_DCMData].DCM[2] = ievno;
00109       dEmcDCMData[i_DCMData].DCM[3] = iclock;
00110       dEmcDCMData[i_DCMData].DCM[4] = idetid;
00111       dEmcDCMData[i_DCMData].DCM[5] = itimecell;
00112       dEmcDCMData[i_DCMData].DCM[6] = iprecell;
00113       dEmcDCMData[i_DCMData].DCM[7] = ipostcell;
00114       
00115       icount = 8;
00116       
00117       
00118       for ( ichan = 0; ichan < 144; ichan++)
00119         {
00120           itime = dEmcFEMData[i].data[ichan * 5] & 0x00000FFF;
00121           ihigain = (dEmcFEMData[i].data[ichan * 5 + 1] & 0x00000FFF)
00122             - (dEmcFEMData[i].data[ichan * 5 + 3] & 0x00000FFF);
00123           ilogain = (dEmcFEMData[i].data[ichan * 5 + 2] & 0x00000FFF)
00124             - (dEmcFEMData[i].data[ichan * 5 + 4] & 0x00000FFF);
00125 
00126           
00127 
00128           /*      if( itime > 0 || ihigain > 0 || ilogain > 0) */
00129           if( itime != 0 || ihigain != 0 || ilogain != 0)
00130             {
00131               /*      time    9 in 19-16   N in bits 27-20  */
00132               /* itime = itime + 0x00090000 + ichan * 0x000FFFFF; */
00133               itime = itime + 0x00090000 + ( ichan << 20 );
00134 
00135               /* 
00136                  Decide if low or high gain should be taken, and
00137                  set corresponding bits
00138 
00139               */
00140               
00141               //              if( ilogain < 2000)  /* Take low gain data */
00142 
00143               ipost = dEmcFEMData[i].data[ichan * 5 + 2] & 0x00000FFF;
00144 
00145 
00146               //              if( ilogain < 2000)  /* Take low gain data */
00147 
00148               if(ipost > i_minvalue)        /* Take low gain data */
00149                 {
00150                   ipost = dEmcFEMData[i].data[ichan * 5 + 2] & 0x00000FFF;
00151                   ipre = dEmcFEMData[i].data[ichan * 5 + 4] & 0x00000FFF;
00152                 }
00153               else
00154                 {
00155                   ipost = dEmcFEMData[i].data[ichan * 5 + 1] & 0x00000FFF
00156                     + 0x00008000;
00157                   ipre = dEmcFEMData[i].data[ichan * 5 + 3] & 0x00000FFF
00158                     + 0x00008000;
00159                 }
00160 
00161               /*
00162                 Take care of channel number and data type bits
00163               */
00164 
00165               /*      post    12 in 19-16  N in bits 27-20  */
00166               ipost = ipost + 0x000C0000 + ( ichan << 20);
00167               /*      pre    10 in 19-16  N in bits 27-20  */
00168               ipre  = ipre + 0x000A0000 + ( ichan << 20);
00169 
00170               dEmcDCMData[i_DCMData].DCM[icount] = ipost;
00171               dEmcDCMData[i_DCMData].DCM[icount + 1] = ipre;
00172               dEmcDCMData[i_DCMData].DCM[icount + 2] = itime;
00173               
00174               icount = icount + 3;
00175               
00176             }  /* At least one is non-zero - time, logain, higain */
00177           
00178           
00179         }  /* Loop over ichan, 144 possible channels */
00180 
00181       for ( j = 0; j < 8; j++)
00182         {
00183           dEmcDCMData[i_DCMData].DCM[icount + j] = 
00184             dEmcFEMData[i].userword[j] & 0x0000FFFF;
00185         }
00186       icount = icount + 8;
00187       dEmcDCMData[i_DCMData].DCM[icount] = iparity;
00188       dEmcDCMData[i_DCMData].DCM[icount + 1] = itrailer;
00189       
00190       i_DCMData = i_DCMData + 1;
00191       
00192     }  /* Loop over i, all rows of dEmcFEMData */
00193   
00194   dEmcDCMData_h->nok = i_DCMData;
00195   
00196 
00197   return STAFCV_OK;
00198 }