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
marty@cosray2.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"