Using the WU SOFT/CRIS C Library

Marty Olevitch
Laboratory for Experimental Astrophysics
Physics Dept, Washington University in St. Louis
St. Louis, MO 63130 USA
EMAIL: marty IS AT physics.wustl.edu

Contents


Introduction

The SOFT/CRIS C Library is a collection of C routines to aid in the analysis of SOFT and CRIS data from the ACE experiment. Use of the library will help to free the programmer from having to deal with the structure of the data stream at its most basic level. It allows one to concentrate on the elements of each ``event'' without concern about the mechanics of reading the data stream or parsing each event.

Several different data formats are supported, including:

Types of coordinates

We deal with three different types of coordinates:


Trajectory selection methods

Telemetry data routines

MSU '95 data handling routines

Charge, trajectory, and coordinate routines

SOFT image manipulation routines

SOFT centroid (blob) routines


Miscellaneous routines


Appendix

Cris telemetry subset format

		Format of CRIS major and minor frames

Byte	Item	Count	Bits	Sum	Description


	A. Major frame = 256 minor frames

0	a	4	8	32	4 byte offset
4	b	128	58x8	xxx	minor frames w/SYNC=0
xxx	c	128	58x8	yyy	minor frames w/SYNC=1



	B. Minor frame = 58 bytes


		Housekeeping bytes

	(Note that these bytes really start at an offset of 4 bytes from
	the start of the data. Those 4 bytes contain the last 4 bytes of
	the previous minor frame.)

0	0	1	1	1	SYNC = 0 for 1st 128 minor frames,
					     = 1 for 2nd 128 minor frames
	1	1	1	2	CMD  = 1 if we have a cmd response
	2	1	1	3	DIAG = 1 for diagnostic mode
	3	1	5	8	housekeeping bits
1	4	1	8	16	more housekeeping bits
2	5	1	8	24	more housekeeping bits


		Command response (if item #1 [CMD bit] is true)

3	6	1	8	8	length L of response (bytes)
4	7	L	Lx8	8+(Lx8)	command echo (ascii chars)


		CRIS normal events (if item #2 [DIAG bit] is false)

	(May be continued from previous minor frame unless this is the
	start of a new major frame. Note that the event may have a
	length of 0, in which case the rest of the current minor frame
	should be skipped. If the normal event is longer than the space
	left in the minor frame, it continues in the next minor frame,
	unless it is the last minor frame in the major frame, in which case
	it is truncated or zeroed.)

3 or
4+L	8	N	X	Y	CRIS Normal events 


		DIAGNOSTIC mode data (if item #2 [DIAG bit] is true)

	(Can extend across minor and major frames. Can interrupt a CRIS
	normal event, which will then resume after Diag mode is done.)

3 or 
4+L	9	N	X	Y	Diagnostic mode data (Normal evt +
					stack data + SOFT image)

Diagram of a SOFT fiber


The L1 level 1.1 library

The ASC level 1 and 1.1 libraries do a great job of handling the data retrieval work for the CRIS data. However, one complexity of the libraries is that they require the application to #include a number of different header files (different ones depending on which routines are being used), and to be linked with a number of different ASC libraries. I found all this detail difficult to keep track of. It also required more complicated makefiles.

To remedy this problem, I have managed to incorporate all the level 1 and level 1.1 stuff into one header file and one library. This library is called the ``L1'' library. When using L1, the application only needs to include one header file (#include <L1.h>) and link with one additional library (-lL1). (in fact, when using softlib, the #include line is unnecessary because softlib.h does it for you. The header file and library are also placed in standard system locations (/usr/local/include and /usr/local/lib).

All this allows for simpler C programs and makefiles, promoting programmer sanity.

The L1 library and header file can be produced from the standard ASC libraries without modifying any of the original distribution files. A makefile that builds the library will hopefully be available here.


Error codes and messages list

These are the error codes and messages that can be retrieved using sc_get_err_code() and sc_get_err_mesg(). See also error codes. Hopefully, the list will be updated.

0 "traj_init: bad fitfunc"
1 "traj_init: can't calloc 'blobhodo'"
2 "traj_init: can't calloc 'I'"
3 "traj_init: can't calloc 'X'"
4 "traj_init: can't calloc 'Y'"
8-13 "traj_init: can't calloc 'blob[%d]'"
14 "traj_init: Can't calloc 'Mx'"
15 "traj_init: Can't calloc 'Bx'"
16 "traj_init: Can't calloc 'My'"
17 "traj_init: Can't calloc 'By'"
100 "sc_cris_traj: recv'd NULL parameter c or t"
101 "sc_cris_traj: garbled Traj_select_method = %d",
102 "sc_cris_traj: zero pha in top detector"
103 "sc_cris_traj: more than 1 hop"
109 "sc_msu_traj: can't fix blobs both cameras"
110 "sc_msu_traj: recv'd NULL parameter"
111 "sc_msu_traj: garbled Traj_select_method = %d",
120 "sc_raw_traj: recv'd NULL parameter x,y,I,c,t, or ntraj"
121 "sc_raw_traj: garbled Traj_select_method = %d"
123 "sc_raw_traj: more than 1 hop"
200 "sc_cris_coords: recv'd NULL param"
201 "sc_cris_coords: bad Traj_select_method = %d", 
202 "sc_cris_coords: nblobs (%d) > max (%d)",
210 "sc_msu_coords: nblobs (%d) and nblobsb (%d) > max (%d)",
211 "sc_msu_coords: nblobsb (%d) > max (%d)",
212 "sc_msu_coords: nblobs (%d) > max (%d)",
250 "fiber_fit: not enough blobs"
251 "fiber_fit: too many blobs"
252 "fiber_fit: too many blobs"
253 "fiber_fit: not all layers (2 or 3)"
253 "fiber_fit: not all layers"
254 "fiber_fit: not all layers (1)"
255 "fiber_fit: no X fit"
256 "fiber_fit: no Y fit"
257 "fiber_fit: bad fiber_to_real 1"
258 "fiber_fit: bad fiber_to_real 2"
259 "fiber_fit: bad fiber_to_real 3"
260 "fiber_fit: bad real x offset"
261 "fiber_fit: bad real y offset"
262 "fiber_fit: fiber bundle hit"
270 "brightest: not enough blobs"
271 "brightest: not all layers (2 or 3)"
272 "brightest: bad fiber_to_real 1"
273 "brightest: bad fiber_to_real 2"
274 "brightest: bad fiber_to_real 3"
275 "brightest: bad real x offset"
276 "brightest: bad real y offset"
277 "brightest: fiber bundle hit"
278 "brightest: not all layers (1)"
280 "sc_short_traj: not enough layers"
283 "sc_short_traj: bad fiber_to_real 2"
284 "sc_short_traj: bad fiber_to_real 3"
310 "sc_trajectory: X chisq = %.2f (> 1000.0)"
311 "sc_trajectory: Y chisq = %.2f (> 1000.0)"
420 "multitraj: recv'd NULL ptr"
421 "multitraj: not enough blobs (%d)"
422 "multitraj: too many blobs"
423 "multitraj: too many blobs"
424 "multitraj: not all layers (2 or 3)"
425 "multitraj: not all layers (1)"
426 "multitraj: fiber bundle hit"
427 "multitraj: no X fit"
429 "multitraj: no Y fit"
430 "multitraj: no fit"
431 "multitraj: bad evttype parameter"
432 "multitraj: can't calloc xtemp, ytemp, or Itemp"
500 "diag_cvt: null parameters"
501 "diag_cvt: bad normal event"
503 "diag_cvt: soft data continued into more than %d structs", 
504 "diag_cvt: no end header"
510 "next_cris_evt: called with NULL parameters\n"
511 "next_cris_evt: sc_L1_set_day() not run yet\n"
512 "next_cris_evt: last evt\n"
513 "next_cris_evt: last evt (B)\n"
520 "next_diag: called with NULL parameters\n"
521 "next_diag: sc_L1_set_day() not run yet\n"
522 "next_diag: last evt\n"
530 "next_hsk_raw: called with NULL parameters\n"
531 "next_hsk_raw: sc_L1_set_day() not run yet\n"
540 "next_cmd: called with NULL parameters\n"
541 "next_cmd: sc_L1_set_day() not run yet\n"
550 "next_hipri: called with NULL parameters\n"
551 "next_hipri: sc_L1_set_day() not run yet\n"
560 "next_lopri_raw: called with NULL parameters\n"
561 "next_lopri_raw: sc_L1_set_day() not run yet\n"
570 "next_hsk: called with NULL parameters\n"
571 "next_hsk: sc_L1_set_day() not run yet\n"
580 "next_lopri: called with NULL parameters\n"
581 "next_lopri: sc_L1_set_day() not run yet\n"
1000 "sc_telescope_hit: negative radius (%d)"
1001 "sc_telescope_hit: bad stack value (%d)"
1002 "sc_telescope_hit: no hit"

Explanation of low-priority rates.

From an email message by Robert Radocinski
Date: Tue, 27 Apr 1999 12:43:08 -0700
From: Robert.G.Radocinski@jpl.nasa.gov (Robert Radocinski)
To: lijowski@cosray2.wustl.edu
Subject: Re: CRIS Low priority rates

Michal,

The following is based on my understanding of how the CRIS firmware
works.  The authority on the CRIS on-board firmware is Rick Cook.
However, your question deals mostly with level-1 processing and my
simplified explanation of the on-board processing are strictly to
clarify the difference about which you inquired.

As you are aware, CRIS has an on-board buffering system for events and
also maintains on-board scalars for the number of events which belong
to each of the 64 on-board event buffers.  When a particle causes an
event to occur, CRIS usually time (256 second resolution) tags it
and puts it in the raw event buffer.  In the unusual case that the
raw event buffer is full, CRIS will increment the NREBFUL flag and 
discard the event.  There is another on-board firmware process that is
continually examaining the raw event buffer for new events.  If this
second process locates an event in the raw event buffer, it will
determine the event buffer number for that event and increment the
on-board scalar for that buffer.  In addition, if there is room in the
proper section of the compressed event buffer it will put the event
into the compressed event buffer; if there is no room, it will
increment the NCEBFUL flag and discard the event.  Once an event makes
it as far as the compressed event buffer, it will make it into the
telemetry.

When the level-0 data reaches the ACE Science center, the level-1 
processing generates the L1CrisLowPriorityRate data structures.  Each
data structure covers one instrument cycle (256 minor frames) and has
the two 64-element arrays EventBuffer and NumberEvents.  The values
stored in the EventBuffer array are nothing more than the on-board
scalars for each of the 64 event buffers.  The values stored in the
NumberEvents array are the number of compressed events for each buffer
in the level-0 data that have the time tag associated with the 
instrument cycle.

The EventBuffer array and the NumberEvents array can differ for the
following reasons:

   1. The on-board firmware finds an event in the raw event buffer
      that belongs to buffer[i] and it increments the on-board scalar
      for that event.  If it cannot store the event in the compressed
      event buffer, it discards it.  In this case, the event never
      makes it into the telemetry and therefore the level-1 processing
      cannot add it to the value in NumberEvents[i].
   2. On-board, there is samll time window (fractions of a second),
      which happens on instrument cycle (256 minor frames) boundaries,
      in which an event is time-tagged in one instrument cycle, but
      the on-board scalar is incremented in the next instrument cycle.
      This occurs because the event is time tagged when it is put into
      the raw event buffer, and the on-board event buffer scalar is
      incremented when the event is taken out of the raw event buffer.
   3. In some cases, when a particle event occurs during a stim event,
      the on-board firmware produces an un-interpretable event.  Since
      the level-1 software cannot interprect this event, it will not
      be able to increment the proper value of NumberEvents.
   4. Lost telemetry will also make the two arrays differ.  When
      a single minor frame is dropped, usually 1-2 compressed events
      are lost.  Therefore, the NumberEvents array will be short
      1-2 events.

In the level-1.1 software package, I generate the
L1_1CrisLowPriorityRate data structure from the L1CrisLowPriorityRate
data structure.  The values stored in the arrays EventBufferRate and
DataBufferRate are generated as follows:

   <efficiency> = NEVPROC / (NEVPROC + NREBFUL)

   <live time> = <H live time> for H buffers,
               = <He live time> for He buffers,
               = <HiZ live time> for HiZ buffers.

For each buffer i,

   EventBufferRate[i] = EventBuffer[i] / (<efficiency> * <live time>)
   DataBufferRate[i] = NumberEvents[i] / (<efficiency> * <live time>)

where EventBuffer[i] and NumberEvents[i] come from the 
L1CrisLowPriorityRate data structure.

I hope this explanation helps.


Thanks,
Robert Radocinski

P.S. The terms NREBFUL, NCEBFUL, and NEVPROC were defined in the Rick
     Cook presentation at the Summer 1997 CRIS/SIS team meeting at
     Caltech.


This line last changed 18 Apr '13.