Get information about an Ntuple

          +----------------------------------------------------+
          |CALL  HGIVEN (ID,CHTITL*,*NVAR*,CHTAG*,RLOW*,RHIGH*) |
          +----------------------------------------------------+
                                  

Action: Routine to provide information about an Ntuple.

Input parameters:
ID
Identifier of the Ntuple.
NVAR
Dimension of arrays TAGS, RLOW and RHIGH.
Output parameters:
CHTITL
Character variable containing the title associated with the Ntuple.
NVAR
The original contents is overwritten by the actual dimension of the Ntuple. If ID1 does not exist or is not an Ntuple NVAR=0 is returned.
CHTAG
Character array of dimension NVAR, which contains the tag names of the Ntuple elements.
RLOW
Array of dimension NVAR, which contains the lowest value for each Ntuple element.
RHIGH
Array of dimension NVAR, which contains the highest value for each Ntuple element.

Retrieve the contents of a RWN into an array

                 +--------------------------------------+
                 |CALL  HGN (ID,*IDN*,IDNEVT,X*,IERROR*) |
                 +--------------------------------------+
                                  
Action: Copy the contents of a RWN event into an array.

Input parameters:
ID
Identifier of the Ntuple.
IDN
Must be initialized to zero before the first call to HGN.
IDNEVT
Event number
Output parameters:
IDN
Internal HBOOK pointer
X
Array to contain variables for the event chosen.
IERROR
Error return code.

This routine returns in the vector X the contents of the row IDNEVT or Ntuple ID. The vector X must be of size NVAR, as specified in the call to HBOOKN. If more than one row of the Ntuple is to be processed, it is more efficient to call first HGNPAR and then HGNF.

                        +------------------------+
                        |CALL  HGNPAR (ID,CHROUT) |
                        +------------------------+
                                  

Action: Obtains the address and parameters of Ntuple ID.

Input parameters:
ID
Identifier of the Ntuple.
CHROUT
Character variable containing the name of the calling subroutine (printed in case of errors).

This routine sets some internal pointers and must be called before the first call to HGNF for a given RWN. When accessing more than one row of an Ntuple it is more efficient to call HGNPAR and then HGNF for each row that is required than to call HGN.

                   +----------------------------------+
                   | CALL  HGNF (ID,IDNEVT,X*,IERROR*) |
                   +----------------------------------+
                                  

Action: Copy the contents of an Ntuple event into an array. The routine HGNPAR must have been called prior to the first call to HGNF for a given Ntuple.

Input parameters:
ID
Identifier of the Ntuple.
IDNEVT
Event number
Output parameters:
X
Array to contain variables for the event chosen.
IERROR
Error return code.

This routine returns in the vector X the contents of the row IDNEVT or Ntuple ID. The vector X must have be of size NVAR, as specified in the call to HBOOKN.

               Example of access to RWN information
                                  

      PROGRAM TEST
      INTEGER    NWPAWC
      PARAMETER (NWPAWC=15000, MTUPLE=5)
      COMMON/PAWC/PAW(NWPAWC)
      CHARACTER*80 CHTITL
      CHARACTER*8 CHTAGS(MTUPLE),CHTAGZ(MTUPLE)
      DIMENSION EVENT(MTUPLE),RLOW(MTUPLE),RHIGH(MTUPLE)
      EQUIVALENCE (EVENT(1),X),(EVENT(2),Y),(EVENT(3),Z)
      EQUIVALENCE (EVENT(4),ENERGY),(EVENT(5),ELOSS)
      DATA CHTAGS/'X','Y','Z','Energy','Eloss'/

*-- Tell HBOOK how many words are in PAWC.
      CALL HLIMIT(NWPAWC)
*-- Book Ntuple
      CALL HBOOKN(10,'A Row-Wise-Ntuple',5,' ',5000,CHTAGS)
*-- Fill the Ntuple
      DO 10 I=1,1000
         CALL RANNOR(X,Y)
         Z=SQRT(X*X+Y*Y)
         ENERGY=50. + 10.*X
         ELOSS=10.*ABS(Y)
         CALL HFN(10,EVENT)
 10   CONTINUE
*--   Obtain the definitions of the Ntuple
      NVAR = MTUPLE
      CALL HGIVEN(10,CHTITL,NVAR,CHTAGZ,RLOW,RHIGH)
      PRINT *,'Definitions of Ntuple # ',10
      PRINT *,'   Title: ',CHTITL(1:LENOCC(CHTITL))
      PRINT *,'   Number of variables: ',NVAR
      DO 20 I=1,NVAR
         PRINT 9001,I,RLOW(I),RHIGH(I)
9001  FORMAT(' Min/Max values for column # ',I3,1X,F10.5,
     +       1X,F10.5)
 20   CONTINUE
*--   Get the contents of 'event' # 333
      CALL HGNPAR(10,'TEST')
      CALL HGNF(10,333,EVENT,IERR)
      PRINT *,IERR,EVENT
*--   Get the number of events in this Ntuple
      CALL HNOENT(10,NEVENT)
      PRINT *,NEVENT
 99   CONTINUE
      END

Retrieve the contents of a CWN into a common block

                      +----------------------------+
                      |CALL  HGNT (ID,IDNEVT,IERR*) |
                      +----------------------------+
                                  

Action:

Retrieve information about a CWN row.

Input parameters:
ID
Identifier of the Ntuple.
IDNEVT
Number of the event about which information is required.
Output parameter:
IERR
Error return code (=0 if event was found)

The information is restored at the addresses specified by HBNAME or HBNAMC (for CHARACTER data). If the information is being retrieved by a program other than the one that wrote the Ntuple then HBNAME or HBNAMC must be called as appropriate (see below).

      CALL HBNAME(ID,' ',0,'$CLEAR')
      CALL HBNAME(ID,CHBLOK,VARIABLE,'$SET')
 
These calls are required as HBOOK must obtain the location at which the requested information is to be returned which is obviously not valid between programs. The first call clears all the addresses stored by HBOOK for the specified Ntuple and the second one sets the addresses for the variables in block CHBLOK starting at variable VARIABLE. The second call should be repeated for every block of which data has to be retrieved. The routine HUWFUN will generate these calls automatically in the skeleton user function.

                   +----------------------------------+
                   |CALL  HGNTB (ID,CHBLOK,IROW,IERR*) |
                   +----------------------------------+
                                  

Action:

Retrieve information about a named block in an Ntuple row.

Input parameters:
ID
Identifier of the Ntuple.
CHBLOK
Character variable specifying the block that is to be retrieved.
IROW
Number of the row about which information is required.
Output parameter:
IERR
Error return code (=0 if row was found)

The information is restored at the addresses specified by HBNAME or HBNAMC (for CHARACTER data).

                 +--------------------------------------+
                 |CALL  HGNTV (ID,CHVAR,NVAR,IROW,IERR*) |
                 +--------------------------------------+
                                  

Action:

Retrieve information about the named variables in an Ntuple row.

Input parameters:
ID
Identifier of the Ntuple.
CHVAR
Array of character variables specifying the variables that are to be retrieved.
NVAR
Number of character variables specified in CHVAR.
IROW
Number of the row about which information is required.
Output parameter:
IERR
Error return code (=0 if row was found)

The information is restored at the addresses specified by HBNAME or HBNAMC (for CHARACTER data).

                      +----------------------------+
                      | CALL  HGNTF (ID,IROW,IERR*) |
                      +----------------------------+
                                  

Action:

Retrieve information about all variables specified in a previous call to either HGNT, HGNTB or HGNTV, in an Ntuple row. This routine is much faster than either HGNT, HGNTB or HGNTV.

Input parameters:
ID
Identifier of the Ntuple.
IROW
Number of the row about which information is required.
Output parameter:
IERR
Error return code (=0 if row was found)

The information is restored at the addresses specified by HBNAME or HBNAMC (for CHARACTER data).

Generate a user function

[sec:userfunction]

HBOOK can automatically produce a skeleton user selection function, which includes the Ntuple declaration via the calls HBNT, HBNAME and HBNAMC, and can be used in a later run to access the elements of the Ntuple. Two cases are available; one for use in batch and the other for use with PAW. In the first case the common block names will be those specifed by the user in the call to HBNAME or HBNAMC. For PAW, these common names are /PAWCR4/, /PAWCR8/ and /PAWCCH/ for storing the ``single precision'' (LOGICAL, INTEGER and REAL*4), ``double precision'' (REAL*8 and COMPLEX) and CHARACTER data respectively.

                +----------------------------------------+
                |CALL  HUWFUN (LUN,ID,CHFUN,ITRUNC,CHOPT) |
                +----------------------------------------+
                                  

Action:

Write an user function or subroutine to access an Ntuple.

Input parameters:
LUN
Logical unit used to write the user routine. LUN must be opened before this call.
ID
Identifier of the Ntuple.
CHFUN
Character variable specifying the routine name.
ITRUNC
All variable names will be truncated to ITRUNC characters. ITRUNC=0 is no truncation.
CHOPT
Character variable specifying the desired options.
'B'
Make an user subroutine for batch usage (i.e. with HBNAME and HBNAMC calls) (default).
'P'
Make a PAW selection function.

A simple example of the two kinds of skeletons generated with routine HUWFUN is given below. Another more complex example can be found on page [more info], where the code of a fully worked out subroutine based on such a sketeton can also be studied.

In PAW, the command UWFUNC generates a skeleton for the RWN or CWN analysis function automatically.

         Example of an Ntuple definition and HUWFUN usage
                                  

      COMMON /CVECT/ V1, V2, V3, V4, V5, V6, V7, V8, V9, V10,
     +               V11, V12, V13, V14, V15, V16, V17, V18, V19, V20
      ...
      ...
*
*-- book N-tuple 20
*
      CALL HBNT(20,'1 block 20 variable N-tuple', ' ')
      CALL HBNAME(20,'VECT',V1,'V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,
     +                          V12,V13,V14,V15,V16,V17,V18,V19,V20')
*
      ...
      OPEN(11,FILE='nt20.f',STATUS='UNKNOWN')
      OPEN(12,FILE='nt20p.f',STATUS='UNKNOWN')
      CALL HUWFUN(11, 20, 'NT20', 0, 'B')
      CALL HUWFUN(12, 20, 'NT20', 0, 'P')
      ...

The HUWFUN output files nt20.f and nt20p.f look like:

                            File nt20.f
                                  

      SUBROUTINE NT20
*********************************************************
*                                                       *
* This file was generated by HUWFUN.                    *
*                                                       *
*********************************************************
*
*     N-tuple Id:     20
*     N-tuple Title:  1 block 20 variable N-tuple
*     Creation:       11/06/92 18.46.10
*
*********************************************************
*
      REAL V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17

     + ,V18,V19,V20
      COMMON /VECT/ V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15
     + ,V16,V17,V18,V19,V20
*
      CALL HBNAME(20,' ',0,'$CLEAR')
      CALL HBNAME(20,'VECT',V1,'$SET')
*
*
*--   Enter user code here
*
*
      END
                           File nt20p.f
                                  

      REAL FUNCTION NT20()
*********************************************************
*                                                       *
* This file was generated by HUWFUN.                    *
*                                                       *
*********************************************************
*
*     N-tuple Id:     20
*     N-tuple Title:  1 block 20 variable N-tuple
*     Creation:       11/06/92 18.46.10
*
*********************************************************
*
      COMMON /PAWIDN/ IDNEVT,VIDN1,VIDN2,VIDN3,VIDN(10)
*
      REAL V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14,V15,V16,V17
     + ,V18,V19,V20
      COMMON /PAWCR4/ V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13,V14
     + ,V15,V16,V17,V18,V19,V20
*
*
*--   Enter user code here
*
      NT20 = 1.
*
      END

Optimizing event loops

PAW is able, before starting the loop over the events, to find out which are the columns of the CWN which are actually referenced in any given query (command line selection expression or COMIS routine). Only the columns which are referenced will be read from the file.

If you analyse Ntuple data without PAW, it is your own responsibility to find out and specify which are the columns referenced via the routines HGNTV or HGNTB (if all variables in a block are needed).

This optimization can be very important. Assume, for instance, that a 100 Mbyte file contains an Ntuple consisting of 300 columns, and that 3 columns are referenced. Then without optimization the complete 100 Mbyte file will have to be read, while, by specifying the columns used, only 1 Mbyte will be input.