next up previous
Next: Variable Registration System Up: The CEBAF Test Package: Previous: CTP Definition Files

Subsections


Fortran Application Interface

The CTP package may be used with analysis software written in either C or Fortran. We describe here only the Fortran interface which is presently available HP-UX, Ultrix and Linux.


Registration Commands

As the variables used in parameter, test and histogram definitions are intended to refer to variables of the same name used by an analysis code, they must be linked in some manner. This is accomplished by having the analyzer ``register'' any variable that is required by the desciption files. This registration must be performed before the parameters, tests and histograms are booked. Four byte integers and four byte real numbers may be registered. A variable is registered by calling the appropriate registration function with a string giving its name and a pointer to the variable's location in memory. At the time a variable is registered, it must be given a class through the use of the appropriate subroutine call.

  character*length name
  character*LEN title
  integer*4 ierr

  
  integer*4 ilen, rlen
  parameter (ilen=LEN)
  parameter (rlen=LEN)
  integer*4 ival
  integer*4 iarray(ilen)
  real*4 rval
  real*4 rarray(rlen)
  character*LEN string

  ierr=regeventint(name,ival,title)                ! I*4 event variable
  ierr=regeventreal(name,rval,title)               ! R*4 event
  ierr=regeventdouble(name,rval,title)             ! R*8 event
  ierr=regparmint(name,ival,title)                 ! I*4 parameter
  ierr=regparmreal(name,rval,title)                ! R*4 parameter
  ierr=regparmdouble(name,rval,title)              ! R*8 parameter
  ierr=regtestint(name,ival,title)                 ! I*4 test result
  ierr=regtestreal(name,rval,title)                ! R*4 test result
  ierr=regtestdouble(name,rval,title)              ! R*8 test result
  ierr=regeventintarray(name,iarray,ilen,title)    ! I*4 event array
  ierr=regeventrealarray(name,rarray,rlen,title)   ! R*4 event array
  ierr=regeventdoublearray(name,rarray,rlen,title) ! R*8 event array
  ierr=regparmintarray(name,iarray,ilen,title)     ! I*4 parameter array
  ierr=regparmrealarray(name,rarray,rlen,title)    ! R*4 parameter array
  ierr=regparmdoublearray(name,rarray,rlen,title)  ! R*8 parameter array
  ierr=regtestmintarray(name,iarray,ilen,title)    ! I*4 test result array
  ierr=regtestrealarray(name,rarray,rlen,title)    ! R*4 test result array
  ierr=regtestdoublearray(name,rarray,rlen,title)  ! R*8 test result array

  ierr=regparmstring(name,string,title)            ! Character string

The title argument is an arbitrary string that may be used to label a variable. It may be omitted by using a zero instead of a string. The above functions return an error code, zero for success, and not zero for failure. No specific meanings have been assigned yet for the failure error codes.

The memory locations of the variables that are registered must be static. In Fortran this can be guaranteed by placing all variables that are registered in common blocks. (Or by listing the variables in SAVE statements.)

A test result variable does need not to be registered unless one wants access to the test result from within the source code. An example would be where one wants to condition analysis (peformed after executing a test block) on the result of one of the tests.

If a test result is to be a real value, then the variable or array must be registered before the tests are booked.

Booking Commands

The following calls are used to load and book the parameters, test definitions, histogram definitions, and report templates. The application must establish the histogramming area with HLIMIT or HLIMAP before the histograms are booked.

  character *(*) filename
  character *(*) histname
  integer*4 id
  integer*4 ierr

  ierr=thload(filename)
  ierr=thbook()
  ierr=thwhalias(filename)
  id = thgetid(histname)

The thload routine loads all of the blocks of parameters, tests and histograms contained in a single file. This file may have any number of blocks of separate types. Several calls to thload may be made to load definitions contained in several files. The loading does not actually set parameter values or book tests or histograms, but merely makes a copy of the files in memory. A single call to thbook will then book all of the blocks that have been loaded and not yet booked. After booking, the routine thwhalias may be used to write a file of PAW[] alias commands that the user may load into PAW so that histograms can be refered to by name rather than by id number.

Test Execution and Test Scalers

In a typical analyzer, as each event is analyzed, all the defined tests will be evaluated. The results of these tests are then available to be used as conditions on histogram incrementing. CTP calls are also available to accumulate scalers of the number of time each test was evaluated as true (not zero.)

All CTP calls return an integer*4 error code. Zero is returned for successful execute. No specific failure codes are defined except that a failure will be indicated by a non-zero return code.

The following calls are available for test evaluation and for incrementing test result scalers:

  character *(*) blockname
  integer*4 ierr

  ierr=thtstexe()           ! Execute all tests
  ierr=thtstexeb(blockname) ! Execute a single block of tests

  ierr=thtstins()           ! Increment all test scalers
  ierr=thtstinsb(blockname) ! Increment scalers for on block

The calls without arguments will cause all the blocks (in alphabetical order) to be processed. For the routines that end with b, only a single block is executed.

The test scalers must be cleared initially before any calls to increment the scalers are made or before a new run is analyzed. As with test execution and scaler incrementing, all test scalers or just those associated with a specific test block may be cleared.

  character *(*) blockname
  integer*4 ierr

  ierr=thtstcls()           ! Clear all test scalers
  ierr=thtstclsb(blockname) ! Clear test scalers for
                            ! a single block of tests

Test test results may be cleared before tests are executed with the following routines.

  character *(*) blockname
  integer*4 ierr

  ierr=thtstclr()           ! Clear all test flags
  ierr=thtstclrb(blockname) ! Clear test flags a single block

Clearing the test results is not required as the execution of each test will result in a definite value. However, there can be situations where clearing the test results is important. Two of the situations are:

In writing the tests that go into CTP test blocks, a given test result name should generally only be used in one block. In particular particular care must be taken if arrays are used for test results. If mutually exclusive array elements (of a given array) are used in more than one test block, the use of test scalers and the clearing of test flags can have undesired results. This is because, the ins, cls, and clr routines will operate on an entire array even if only one element of that array is used as a test result in a given block. Since the indices of arrays can be variable as well as fixed, CTP has no easy way of determining which elements of these arrays to operate on (increment or clear.)

Histogram Filling

In a typical analyzer, as each event is analyzed, all the defined tests will be evaluated. Then the histograms will be filled with the results of the event analysis conditioned by the test flags. The following calls are available for test evaluation and histogram filling.

  character *(*) blockname
  integer*4 ierr

  ierr=thhstexe()
  ierr=thhstexeb(blockname)

The CTP histogram filling calls should be called after tests have been executed.

CTP has no routines for saving histograms to a file. This should be accomplished with

Gethit Routines

To fill the gethit value and test variables, two routines are available to execute a single gethit block or all gethit blocks.
  character *(*) blockname
  integer*4 ierr

  ierr=thgethit()
  ierr=thgethitb(blockname)

Calls to execute gethit blocks should generally be performed before test execution and histogram filling calls.


Report Generation

  character *(*) blockname
  integer*4 ierr

  ierr=threp(blockname,filename)
  ierr=threpa(blockname,filename)

The threp will copy the text contained in the specified block into the specified output file, replacing strings insides of braces ({}) with the expressions contained within them. The routine threpa is identical except that the report is appended to the specified file, rather than overwriting it.

Sample Code

As a coding example, we give fragments of code that would work with then example CTP input files used above. (The parameter block ``constants'', the test block ``hms'' and , the histogram block ``hms''.) We assume that all three of the CTP blocks are contained in the single file ctp.input.

Sample Variable registration

Before the CTP input file can be read in, the variables used must be registered by the physics analysis code. We do that by a call to the following routine:
  subroutine regallvars()

  implicit none

  include 'parcommon.inc'
  include 'testcommon.inc'
  include 'eventcommon.inc'

  integer*4 regparmint, regparmreal
  integer*4 ierr
c
c Register the parameters used in the ``constants block''
c
  ierr = regparmreal('proton',proton,'Mass of the proton')
  ierr = regparmreal('neutron',neutron,'Mass of the neutron')
  ierr = regparmreal('pion',pion,'Mass of the charged pion')
  ierr = regparmreal('pizero',pizero,'Mass of the neutral pion')
  ierr = regparmrealarray('offsets',offsets,8,'An array of offsets')
  ierr = regparmreal('thmin',thmin,'Low end of theta cut')
  ierr = regparmreal('thmax',thmax,'High end of theta cut')
  ierr = regparmreal('phimin',phimin,'Low end of phi cut')
  ierr = regparmreal('phimax',phimax,'High end of phi cut')
  ierr = regparmstring('hbook_filename',hbook_filename,
		'HBOOK Filename')
  ierr = regparmstring('report_filename',report_filename,
		'Report Generator Filename')
c
c Register some test result variables.  Only the array clean is
c registered as CTP will automatically register test result variables
c as the test block is booked.  If you want to easily access
c
  ierr = regtestintarray('clean',clean,6,'Array of test results')
c
c Register variables that are recalculated each event which contain
c quantities that may be histogrammed.
c
  ierr = regeventreal('mass',mass,'Calculated mass')
  ierr = regeventreal('fptheta',fptheta,'Theta angle at focal plane')
c
  return
  end

Sample common blocks

The following are sample include files that put the registered variables into common blocks.
c
c parcommon.inc  -  Common block for registered parameters
c
  real*4 proton, neutron, pion, pizero
  real*4 offsets(8)
  real*4 thmin, thmax, phimin, phimax
  character*80 hbook_filename,report_filename
c
  common /parms/ proton, neutron, pion, pizero
 &      ,offsets, thmin, thmax, phimin, phimax
  common /strings/ hbook_filename,report_filename

c
c testcommon.inc - Common block for test results
c
  integer*4 clean(6)
c
  common /tests/ clean


c
c eventcommon.inc - Common for event variables
c
  real*4 mass, fptheta
c
  common /event/ mass,fptheta

Sample initialization code

The following is an example of a routine that calls the above routine to register all of the variables, and then loads and books the CTP files.

  subroutine initialize()

  implicit none
  integer*4 hmemor(20000)
  common /pawc/ hmemor
  integer*4 ierr

  call regallvars

  call hlimit(20000)
  ierr = thload('ctp.input')
  ierr = thbook()
  ierr = thwalias('paw.aliases')

  ierr = thtstcls()  ! Clear all test scalers

  return
  end

Example Event code

The following sample routine is called for each event.
  subroutine analyze_event

  implicit none

  include 'parcommon.inc'
  include 'testcommon.inc'
  include 'eventcommon.inc'

  integer*4 ierr
c OTHER DECLARATIONS

c GET THE EVENT

c DO EVENT ANALYSIS

  ierr = thtstexeb('hms') ! Exec tests

  ierr = thtstinsb('hms') ! Incr scalers

  ierr = thhstexeb('hms') ! Fill histograms

  return
  end

Example End of Run Code

After analyzing a set of data, an analyzer program will typically save the histograms a write out various calculations and statistics. The following example saves the histograms into a file and uses the CTP report generator to print some statistics.

  subroutine end_analysis

  implicit none

  include 'parcommon.inc'
  include 'testcommon.inc'
  include 'eventcommon.inc'

  integer*4 ierr

  hbook calls to save file
  threpout call.


next up previous
Next: Variable Registration System Up: The CEBAF Test Package: Previous: CTP Definition Files
Stephen A. Wood 2005-03-18