~maddevelopers/mg5amcnlo/2.9.4

« back to all changes in this revision

Viewing changes to vendor/StdHEP/src/stdhep/mcf_Stdhep_xdr.c

pass to v2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
*                                                                              *
 
3
* mcf_Stdhep_xdr.c -- XDR Utility routines for the Block Stdhep filters        *
 
4
*                                                                              *
 
5
* Copyright (c) 1994 Universities Research Association, Inc.                   *
 
6
* All rights reserved.                                                         *
 
7
*                                                                              *
 
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.           *
 
18
*                                                                              *
 
19
*                                                                              *
 
20
* Written by Paul Lebrun, Lynn Garren                                          *
 
21
*                                                                              *
 
22
*                                                                              *
 
23
*******************************************************************************/
 
24
#include <stdio.h>
 
25
#include <string.h>
 
26
#include <sys/param.h>
 
27
#include <rpc/types.h>
 
28
#include <sys/types.h>
 
29
#include <rpc/xdr.h>
 
30
#include <limits.h>
 
31
#ifdef SUNOS
 
32
#include <floatingpoint.h>
 
33
#else /* SUNOS */
 
34
#include <float.h>
 
35
#endif /* SUNOS */
 
36
#include <stdlib.h>
 
37
#include <time.h>
 
38
#include "mcfio_Dict.h"
 
39
#include "mcf_xdr.h"
 
40
#include "stdhep.h"
 
41
#include "stdtmp.h"
 
42
#include "stdver.h"
 
43
#ifndef FALSE
 
44
#define FALSE 0
 
45
#endif
 
46
#ifndef TRUE
 
47
#define TRUE 1
 
48
#endif
 
49
 
 
50
struct stdver stdver_;
 
51
 
 
52
bool_t xdr_stdhep_(XDR *xdrs, int *blockid,
 
53
                                 int *ntot, char** version)
 
54
 
 
55
{
 
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 
 
59
    string version.  */
 
60
    
 
61
    unsigned int nn, nn2, nn4, nn5, nnw, nnw2, nnw4, nnw5;
 
62
    int *idat;
 
63
    double *dat;
 
64
    
 
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 ", 
 
68
           (*blockid));
 
69
          return FALSE;
 
70
       }
 
71
 
 
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;
 
77
       nnw2 = 2 * nnw;
 
78
       nnw4 = 4 * nnw;
 
79
       nnw5 = 5 * nnw;
 
80
 
 
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);
 
84
 
 
85
       if (xdrs->x_op == XDR_MCFIOCODE) return TRUE;
 
86
       strncpy(version[0],stdver_.stdhep_ver, 4);
 
87
       } 
 
88
      
 
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;
 
94
              
 
95
     if ((xdrs->x_op == XDR_DECODE) && ( *blockid != MCFIO_STDHEP) ) {
 
96
          fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ", 
 
97
           (*blockid));
 
98
          return FALSE;
 
99
     }
 
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;
 
118
     return TRUE;
 
119
}   
 
120
 
 
121
bool_t xdr_stdhep_multi_(XDR *xdrs, int *blockid,
 
122
                                 int *ntot, char** version)
 
123
 
 
124
{
 
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 
 
128
    string version. 
 
129
    Also translate the HEPEV2 COMMON block from the STDHEP package to/from
 
130
    an XDR stream. HEPEV2 contains multiple interaction information */
 
131
    
 
132
    unsigned int nn, nn2, nn4, nn5, nnw, nnw2, nnw4, nnw5, nmlt, nnmlt;
 
133
    int i;
 
134
    int *idat;
 
135
    char *vers;
 
136
    double *dat;
 
137
    
 
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 ", 
 
141
           (*blockid));
 
142
          return FALSE;
 
143
       }
 
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;
 
150
       nnw2 = 2 * nnw;
 
151
       nnw4 = 4 * nnw;
 
152
       nnw5 = 5 * nnw;
 
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);
 
157
       } 
 
158
      
 
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;
 
164
              
 
165
     if ((xdrs->x_op == XDR_DECODE) && ( *blockid != MCFIO_STDHEPM) ) {
 
166
          fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ", 
 
167
           (*blockid));
 
168
          return FALSE;
 
169
     }
 
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;
 
188
     /*
 
189
     ** V2.02 Upgrade : adding Multiple interactions. 
 
190
     */ 
 
191
     vers = *version;          
 
192
     if ((strcmp(vers,"1.05") == 0)  && (xdrs->x_op == XDR_DECODE)) {
 
193
           hepev2_.nmulti = -1;
 
194
           return TRUE;
 
195
     }      
 
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;
 
200
     /*
 
201
     ** V4.04 Upgrade : adding more Multiple interaction information
 
202
     */ 
 
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;
 
209
           }
 
210
           return TRUE;
 
211
     }      
 
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;
 
219
           }
 
220
           return TRUE;
 
221
     }      
 
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;
 
231
     return TRUE;
 
232
}   
 
233
 
 
234