logical function hec_nextevt_online_epio(irecbuf,iepbuf) c c read next event from data and save into common blocks c in include files c c hec_nextevt_online_epio = .true. => event read successfully c = .false. => event read successfully and eof c c Author: 07.04.97 Dieter Striegel c modified: 29.04.97 Dugan O'Neil c modified: 12.10.97 Rob Davis c modified: 24.11.99 Carla Sbarra c implicit none c include'hec_par.inc' !shared parameters include'hec_datacard.inc' include'hec_epio.inc' include'hec_evth.inc' include'hec_online.inc' include'hec_runh.inc' include'hec_stats_epio.inc' !epio banks stats c c set the maximum number of records to search for the first c record containing an event header bank c integer maxrecords parameter (maxrecords = 10) c c set the maximum number of banks expected in a record c integer maxsubl parameter (maxsubl = 10) c c local variable declarations c integer i, ib, id, ierr, nw, len integer irecords, nbank, lenrec c integer lbank(maxsubl) logical getmore logical b_adc c c dimension epio buffer arrays c integer*2 irecbuf, iepbuf dimension irecbuf(lrecbuf), iepbuf(lepbuf) c c we are looking for the logical record whose first bank is the c event header bank. In such logical record are also stored: c the adc value bank c the beam chamber bank c the tdc value bank c the fadc value bank c start by assuming we do not have it c b_adc = .false. c c loop over all records, until a record starting with an c event header bank is found c irecords = 0 getmore = .true. do while (irecords .lt. maxrecords .and. getmore) c c call epio reading c call epread(in_typ(2), 1, nw, irecbuf, iepbuf, ierr) c C print *, ' number of words in epio record ', irecbuf(1) C write(*, '(10i6)') (irecbuf(i), i = 1, irecbuf(1)) c if (ierr .eq. 1) then c c end of file c eorflag = .true. print *, ' *** end of epio file reached' hec_nextevt_online_epio = .false. return c elseif (ierr .ne. 0) then c c epread error c print *, ' *** epread error in hec_nextevt_online_epio ' + , ierr, ' returning to event loop' hec_nextevt_online_epio = .false. return c else c c count number of records read c irecords = irecords + 1 c c get first bank c len = irecbuf(2) do i = 1, min(len + 1, lrecbuf) ibankbuf(i) = irecbuf(1 + i) enddo c c get id and pointer of first bank in record c id = ibankbuf(2) c c record starts with event header c this is a proper event record c if (id .eq. id_evth) then getmore=.false. endif endif c enddo c c check that we have found an event header, if not, stop c if (irecords .ge. maxrecords) then print *, ' *** no event record found in ', + 'hec_nextevt_online_epio' hec_nextevt_online_epio = .false. return endif c c find pointers to banks in event record c getmore = .true. nbank = 0 ipointep = 2 do while (nbank .lt. maxsubl .and. getmore) len = irecbuf(ipointep) if (len .lt. 1) then print *,' *** bad bank length in ', + ' hec_nextevt_online_epio', len hec_nextevt_online_epio = .false. return endif c len = len + 1 nbank = nbank + 1 lbank(nbank)= ipointep ipointep = ipointep + len c c make sure not to go past end of record c fixes for particular run periods c lenrec = irecbuf(1) if (irunpd .eq. 1 .or. irunpd .eq. 3) then if (ipointep .lt. lenrec - 1) then getmore = .true. else getmore = .false. endif else if (ipointep - 2 .lt. lenrec - 1) then getmore = .true. else getmore = .false. endif endif enddo c c for this event record, loop over banks and fill commons c do ib = 1, nbank c c get pointer to the beginning of current bank c ipointep = lbank(ib) c c get current bank c len = irecbuf(ipointep) do i = 1, min(len + 1, lrecbuf) ibankbuf(i) = irecbuf(ipointep - 1 + i) enddo c c get bank id c id = ibankbuf(2) c c event header bank c if (id .eq. id_evth) then call hec_evth_epio stat_evth = stat_evth + 1 c c beam chamber bank c elseif (id .eq. id_dwpc) then call hec_dwpc_epio stat_dwpc = stat_dwpc + 1 c c adc values bank c elseif (id .eq. id_adc_96 .or. id .eq. id_adc_97) then call hec_adc_epio stat_adc = stat_adc + 1 b_adc = .true. c c fadc values bank c ccc elseif (id .eq. id_fadc) then ccc call hec_fadc_epio ccc stat_fadc = stat_fadc + 1 c c tdc values bank c elseif (id .eq. id_tdc) then call hec_tdc_epio stat_tdc = stat_tdc + 1 endif c enddo c c check conditions for good event c event header has been found c if (calo_on_flag) then hec_nextevt_online_epio = b_adc else hec_nextevt_online_epio = .true. endif c if (.not. hec_nextevt_online_epio) then print *, ' *** bad event structure in ', + ' hec_nextevt_online_epio' hec_nextevt_online_epio = .false. return endif c end