C------------------------------------------------
      FUNCTION OPTOFLEV1(name,trnev)
C------------------------------------------------
C     Written by Emiliano Mocchiutti
C     v. 0.2
C	  
      INCLUDE 'COMMONTOF.TXT'
C
      CHARACTER*100 name
C
      INTEGER lrec, optoflev1,trnev
      INTEGER istat
      PARAMETER (lrec=8190)
      REAL hmemor(9000000)
      integer Iquest(100)    
      COMMON /pawc/hmemor
      save /pawc/
      Common /QUEST/ Iquest
      save /quest/
      CALL HLIMIT(9000000)
      Iquest(10) = 256000
C
      optoflev1 = 0
      trnev = 0
C 
C     CHANGE here (hbname and hbnt if you want another ntuple id number
C
      call HROPEN(89,'TOF',name,'QP',4096,istat)
      if(istat.ne.0) goto 19      
      call HRIN(2,9999,0)       
      call access_tof
      call HNOENT(2,trnev)

 19   continue

C
c
      RETURN
      END


      SUBROUTINE access_tof
*
      include 'COMMONTOF.TXT'

      CALL HBNAME(2,' ',0,'$CLEAR')
*
      CALL HBNAME(2,'EVENT',GOOD2,'$SET')
*
      CALL HBNAME(2,'CPU',PKT_TYPE,'$SET')
*
      CALL HBNAME(2,'TOF',TDCID,'$SET')
*
      CALL HBNAME(2,'TRIGGER',TRIG_EVCOUNT,'$SET')
*
      CALL HBNAME(2,'TRACKS',NTRK,'$SET')
*
      CALL HBNAME(2,'SINGLETS',NCLSX,'$SET')
*

*
      return
      END
