Fork me on GitHub

source: svn/trunk/Utilities/mcfio/mcf_evt_xdr.c@ 585

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

first commit

File size: 63.4 KB
Line 
1/*******************************************************************************
2* *
3* mcf_evt_xdr.c -- XDR Utility routines for the McFast Monte-Carlo *
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 *
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 "mcf_nTupleDescript.h"
39#include "mcf_xdr.h"
40#include "mcf_xdr_Ntuple.h"
41#include "mcf_NTuIOFiles.h"
42#include "mcf_NTuIOUtils.h"
43#include "mcfio_Util1.h"
44#ifndef FALSE
45#define FALSE 0
46#endif
47#ifndef TRUE
48#define TRUE 1
49#endif
50
51
52static bool_t xdr_mcfast_NTuDDL(XDR *xdrs, char *version, nTuDDL *ddl);
53static bool_t xdr_mcfast_descrNTU(XDR *xdrs, char *version,
54 descrGenNtuple *dNTu);
55static bool_t xdr_mcfast_varDescrNTU(XDR *xdrs, char *version,
56 varGenNtuple *var);
57
58extern nTuDDL **NTuDDLList;
59extern int NumOfNTuples;
60
61bool_t xdr_mcfast_generic(XDR *xdrs, int *blockid,
62 int *ntot, char** version, char** data)
63{
64/* Translate a Generic mcfFast block. This module will allocate memory
65 for the data. */
66
67 unsigned int nn;
68
69 if (xdrs->x_op == XDR_ENCODE) {
70 nn = strlen(*data);
71 *ntot = 12+nn;
72 strcpy(*version, "0.00");
73 } else if (xdrs->x_op == XDR_FREE) {
74 free(*data);
75 return 1;
76 }
77
78 if (( xdr_int(xdrs, blockid) &&
79 xdr_int(xdrs, ntot) &&
80 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH))
81 == FALSE) return FALSE;
82 nn = *ntot - 12;
83 if (xdrs->x_op == XDR_DECODE) *data = NULL;
84 return (xdr_string(xdrs, data, nn));
85}
86
87
88bool_t xdr_mcfast_headerBlock(XDR *xdrs, int *blockid,
89 int *ntot, char** version)
90{
91/* Translate a Generic mcfFast block. This module will allocate memory
92 for the data. */
93
94 if (xdrs->x_op == XDR_ENCODE) {
95 printf ("xdr_mcfast_headerBlock: Internal error \n");
96 return FALSE;
97 }
98
99 return ( xdr_int(xdrs, blockid) &&
100 xdr_int(xdrs, ntot) &&
101 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH));
102}
103bool_t xdr_mcfast_fileheader(XDR *xdrs, int *blockid,
104 int *ntot, char** version, mcfxdrFileHeader **mcf,
105 int streamId)
106{
107/* Translate a mcf FileHeader block. This subroutine will allocate
108 the memory needed if the stream is DECODE */
109
110 int i;
111 unsigned int nn, oldNumOfNTuples;
112 char **ctmp;
113 char *atmp, *btmp, *dtmp;
114 int *itmp;
115 mcfxdrFileHeader *mcftmp;
116 nTuDDL *ddl;
117 float fv;
118
119
120 mcftmp = *mcf;
121 if (xdrs->x_op == XDR_ENCODE) {
122 *ntot = sizeof(mcfxdrFileHeader) - sizeof(int *) - sizeof(char **)
123 + 2 * sizeof(int) * mcftmp->nBlocks
124 - sizeof(char) * MCF_XDR_F_TITLE_LENGTH
125 + sizeof(char) * strlen(mcftmp->title) +
126 + sizeof(char) * strlen(mcftmp->comment) ;
127 for (i=0, ctmp = mcftmp->blockNames;
128 i< mcftmp->nBlocks; i++, ctmp++) *ntot += strlen(*ctmp);
129 strcpy(*version, "2.01");
130 } else if (xdrs->x_op == XDR_FREE) {
131 mcfioC_Free_FileHeader(mcf);
132 return 1;
133 } else if((xdrs->x_op == XDR_DECODE) && (*mcf == NULL)) {
134 mcftmp = (mcfxdrFileHeader *) malloc(sizeof(mcfxdrFileHeader));
135 *mcf = mcftmp;
136 }
137
138
139
140 if (( xdr_int(xdrs, blockid) &&
141 xdr_int(xdrs, ntot) &&
142 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH))
143 == FALSE) return FALSE;
144
145 /*
146 ** Code valid for version 1.00
147 */
148 if (strcmp(*version, "1.00") == 0) {
149 atmp = &(mcftmp->title[0]);
150 btmp = &(mcftmp->comment[0]);
151 dtmp = &(mcftmp->date[0]);
152
153 if ((xdr_string(xdrs, &atmp, MCF_XDR_F_TITLE_LENGTH) &&
154 xdr_string(xdrs,&btmp, MCF_XDR_F_TITLE_LENGTH) &&
155 xdr_string(xdrs,&dtmp, 30)) == FALSE) return FALSE;
156
157 if ((xdr_u_int(xdrs,&(mcftmp->numevts_expect)) &&
158 xdr_u_int(xdrs,&(mcftmp->numevts)) &&
159 xdr_u_int(xdrs,&(mcftmp->firstTable)) &&
160 xdr_u_int(xdrs,&(mcftmp->dimTable)) &&
161 xdr_u_int(xdrs,&(mcftmp->nBlocks))) == FALSE) return FALSE;
162 if(xdrs->x_op == XDR_DECODE) {
163 mcftmp->blockIds = (int *) malloc(sizeof(int) * mcftmp->nBlocks);
164 mcftmp->blockNames =
165 (char**) malloc(sizeof(char *) * mcftmp->nBlocks);
166 for (i=0; i<mcftmp->nBlocks; i++)
167 mcftmp->blockNames[i] =
168 (char *) malloc(sizeof(char) * (MCF_XDR_B_TITLE_LENGTH +1));
169 }
170 itmp = mcftmp->blockIds;
171 if (xdrs->x_op == XDR_ENCODE) nn = mcftmp->nBlocks;
172 if (xdr_array(xdrs, (char **) &itmp, &nn,
173 mcftmp->nBlocks, sizeof(int), (void *) xdr_int) == FALSE)
174 return FALSE;
175 for (i=0; i<mcftmp->nBlocks; i++) {
176 if (xdr_string(xdrs, &(mcftmp->blockNames[i]),
177 MCF_XDR_B_TITLE_LENGTH) == FALSE) return FALSE;
178 }
179 mcftmp->nNTuples = 0;
180 } else if (strncmp(*version, "2.",2) == 0){
181 sscanf(*version, "%f", &fv);
182 /*
183 ** Code valid for version 2.xx, adding the NTuples
184 */
185 atmp = &(mcftmp->title[0]);
186 btmp = &(mcftmp->comment[0]);
187 dtmp = &(mcftmp->date[0]);
188
189 if ((xdr_string(xdrs, &atmp, MCF_XDR_F_TITLE_LENGTH) &&
190 xdr_string(xdrs,&btmp, MCF_XDR_F_TITLE_LENGTH) &&
191 xdr_string(xdrs,&dtmp, 30)) == FALSE) return FALSE;
192
193 if (fv == 2.) strcpy(mcftmp->closingDate, mcftmp->date);
194 else {
195 atmp = &(mcftmp->closingDate[0]);
196 if (xdr_string(xdrs, &atmp, 30) == FALSE) return FALSE;
197 }
198 if ((xdr_u_int(xdrs,&(mcftmp->numevts_expect)) &&
199 xdr_u_int(xdrs,&(mcftmp->numevts)) &&
200 xdr_u_int(xdrs,&(mcftmp->firstTable)) &&
201 xdr_u_int(xdrs,&(mcftmp->dimTable)) &&
202 xdr_u_int(xdrs,&(mcftmp->nBlocks)) &&
203 xdr_u_int(xdrs,&(mcftmp->nNTuples))) == FALSE) return FALSE;
204 if((xdrs->x_op == XDR_DECODE) && (mcftmp->nBlocks > 0)) {
205 mcftmp->blockIds = (int *) malloc(sizeof(int) * mcftmp->nBlocks);
206 mcftmp->blockNames =
207 (char**) malloc(sizeof(char *) * mcftmp->nBlocks);
208 for (i=0; i<mcftmp->nBlocks; i++)
209 mcftmp->blockNames[i] =
210 (char *) malloc(sizeof(char) * (MCF_XDR_B_TITLE_LENGTH +1));
211 }
212 itmp = mcftmp->blockIds;
213 if (xdrs->x_op == XDR_ENCODE) nn = mcftmp->nBlocks;
214 if (mcftmp->nBlocks > 0) {
215 if (xdr_array(xdrs, (char **) &itmp, &nn,
216 mcftmp->nBlocks, sizeof(int), (void *) xdr_int) == FALSE)
217 return FALSE;
218 for (i=0; i<mcftmp->nBlocks; i++) {
219 if (xdr_string(xdrs, &(mcftmp->blockNames[i]),
220 MCF_XDR_B_TITLE_LENGTH) == FALSE) return FALSE;
221 }
222 } else {
223 mcftmp->blockNames = NULL;
224 mcftmp->blockIds = NULL;
225 }
226 /*
227 ** Now take care of the Ntuples
228 */
229 if((xdrs->x_op == XDR_DECODE) && (mcftmp->nNTuples > 0)) {
230 oldNumOfNTuples = NumOfNTuples;
231 for (i=0; i<mcftmp->nNTuples; i++) {
232 ddl = (nTuDDL * ) malloc(sizeof(nTuDDL));
233 AddNTuDDLtoList(ddl);
234 if (xdr_mcfast_NTuDDL(xdrs, *version, ddl) == FALSE)
235 return FALSE;
236 }
237 } else if ((xdrs->x_op == XDR_ENCODE) && (mcftmp->nNTuples > 0)) {
238 for (i=0; i<NumOfNTuples; i++) {
239 ddl =mcf_GetNTuByPtrID(i+1);
240 if ((ddl->streamId == streamId) &&
241 (xdr_mcfast_NTuDDL(xdrs, *version, ddl) == FALSE))
242 return FALSE;
243 }
244 }
245
246 } else return FALSE; /* Other Futur version encoded here. */
247 return TRUE;
248
249}
250
251bool_t xdr_mcfast_eventtable(XDR *xdrs, int *blockid,
252 int *ntot, char** version, mcfxdrEventTable **mcf)
253{
254/* Translate a mcf EventTable block. This subroutine will allocate
255 the memory needed if the stream is DECODE */
256
257 int *idat;
258 unsigned int nn, nnold, *uidat;
259 mcfxdrEventTable *mcftmp;
260
261
262 mcftmp = *mcf;
263 if (xdrs->x_op == XDR_ENCODE) {
264 *ntot = sizeof(mcfxdrEventTable) + 4 * sizeof(int)* mcftmp->dim
265 + sizeof(unsigned int)* mcftmp->dim - 2 * sizeof(int)
266 - 4 * sizeof(int *) - sizeof(u_int *);
267 strcpy(*version, "1.00");
268 } else if (xdrs->x_op == XDR_FREE) {
269 mcfioC_Free_EventTable(mcf);
270 return 1;
271 } else if((xdrs->x_op == XDR_DECODE) && ( mcftmp == NULL)) {
272 mcftmp = (mcfxdrEventTable *) malloc(sizeof(mcfxdrEventTable));
273 *mcf = mcftmp;
274 }
275
276
277
278 if (( xdr_int(xdrs, blockid) &&
279 xdr_int(xdrs, ntot) &&
280 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH))
281 == FALSE) return FALSE;
282
283 /*
284 ** Code valid for version 1.00
285 */
286 if (strcmp(*version, "1.00") == 0) {
287
288 if((xdrs->x_op == XDR_DECODE) && (mcftmp->evtnums != NULL))
289 nnold = mcftmp->previousnumevts;
290 else nnold = 0;
291 idat = &mcftmp->nextLocator;
292 uidat = (u_int *) &mcftmp->numevts;
293 if ((xdr_int(xdrs,idat) && xdr_u_int(xdrs,uidat )) == FALSE)
294 return FALSE;
295 if(xdrs->x_op == XDR_DECODE) {
296 if ((mcftmp->evtnums == NULL) || (mcftmp->numevts > nnold)) {
297 if (mcftmp->evtnums != NULL) {
298 /*
299 ** I don't trust realloc.. just alloc again..
300 */
301 free(mcftmp->evtnums); free(mcftmp->storenums);
302 free(mcftmp->runnums); free(mcftmp->trigMasks);
303 free(mcftmp->ptrEvents);
304 }
305 mcftmp->evtnums = (int *) malloc(sizeof(int) * mcftmp->dim);
306 mcftmp->storenums = (int *) malloc(sizeof(int) * mcftmp->dim);
307 mcftmp->runnums = (int *) malloc(sizeof(int) * mcftmp->dim);
308 mcftmp->trigMasks = (int *) malloc(sizeof(int) * mcftmp->dim);
309 mcftmp->ptrEvents =
310 (unsigned int *) malloc(sizeof(unsigned int) * mcftmp->dim);
311 mcftmp->previousnumevts = mcftmp->dim;
312 }
313 }
314 if (xdrs->x_op == XDR_ENCODE) nn = mcftmp->dim;
315 idat = mcftmp->evtnums;
316 if (xdr_array(xdrs, (char **) &idat, &nn,
317 mcftmp->dim, sizeof(int), (void *) xdr_int) == FALSE)
318 return FALSE;
319 idat = mcftmp->storenums;
320 if (xdr_array(xdrs, (char **) &idat, &nn,
321 mcftmp->dim, sizeof(int), (void *) xdr_int) == FALSE)
322 return FALSE;
323 idat = mcftmp->runnums;
324 if (xdr_array(xdrs, (char **) &idat, &nn,
325 mcftmp->dim, sizeof(int), (void *) xdr_int) == FALSE)
326 return FALSE;
327 idat = mcftmp->trigMasks;
328 if (xdr_array(xdrs, (char **) &idat, &nn,
329 mcftmp->dim, sizeof(int), (void *) xdr_int) == FALSE)
330 return FALSE;
331 uidat = mcftmp->ptrEvents;
332 if (xdr_array(xdrs, (char **) &uidat, &nn,
333 mcftmp->dim, sizeof(int), (void *) xdr_u_int) == FALSE)
334 return FALSE;
335 } else return FALSE; /* Future version encoded here. */
336 return TRUE;
337
338}
339
340bool_t xdr_mcfast_seqheader(XDR *xdrs, int *blockid,
341 int *ntot, char** version, mcfxdrSequentialHeader **mcf)
342{
343/* Translate a mcf EventTable block. This subroutine will allocate
344 the memory needed if the stream is DECODE */
345
346 mcfxdrSequentialHeader *mcftmp;
347
348
349 if (xdrs->x_op == XDR_ENCODE) {
350 mcftmp = *mcf;
351 *ntot = sizeof(mcfxdrSequentialHeader);
352 strcpy(*version, "1.00");
353 } else if (xdrs->x_op == XDR_FREE) {
354 mcfioC_Free_SeqHeader(mcf);
355 return 1;
356 } else if(xdrs->x_op == XDR_DECODE) {
357 if (*mcf == NULL) {
358 mcftmp = (mcfxdrSequentialHeader *)
359 malloc(sizeof(mcfxdrSequentialHeader));
360 *mcf = mcftmp;
361 } else mcftmp = *mcf;
362
363 }
364
365
366
367/* if (( xdr_int(xdrs, blockid) &&
368 xdr_int(xdrs, ntot) &&
369 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH))
370 == FALSE) return FALSE;
371*/
372 if (xdr_int(xdrs,blockid) == FALSE) return FALSE;
373 if (xdr_int(xdrs,ntot) == FALSE) return FALSE;
374 if (xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH)
375 == FALSE) return FALSE;
376 /*
377 ** Code valid for version 1.00
378 */
379 if (strcmp(*version, "1.00") == 0) {
380
381 if (xdr_u_int(xdrs,&(mcftmp->nRecords)) == FALSE) return FALSE;
382 } else return FALSE; /* Futur version encoded here. */
383 return TRUE;
384
385}
386
387bool_t xdr_mcfast_eventheader(XDR *xdrs, int *blockid,
388 int *ntot, char** version, mcfxdrEventHeader **mcf)
389{
390/* Translate a mcf Event header block. This subroutine will allocate
391 the memory needed if the stream is DECODE */
392
393 int *itmp;
394 unsigned int nn, nnold, nNTuOld, *uitmp;
395 mcfxdrEventHeader *mcftmp;
396
397
398 mcftmp = *mcf;
399 if (xdrs->x_op == XDR_ENCODE) {
400 *ntot = sizeof(mcfxdrEventHeader)
401 + sizeof(unsigned int)* mcftmp->nBlocks
402 + sizeof(int ) * mcftmp->nBlocks
403 - sizeof(int *) - sizeof(u_int *) ;
404 strcpy(*version, "2.00");
405 } else if (xdrs->x_op == XDR_FREE) {
406 mcfioC_Free_EventHeader(mcf);
407 return 1;
408 } else if((xdrs->x_op == XDR_DECODE) && (mcftmp == NULL)) {
409 mcftmp =
410 (mcfxdrEventHeader *) malloc(sizeof(mcfxdrEventHeader));
411 *mcf = mcftmp;
412 mcftmp->blockIds = NULL;
413 mcftmp->ptrBlocks = NULL;
414 }
415
416
417
418 if (( xdr_int(xdrs, blockid) &&
419 xdr_int(xdrs, ntot) &&
420 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH))
421 == FALSE) return FALSE;
422
423 /*
424 ** Code valid for version 1.00
425 */
426 if (strcmp(*version, "1.00") == 0) {
427 if((xdrs->x_op == XDR_DECODE) && (mcftmp->blockIds != NULL))
428 nnold = mcftmp->dimBlocks;
429 else nnold = 0;
430 if ((xdr_int(xdrs,&(mcftmp->evtnum)) &&
431 xdr_int(xdrs,&(mcftmp->storenum)) &&
432 xdr_int(xdrs,&(mcftmp->runnum)) &&
433 xdr_int(xdrs,&(mcftmp->trigMask)) &&
434 xdr_u_int(xdrs,&(mcftmp->nBlocks)) &&
435 xdr_u_int(xdrs,&(mcftmp->dimBlocks))) == FALSE) return FALSE;
436 if(xdrs->x_op == XDR_DECODE) {
437 if ((mcftmp->blockIds == NULL) || (mcftmp->dimBlocks > nnold)) {
438 if (mcftmp->blockIds != NULL) {
439 /*
440 ** I don't trust realloc.. just alloc again..
441 */
442 free(mcftmp->blockIds); free(mcftmp->ptrBlocks);
443 }
444 mcftmp->blockIds =
445 (int *) malloc(sizeof(unsigned int) * mcftmp->dimBlocks);
446 mcftmp->ptrBlocks =
447 (unsigned int *) malloc(sizeof(unsigned int) * mcftmp->dimBlocks);
448 }
449 }
450 if (xdrs->x_op == XDR_ENCODE) nn = mcftmp->dimBlocks;
451 itmp = mcftmp->blockIds;
452 if (xdr_array(xdrs, (char **) &itmp, &nn,
453 mcftmp->dimBlocks, sizeof(int), (void *) xdr_int) == FALSE)
454 return FALSE;
455 uitmp = mcftmp->ptrBlocks;
456 if (xdr_array(xdrs, (char **) &uitmp, &nn,
457 mcftmp->dimBlocks, sizeof(u_int), (void *) xdr_u_int) == FALSE)
458 return FALSE;
459 } else if (strcmp(*version, "2.00") == 0) {
460 if (xdrs->x_op == XDR_DECODE) {
461 nnold = 0;
462 if (mcftmp->blockIds != NULL) nnold = mcftmp->dimBlocks;
463 nNTuOld = 0;
464 if (mcftmp->nTupleIds != NULL) nNTuOld = mcftmp->dimNTuples;
465 }
466 if ((xdr_int(xdrs,&(mcftmp->evtnum)) &&
467 xdr_int(xdrs,&(mcftmp->storenum)) &&
468 xdr_int(xdrs,&(mcftmp->runnum)) &&
469 xdr_int(xdrs,&(mcftmp->trigMask)) &&
470 xdr_u_int(xdrs,&(mcftmp->nBlocks)) &&
471 xdr_u_int(xdrs,&(mcftmp->dimBlocks)) &&
472 xdr_u_int(xdrs,&(mcftmp->nNTuples)) &&
473 xdr_u_int(xdrs,&(mcftmp->dimNTuples))) == FALSE) return FALSE;
474 if(xdrs->x_op == XDR_DECODE) {
475 if ((mcftmp->blockIds == NULL) || (mcftmp->dimBlocks > nnold)) {
476 if (mcftmp->blockIds != NULL) {
477 free(mcftmp->blockIds);
478 free(mcftmp->ptrBlocks);
479 }
480 mcftmp->blockIds =
481 (int *) malloc(sizeof(unsigned int) * mcftmp->dimBlocks);
482 mcftmp->ptrBlocks =
483 (unsigned int *) malloc(sizeof(unsigned int) * mcftmp->dimBlocks);
484 }
485 if ((mcftmp->nTupleIds == NULL) || (mcftmp->dimNTuples > nNTuOld)) {
486 if (mcftmp->nTupleIds != NULL) {
487 free(mcftmp->nTupleIds);
488 free(mcftmp->ptrNTuples);
489 }
490 mcftmp->nTupleIds =
491 (int *) malloc(sizeof(unsigned int) * mcftmp->dimNTuples);
492 mcftmp->ptrNTuples =
493 (unsigned int *) malloc(sizeof(unsigned int) * mcftmp->dimNTuples);
494 }
495 }
496 if (mcftmp->dimBlocks > 0) {
497 if (xdrs->x_op == XDR_ENCODE) nn = mcftmp->dimBlocks;
498 itmp = mcftmp->blockIds;
499 if (xdr_array(xdrs, (char **) &itmp, &nn,
500 mcftmp->dimBlocks, sizeof(int), (void *) xdr_int) == FALSE)
501 return FALSE;
502 uitmp = mcftmp->ptrBlocks;
503 if (xdr_array(xdrs, (char **) &uitmp, &nn,
504 mcftmp->dimBlocks, sizeof(u_int), (void *) xdr_u_int) == FALSE)
505 return FALSE;
506 }
507 if (mcftmp->dimNTuples > 0) {
508 if (xdrs->x_op == XDR_ENCODE) nn = mcftmp->dimNTuples;
509 itmp = mcftmp->nTupleIds;
510 if (xdr_array(xdrs, (char **) &itmp, &nn,
511 mcftmp->dimNTuples, sizeof(int), (void *) xdr_int) == FALSE)
512 return FALSE;
513 uitmp = mcftmp->ptrNTuples;
514 if (xdr_array(xdrs, (char **) &uitmp, &nn,
515 mcftmp->dimNTuples, sizeof(u_int), (void *) xdr_u_int) == FALSE)
516 return FALSE;
517 }
518 } else
519 return FALSE; /* Futur version encoded here. */
520 return TRUE;
521
522}
523
524static bool_t xdr_mcfast_NTuDDL(XDR *xdrs, char *version, nTuDDL *ddl)
525{
526 int i, nc_title, nc_category, idRef;
527 descrGenNtuple *dNTu;
528
529
530 /*
531 ** This is the first version, let us not get too compilcated..
532 */
533 if (xdrs->x_op == XDR_ENCODE) {
534 nc_title = strlen(ddl->title);
535 nc_category = strlen(ddl->category);
536 idRef = -1;
537 /*
538 ** Cross reference is only valid within the same stream.
539 */
540 if ((ddl->reference != NULL) &&
541 (ddl->streamId == ddl->reference->streamId )) {
542 /*
543 ** compute the rerefence token. This is the sequential
544 ** number of the reference Ntuple for this stream.
545 */
546 for (i=0, idRef=0; i<NumOfNTuples; i++) {
547 if (NTuDDLList[i]->streamId == ddl->reference->streamId)
548 idRef++;
549 if (NTuDDLList[i]->id == ddl->reference->id) break;
550 }
551 }
552 }
553 if (xdr_int(xdrs, &nc_title) == FALSE) return FALSE;
554 if (xdr_int(xdrs, &nc_category) == FALSE) return FALSE;
555 if (xdr_int(xdrs, &idRef) == FALSE) return FALSE;
556 if (xdrs->x_op == XDR_DECODE) {
557 ddl->title = (char *) malloc(sizeof(char) * (nc_title +1));
558 ddl->category = (char *) malloc(sizeof(char) * (nc_category +1));
559 ddl->dbinFileName = NULL;
560 ddl->streamId = -1;
561 }
562 if (xdr_int(xdrs,&(ddl->uid)) == FALSE) return FALSE;
563 if (xdr_string(xdrs, &(ddl->title), nc_title) == FALSE) return FALSE;
564 if (xdr_string(xdrs, &(ddl->category),
565 nc_category) == FALSE) return FALSE;
566 if (idRef == -1) {
567 if (xdrs->x_op == XDR_DECODE)
568 ddl->descrNtu = (descrGenNtuple *) malloc (sizeof(descrGenNtuple));
569 if (ddl->descrNtu == NULL) dNTu = ddl->reference->descrNtu;
570 else dNTu = ddl->descrNtu;
571 if (xdr_mcfast_descrNTU(xdrs, version, dNTu) == FALSE)
572 return FALSE;
573 if (xdrs->x_op == XDR_DECODE) ddl->reference = NULL;
574 } else {
575 if (xdrs->x_op == XDR_DECODE) {
576 ddl->descrNtu = NULL;
577 ddl->referenceId = idRef;
578 /* we will set the reference pointer in mcfio_Direct */
579 }
580 }
581 return TRUE;
582
583}
584
585static bool_t xdr_mcfast_descrNTU(XDR *xdrs, char *version,
586 descrGenNtuple *dNTu)
587{
588 int i, nc_desc, nc_title;
589 u_int nn;
590 char *tc;
591 /*
592 ** This is the first version, let us not get too compilcated..
593 */
594
595 if (xdr_int(xdrs,&(dNTu->numVariables)) == FALSE) return FALSE;
596 dNTu->numAvailable = dNTu->numVariables;
597 if (xdr_int(xdrs,&(dNTu->maxMultiplicity)) == FALSE) return FALSE;
598 if (xdr_int(xdrs,&(dNTu->orgStyle)) == FALSE)return FALSE;
599 if (xdr_int(xdrs,&(dNTu->firstIndexed)) == FALSE) return FALSE;
600 if (xdrs->x_op == XDR_ENCODE) nc_title = strlen(dNTu->title);
601 if (xdr_int(xdrs, &nc_title) == FALSE) return FALSE;
602 if (xdrs->x_op == XDR_ENCODE) nc_desc = strlen(dNTu->description);
603 if (xdr_int(xdrs, &nc_desc) == FALSE) return FALSE;
604 if (xdrs->x_op == XDR_DECODE) {
605 dNTu->title = (char *) malloc(sizeof(char) * (nc_title+1));
606 dNTu->subXDROffset = NULL;
607 dNTu->description = (char *) malloc(sizeof(char) * (nc_desc+1));
608 dNTu->varOrdering = (int *) malloc(sizeof(int) * dNTu->numVariables);
609 for (i=0; i<dNTu->numVariables; i++) dNTu->varOrdering[i] = i;
610 if (dNTu->orgStyle == PARALLEL_ARRAY_NTU) {
611 dNTu->subXDROffset = NULL;
612 dNTu->subOffset = NULL;
613 } else {
614 dNTu->subOffset =
615 (long *) malloc(sizeof(long) * dNTu->maxMultiplicity);
616 dNTu->subXDROffset =
617 (u_int *) malloc(sizeof(long) * dNTu->maxMultiplicity);
618 }
619 dNTu->variables =
620 (varGenNtuple **) malloc(sizeof(varGenNtuple *) * dNTu->numVariables);
621 for (i=0; i<dNTu->numVariables; i++)
622 dNTu->variables[i] = (varGenNtuple *) malloc(sizeof(varGenNtuple));
623 }
624 tc = dNTu->nameIndex;
625 if (xdr_string(xdrs, &tc, 31) == FALSE) return FALSE;
626 if (xdr_string(xdrs,
627 (char **) &(dNTu->title), nc_title) == FALSE) return FALSE;
628 if (xdr_string(xdrs,
629 &(dNTu->description), nc_desc) == FALSE) return FALSE;
630 tc = dNTu->version;
631 if (xdr_string(xdrs, &tc, 7) == FALSE) return FALSE;
632 if (xdr_long(xdrs, &(dNTu->multOffset)) == FALSE) return FALSE;
633 if (xdr_long(xdrs, &(dNTu->fenceOffset)) == FALSE) return FALSE;
634 nn = dNTu->maxMultiplicity;
635 if (dNTu->orgStyle != PARALLEL_ARRAY_NTU) {
636 if (xdr_array(xdrs,
637 (char **) &(dNTu->subOffset), &nn, nn, sizeof(long), (void *) xdr_long) == FALSE)
638 return FALSE;
639 }
640 for (i=0; i<dNTu->numVariables; i++)
641 if (xdr_mcfast_varDescrNTU(xdrs, version, dNTu->variables[i]) == FALSE)
642 return FALSE;
643 return TRUE;
644}
645static bool_t xdr_mcfast_varDescrNTU(XDR *xdrs, char *version,
646 varGenNtuple *var)
647{
648 int nc_name, nc_desc, *pdim;
649 u_int nn;
650
651
652
653 if (xdrs->x_op == XDR_ENCODE) nc_name = strlen(var->name);
654 if (xdr_int(xdrs, &nc_name) == FALSE) return FALSE;
655 if (xdrs->x_op == XDR_ENCODE) {
656 if (var->description == NULL) nc_desc = 0;
657 else nc_desc = strlen(var->description);
658 }
659 if (xdr_int(xdrs, &nc_desc) == FALSE) return FALSE;
660 if (xdrs->x_op == XDR_DECODE) {
661 var->name = (char *) malloc(sizeof(char) * (nc_name+1));
662 if (nc_desc>0)
663 var->description = (char *) malloc(sizeof(char) * (nc_desc+1));
664 else var->description = NULL;
665 var->nameBlank = FALSE;
666 }
667
668 if (xdr_string(xdrs, &(var->name), nc_name) == FALSE) return FALSE;
669 if (nc_desc > 0)
670 if (xdr_string(xdrs, &(var->description), nc_desc) == FALSE)
671 return FALSE;
672 if (xdr_int(xdrs,&(var->type)) == FALSE) return FALSE;
673 if (xdr_char(xdrs,&(var->isFixedSize)) == FALSE) return FALSE;
674 if (xdr_int(xdrs,&(var->numDim)) == FALSE) return FALSE;
675 nn = var->numDim;
676 pdim = var->dimensions;
677 if ((nn > 0) && (xdr_array(xdrs,
678 (char **) &pdim, &nn, nn, sizeof(int), (void *) xdr_int)) == FALSE)
679 return FALSE;
680 if (xdrs->x_op == XDR_ENCODE) nn = (u_int) var->lengthB;
681 if (xdr_u_int(xdrs,&(nn)) == FALSE) return FALSE;
682 if (xdrs->x_op == XDR_DECODE) var->lengthB = (size_t) nn;
683 if (xdrs->x_op == XDR_ENCODE) nn = (u_int) var->lengthW;
684 if (xdr_u_int(xdrs,&(nn)) == FALSE) return FALSE;
685 if (xdrs->x_op == XDR_DECODE) var->lengthW = (size_t) nn;
686 if (xdr_long(xdrs,&(var->offset)) == FALSE) return FALSE;
687 return TRUE;
688}
689/*
690** Generalized NTuple XDR filter
691*/
692bool_t xdr_mcfast_NTuple(XDR *xdrs, descrGenNtuple *dNTu,
693 int *pnTot, int nTupleId, char* version)
694{
695 int i, j, id, nm, lastFixed;
696 u_int nn;
697 char *vv, *cDat, *start;
698 int *pnMult;
699 void *pnFence;
700 int *ipnFence;
701 void *pt;
702 bool_t ok;
703/*
704** Upon write, check that the version token is identical to the one stored
705** in the ddl.
706*/
707 start = version;
708 if(dNTu->firstIndexed == -1) lastFixed = dNTu->numVariables;
709 else lastFixed = dNTu->firstIndexed;
710 if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_MCFIOCODE)) {
711 nn = strlen(dNTu->version);
712 if (strncmp(version, dNTu->version, (size_t) nn ) != 0) {
713 fprintf (stderr, "mcfio_NTuple: version mismatch! \n\
714 Version used in the Event loop = %s\n\
715 ... in the DDl template = %s\n", version,dNTu->version);
716 return FALSE;
717 }
718 id = nTupleId;
719/*
720** Compute the total length
721*/
722 cDat = start; cDat += dNTu->multOffset;
723 pnMult = (int *) cDat;
724 nm = *pnMult;
725 for (i=0, nn=0; i<lastFixed; i++)
726 nn += dNTu->variables[i]->lengthB;
727 if(dNTu->firstIndexed != -1)
728 for(i=dNTu->firstIndexed; i<dNTu->numVariables; i++)
729 nn += (dNTu->variables[i]->lengthB * nm);
730 *pnTot = 6 + nn/4;
731 }
732 if (xdr_int(xdrs, &id) == FALSE) return FALSE;
733 if (xdr_int(xdrs, pnTot) == FALSE) return FALSE;
734 if (xdrs->x_op == XDR_ENCODE) {
735 vv = dNTu->version;
736 if (xdr_string(xdrs, &vv, 11) == FALSE) return FALSE;
737 } else if (xdrs->x_op == XDR_DECODE) {
738 if (xdr_string(xdrs, &version, 11) == FALSE) return FALSE;
739 if (strcmp(version, dNTu->version) != 0) {
740 fprintf (stderr, "mcfio_NTuple: version mismatch! \n\
741 Version used in the Event loop = %s\n\
742 ... in the DDl template = %s\n", version,dNTu->version);
743 return FALSE;
744 }
745 if (id != nTupleId) {
746 fprintf (stderr, "mcfio_NTuple: internal error! \n\
747 Unexpected NTuple identifier %d instead of %d\n", id, nTupleId);
748 return FALSE;
749 }
750 }
751
752 cDat = start; cDat += dNTu->multOffset;
753 pnMult = (int *) cDat;
754 if (xdr_int(xdrs, pnMult) == FALSE) return FALSE;
755 /*
756 ** Close the fence now, we will check it upon DECODE at the end
757 */
758 cDat = start; cDat += dNTu->fenceOffset;
759 pnFence = (void *) cDat;
760 if (xdrs->x_op == XDR_ENCODE) memcpy(pnFence, pnTot, sizeof(int));
761 if (xdr_int(xdrs, (int *) pnFence) == FALSE) return FALSE;
762 nm = *pnMult;
763 for (i=0; i<lastFixed; i++) {
764 if (dNTu->variables[i]->lengthW == 1) {
765 cDat = start; cDat += dNTu->variables[i]->offset;
766 pt = (void *) cDat;
767 switch (dNTu->variables[i]->type) {
768 case BYTE_NTU: case CHARACTER_NTU:
769 ok = xdr_char(xdrs, (char *) pt);
770 break;
771 case INTEGER2_NTU:
772 ok = xdr_short(xdrs, (short *) pt);
773 break;
774 case LOGICAL_NTU: case INTEGER_NTU:
775 ok = xdr_int(xdrs, (int *) pt);
776 break;
777 case REAL_NTU:
778 ok = xdr_float(xdrs, (float *) pt);
779 break;
780 case DBL_PRECISION_NTU:
781 ok = xdr_double(xdrs, (double *) pt);
782 break;
783 case COMPLEX_NTU:
784 nn =2;
785 ok = xdr_array(xdrs,
786 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
787 break;
788 case DBL_COMPLEX_NTU:
789 nn =2;
790 ok = xdr_array(xdrs,
791 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
792 break;
793 case POINTER_NTU:
794 ok = xdr_long(xdrs, (long *) pt);
795 break;
796 default :
797 fprintf (stderr, "mcfio_NTuple: internal error! \n\
798 Unexpected variables type %d on NTuple %d\n",
799 dNTu->variables[i]->type, nTupleId);
800 break;
801 }
802 }
803 else if (dNTu->variables[i]->lengthW > 0) {
804 cDat = start; cDat += dNTu->variables[i]->offset;
805 pt = (void *) cDat;
806 nn = dNTu->variables[i]->lengthW;
807 switch (dNTu->variables[i]->type) {
808 case BYTE_NTU: case CHARACTER_NTU:
809 ok = xdr_bytes(xdrs, (char **) &pt, &nn, nn);
810 break;
811 case INTEGER2_NTU:
812 ok = xdr_array(xdrs,
813 (char **) &pt, &nn, nn, sizeof(short), (void *) xdr_short);
814 break;
815 case LOGICAL_NTU: case INTEGER_NTU:
816 ok = xdr_array(xdrs,
817 (char **) &pt, &nn, nn, sizeof(int), (void *) xdr_int);
818 break;
819 case REAL_NTU:
820 ok = xdr_array(xdrs,
821 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
822 break;
823 case DBL_PRECISION_NTU:
824 ok = xdr_array(xdrs,
825 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
826 break;
827 case COMPLEX_NTU:
828 nn = nn*2;
829 ok = xdr_array(xdrs,
830 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
831 break;
832 case DBL_COMPLEX_NTU:
833 nn = nn*2;
834 ok = xdr_array(xdrs,
835 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
836 break;
837 case POINTER_NTU:
838 ok = xdr_array(xdrs,
839 (char **) &pt, &nn, nn, sizeof(long), (void *) xdr_long);
840 break;
841 default :
842 fprintf (stderr, "mcfio_NTuple: internal error! \n\
843 Unexpected variables type %d on NTuple %d\n",
844 dNTu->variables[i]->type, nTupleId);
845 break;
846 }
847 if (ok == FALSE) return FALSE;
848 }
849 }
850 if (dNTu->firstIndexed != -1) {
851 if (dNTu->orgStyle == PARALLEL_ARRAY_NTU) {
852 for (i=dNTu->firstIndexed; i<dNTu->numVariables; i++) {
853 cDat = start; cDat += dNTu->variables[i]->offset;
854 pt = (void *) cDat;
855 nn = nm * dNTu->variables[i]->lengthW;
856 switch (dNTu->variables[i]->type) {
857 case BYTE_NTU: case CHARACTER_NTU:
858 vv = (char *) pt;
859 ok = xdr_bytes(xdrs, (char **) &pt, &nn, nn);
860 break;
861 case INTEGER2_NTU:
862 ok = xdr_array(xdrs,
863 (char **) &pt, &nn, nn, sizeof(short), (void *) xdr_short);
864 break;
865 case LOGICAL_NTU: case INTEGER_NTU:
866 ok = xdr_array(xdrs,
867 (char **) &pt, &nn, nn, sizeof(int), (void *) xdr_int);
868 break;
869 case REAL_NTU:
870 ok = xdr_array(xdrs,
871 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
872 break;
873 case DBL_PRECISION_NTU:
874 ok = xdr_array(xdrs,
875 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
876 break;
877 case COMPLEX_NTU:
878 nn = nn*2;
879 ok = xdr_array(xdrs,
880 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
881 break;
882 case DBL_COMPLEX_NTU:
883 nn = nn*2;
884 ok = xdr_array(xdrs,
885 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
886 break;
887 case POINTER_NTU:
888 ok = xdr_array(xdrs,
889 (char **) &pt, &nn, nn, sizeof(long), (void *) xdr_long);
890 break;
891 default :
892 fprintf (stderr, "mcfio_NTuple: internal error! \n\
893 Unexpected variables type %d on NTuple %d\n",
894 dNTu->variables[i]->type, nTupleId);
895 break;
896 }
897 if (ok == FALSE) return FALSE;
898 }
899 } else { /*dump the substructures one a time */
900 for (j=0; j<nm; j++) {
901 for (i=dNTu->firstIndexed; i<dNTu->numVariables; i++) {
902 cDat = start;
903 cDat += (dNTu->subOffset[j] + dNTu->variables[i]->offset);
904 pt = (void *) cDat;
905 if (dNTu->variables[i]->lengthW == 1) {
906 switch (dNTu->variables[i]->type) {
907 case BYTE_NTU: case CHARACTER_NTU:
908 ok = xdr_char(xdrs, (char *) pt);
909 break;
910 case INTEGER2_NTU:
911 ok = xdr_short(xdrs, (short *) pt);
912 break;
913 case LOGICAL_NTU: case INTEGER_NTU:
914 ok = xdr_int(xdrs, (int *) pt);
915 break;
916 case REAL_NTU:
917 ok = xdr_float(xdrs, (float *) pt);
918 break;
919 case DBL_PRECISION_NTU:
920 ok = xdr_double(xdrs, (double *) pt);
921 break;
922 case COMPLEX_NTU:
923 nn =2;
924 ok = xdr_array(xdrs,
925 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
926 break;
927 case DBL_COMPLEX_NTU:
928 nn =2;
929 ok = xdr_array(xdrs,
930 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
931 break;
932 case POINTER_NTU:
933 ok = xdr_long(xdrs, (long *) pt);
934 break;
935 default :
936 fprintf (stderr, "mcfio_NTuple: internal error! \n\
937 Unexpected variables type %d on NTuple %d\n",
938 dNTu->variables[i]->type, nTupleId);
939 break;
940 }
941 }
942 else if (dNTu->variables[i]->lengthW > 0) {
943 nn = dNTu->variables[i]->lengthW;
944 switch (dNTu->variables[i]->type) {
945 case BYTE_NTU: case CHARACTER_NTU:
946 ok = xdr_bytes(xdrs, (char **) &pt, &nn, nn);
947 break;
948 case INTEGER2_NTU:
949 ok = xdr_array(xdrs,
950 (char **) &pt, &nn, nn, sizeof(short), (void *) xdr_short);
951 break;
952 case LOGICAL_NTU: case INTEGER_NTU:
953 ok = xdr_array(xdrs,
954 (char **) &pt, &nn, nn, sizeof(int), (void *) xdr_int);
955 break;
956 case REAL_NTU:
957 ok = xdr_array(xdrs,
958 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
959 break;
960 case DBL_PRECISION_NTU:
961 ok = xdr_array(xdrs,
962 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
963 break;
964 case COMPLEX_NTU:
965 nn = nn*2;
966 ok = xdr_array(xdrs,
967 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
968 break;
969 case DBL_COMPLEX_NTU:
970 nn = nn*2;
971 ok = xdr_array(xdrs,
972 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
973 break;
974 case POINTER_NTU:
975 ok = xdr_array(xdrs,
976 (char **) &pt, &nn, nn, sizeof(long), (void *) xdr_long);
977 break;
978 default :
979 fprintf (stderr, "mcfio_NTuple: internal error! \n\
980 Unexpected variables type %d on NTuple %d\n",
981 dNTu->variables[i]->type, nTupleId);
982 break;
983 }
984 if (ok == FALSE) return FALSE;
985 }
986 } /*end of i loop */
987 } /*end of j loop */
988 } /* End of orgStyle clause */
989 } /* End of firstIndexed clause */
990 /*
991 ** Check the fence..
992 */
993 ipnFence = (int *) pnFence;
994 if ((xdrs->x_op == XDR_DECODE) && (*ipnFence != *pnTot)) {
995 fprintf (stderr, "mcfio_NTuple: Suspected Data Overwrite! \n\
996 Fence content found on the input stream is = %d\n\
997 ... while we expect %d\n", *ipnFence, *pnTot);
998 return FALSE;
999 }
1000 return TRUE;
1001}
1002
1003/*
1004** Generalized NTuple XDR filter, for DECODE only, used exclusively
1005** to establish the relative XDR pointers.
1006*/
1007bool_t xdr_mcfast_NTupleXDRPtr(XDR *xdrs, descrGenNtuple *dNTu,
1008 int *pnTot, int nTupleId, char* version)
1009{
1010 int i, j, id, nm, lastFixed;
1011 u_int nn, startXDR;
1012 char *vv, *cDat;
1013 int *pnMult, *pnFence;
1014 void *start, *pt;
1015 bool_t ok;
1016
1017 /*
1018 ** Allocate memory for supointer array if need be.
1019 */
1020 if(dNTu->firstIndexed == -1) lastFixed = dNTu->numVariables;
1021 else lastFixed = dNTu->firstIndexed;
1022
1023 if (dNTu->subXDROffset != NULL) free(dNTu->subXDROffset);
1024 dNTu->subXDROffset =
1025 (u_int *) malloc (sizeof(u_int) * dNTu->maxMultiplicity);
1026 start = (void *) version;
1027 startXDR = xdr_getpos(xdrs);
1028 if (xdr_int(xdrs, &id) == FALSE) return FALSE;
1029 if (xdr_int(xdrs, pnTot) == FALSE) return FALSE;
1030
1031 if (xdr_string(xdrs, &version, 11) == FALSE) return FALSE;
1032 if (id != nTupleId) {
1033 fprintf (stderr, "mcfio_NTuple: internal error! \n\
1034 Unexpected NTuple identifier %d instead of %d\n", id, nTupleId);
1035 return FALSE;
1036 }
1037 cDat = start; cDat += dNTu->multOffset;
1038 pnMult = (int *) cDat;
1039 dNTu->multXDROffset = xdr_getpos(xdrs) - startXDR;
1040 if (xdr_int(xdrs, pnMult) == FALSE) return FALSE;
1041 /*
1042 ** Close the fence now, we will check it upon DECODE at the end
1043 */
1044 cDat = start; cDat += dNTu->fenceOffset;
1045 pnFence = (int *) cDat;
1046 dNTu->fenceXDROffset = xdr_getpos(xdrs) - startXDR;
1047 if (xdr_int(xdrs, (int *) pnFence) == FALSE) return FALSE;
1048 nm = *pnMult;
1049 for (i=0; i<lastFixed; i++) {
1050 dNTu->variables[i]->offsetXDR = 0;
1051 if (dNTu->variables[i]->lengthW == 1) {
1052 cDat = start; cDat += dNTu->variables[i]->offset;
1053 pt = (void *) cDat;
1054 dNTu->variables[i]->offsetXDR = xdr_getpos(xdrs) - startXDR;
1055 switch (dNTu->variables[i]->type) {
1056 case BYTE_NTU: case CHARACTER_NTU:
1057 ok = xdr_char(xdrs, (char *) pt);
1058 break;
1059 case INTEGER2_NTU:
1060 ok = xdr_short(xdrs, (short *) pt);
1061 break;
1062 case LOGICAL_NTU: case INTEGER_NTU:
1063 ok = xdr_int(xdrs, (int *) pt);
1064 break;
1065 case REAL_NTU:
1066 ok = xdr_float(xdrs, (float *) pt);
1067 break;
1068 case DBL_PRECISION_NTU:
1069 ok = xdr_double(xdrs, (double *) pt);
1070 break;
1071 case COMPLEX_NTU:
1072 nn =2;
1073 ok = xdr_array(xdrs,
1074 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1075 break;
1076 case DBL_COMPLEX_NTU:
1077 nn =2;
1078 ok = xdr_array(xdrs,
1079 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1080 break;
1081 case POINTER_NTU:
1082 ok = xdr_long(xdrs, (long *) pt);
1083 break;
1084 default :
1085 fprintf (stderr, "mcfio_NTuple: internal error! \n\
1086 Unexpected variables type %d on NTuple %d\n",
1087 dNTu->variables[i]->type, nTupleId);
1088 break;
1089 }
1090 }
1091 else if (dNTu->variables[i]->lengthW > 0) {
1092 cDat = start; cDat += dNTu->variables[i]->offset;
1093 pt = (void *) cDat;
1094 nn = dNTu->variables[i]->lengthW;
1095 dNTu->variables[i]->offsetXDR = xdr_getpos(xdrs) - startXDR;
1096 switch (dNTu->variables[i]->type) {
1097 case BYTE_NTU: case CHARACTER_NTU:
1098 ok = xdr_bytes(xdrs, (char **) &pt, &nn, nn);
1099 break;
1100 case INTEGER2_NTU:
1101 ok = xdr_array(xdrs,
1102 (char **) &pt, &nn, nn, sizeof(short), (void *) xdr_short);
1103 break;
1104 case LOGICAL_NTU: case INTEGER_NTU:
1105 ok = xdr_array(xdrs,
1106 (char **) &pt, &nn, nn, sizeof(int), (void *) xdr_int);
1107 break;
1108 case REAL_NTU:
1109 ok = xdr_array(xdrs,
1110 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1111 break;
1112 case DBL_PRECISION_NTU:
1113 ok = xdr_array(xdrs,
1114 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1115 break;
1116 case COMPLEX_NTU:
1117 nn = nn*2;
1118 ok = xdr_array(xdrs,
1119 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1120 break;
1121 case DBL_COMPLEX_NTU:
1122 nn = nn*2;
1123 ok = xdr_array(xdrs,
1124 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1125 break;
1126 case POINTER_NTU:
1127 ok = xdr_array(xdrs,
1128 (char **) &pt, &nn, nn, sizeof(long), (void *) xdr_long);
1129 break;
1130 default :
1131 fprintf (stderr, "mcfio_NTuple: internal error! \n\
1132 Unexpected variables type %d on NTuple %d\n",
1133 dNTu->variables[i]->type, nTupleId);
1134 break;
1135 }
1136 if (ok == FALSE) return FALSE;
1137 }
1138 }
1139 if (dNTu->firstIndexed != -1) {
1140 if (dNTu->orgStyle == PARALLEL_ARRAY_NTU) {
1141 for (i=dNTu->firstIndexed; i<dNTu->numVariables; i++) {
1142 cDat =start; cDat += dNTu->variables[i]->offset;
1143 pt = (void *) cDat;
1144 nn = nm * dNTu->variables[i]->lengthW;
1145 dNTu->variables[i]->offsetXDR = xdr_getpos(xdrs) - startXDR;
1146 switch (dNTu->variables[i]->type) {
1147 case BYTE_NTU: case CHARACTER_NTU:
1148 vv = (char *) pt;
1149 ok = xdr_bytes(xdrs, (char **) &pt, &nn, nn);
1150 break;
1151 case INTEGER2_NTU:
1152 ok = xdr_array(xdrs,
1153 (char **) &pt, &nn, nn, sizeof(short), (void *) xdr_short);
1154 break;
1155 case LOGICAL_NTU: case INTEGER_NTU:
1156 ok = xdr_array(xdrs,
1157 (char **) &pt, &nn, nn, sizeof(int), (void *) xdr_int);
1158 break;
1159 case REAL_NTU:
1160 ok = xdr_array(xdrs,
1161 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1162 break;
1163 case DBL_PRECISION_NTU:
1164 ok = xdr_array(xdrs,
1165 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1166 break;
1167 case COMPLEX_NTU:
1168 nn = nn*2;
1169 ok = xdr_array(xdrs,
1170 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1171 break;
1172 case DBL_COMPLEX_NTU:
1173 nn = nn*2;
1174 ok = xdr_array(xdrs,
1175 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1176 break;
1177 case POINTER_NTU:
1178 ok = xdr_array(xdrs,
1179 (char **) &pt, &nn, nn, sizeof(long), (void *) xdr_long);
1180 break;
1181 default :
1182 fprintf (stderr, "mcfio_NTuple: internal error! \n\
1183 Unexpected variables type %d on NTuple %d\n",
1184 dNTu->variables[i]->type, nTupleId);
1185 break;
1186 }
1187 if (ok == FALSE) return FALSE;
1188 }
1189 } else { /*dump the substructure one a time */
1190 for (j=0; j<nm; j++) {
1191 dNTu->subXDROffset[j] = xdr_getpos(xdrs) - startXDR;
1192 for (i=dNTu->firstIndexed; i<dNTu->numVariables; i++) {
1193 cDat = start;
1194 cDat += (dNTu->subOffset[j] + dNTu->variables[i]->offset);
1195 pt = (void *) cDat;
1196 if (j == 0) dNTu->variables[i]->offsetXDR = 0;
1197 if (dNTu->variables[i]->lengthW == 1) {
1198 if (j == 0) dNTu->variables[i]->offsetXDR =
1199 xdr_getpos(xdrs) - startXDR- dNTu->subXDROffset[j];
1200 switch (dNTu->variables[i]->type) {
1201 case BYTE_NTU: case CHARACTER_NTU:
1202 ok = xdr_char(xdrs, (char *) pt);
1203 break;
1204 case INTEGER2_NTU:
1205 ok = xdr_short(xdrs, (short *) pt);
1206 break;
1207 case LOGICAL_NTU: case INTEGER_NTU:
1208 ok = xdr_int(xdrs, (int *) pt);
1209 break;
1210 case REAL_NTU:
1211 ok = xdr_float(xdrs, (float *) pt);
1212 break;
1213 case DBL_PRECISION_NTU:
1214 ok = xdr_double(xdrs, (double *) pt);
1215 break;
1216 case COMPLEX_NTU:
1217 nn =2;
1218 ok = xdr_array(xdrs,
1219 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1220 break;
1221 case DBL_COMPLEX_NTU:
1222 nn =2;
1223 ok = xdr_array(xdrs,
1224 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1225 break;
1226 case POINTER_NTU:
1227 ok = xdr_long(xdrs, (long *) pt);
1228 break;
1229 default :
1230 fprintf (stderr, "mcfio_NTuple: internal error! \n\
1231 Unexpected variables type %d on NTuple %d\n",
1232 dNTu->variables[i]->type, nTupleId);
1233 break;
1234 }
1235 }
1236 else if (dNTu->variables[i]->lengthW > 0) {
1237 nn = dNTu->variables[i]->lengthW;
1238 if (j == 0) dNTu->variables[i]->offsetXDR =
1239 xdr_getpos(xdrs) - startXDR - dNTu->subXDROffset[0];
1240 switch (dNTu->variables[i]->type) {
1241 case BYTE_NTU: case CHARACTER_NTU:
1242 ok = xdr_bytes(xdrs, (char **) &pt, &nn, nn);
1243 break;
1244 case INTEGER2_NTU:
1245 ok = xdr_array(xdrs,
1246 (char **) &pt, &nn, nn, sizeof(short), (void *) xdr_short);
1247 break;
1248 case LOGICAL_NTU: case INTEGER_NTU:
1249 ok = xdr_array(xdrs,
1250 (char **) &pt, &nn, nn, sizeof(int), (void *) xdr_int);
1251 break;
1252 case REAL_NTU:
1253 ok = xdr_array(xdrs,
1254 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1255 break;
1256 case DBL_PRECISION_NTU:
1257 ok = xdr_array(xdrs,
1258 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1259 break;
1260 case COMPLEX_NTU:
1261 nn = nn*2;
1262 ok = xdr_array(xdrs,
1263 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1264 break;
1265 case DBL_COMPLEX_NTU:
1266 nn = nn*2;
1267 ok = xdr_array(xdrs,
1268 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1269 break;
1270 case POINTER_NTU:
1271 ok = xdr_array(xdrs,
1272 (char **) &pt, &nn, nn, sizeof(long), (void *) xdr_long);
1273 break;
1274 default :
1275 fprintf (stderr, "mcfio_NTuple: internal error! \n\
1276 Unexpected variables type %d on NTuple %d\n",
1277 dNTu->variables[i]->type, nTupleId);
1278 break;
1279 }
1280 if (ok == FALSE) return FALSE;
1281 }
1282 } /*end of i loop */
1283 } /*end of j loop */
1284 } /* End of orgStyle clause */
1285 } /* End of firstIndexed clause */
1286 /*
1287 ** Check the fence..
1288 */
1289 if (*pnFence != *pnTot) {
1290 fprintf (stderr, "mcfio_NTuple: Suspected Data Overwrite! \n\
1291 Fence content found on the input stream is = %d\n\
1292 ... while we expect %d\n", *pnFence, *pnTot);
1293 return FALSE;
1294 }
1295 return TRUE;
1296}
1297/*
1298** Generalized NTuple XDR filter, used for Decode only.
1299** Simply decode the multiplicty value. No checks whatsoever!
1300*/
1301bool_t xdr_mcfast_NTupleMult(mcfStream *str, descrGenNtuple *dNTu,
1302 char* version)
1303{
1304 char *cDat;
1305
1306 cDat = version;
1307 cDat += dNTu->multOffset;
1308 xdr_setpos(str->xdr, (str->currentPos + dNTu->multXDROffset) );
1309 return (xdr_int(str->xdr, ((int *) cDat)));
1310}
1311
1312/*
1313** Generalized NTuple XDR filter, used for Decode only.
1314** Simply decode one variable (scalar) or array value. No checks whatsoever!
1315** Not applicable if the structure organization style is VAX FORTRAN d/s
1316** and the index corresponds to an indexed variable.
1317*/
1318bool_t xdr_mcfast_NTupleVar(mcfStream *str, descrGenNtuple *dNTu,
1319 int ivar, char* version)
1320{
1321 char *cDat;
1322 u_int nn;
1323 void *pt;
1324 int ivarP;
1325
1326 ivarP = ivar;
1327 while (dNTu->variables[ivarP]->lengthW == 0) ivarP--;
1328 cDat = version;
1329 cDat += dNTu->variables[ivarP]->offset;
1330 pt = (void *) cDat;
1331 xdr_setpos(str->xdr,
1332 (str->currentPos + dNTu->variables[ivarP]->offsetXDR));
1333 if ((dNTu->variables[ivarP]->lengthW == 1) &&
1334 (ivarP < dNTu->firstIndexed)) {
1335 switch (dNTu->variables[ivarP]->type) {
1336 case BYTE_NTU: case CHARACTER_NTU:
1337 return xdr_char(str->xdr, (char *) pt);
1338 case INTEGER2_NTU:
1339 return xdr_short(str->xdr, (short *) pt);
1340 case LOGICAL_NTU: case INTEGER_NTU:
1341 return xdr_int(str->xdr, (int *) pt);
1342 case REAL_NTU:
1343 return xdr_float(str->xdr, (float *) pt);
1344 case DBL_PRECISION_NTU:
1345 return xdr_double(str->xdr, (double *) pt);
1346 case COMPLEX_NTU:
1347 nn =2;
1348 return xdr_array(str->xdr,
1349 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1350 case DBL_COMPLEX_NTU:
1351 nn =2;
1352 return xdr_array(str->xdr,
1353 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1354 case POINTER_NTU:
1355 return xdr_long(str->xdr, (long *) pt);
1356 default :
1357 return FALSE;
1358 }
1359 } else {
1360 nn = dNTu->variables[ivarP]->lengthW;
1361 switch (dNTu->variables[ivarP]->type) {
1362 case BYTE_NTU: case CHARACTER_NTU:
1363 return xdr_bytes(str->xdr, (char **) &pt, &nn, nn);
1364 case INTEGER2_NTU:
1365 return xdr_array(str->xdr,
1366 (char **) &pt, &nn, nn, sizeof(short), (void *) xdr_short);
1367 case LOGICAL_NTU: case INTEGER_NTU:
1368 return xdr_array(str->xdr,
1369 (char **) &pt, &nn, nn, sizeof(int), (void *) xdr_int);
1370 case REAL_NTU:
1371 return xdr_array(str->xdr,
1372 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1373 case DBL_PRECISION_NTU:
1374 return xdr_array(str->xdr,
1375 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1376 case COMPLEX_NTU:
1377 nn = nn*2;
1378 return xdr_array(str->xdr,
1379 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1380 case DBL_COMPLEX_NTU:
1381 nn = nn*2;
1382 return xdr_array(str->xdr,
1383 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1384 case POINTER_NTU:
1385 return xdr_array(str->xdr,
1386 (char **) &pt, &nn, nn, sizeof(long), (void *) xdr_long);
1387 default :
1388 return FALSE;
1389 }
1390 }
1391}
1392/*
1393** Generalized NTuple XDR filter, used for Decode only.
1394** Simply decode one variable (scalar) or array value. No checks whatsoever!
1395** Not applicable if the structure organization style is parallel array
1396** or the index corresponds to a fixed size variable.
1397*/
1398bool_t xdr_mcfast_NTupleSubVar(mcfStream *str, descrGenNtuple *dNTu,
1399 int ivar, int multIndex, char* version)
1400{
1401 char *cDat;
1402 u_int nn;
1403 void *pt;
1404 int ivarP;
1405
1406 ivarP = ivar;
1407 while (dNTu->variables[ivarP]->lengthW == 0) ivarP--;
1408 cDat = version;
1409 cDat += dNTu->subOffset[multIndex];
1410 cDat += dNTu->variables[ivarP]->offset;
1411 pt = (void *) cDat;
1412 xdr_setpos(str->xdr,
1413 (str->currentPos + dNTu->subXDROffset[multIndex] +
1414 dNTu->variables[ivarP]->offsetXDR));
1415 if (dNTu->variables[ivarP]->lengthW == 1) {
1416 switch (dNTu->variables[ivarP]->type) {
1417 case BYTE_NTU: case CHARACTER_NTU:
1418 return xdr_char(str->xdr, (char *) pt);
1419 case INTEGER2_NTU:
1420 return xdr_short(str->xdr, (short *) pt);
1421 case LOGICAL_NTU: case INTEGER_NTU:
1422 return xdr_int(str->xdr, (int *) pt);
1423 case REAL_NTU:
1424 return xdr_float(str->xdr, (float *) pt);
1425 case DBL_PRECISION_NTU:
1426 return xdr_double(str->xdr, (double *) pt);
1427 case COMPLEX_NTU:
1428 nn =2;
1429 return xdr_array(str->xdr,
1430 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1431 case DBL_COMPLEX_NTU:
1432 nn =2;
1433 return xdr_array(str->xdr,
1434 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1435 case POINTER_NTU:
1436 return xdr_long(str->xdr, (long *) pt);
1437 default :
1438 return FALSE;
1439 }
1440 } else {
1441 nn = dNTu->variables[ivarP]->lengthW;
1442 switch (dNTu->variables[ivarP]->type) {
1443 case BYTE_NTU: case CHARACTER_NTU:
1444 return xdr_bytes(str->xdr, (char **) &pt, &nn, nn);
1445 case INTEGER2_NTU:
1446 return xdr_array(str->xdr,
1447 (char **) &pt, &nn, nn, sizeof(short), (void *) xdr_short);
1448 case LOGICAL_NTU: case INTEGER_NTU:
1449 return xdr_array(str->xdr,
1450 (char **) &pt, &nn, nn, sizeof(int), (void *) xdr_int);
1451 case REAL_NTU:
1452 return xdr_array(str->xdr,
1453 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1454 case DBL_PRECISION_NTU:
1455 return xdr_array(str->xdr,
1456 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1457 case COMPLEX_NTU:
1458 nn = nn*2;
1459 return xdr_array(str->xdr,
1460 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1461 case DBL_COMPLEX_NTU:
1462 nn = nn*2;
1463 return xdr_array(str->xdr,
1464 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1465 case POINTER_NTU:
1466 return xdr_array(str->xdr,
1467 (char **) &pt, &nn, nn, sizeof(long), (void *) xdr_long);
1468 default :
1469 return FALSE;
1470 }
1471 }
1472}
1473/*
1474** Generalized NTuple XDR filter, used for Decode only.
1475** Simply decode a sub-structure given a value for the multiplicity index.
1476** Not applicable if the structure organization style is parallel array.
1477** No check whatsover!
1478*/
1479bool_t xdr_mcfast_NTupleSubStruct(mcfStream *str, descrGenNtuple *dNTu,
1480 int multIndex, char* version)
1481{
1482 char *cDat;
1483 u_int nn;
1484 void *pt;
1485 int iv;
1486 bool_t ok;
1487
1488 xdr_setpos(str->xdr,
1489 (str->currentPos + dNTu->subXDROffset[multIndex]));
1490 for (iv=dNTu->firstIndexed; iv<dNTu->numVariables; iv++) {
1491 cDat = version;
1492 cDat +=
1493 dNTu->subOffset[multIndex] + dNTu->variables[iv]->offset;
1494 pt = (void *) cDat;
1495 if (dNTu->variables[iv]->lengthW == 1) {
1496 switch (dNTu->variables[iv]->type) {
1497 case BYTE_NTU: case CHARACTER_NTU:
1498 ok = xdr_char(str->xdr, (char *) pt);
1499 break;
1500 case INTEGER2_NTU:
1501 ok = xdr_short(str->xdr, (short *) pt);
1502 break;
1503 case LOGICAL_NTU: case INTEGER_NTU:
1504 ok = xdr_int(str->xdr, (int *) pt);
1505 break;
1506 case REAL_NTU:
1507 ok = xdr_float(str->xdr, (float *) pt);
1508 break;
1509 case DBL_PRECISION_NTU:
1510 ok = xdr_double(str->xdr, (double *) pt);
1511 break;
1512 case COMPLEX_NTU:
1513 nn =2;
1514 ok = xdr_array(str->xdr,
1515 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1516 break;
1517 case DBL_COMPLEX_NTU:
1518 nn =2;
1519 ok = xdr_array(str->xdr,
1520 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1521 break;
1522 case POINTER_NTU:
1523 ok = xdr_long(str->xdr, (long *) pt);
1524 default :
1525 return FALSE;
1526 }
1527 } else if (dNTu->variables[iv]->lengthW > 1){
1528 nn = dNTu->variables[iv]->lengthW;
1529 switch (dNTu->variables[iv]->type) {
1530 case BYTE_NTU: case CHARACTER_NTU:
1531 ok = xdr_bytes(str->xdr, (char **) &pt, &nn, nn);
1532 break;
1533 case INTEGER2_NTU:
1534 ok = xdr_array(str->xdr,
1535 (char **) &pt, &nn, nn, sizeof(short), (void *) xdr_short);
1536 break;
1537 case LOGICAL_NTU: case INTEGER_NTU:
1538 ok = xdr_array(str->xdr,
1539 (char **) &pt, &nn, nn, sizeof(int), (void *) xdr_int);
1540 break;
1541 case REAL_NTU:
1542 ok = xdr_array(str->xdr,
1543 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1544 break;
1545 case DBL_PRECISION_NTU:
1546 ok = xdr_array(str->xdr,
1547 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1548 break;
1549 case COMPLEX_NTU:
1550 nn = nn*2;
1551 ok = xdr_array(str->xdr,
1552 (char **) &pt, &nn, nn, sizeof(float), (void *) xdr_float);
1553 break;
1554 case DBL_COMPLEX_NTU:
1555 nn = nn*2;
1556 ok = xdr_array(str->xdr,
1557 (char **) &pt, &nn, nn, sizeof(double), (void *) xdr_double);
1558 break;
1559 case POINTER_NTU:
1560 ok = xdr_array(str->xdr,
1561 (char **) &pt, &nn, nn, sizeof(long), (void *) xdr_long);
1562 break;
1563 default :
1564 return FALSE;
1565 }
1566 }
1567 }
1568 return TRUE;
1569}
Note: See TracBrowser for help on using the repository browser.