1
/*******************************************************************************
3
* mcf_Stdhep_xdr.c -- XDR Utility routines for the Block Stdhep filters *
5
* Copyright (c) 1994 Universities Research Association, Inc. *
6
* All rights reserved. *
8
* This material resulted from work developed under a Government Contract and *
9
* is subject to the following license: The Government retains a paid-up, *
10
* nonexclusive, irrevocable worldwide license to reproduce, prepare derivative *
11
* works, perform publicly and display publicly by or for the Government, *
12
* including the right to distribute to other Government contractors. Neither *
13
* the United States nor the United States Department of Energy, nor any of *
14
* their employees, makes any warranty, express or implied, or assumes any *
15
* legal liability or responsibility for the accuracy, completeness, or *
16
* usefulness of any information, apparatus, product, or process disclosed, or *
17
* represents that its use would not infringe privately owned rights. *
20
* Written by Paul Lebrun, Lynn Garren *
23
*******************************************************************************/
26
#include <sys/param.h>
27
#include <rpc/types.h>
28
#include <sys/types.h>
32
#include <floatingpoint.h>
38
#include "mcfio_Dict.h"
50
struct stdver stdver_;
52
bool_t xdr_stdhep_(XDR *xdrs, int *blockid,
53
int *ntot, char** version)
56
/* Translate the HEPEVT temporary COMMON block from the STDHEP package to/from
57
an XDR stream. Note that we do not allocate memory, because we fill
58
directly the COMMON. Also, mcfio will allocate the space for the
61
unsigned int nn, nn2, nn4, nn5, nnw, nnw2, nnw4, nnw5;
65
if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_MCFIOCODE)) {
66
if (*blockid != MCFIO_STDHEP) {
67
fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ",
72
nn = (unsigned int) stdtmp_.nhept; /* Number of elements in isthep or idhep */
73
nn2 = 2*(unsigned int) stdtmp_.nhept; /* Number of elements in jmohep or jdahep */
74
nn4 = 4*(unsigned int) stdtmp_.nhept; /* Number of elements in vhep */
75
nn5 = 5*(unsigned int) stdtmp_.nhept; /* Number of elements in phep */
76
nnw = (unsigned int) stdtmp_.nhept;
81
/* Total length in bytes include blockid, ntot, version, nevhept and nhept as well
82
as the arrays remembering doubles are longer than ints. */
83
*ntot = 5*sizeof(int) + sizeof(int)*(2*nn + 2*nn2) + sizeof(double)*(nn4 + nn5);
85
if (xdrs->x_op == XDR_MCFIOCODE) return TRUE;
86
strncpy(version[0],stdver_.stdhep_ver, 4);
89
if ( (xdr_int(xdrs, blockid) &&
90
xdr_int(xdrs, ntot) &&
91
xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH) &&
92
xdr_int(xdrs, &(stdtmp_.nevhept)) &&
93
xdr_int(xdrs, &(stdtmp_.nhept))) == FALSE) return FALSE;
95
if ((xdrs->x_op == XDR_DECODE) && ( *blockid != MCFIO_STDHEP) ) {
96
fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ",
100
idat = stdtmp_.isthept;
101
if ( xdr_array(xdrs, (char **) &idat,
102
&nnw, NMXHEP, sizeof(int), xdr_int) == FALSE) return FALSE;
103
idat = stdtmp_.idhept;
104
if ( xdr_array(xdrs, (char **) &idat,
105
&nnw, NMXHEP, sizeof(int), xdr_int) == FALSE) return FALSE;
106
idat = (int *) stdtmp_.jmohept;
107
if ( xdr_array(xdrs, (char **) &idat,
108
&nnw2, 2*NMXHEP, sizeof(int), xdr_int) == FALSE) return FALSE;
109
idat = (int *) stdtmp_.jdahept;
110
if ( xdr_array(xdrs, (char **) &idat,
111
&nnw2, 2*NMXHEP, sizeof(int), xdr_int) == FALSE) return FALSE;
112
dat = (double *) stdtmp_.phept;
113
if ( xdr_array(xdrs, (char **) &dat,
114
&nnw5, 5*NMXHEP, sizeof(double), xdr_double) == FALSE) return FALSE;
115
dat = (double *) stdtmp_.vhept;
116
if ( xdr_array(xdrs, (char **) &dat,
117
&nnw4, 4*NMXHEP, sizeof(double), xdr_double) == FALSE) return FALSE;
121
bool_t xdr_stdhep_multi_(XDR *xdrs, int *blockid,
122
int *ntot, char** version)
125
/* Translate the HEPEVT COMMON block from the STDHEP package to/from
126
an XDR stream. Note that we do not allocate memory, because we fill
127
directly the COMMON. Also, mcfio will allocate the space for the
129
Also translate the HEPEV2 COMMON block from the STDHEP package to/from
130
an XDR stream. HEPEV2 contains multiple interaction information */
132
unsigned int nn, nn2, nn4, nn5, nnw, nnw2, nnw4, nnw5, nmlt, nnmlt;
138
if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_MCFIOCODE)) {
139
if (*blockid != MCFIO_STDHEPM) {
140
fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ",
144
nn = sizeof(int) * hepevt_.nhep;
145
nn2 = 2 * sizeof(int) * hepevt_.nhep;
146
nn4 = 4 * sizeof(double) * hepevt_.nhep;
147
nn5 = 5 * sizeof(double) * hepevt_.nhep;
148
nmlt = sizeof(int) * hepev2_.nmulti;
149
nnw = (unsigned int) hepevt_.nhep;
153
nnmlt = (unsigned int) hepev2_.nmulti;
154
*ntot = 6 * sizeof(int) + 3 * nn + 2 * nn2 + nn4 + nn5 + 3 * nmlt;
155
if (xdrs->x_op == XDR_MCFIOCODE) return TRUE;
156
strncpy(version[0],stdver_.stdhep_ver, 4);
159
if ( (xdr_int(xdrs, blockid) &&
160
xdr_int(xdrs, ntot) &&
161
xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH) &&
162
xdr_int(xdrs, &(hepevt_.nevhep)) &&
163
xdr_int(xdrs, &(hepevt_.nhep))) == FALSE) return FALSE;
165
if ((xdrs->x_op == XDR_DECODE) && ( *blockid != MCFIO_STDHEPM) ) {
166
fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ",
170
idat = hepevt_.isthep;
171
if ( xdr_array(xdrs, (char **) &idat,
172
&nnw, NMXHEP, sizeof(int), xdr_int) == FALSE) return FALSE;
173
idat = hepevt_.idhep;
174
if ( xdr_array(xdrs, (char **) &idat,
175
&nnw, NMXHEP, sizeof(int), xdr_int) == FALSE) return FALSE;
176
idat = (int *) hepevt_.jmohep;
177
if ( xdr_array(xdrs, (char **) &idat,
178
&nnw2, 2*NMXHEP, sizeof(int), xdr_int) == FALSE) return FALSE;
179
idat = (int *) hepevt_.jdahep;
180
if ( xdr_array(xdrs, (char **) &idat,
181
&nnw2, 2*NMXHEP, sizeof(int), xdr_int) == FALSE) return FALSE;
182
dat = (double *) hepevt_.phep;
183
if ( xdr_array(xdrs, (char **) &dat,
184
&nnw5, 5*NMXHEP, sizeof(double), xdr_double) == FALSE) return FALSE;
185
dat = (double *) hepevt_.vhep;
186
if ( xdr_array(xdrs, (char **) &dat,
187
&nnw4, 4*NMXHEP, sizeof(double), xdr_double) == FALSE) return FALSE;
189
** V2.02 Upgrade : adding Multiple interactions.
192
if ((strcmp(vers,"1.05") == 0) && (xdrs->x_op == XDR_DECODE)) {
196
if ( xdr_int(xdrs, &(hepev2_.nmulti)) == FALSE) return FALSE;
197
idat = hepev2_.jmulti;
198
if ( xdr_array(xdrs, (char **) &idat,
199
&nnw, NMXHEP, sizeof(int), xdr_int) == FALSE) return FALSE;
201
** V4.04 Upgrade : adding more Multiple interaction information
203
if (((strcmp(vers,"2.") > 0) || (strcmp(vers,"3.") > 0))
204
&& (xdrs->x_op == XDR_DECODE)) {
205
for (i = 0; i <= NMXMLT; i++) {
206
hepev3_.nevmulti[i] = 0;
207
hepev3_.itrkmulti[i] = 0;
208
hepev3_.mltstr[i] = 0;
212
if (((strcmp(vers,"4.00") == 0) || (strcmp(vers,"4.01") == 0) ||
213
(strcmp(vers,"4.02") == 0) || (strcmp(vers,"4.03") == 0) )
214
&& (xdrs->x_op == XDR_DECODE)) {
215
for (i = 0; i <= NMXMLT; i++) {
216
hepev3_.nevmulti[i] = 0;
217
hepev3_.itrkmulti[i] = 0;
218
hepev3_.mltstr[i] = 0;
222
idat = hepev3_.nevmulti;
223
if ( xdr_array(xdrs, (char **) &idat,
224
&nnmlt, NMXMLT, sizeof(int), xdr_int) == FALSE) return FALSE;
225
idat = hepev3_.itrkmulti;
226
if ( xdr_array(xdrs, (char **) &idat,
227
&nnmlt, NMXMLT, sizeof(int), xdr_int) == FALSE) return FALSE;
228
idat = hepev3_.mltstr;
229
if ( xdr_array(xdrs, (char **) &idat,
230
&nnmlt, NMXMLT, sizeof(int), xdr_int) == FALSE) return FALSE;