source: trunk/mcfio/mcfio_Util1.c@ 20

Last change on this file since 20 was 2, checked in by Pavel Demin, 16 years ago

first commit

File size: 27.0 KB
Line 
1/*******************************************************************************
2* *
3* mcfio_Init.c -- Utility routines for the McFast Monte-Carlo *
4* Initialisation & info routines *
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 *
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#include <stdlib.h>
33#ifdef SUNOS
34#include <floatingpoint.h>
35#else /* SUNOS */
36#include <float.h>
37#endif /* SUNOS */
38#include <time.h>
39#include "mcf_nTupleDescript.h"
40#include "mcf_xdr.h"
41#include "mcfio_Util1.h"
42#include "mcfio_Direct.h"
43#include "mcfio_Sequential.h"
44#include "mcfio_Dict.h"
45#include "mcf_ntubld_db.h"
46#include "mcf_NTuIOFiles.h"
47#include "mcf_NTuIOUtils.h"
48#include "mcf_NTuIOUtils.h"
49#include "mcfio_UserDictionary.h"
50#ifndef FALSE
51#define FALSE 0
52#endif
53#ifndef TRUE
54#define TRUE 1
55#endif
56
57mcfStream **McfStreamPtrList=NULL;
58unsigned int McfNumOfStreamActive=0;
59char **McfGenericVersion=NULL;
60
61/*
62** This stuff is needed for dbin utilities...
63*/
64struct line_title_c line_title_c_;
65struct header_c header_c_;
66struct variable_c variable_c_;
67/*
68** Names of variable types for Ntuple utilities
69*/
70char *VarTypesNamesF77[N_VAR_TYPES];
71char *VarTypesNamesC[N_VAR_TYPES];
72/*
73** Ntuple global list
74*/
75extern nTuDDL **NTuDDLList;
76extern int NumOfNTuples;
77
78
79void mcfioC_Init(void)
80/* Global Initialisation routine. Simply set the
81**
82*/
83{
84 int i;
85
86/*
87** This is no longer needed...
88
89 char *env, *line;
90 FILE *Ffp;
91
92 env = NULL;
93 env = getenv("MCFIO_DIR");
94 if (env == NULL) {
95 printf ("You must first set the environment variable MCFIO_DIR\n");
96 printf (" by either setting up mcfio (Fermi UPS), or setting \n");
97 printf
98 (" this env. variable to the place where mcf_NTuBld.db resides.\n");
99 exit(0);
100 } */
101
102
103 /*
104 ** Check now that the master template exist.
105
106 line = (char *) malloc(sizeof(char) * (FILENAME_MAX+1));
107 sprintf(line,"%s/mcf_NTuBld.db", env);
108 Ffp = fopen(line, "r");
109 if (Ffp == NULL) {
110 printf ("The file %s could not be opened. \n", line);
111 printf (" Please check MCFIO installation. \n");
112 exit(0);
113 }
114 fclose(Ffp);
115 free(line);
116
117*/
118 /*
119 ** Use only one version for now. Possible extension here.
120 */
121 McfGenericVersion = (char **) malloc(sizeof(char *));
122 *McfGenericVersion = (char *) malloc(sizeof(char) * 8);
123
124 VarTypesNamesF77[0]= "Byte ";
125 VarTypesNamesF77[1]= "Character ";
126 VarTypesNamesF77[2]= "Integer*2 ";
127 VarTypesNamesF77[3]= "Logical ";
128 VarTypesNamesF77[4]= "Integer ";
129 VarTypesNamesF77[5]= "Real ";
130 VarTypesNamesF77[6]= "Double Precision";
131 VarTypesNamesF77[7]= "Complex ";
132 VarTypesNamesF77[8]= "Double Complex ";
133 VarTypesNamesF77[9]= "Pointer ";
134
135 VarTypesNamesC[0]= "char ";
136 VarTypesNamesC[1]= "char ";
137 VarTypesNamesC[2]= "short ";
138 VarTypesNamesC[3]= "int ";
139 VarTypesNamesC[4]= "int ";
140 VarTypesNamesC[5]= "float ";
141 VarTypesNamesC[6]= "double ";
142 VarTypesNamesC[7]= "float[2] ";
143 VarTypesNamesC[8]= "double[2] ";
144 VarTypesNamesC[9]= "void * ";
145
146 if (NTuDDLList != NULL) {
147 for (i=0; i<NumOfNTuples; i++) DestroyNTuDDL(NTuDDLList[i]);
148 free(NTuDDLList);
149 }
150 NTuDDLList = (nTuDDL **) malloc(sizeof(int *)* NTU_START_LIST_SIZE);
151 NumOfNTuples = 0;
152
153 if (McfStreamPtrList == NULL) {
154 McfStreamPtrList = (mcfStream **)
155 malloc(sizeof(mcfStream *) * MCF_STREAM_NUM_MAX);
156 for (i=0; i< MCF_STREAM_NUM_MAX; i++) McfStreamPtrList[i] = NULL;
157 return;
158 }
159 for (i=0; i< MCF_STREAM_NUM_MAX; i++) McfStreamPtrList[i] = NULL;
160 mcfioC_Close(0);
161 McfNumOfStreamActive=0;
162
163}
164
165void mcfioC_Close(int istream)
166/*
167** Closing a Stream istream is the F77 index to the array of mcf Streams.
168*/
169{
170 int i;
171
172 if (McfStreamPtrList == NULL) return;
173 if ((istream < 0) || (istream > MCF_STREAM_NUM_MAX)) {
174 fprintf (stderr, "mcf_close, Illegal argument, stream = %d \n", istream);
175 return;
176 }
177 if (istream == 0) {
178 for (i=0; i<MCF_STREAM_NUM_MAX; i++) {
179 if (McfStreamPtrList[i] != NULL) {
180 switch (McfStreamPtrList[i]->dos) {
181 case MCFIO_DIRECT: case MCFIO_MEMMAPPED:
182 mcfioC_CloseDirect(i);
183 break;
184 case MCFIO_SEQUENTIAL:
185 mcfioC_CloseSequentialTape(i);
186 break;
187 default:
188 fprintf
189 (stderr," mcf_close, Internal Error, please report \n");
190 break;
191 }
192 mcfioC_FreeStream(&McfStreamPtrList[i]);
193 }
194 }
195 return;
196 }
197 i = istream -1;
198 if (McfStreamPtrList[i] != NULL) {
199 switch (McfStreamPtrList[i]->dos) {
200 case MCFIO_DIRECT: case MCFIO_MEMMAPPED:
201 mcfioC_CloseDirect(i);
202 break;
203 case MCFIO_SEQUENTIAL:
204 mcfioC_CloseSequentialTape(i);
205 break;
206 default:
207 fprintf
208 (stderr," mcf_close, Internal Error, please report \n");
209 break;
210 }
211 mcfioC_FreeStream(&McfStreamPtrList[i]);
212 }
213}
214
215void mcfioC_Rewind(int istream)
216/*
217** Closing a Stream istream is the F77 index to the array of mcf Streams.
218*/
219{
220 int i;
221
222 if (McfStreamPtrList == NULL) return;
223 if ((istream <= 0) || (istream > MCF_STREAM_NUM_MAX)) {
224 fprintf (stderr, "mcfio_Rewind, Illegal argument, stream = %d \n",
225 istream);
226 return;
227 }
228 i = istream -1;
229
230 if (McfStreamPtrList[i] != NULL) {
231 if(McfStreamPtrList[i]->row == MCFIO_WRITE) {
232 fprintf
233 (stderr," mcf_Rewind, Not support for Output Stream \n");
234 return;
235 }
236 switch (McfStreamPtrList[i]->dos) {
237 case MCFIO_DIRECT: case MCFIO_MEMMAPPED:
238 mcfioC_RewindDirect(i);
239 break;
240 case MCFIO_SEQUENTIAL:
241 fprintf
242 (stderr," mcf_Rewind, Sequential, done by a close Sequential File\n\
243 Then reopening a stream on the same sequential media \n");
244 break;
245 default:
246 fprintf
247 (stderr," mcf_Rewind, Internal Error, please report \n");
248 break;
249 }
250 McfStreamPtrList[i]->numWordsC = 0;
251 McfStreamPtrList[i]->numWordsT = 0;
252 }
253}
254
255void mcfioC_Free_FileHeader(mcfxdrFileHeader **p)
256{
257 int i;
258 mcfxdrFileHeader *head = *p;
259
260 if (head == NULL) return;
261 for (i=0; i<head->nBlocks; i++)
262 if (head->blockNames[i] != NULL) free(head->blockNames[i]);
263 if (head->blockNames != NULL) free (head->blockNames);
264 if (head->blockIds != NULL) free(head->blockIds);
265 free(head);
266 *p = NULL;
267}
268
269void mcfioC_Free_SeqHeader(mcfxdrSequentialHeader **p)
270{
271 mcfxdrSequentialHeader *head = *p;
272
273 if (head == NULL) return;
274 free(head);
275 *p = NULL;
276}
277
278void mcfioC_Free_EventHeader(mcfxdrEventHeader **p)
279{
280 mcfxdrEventHeader *head = *p;
281
282 if (head == NULL) return;
283 if (head->ptrBlocks != NULL) free(head->ptrBlocks);
284 if (head->blockIds != NULL) free(head->blockIds);
285 if (head->ptrNTuples != NULL) free(head->ptrNTuples);
286 if (head->nTupleIds != NULL) free(head->nTupleIds);
287 free(head);
288 *p = NULL;
289}
290
291void mcfioC_Free_EventTable(mcfxdrEventTable **p)
292{
293 mcfxdrEventTable *table = *p;
294
295 if (table == NULL) return;
296 if (table->evtnums != NULL) free(table->evtnums);
297 if (table->storenums != NULL) free(table->storenums);
298 if (table->runnums != NULL) free(table->runnums);
299 if (table->trigMasks != NULL) free(table->trigMasks);
300 if (table->ptrEvents != NULL) free(table->ptrEvents);
301 free(table);
302 *p = NULL;
303}
304
305void mcfioC_FreeStream(mcfStream **stream)
306{
307 mcfStream *str = *stream;
308 if (str == NULL) return;
309 if (str->filename != NULL) free (str->filename);
310 if (str->device != NULL) free (str->device);
311 if (str->vsn != NULL) free (str->vsn);
312 if (str->fhead != NULL) mcfioC_Free_FileHeader(&(str->fhead));
313 if (str->shead != NULL) mcfioC_Free_SeqHeader(&(str->shead));
314 if (str->ehead != NULL) mcfioC_Free_EventHeader(&(str->ehead));
315 if (str->table != NULL) mcfioC_Free_EventTable(&(str->table));
316 if (str->buffer != NULL) free (str->buffer);
317 if (str->buffer2 != NULL) free (str->buffer2);
318 free(str);
319 *stream = NULL;
320 McfNumOfStreamActive--;
321}
322
323
324void mcfioC_PrintDictionary(void)
325{
326 printf (" \n");
327 printf
328 (" Mcfast I/o Dictionary for Key words used in mcfio_Info routines \n");
329
330 printf
331 (" --------------------------------------------------------------- \n");
332 printf (" \n");
333 printf (" For Streams \n");
334 printf (" -------------- \n");
335 printf (" MCFIO_STATUS: The current status of the file; \n");
336 printf (" the answer can be set to: \n");
337 printf
338 (" MCFIO_BOF : at beginning of file \n");
339 printf
340 (" MCFIO_EOF : at the end of file \n");
341 printf
342 (" MCFIO_RUNNING: At least a valid file header has been read or written\n");
343
344 printf
345 (" MCFIO_READORWRITE: if set MCFIO_READ, open for read only \n");
346 printf
347 (" if set MCFIO_WRITE, open for write only \n");
348 printf
349 (" MCFIO_DIRECTORSEQUENTIAL: if set MCFIO_DIRECT, accessing a UNIX file \n");
350 printf
351 (" : if set MCFIO_SEQUENTIAL, accessing a tape \n");
352 printf
353 (" MCFIO_NUMEVTS : Total number of events encode/decoded so far. \n");
354 printf
355 (" MCFIO_NUMBLOCK: The number of blocks defined in the file. \n");
356
357 printf
358 (" MCFIO_BLOCKIDS: The I.D. of the block defined in the file.\n");
359 printf
360 (" MCFIO_NUMWORDS: Total number of 4-bytes words encode/decoded so far. \n");
361 printf
362 (" MCFIO_EFFICIENCY: The overhead in blocking and XDR (*10000 ) \n");
363 printf
364 (" MCFIO_CREATIONDATE: The date (30 Character) when the file was opened \n");
365 printf
366 (" MCFIO_CLOSINGDATE: The date (30 Character) when the file was closed \n");
367 printf
368 (" MCFIO_TITLE: The title (255 Characters max) for the job \n");
369 printf
370 (" MCFIO_COMMENT: The comment (255 Characters max) for the job \n");
371
372 printf (" \n");
373 printf (" For Sequential Access only \n");
374 printf
375 (" MCFIO_FILENUMBER : The Sequential file number currently accessed.\n");
376 printf (" MCFIO_MAXLREC: Maximum Record length\n");
377 printf (" MCFIO_MINLREC: Minumum Record length\n");
378 printf
379 (" MCFIO_NUMRECORDS: The number of records in the current event\n");
380 printf
381 (" MCFIO_RECORDLENGTHS: The record lengths for the current event\n");
382 printf (" MCFIO_DEVICENAME: The device name opened by the stream\n ");
383 printf (" (character string, 255 l.)\n");
384 printf (" \n");
385 printf (" For Direct Access only \n");
386 printf (" MCFIO_FILENAME: The UNIX file name opened by the stream\n ");
387 printf (" (character string, 255 l.)\n");
388
389 printf (" \n");
390 printf (" For Events \n");
391 printf (" -------------- \n");
392 printf
393 (" MCFIO_NUMBLOCK: The number of blocks defined in the event.\n");
394
395 printf
396 (" MCFIO_BLOCKIDS: The I.D. of the block defined in the event.\n");
397 printf
398 (" MCFIO_EVENTNUMBER: The Event Number for this event. \n");
399 printf
400 (" MCFIO_STORENUMBER: The Store Number for this event. \n");
401 printf
402 (" MCFIO_RUNNUMBER: The Run Number for this event. \n");
403 printf
404 (" MCFIO_TRIGGERMASK: The Trigger Mask for this event. \n");
405 printf (" MCFIO_VERSION: The 4-Character version of the event header \n ");
406
407 printf (" \n");
408 printf (" For Blocks \n");
409 printf (" -------------- \n");
410 printf (" MCFIO_VERSION: The 4-Character version of a particular block \n ");
411
412 printf (" \n");
413 printf (" For NTuples \n");
414 printf (" -------------- \n");
415 printf (" MCFIO_NUMNTUPLES: The number of defined NTuples on a stream \n ");
416 printf (" See also mcfio_GetNTupleIds, mcfio_GetNTupleUID, \n");
417 printf (" mcfio_GetNTupleCategory, mcfio_GetNTupleTitle and \n");
418 printf (" mcfio_GetNTupleName \n");
419
420}
421
422unsigned int mcfioC_InfoNumStream(int *istreams, unsigned int nmax)
423/*
424** Returns in the arrary istream the list of active stream indices.
425**
426*/
427{
428 int i,j;
429
430 if (nmax >= MCF_STREAM_NUM_MAX) {
431 fprintf(stderr, "mcfio_Info, Illegal size of Stream Pointer array \n");
432 return 0;
433 }
434 for (i=0,j=0; i<MCF_STREAM_NUM_MAX; i++) {
435 if (McfStreamPtrList[i] != NULL) {
436 if (j < nmax) istreams[j] = McfStreamPtrList[i]->id;
437 j++;
438 }
439 }
440 return McfNumOfStreamActive;
441}
442
443void mcfioC_InfoStreamInt(int stream, int key, int *values)
444/*
445** Information routine for the Stream. Based on key, return in *values
446** the requested information
447*/
448{
449 int i, num, jstr;
450 float a;
451 mcfStream *str;
452 jstr = stream - 1;
453 if ((jstr <0) || (jstr >= MCF_STREAM_NUM_MAX)) {
454 fprintf(stderr,"mcfio_InfoStream: Stream id %d is illegal \n",
455 stream);
456 return;
457 }
458 str = McfStreamPtrList[jstr];
459 if (str == NULL) {
460 fprintf(stderr,"mcfio_InfoStream: Stream id %d is inactive \n",
461 stream);
462 return;
463 }
464 switch (key) {
465 case MCFIO_STATUS:
466 *values = str->status;
467 break;
468 case MCFIO_READORWRITE:
469 *values = str->row;
470 break;
471 case MCFIO_DIRECTORSEQUENTIAL:
472 *values = str->dos;
473 break;
474 case MCFIO_NUMWORDS:
475 *values = str->numWordsT;
476 break;
477 case MCFIO_EFFICIENCY:
478 a = ((float ) (str->numWordsC))/ (float) (str->numWordsT);
479 *values = (int) (10000. * a);
480 break;
481 case MCFIO_NUMEVTS:
482 if(str->fhead != NULL) *values = str->fhead->numevts;
483 break;
484 case MCFIO_NUMBLOCKS:
485 if(str->fhead != NULL) *values = str->fhead->nBlocks;
486 break;
487 case MCFIO_BLOCKIDS:
488 /*
489 ** Crash bug possibility here, if the dimension is wrong !
490 */
491 if(str->fhead != NULL) {
492 for (i=0; i<str->fhead->nBlocks; i++)
493 values[i] = str->fhead->blockIds[i];
494 }
495 break;
496 /*
497 ** Now the specific items for Sequential stuff
498 */
499 case MCFIO_FILENUMBER:
500 if (str->dos != MCFIO_SEQUENTIAL) {
501 fprintf(stderr,
502 "mcfio_InfoStream: Meaningless request for stream %d, key MCFIO_FILENUMBER\n",
503 stream);
504 return;
505 }
506 *values = str->filenumber;
507 break;
508 case MCFIO_MAXREC:
509 if (str->dos != MCFIO_SEQUENTIAL) {
510 fprintf(stderr,
511 "mcfio_InfoStream: Meaningless request for stream %d, key MCFIO_MAXREC\n",
512 stream);
513 return;
514 }
515 *values = str->maxlrec;
516 break;
517 case MCFIO_MINREC:
518 if (str->dos != MCFIO_SEQUENTIAL) {
519 fprintf(stderr,
520 "mcfio_InfoStream: Meaningless request for stream %d, key MCFIO_MINREC \n",
521 stream);
522 return;
523 }
524 *values = str->minlrec;
525 break;
526 case MCFIO_NUMRECORDS:
527 if ((str->dos != MCFIO_SEQUENTIAL) || (str->shead == NULL) ) {
528 fprintf(stderr,
529 "mcfio_InfoStream: Meaningless request for stream %d, key MCFIO_NUMRECORDS \n",
530 stream);
531 return;
532 }
533 *values = str->shead->nRecords;
534 break;
535 case MCFIO_RECORDLENGTHS:
536 if ((str->dos != MCFIO_SEQUENTIAL) || (str->shead == NULL) ) {
537 fprintf(stderr,
538 "mcfio_InfoStream: Meaningless request for stream %d, key MCFIO_RECORDLENGTHS \n",
539 stream);
540 return;
541 }
542 *values = str->maxlrec;
543 break;
544 case MCFIO_NUMNTUPLES:
545 for (i=0, num=0; i<NumOfNTuples; i++)
546 if (NTuDDLList[i]->streamId == stream) num++;
547 *values = num;
548 break;
549 default:
550 fprintf(stderr,
551 "mcfio_InfoStream: Unrecognized Keyword %d\n", key);
552 }
553}
554
555void mcfioC_InfoStreamChar(int stream, int key, char *answer, int *lret)
556/*
557** Information routine for the Stream. Based on key, return in *values
558** the requested information
559*/
560{
561 int jstr;
562 mcfStream *str;
563 jstr = stream - 1;
564 if ((jstr <0) || (jstr >= MCF_STREAM_NUM_MAX)) {
565 fprintf(stderr,"mcfio_InfoStream: Stream id %d is illegal \n",
566 stream);
567 *lret = 0;
568 return;
569 }
570 str = McfStreamPtrList[jstr];
571 if (str == NULL) {
572 fprintf(stderr,"mcfio_InfoStream: Stream id %d is inactive \n",
573 stream);
574 *lret = 0;
575 return;
576 }
577 switch (key) {
578 case MCFIO_TITLE:
579 if (str->fhead != NULL) strcpy(answer,str->fhead->title);
580 break;
581 case MCFIO_COMMENT:
582 if (str->fhead != NULL) strcpy(answer,str->fhead->comment);
583 break;
584 case MCFIO_CREATIONDATE:
585 if (str->fhead != NULL) strcpy(answer,str->fhead->date);
586 break;
587 case MCFIO_CLOSINGDATE:
588 if (str->fhead != NULL) strcpy(answer,str->fhead->closingDate);
589 break;
590 case MCFIO_FILENAME:
591 if (str->dos == MCFIO_SEQUENTIAL) {
592 fprintf(stderr,
593 "mcfio_InfoStream: Meaningless request for stream %d, key MCFIO_FILENAME \n",
594 stream);
595 *lret = 0;
596 return;
597 }
598 strcpy(answer,str->filename);
599 break;
600 case MCFIO_DEVICENAME:
601 if (str->dos != MCFIO_SEQUENTIAL) {
602 fprintf(stderr,
603 "mcfio_InfoStream: Meaningless request for stream %d, key MCFIO_DEVICENAME \n",
604 stream);
605 *lret = 0;
606 return;
607 }
608 strcpy(answer,str->device);
609 break;
610 default:
611 fprintf(stderr,
612 "mcfio_InfoStream: Unrecognized Keyword %d\n", key);
613 *lret = 0;
614 return;
615
616 }
617 *lret = strlen(answer);
618}
619void mcfioC_InfoEventInt(int stream, int key, int *values)
620/*
621** Information routine for the current Event.
622** Based on key, return in *values the requested information
623*/
624{
625 int i, jstr;
626 mcfStream *str;
627 jstr = stream - 1;
628 if ((jstr <0) || (jstr >= MCF_STREAM_NUM_MAX)) {
629 fprintf(stderr,"mcfio_InfoEvent: Stream id %d is illegal \n",
630 stream);
631 return;
632 }
633 str = McfStreamPtrList[jstr];
634 if (str == NULL) {
635 fprintf(stderr,"mcfio_InfoEvent: Stream id %d is inactive \n",
636 stream);
637 return;
638 }
639 if (str->ehead ==NULL) {
640 fprintf(stderr,"mcfio_InfoEvent: Stream id %d is at beginning \n",
641 stream);
642 return;
643 }
644 switch (key) {
645 case MCFIO_EVENTNUMBER:
646 *values = str->ehead->evtnum;
647 break;
648 case MCFIO_STORENUMBER:
649 *values = str->ehead->storenum;
650 break;
651 case MCFIO_RUNNUMBER:
652 *values = str->ehead->runnum;
653 break;
654 case MCFIO_TRIGGERMASK:
655 *values = str->ehead->trigMask;
656 break;
657 case MCFIO_NUMBLOCKS:
658 *values = str->ehead->nBlocks;
659 break;
660 case MCFIO_BLOCKIDS:
661 for(i=0; i<str->ehead->nBlocks; i++)
662 values[i] = str->ehead->blockIds[i];
663 break;
664 case MCFIO_NUMNTUPLES:
665 *values = str->ehead->nNTuples;
666 break;
667 case MCFIO_NTUPLESLIST:
668 for(i=0; i<str->ehead->nNTuples; i++)
669 values[i] = str->ehead->nTupleIds[i];
670 break;
671 default:
672 fprintf(stderr,
673 "mcfio_InfoEvent: Unrecognized Keyword %d\n", key);
674
675 }
676}
677
678void mcfioC_SetEventInfo(int stream, int key, int *values)
679/*
680** Set anciallary information for the current Event.
681** Based on key, return in *values the requested information
682** Only valid for Output Streams.
683*/
684{
685 int jstr;
686 mcfStream *str;
687 jstr = stream - 1;
688 if ((jstr <0) || (jstr >= MCF_STREAM_NUM_MAX)) {
689 fprintf(stderr,"mcfio_InfoStream: Stream id %d is illegal \n",
690 stream);
691 return;
692 }
693 str = McfStreamPtrList[jstr];
694 if (str == NULL) {
695 fprintf(stderr,"mcfio_SetEvent: Stream id %d is inactive \n",
696 stream);
697 return;
698 }
699 if (str->ehead ==NULL) {
700 fprintf(stderr,"mcfio_SetEvent: Stream id %d is at beginning \n",
701 stream);
702 return;
703 }
704 if (str->row != MCFIO_WRITE) {
705 fprintf(stderr,
706 "mcfio_SetEvent: Stream id %d must be an Output stream \n",
707 stream);
708 return;
709 }
710 switch (key) {
711 case MCFIO_EVENTNUMBER:
712 str->ehead->evtnum = *values;
713 break;
714 case MCFIO_STORENUMBER:
715 str->ehead->storenum = *values;
716 break;
717 case MCFIO_RUNNUMBER:
718 str->ehead->runnum = *values;
719 break;
720 case MCFIO_TRIGGERMASK:
721 str->ehead->trigMask = *values;
722 break;
723 case MCFIO_NUMBLOCKS: case MCFIO_BLOCKIDS:
724 fprintf(stderr,
725 "mcfio_SetEvent: Blocks and Block contents are set by mcfio_Blocks\n" );
726 return;
727 default:
728 fprintf(stderr,
729 "mcfio_SetEvent: Unrecognized Keyword %d\n", key);
730
731 }
732}
733
734void mcfioC_InfoEventChar(int stream, int key, char *answer, int *lret)
735/*
736** Information routine for the current Event.
737** Based on key, return in *values the requested information
738*/
739{
740 int jstr;
741 mcfStream *str;
742 jstr = stream - 1;
743 if ((jstr <0) || (jstr >= MCF_STREAM_NUM_MAX)) {
744 fprintf(stderr,"mcfio_InfoStream: Stream id %d is illegal \n",
745 stream);
746 *lret = 0;
747 return;
748 }
749 str = McfStreamPtrList[jstr];
750 if (str == NULL) {
751 fprintf(stderr,"mcfio_InfoStream: Stream id %d is inactive \n",
752 stream);
753 *lret = 0;
754 return;
755 }
756 if (str->ehead ==NULL) {
757 fprintf(stderr,"mcfio_InfoStream: Stream id %d is at beginning \n",
758 stream);
759 *lret = 0;
760 return;
761 }
762 switch (key) {
763 case MCFIO_VERSION:
764 strcpy(answer, str->ehead->version);
765 break;
766
767 default:
768 fprintf(stderr,
769 "mcfio_InfoEvent: Unrecognized Keyword %d\n", key);
770 *lret = 0;
771 return;
772
773 }
774 *lret = strlen(answer);
775}
776
777void mcfioC_InfoBlockChar(int stream, int blkid,
778 int key, char *answer, int *lret)
779/*
780** Information routine for a particular block within the current Event.
781** Based on key, return the requested information in string answer.
782*/
783{
784 int i, jstr, itmp, nn;
785 u_int pos;
786 bool_t tt;
787 char* data, *vv;
788 mcfStream *str;
789 jstr = stream - 1;
790 if ((jstr <0) || (jstr >= MCF_STREAM_NUM_MAX)) {
791 fprintf(stderr,"mcfio_InfoStream: Stream id %d is illegal \n",
792 stream);
793 *lret = 0;
794 return;
795 }
796 str = McfStreamPtrList[jstr];
797 if (str == NULL) {
798 fprintf(stderr,"mcfio_InfoStream: Stream id %d is inactive \n",
799 stream);
800 *lret = 0;
801 return;
802 }
803 if (str->ehead ==NULL) {
804 fprintf(stderr,"mcfio_InfoStream: Stream id %d is at beginning \n",
805 stream);
806 *lret = 0;
807 return;
808 }
809 pos = 0;
810 if(str->xdr != NULL) for(i=0; i<str->ehead->nBlocks; i++)
811 if( str->ehead->blockIds[i] == blkid) pos = str->ehead->ptrBlocks[i];
812 if (pos == 0) {
813 fprintf(stderr,
814 "mcfio_InfoStream: Stream id %d event %d does not contain block %d \n",
815 stream,str->ehead->evtnum, blkid );
816 *lret = 0;
817 return;
818 }
819
820 switch (key) {
821 case MCFIO_VERSION:
822 tt = xdr_setpos(str->xdr, pos);
823 tt = xdr_mcfast_generic(str->xdr, &itmp, &nn, &vv, &data);
824 xdr_free((void *) xdr_string, data);
825 strcpy(answer, vv);
826 break;
827
828 default:
829 fprintf(stderr,
830 "mcfio_InfoEvent: Unrecognized Keyword %d\n", key);
831 *lret = 0;
832 return;
833
834 }
835 *lret = strlen(answer);
836}
837void mcfioC_GetBlockName(int blkId, char *answer)
838/*
839** Get a Block name from the dictionary..It is assume that answer has
840** pre-malloc, size MCF_XDR_B_TITLE_LENGTH
841*/
842{
843 char *uDescr;
844 switch (blkId) {
845 case MCFIO_STDHEP:
846 strcpy(answer,
847 " Standard HEP COMMON block, see STDHEP Product");
848 break;
849
850 case MCFIO_STDHEPM:
851 strcpy(answer,
852 " Standard HEP COMMON block with multiple interaction, see STDHEP Product");
853 break;
854
855 case MCFIO_STDHEP4:
856 strcpy(answer,
857 " Standard HEP COMMON block with Les Houches, see STDHEP Product");
858 break;
859
860 case MCFIO_STDHEP4M:
861 strcpy(answer,
862 " Standard HEP COMMON block with Les Houches and multiple interaction");
863 break;
864
865 case MCFIO_HEPEUP:
866 strcpy(answer,
867 " Les Houches HEPEUP common block");
868 break;
869
870 case MCFIO_HEPRUP:
871 strcpy(answer,
872 " Les Houches HEPRUP common block");
873 break;
874
875 case MCFIO_STDHEPCXX:
876 strcpy(answer,
877 " StdHep::Event class, see StdHepC++ Product");
878 break;
879
880 case MCFIO_STDHEPBEG:
881 strcpy(answer,
882 " Stdhep begin run record, see STDHEP Product");
883 break;
884
885 case MCFIO_STDHEPEND:
886 strcpy(answer,
887 " Stdhep end run record, see STDHEP Product");
888 break;
889
890 case MCFIO_OFFTRACKARRAYS:
891 strcpy(answer,
892 " The mcfast Offline Tracks, saved into parallel arrays");
893 break;
894
895 case MCFIO_OFFTRACKSTRUCT:
896 strcpy(answer,
897 " The mcfast Offline Tracks, saved as the structure");
898 break;
899 default:
900 sprintf(answer, " Private User Block number %d ", blkId );
901 uDescr = mcfioC_UserBlockDescript(blkId);
902 if (uDescr == NULL) fprintf(stderr,
903 "mcfio_GetBlockName: Warning Unrecognized block I.D. %d\n", blkId);
904 else answer = uDescr;
905 }
906
907}
908
909
910
Note: See TracBrowser for help on using the repository browser.