Fork me on GitHub

source: svn/trunk/Utilities/stdhep/mcf_hepev4_xdr.c@ 208

Last change on this file since 208 was 3, checked in by Xavier Rouby, 16 years ago

first commit

File size: 12.1 KB
Line 
1/*******************************************************************************
2* *
3* mcf_hepev4_xdr.c -- XDR Utility routines for the Block Stdhep filters *
4* hepevt and hepev4 (and optionally hepev2 and hepev3) *
5* *
6* Copyright (c) 1994 Universities Research Association, Inc. *
7* All rights reserved. *
8* *
9* This material resulted from work developed under a Government Contract and *
10* is subject to the following license: The Government retains a paid-up, *
11* nonexclusive, irrevocable worldwide license to reproduce, prepare derivative *
12* works, perform publicly and display publicly by or for the Government, *
13* including the right to distribute to other Government contractors. Neither *
14* the United States nor the United States Department of Energy, nor any of *
15* their employees, makes any warranty, express or implied, or assumes any *
16* legal liability or responsibility for the accuracy, completeness, or *
17* usefulness of any information, apparatus, product, or process disclosed, or *
18* represents that its use would not infringe privately owned rights. *
19* *
20* *
21* Written by Paul Lebrun, Lynn Garren *
22* *
23* *
24*******************************************************************************/
25#include <stdio.h>
26#include <string.h>
27#include <sys/param.h>
28#include <rpc/types.h>
29#include <sys/types.h>
30#include <rpc/xdr.h>
31#include <limits.h>
32#ifdef SUNOS
33#include <floatingpoint.h>
34#else /* SUNOS */
35#include <float.h>
36#endif /* SUNOS */
37#include <stdlib.h>
38#include <time.h>
39#include "Utilities/mcfio/mcfio_Dict.h"
40#include "Utilities/mcfio/mcf_xdr.h"
41#include "Utilities/stdhep/stdhep.h"
42#include "Utilities/stdhep/hepev4.h"
43#include "Utilities/stdhep/stdtmp.h"
44#include "Utilities/stdhep/stdver.h"
45#ifndef FALSE
46#define FALSE 0
47#endif
48#ifndef TRUE
49#define TRUE 1
50#endif
51
52extern struct stdver stdver_;
53extern struct hepevt myhepevt;
54extern struct hepev2 hepev2_;
55extern struct hepev3 hepev3_;
56extern struct hepev4 hepev4_;
57extern struct hepev5 hepev5_;
58extern struct stdtmp stdtmp_;
59extern struct tmpev4 tmpev4_;
60
61bool_t xdr_stdhep_4_(XDR *xdrs, int *blockid,
62 int *ntot, char** version)
63
64{
65/* Translate the HEPEVT temporary COMMON block from the STDHEP package to/from
66 an XDR stream. Note that we do not allocate memory, because we fill
67 directly the COMMON. Also, mcfio will allocate the space for the
68 string version. */
69
70 unsigned int nn, nn2, nn3, nn4, nn5, nnw, nnw2, nnw3, nnw4, nnw5;
71 int *idat;
72 double *dat;
73 unsigned int n5 = 5; /* for scale */
74
75 if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_MCFIOCODE)) {
76 if (*blockid != MCFIO_STDHEP4) {
77 fprintf (stderr, "mcf_hepev4_xdr: Inconsistent Blockid %d \n ",
78 (*blockid));
79 return FALSE;
80 }
81
82 nn = (unsigned int) stdtmp_.nhept; /* Number of elements in isthep or idhep */
83 nn2 = 2*(unsigned int) stdtmp_.nhept; /* Number of elements in jmohep or jdahep */
84 nn3 = 3*(unsigned int) stdtmp_.nhept; /* Number of elements in spinlh */
85 nn4 = 4*(unsigned int) stdtmp_.nhept; /* Number of elements in vhep */
86 nn5 = 5*(unsigned int) stdtmp_.nhept; /* Number of elements in phep */
87 nnw = (unsigned int) stdtmp_.nhept;
88 nnw2 = 2 * nnw;
89 nnw3 = 3 * nnw;
90 nnw4 = 4 * nnw;
91 nnw5 = 5 * nnw;
92
93 /* Total length in bytes include blockid, ntot, version, nevhept and nhept as well
94 as the arrays remembering doubles are longer than ints. */
95 *ntot = 5*sizeof(int) + sizeof(int)*(2*nn + 2*nn2)
96 + sizeof(double)*(nn4 + nn5)
97 + (8 + nn3)*sizeof(double) + (1 + nn2)*sizeof(int);
98
99 if (xdrs->x_op == XDR_MCFIOCODE) return TRUE;
100 strncpy(version[0],stdver_.stdhep_ver, 4);
101 }
102
103 if ( (xdr_int(xdrs, blockid) &&
104 xdr_int(xdrs, ntot) &&
105 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH) &&
106 xdr_int(xdrs, &(stdtmp_.nevhept)) &&
107 xdr_int(xdrs, &(stdtmp_.nhept))) == FALSE) return FALSE;
108
109 if ((xdrs->x_op == XDR_DECODE) && ( *blockid != MCFIO_STDHEP4) ) {
110 fprintf (stderr, "mcf_hepev4_xdr: Inconsistent Blockid %d \n ",
111 (*blockid));
112 return FALSE;
113 }
114 idat = stdtmp_.isthept;
115 if ( xdr_array(xdrs, (char **) &idat,
116 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
117 idat = stdtmp_.idhept;
118 if ( xdr_array(xdrs, (char **) &idat,
119 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
120 idat = (int *) stdtmp_.jmohept;
121 if ( xdr_array(xdrs, (char **) &idat,
122 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
123 idat = (int *) stdtmp_.jdahept;
124 if ( xdr_array(xdrs, (char **) &idat,
125 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
126 dat = (double *) stdtmp_.phept;
127 if ( xdr_array(xdrs, (char **) &dat,
128 &nnw5, 5*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
129 dat = (double *) stdtmp_.vhept;
130 if ( xdr_array(xdrs, (char **) &dat,
131 &nnw4, 4*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
132 /* valid for stdhep 5.01 and later */
133 if ( xdr_double(xdrs, &(tmpev4_.eventweightt) ) == FALSE) return FALSE;
134 if ( xdr_double(xdrs, &(tmpev4_.alphaqedt) ) == FALSE) return FALSE;
135 if ( xdr_double(xdrs, &(tmpev4_.alphaqcdt) ) == FALSE) return FALSE;
136 dat = (double *) tmpev4_.scalet;
137 if ( xdr_array(xdrs, (char **) &dat,
138 &n5, 10, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
139 dat = (double *) tmpev4_.spint;
140 if ( xdr_array(xdrs, (char **) &dat,
141 &nnw3, 3*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
142 idat = (int *) tmpev4_.icolorflowt;
143 if ( xdr_array(xdrs, (char **) &idat,
144 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
145 if ( xdr_int(xdrs, &(tmpev4_.idrupt) ) == FALSE) return FALSE;
146 return TRUE;
147}
148
149bool_t xdr_stdhep_4_multi_(XDR *xdrs, int *blockid,
150 int *ntot, char** version)
151
152{
153/* Translate the HEPEVT COMMON block from the STDHEP package to/from
154 an XDR stream. Note that we do not allocate memory, because we fill
155 directly the COMMON. Also, mcfio will allocate the space for the
156 string version.
157 Also translate the HEPEV2 COMMON block from the STDHEP package to/from
158 an XDR stream. HEPEV2 contains multiple interaction information */
159
160 unsigned int nn, nn2, nn3, nn4, nn5, nnw, nnw2, nnw3, nnw4, nnw5;
161 unsigned int nmlt, nnmlt, nmltd, nnmlt5;
162 int *idat;
163 double *dat;
164 unsigned int n5 = 10; /* for scale */
165
166 if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_MCFIOCODE)) {
167 if (*blockid != MCFIO_STDHEP4M) {
168 fprintf (stderr, "mcf_hepev4_xdr: Inconsistent Blockid %d \n ",
169 (*blockid));
170 return FALSE;
171 }
172 nn = sizeof(int) * myhepevt.nhep;
173 nn2 = 2 * sizeof(int) * myhepevt.nhep;
174 nn3 = 3 * sizeof(double) * myhepevt.nhep;
175 nn4 = 4 * sizeof(double) * myhepevt.nhep;
176 nn5 = 10 * sizeof(double) * myhepevt.nhep;
177 nmlt = sizeof(int) * hepev2_.nmulti;
178 nmltd = sizeof(double) * hepev2_.nmulti;
179 nnw = (unsigned int) myhepevt.nhep;
180 nnw2 = 2 * nnw;
181 nnw3 = 3 * nnw;
182 nnw4 = 4 * nnw;
183 nnw5 = 5 * nnw;
184 nnmlt = (unsigned int) hepev2_.nmulti;
185 nnmlt5 = 5 * nnmlt;
186 *ntot = 6 * sizeof(int) + 3 * nn + 2 * nn2 + nn4 + nn5 + 3 * nmlt
187 + nn3 + 8 * sizeof(double) + nn2 + sizeof(int)
188 + 8 * nmltd + nmlt;
189 if (xdrs->x_op == XDR_MCFIOCODE) return TRUE;
190 strncpy(version[0],stdver_.stdhep_ver, 4);
191 }
192
193 if ( (xdr_int(xdrs, blockid) &&
194 xdr_int(xdrs, ntot) &&
195 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH) &&
196 xdr_int(xdrs, &(myhepevt.nevhep)) &&
197 xdr_int(xdrs, &(myhepevt.nhep))) == FALSE) return FALSE;
198
199 if ((xdrs->x_op == XDR_DECODE) && ( *blockid != MCFIO_STDHEP4M) ) {
200 fprintf (stderr, "mcf_hepev4_xdr: Inconsistent Blockid %d \n ",
201 (*blockid));
202 return FALSE;
203 }
204 idat = myhepevt.isthep;
205 if ( xdr_array(xdrs, (char **) &idat,
206 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
207 idat = myhepevt.idhep;
208 if ( xdr_array(xdrs, (char **) &idat,
209 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
210 idat = (int *) myhepevt.jmohep;
211 if ( xdr_array(xdrs, (char **) &idat,
212 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
213 idat = (int *) myhepevt.jdahep;
214 if ( xdr_array(xdrs, (char **) &idat,
215 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
216 dat = (double *) myhepevt.phep;
217 if ( xdr_array(xdrs, (char **) &dat,
218 &nnw5, 5*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
219 dat = (double *) myhepevt.vhep;
220 if ( xdr_array(xdrs, (char **) &dat,
221 &nnw4, 4*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
222 /*
223 ** V2.02 Upgrade : adding Multiple interactions.
224 */
225 if ( xdr_int(xdrs, &(hepev2_.nmulti)) == FALSE) return FALSE;
226 idat = hepev2_.jmulti;
227 if ( xdr_array(xdrs, (char **) &idat,
228 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
229 /*
230 ** V4.04 Upgrade : adding more Multiple interaction information
231 */
232 idat = hepev3_.nevmulti;
233 if ( xdr_array(xdrs, (char **) &idat,
234 &nnmlt, NMXMLT, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
235 idat = hepev3_.itrkmulti;
236 if ( xdr_array(xdrs, (char **) &idat,
237 &nnmlt, NMXMLT, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
238 idat = hepev3_.mltstr;
239 if ( xdr_array(xdrs, (char **) &idat,
240 &nnmlt, NMXMLT, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
241 /* valid for stdhep 5.01 and later */
242 if ( xdr_double(xdrs, &(hepev4_.eventweightlh) ) == FALSE) return FALSE;
243 if ( xdr_double(xdrs, &(hepev4_.alphaqedlh) ) == FALSE) return FALSE;
244 if ( xdr_double(xdrs, &(hepev4_.alphaqcdlh) ) == FALSE) return FALSE;
245 dat = (double *) hepev4_.scalelh;
246 if ( xdr_array(xdrs, (char **) &dat,
247 &n5, 10, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
248 dat = (double *) hepev4_.spinlh;
249 if ( xdr_array(xdrs, (char **) &dat,
250 &nnw3, 3*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
251 idat = (int *) hepev4_.icolorflowlh;
252 if ( xdr_array(xdrs, (char **) &idat,
253 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
254 if ( xdr_int(xdrs, &(hepev4_.idruplh) ) == FALSE) return FALSE;
255 dat = (double *) hepev5_.eventweightmulti;
256 if ( xdr_array(xdrs, (char **) &dat,
257 &nnmlt, NMXMLT, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
258 dat = (double *) hepev5_.alphaqedmulti;
259 if ( xdr_array(xdrs, (char **) &dat,
260 &nnmlt, NMXMLT, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
261 dat = (double *) hepev5_.alphaqcdmulti;
262 if ( xdr_array(xdrs, (char **) &dat,
263 &nnmlt, NMXMLT, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
264 dat = (double *) hepev5_.scalemulti;
265 if ( xdr_array(xdrs, (char **) &dat,
266 &nnmlt5, 10*NMXMLT, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
267 idat = hepev5_.idrupmulti;
268 if ( xdr_array(xdrs, (char **) &idat,
269 &nnmlt, NMXMLT, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
270 return TRUE;
271}
272
273
Note: See TracBrowser for help on using the repository browser.