AntiSender documentation

The AntiSender software documentation is under construction!

If you have questions about it please contact Andy Stachyra or Hans Berns.

/*********************************************************************
*                                                                    *
*                            antisender.c                            *
*                                                                    *
*                      By Andrew L. Stachyra                         *
*                               and                                  *
*                         Yoshinari Hayato                           *
*                                                                    *
*            [currently maintained/updated by Hans Berns]            *
*                                                                    *
*  This program is designed to send data from the SuperKamiokande    *
*  outer detector to a program called event_builder, written by      *
*  Hayato-san, which runs on the main host computer.                 *
*                                                                    *
*********************************************************************/

Revisions

CURRENT VERSION = antisender.c.030818

(reverse order: last update first)

/*********************************************************************
*
*  Version history (reverse order, last comes first):
*
*  030818 HGB: - new "delay" number isn't working as expected => fixed.
*
*  030817 HGB: - add column "delay" in sendperf.run_XXXXX logfile to
*                record&debug collector->sender processing delays, where
*                "delay" = current local time - last event (gps)time.
*
*  030319 HGB: - modified the use of errlogfp: now fopen() and fclose()
*                only when needed, instead of leaving open for the
*                entire run.
*              - better limits on repeated "Event count did not increment"
*                and "Event count jumped" messages, to avoid error
*                message flooding.
*
*  030218 HGB: - added stop_evbuild flag to check for evbuild_ready flag,
*                requested by Shiozawa-san. Hopefully this will eliminate
*                occasional run end error messages from the event builder.
*
*  021115 HGB: - changed nblab_file path to /home/online/flags/
*
*  021016 HGB: - log ANTI/ODPED/GPS type count in summary file
*
*  021001 HGB: - added ODPED_DATA_TYPE=52 to process OD pedestal events
*
*  020929 HGB: - online/net_shm header change requires recompile
*
*  010223 HGB: - now ignores invalid event builder request (i.e. if
*                event_requested_to = 0), instead of sending empty block.
*                Hopefully, that'll finally fix occasional missing OD data
*                at beginnings of new runs after stop/start.
*              - additional shift instruction for errsend messages.
*
*  010108-14:  - additional log messages if initial event builder request
*                is invalid (e.g. leftover from previous run).
*
*  001025 HGB: - reset net_shm->stab[].from/.to at SETUP phase.
*
*  001023 HGB: - added checking condition 
*                (event_ctr >= net_shm->stab[server_number].from)
*                at beginning of a new run.  Some runs found to start
*                with eventbuilder request of final event block of
*                the previous run.  This caused the reformatter to
*                miss OD events for 1-3 minutes after run start.
*
*  001018/22:  - additional debug logs at run beginning (first 40 blocks
*                sent to event builder) [response to Hayato's finding of
*                missing OD data at start of some runs].
*
*  000410 HGB: - removed oh_shit script call...
*
*  000404 HGB: - moved stop_func() after inner while() loop is finished
*                and added new flag stop_request instead.  now the sender
*                should be able to catch the very final eventbuilder
*                request, after final nova buffer acknowledged, before
*                returning to init state.
*
*  000320/24:  - put request() calls in send_next_events() into new
*                subsection update_net_shm() and rearranged order of
*                statistics updater to minimize send/request times with
*                event builder.
*              - make header/trailer handling in send_data() faster.
*              - after receiving final nova buffer, adjust final event
*                to last event requested via net_shm.
*
*  000317 HGB: - changed MIN_OBSRV_INTERVAL to variable min_obsrv_events
*                for user selectable heartbeat rate (for future when
*                SLE rate will be increased again).
*
*  000313 HGB: - added sendtime.run_XXXX log file for debugging sender's
*                transfer rate and throughput.
*              - rearranged summary statistics output
*
*  000312 HGB: - added FILL_BLANK_HEADERS flag to gpshead_flag to select
*                whether to generate fake blank headers or no headers
*                for non-split trigger data.
*
*  000111 HGB: - added ERR_LOG and PERF_LOG control variables to avoid
*                using fprintf() to file pointers errlogfp or perflog if
*                they're neither open nor NULL pointers.  Precautionary
*                change after anticollector problems with file NULL pointer
*                were discovered.
*                
*  991007 HGB: - adjusted heart-beat rate (MIN_OBSRV_INTERVAL) to 1000
*                events and MIN_EVENT_JUMP to 5000 to adjust to recently
*                increased Super-SLE rate.
*
*  990812 HGB: - write_summary_file() now for first 5 buffers, too.
*
*  990810 HGB: - in write_summary_file() replaced net_shm->run_num with
*                screwed_up_anti_header.run_number so that subroutine will
*                correctly finish even when there's a network error.
*              - added printing "*" when in while() setup loops with sleep().
*
*  990806 HGB: - reorganized fatal error messages to new subroutine
*                send_error_messages(), and changed all msgsend() call
*                before an exit() to errsend().
*
*  990730 HGB: - additional error messages if fatal errors are detected
*                before exit() is called.  Better for debugging...
*
*  990724 HGB: - changed heartbeat frequency to adapt to higher SLE vs.
*                OD/HE trigger rate; now MIN_OBSRV_INTERVAL = 300.
*              - place "H" in heartbeat count if only ANTI/GPS header
*                without TDC data.
*
*  990504/5:   - Network errors found to be mostly fatal.  Therefore,
*                some changes with error message display and summary file.
*              - changed nblab parametring slightly:  squeezed in level 2
*                to display NONFATAL_ERR in addition to level 1; levels >2
*                moved one level up; so, now levels 0...7 are valid.
*
*  990503 HGB: - possible cause for occasional segmentatin fault crahes:
*                send_next_event() seems to be called via signal interrupt
*                even if stop notification has already been acknowledged.
*                quick fix: added if(!stop_flag) into send_next_events().
*
*  990426 HGB: - added debugging lines before and after stop_func()
*                is called to trace why the sender still occasionally
*                crashes with segmentation fault.
*
*  990423 HGB: - in inner while() loop of main() placed an if(!stop_flag)
*                to avoid calling read_new_nova_buffer() twice if
*                final NOVA buffer has already been received.
*
*  990215/18:  - in get_sendlength() take into account GPS headers
*                from sorter if GPSHEAD is not selected, otherwise
*                the sender will interpret a GPS header as valid ANTI
*                data and complain about non-incrementing event numbers.
*
*  990214 HGB: - added on-the-fly option to change output data from
*                ANTI-DATA-only to ANTI_DATA-with-GPS_HEADER via flag
*                file /home/online/flag/gpshead_flag
*
*  990207 HGB: - a little code cleanup (introducing Summary structure)
*                and write_summary_file()
*
*  990205 HGB: - added gps_header datastructure and changed all sections
*                to deal with additional GPS data at end of each event
*                as transfered by the new sorter/collector
*
*  980501 HGB: - changed inner while(1) loop to while(!stop_func)
*                and removed the if(stop_func==TRUE) section at end
*                of loop.  [I hate "break;" statements!!].
*              - removed histogramming of event gap statistics since
*                it turned out to be useless.
*
*  980429 HGB: - added one final error message for case of "imperfect" run
*                (forgot at last version).
*
*  980212 HGB: - added another variable to histogram.event_gaps for
*                 debugging
*
*  980205 HGB: - added more debugging features:
*                - timestamps to performance log file
*                - histogram file of event gap statistics.
*
*  980202 HGB: - nova_filled_events had no data -> corrected.
*              - slight changes in read_new_nova_buffer().
*
*  980128 HGB: - changed the NBLAB decision tree and error
*                 messaging slightly.
*              - introducing log file sendperf.run_XXXX
*
*  980119 HGB: - start of code cleanup and re-arrangement
*
*  970710 AS:  I changed the heartbeat so that it prints a "." if
*              substantive data is being passed to the event builder,
*              and it prints a "_" if empty headers are sent to the
*              event bulider.  Additionally, it prints an "X" if the
*              low-level sockets routine that sends data ever fails,
*              although this should be extremely rare.  I also shortened
*              the end-of-run summary message in the errorlog file.
*
*  970625 AS:  I gave the sender the ability to recognize "empty" nova
*              buffers.  These are buffers that do not contain any useful
*              data.  The sorter communicates to the sender that the
*              buffer is garbage by setting its length equal to
*              EMPTY_NOVA_BUFFER bytes.
*
*  970529 AS:  I added a "heartbeat" for when the nblab variable is set
*              really low, so that at a bare minimum one always gets a
*              dot printed to the screen every so often.
*              Also I reduced and eliminated some of the error messaging
*              associated with filling in events for which there is no
*              data, because it is now the norm for the new split-trigger
*              configuration that we will be using regularly very soon.
*
*  970212b AS: I changed one small thing about the errorlog file so that
*              it makes more intuitive sense.
*
*  970212 AS:  I added in some counters to give us some stats, and
*              revamped the performance/errorfile, as well as added a few
*              comments.
* 
*  970211 AS:  I added in code to control error messaging.  This code
*              uses a variable called "nblab" to decide which messages to
*              print.
*
*  961230 AS:  I removed the line which defines DO_ACK at Shiozawa-san's
*              request.  This will increase the rate of data transfer by
*              eliminating some hand-shaking process.
*
*  960822 JG:  antisender.c.aug22
*
************************************************************************/