]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/icepack/iceconvert/rdmc_mcfile.c
Avoid linking with pythia.
[u/mrichter/AliRoot.git] / RALICE / icepack / iceconvert / rdmc_mcfile.c
1 /*
2  *  functions for the mcfile structure 
3  */
4
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include "rdmc.h"
9 #include "rdmc_local.h"
10
11 #include "f2k.h"
12
13 void rdmc_init_mcfile_f2000(f2000_fp_t *t);
14 void rdmc_free_mcfile_f2000(f2000_fp_t *t);
15 void rdmc_init_mcfile_dumand(dumand_fp_t  *t);
16 void rdmc_init_mcfile_uwi(uwi_fp_t   *t);
17 void rdmc_init_mcfile_baikal(baikal_fp_t   *t);
18
19
20 /****************************************************************************/
21 /* mccpfp() copies the relevant fields from one mcfile* to another          */
22 /* (this is useful for file transforming)                                   */
23 /****************************************************************************/
24
25 int rdmc_mccpfp(const mcfile *src, mcfile *dest)
26 {
27   if ((src == NULL) || (dest == NULL))
28     return -1;
29   /* do not copy 
30      the file pointer, src->fp 
31      the mode, src->mode
32      the format, src->format 
33   also not: fpos,fmajor,fminor,zipped,errline,sloppy, last_line h_buff,e_buff
34   But: creator,comment,nrun,time
35   The format specific stuff is converted to comments */
36 #if 0
37   dest->time = src->time;
38   dest->nrun = src->nrun;
39 #endif
40   memcpy(dest->last_line,src->last_line,RDMC_MAXLINE*sizeof(char));
41
42   /* copy creator + comment structure */
43   if( src->creator)
44     rdmc_append_comment(&(dest->creator),src->creator);
45   if (src->comment)
46     rdmc_append_comment(&(dest->comment),src->comment);
47
48   /* now tryy to convert the special info */
49   switch (src->format){
50 #ifdef AMANDA_ASCII_F 
51   case AMANDA_ASCII_F :
52     /* nothing is to be copied here */
53     break;
54 #endif
55 #ifdef DUMAND_ASCII_F
56   case DUMAND_ASCII_F:       /* if it is a dumand-like format */
57     switch (dest->format){
58     case DUMAND_ASCII_F:
59       memcpy(&(dest->info),&(src->info),sizeof(rdmc_special_format_info_t));
60       break;
61 #ifdef AMANDA_ASCII_F 
62     case AMANDA_ASCII_F :
63       {     /* copy everything to a comment line */
64         char tmp[RDMC_MAXLINE];
65         sprintf(tmp,"! DUM-Form M-header: id=%c mc_vers=%s \n",src->info.dum.mc_id,src->info.dum.mc_vers);
66         rdmc_append_comment(&(dest->comment),tmp);
67         sprintf(tmp,
68                 "! DUM-Form M-header: igen=%i, igeo=%i, igtrack=%i, daswrun=%i\n"
69                 ,src->info.dum.igen,src->info.dum.igeo
70                 ,src->info.dum.igtrack,src->info.dum.daswrun);
71         rdmc_append_comment(&(dest->comment),tmp);
72       }
73       break;
74 #endif
75 #ifdef UWI_ASCII_F 
76     case UWI_ASCII_F :
77       dest->info.uwi.mc_id = src->info.dum.mc_id;
78       strcpy(dest->info.uwi.mc_vers, src->info.dum.mc_vers);
79       break;
80 #endif
81 #ifdef BAIKAL_BIN_F 
82     case BAIKAL_BIN_F :
83       dest->info.bai.mc_id = src->info.dum.mc_id;
84       dest->info.bai.igen = src->info.dum.igen;
85       dest->info.bai.igtrack = src->info.dum.igtrack;
86       dest->info.bai.time = src->info.dum.time;
87       dest->info.bai.nrun = src->info.dum.nrun;
88       strcpy(dest->info.bai.mc_vers, src->info.dum.mc_vers);
89       break;
90 #endif
91     default: 
92       return RDMC_UNKNOWN_FORMAT;
93     }
94     break;
95 #endif
96 #ifdef UWI_ASCII_F
97   case UWI_ASCII_F:       /* if it is the UWI format: read default geometry */
98     switch (dest->format){
99     case UWI_ASCII_F:
100       memcpy(&(dest->info),&(src->info),sizeof(rdmc_special_format_info_t));
101       break;
102 #ifdef AMANDA_ASCII_F 
103     case AMANDA_ASCII_F :
104       {     /* copy everything to a comment line */
105         char tmp[RDMC_MAXLINE];
106         sprintf(tmp,"! UWI-Format header: id=%c mc_vers=%s \n"
107                 ,src->info.uwi.mc_id,src->info.uwi.mc_vers);
108         rdmc_append_comment(&(dest->comment),tmp);
109       }
110       break;
111 #endif
112 #ifdef DUMAND_ASCII_F 
113     case DUMAND_ASCII_F :
114       dest->info.dum.mc_id = src->info.uwi.mc_id;
115       strcpy(dest->info.dum.mc_vers, src->info.uwi.mc_vers);
116       break;
117 #endif
118 #ifdef BAIKAL_BIN_F 
119     case BAIKAL_BIN_F :
120       dest->info.bai.mc_id = src->info.uwi.mc_id;
121       strcpy(dest->info.bai.mc_vers, src->info.uwi.mc_vers);
122       break;
123 #endif
124     default: 
125       return RDMC_UNKNOWN_FORMAT;
126     }
127     break;
128 #endif
129 #ifdef BAIKAL_BIN_F
130   case BAIKAL_BIN_F:                       /* if it is a baikal-like format */
131     switch (dest->format){
132     case BAIKAL_BIN_F:
133       memcpy(&(dest->info),&(src->info),sizeof(rdmc_special_format_info_t));
134       break;
135 #ifdef AMANDA_ASCII_F 
136     case AMANDA_ASCII_F :
137       {     /* copy everything to a comment line */
138         char tmp[RDMC_MAXLINE];
139         sprintf(tmp,"! BAI-Form header: id=%c mc_vers=%s \n",src->info.bai.mc_id,src->info.bai.mc_vers);
140         rdmc_append_comment(&(dest->comment),tmp);
141         sprintf(tmp,"! BAI-Form header: igen=%i, igtrack=%i\n"
142                 ,src->info.bai.igen,src->info.dum.igtrack);
143         rdmc_append_comment(&(dest->comment),tmp);
144         sprintf(tmp,"! BAI-Form header: rec_vers=%i, min_vers=%i mc=%i\n"
145                 ,src->info.bai.rec_vers,src->info.bai.min_vers
146                 ,src->info.bai.mc);
147         rdmc_append_comment(&(dest->comment),tmp);
148       }
149       break;
150 #endif
151 #ifdef DUMAND_ASCII_F 
152     case DUMAND_ASCII_F :
153       dest->info.dum.mc_id = src->info.bai.mc_id;
154       dest->info.dum.igen = src->info.bai.igen;
155       dest->info.dum.igtrack = src->info.bai.igtrack;
156       dest->info.dum.time = src->info.bai.time;
157       dest->info.dum.nrun = src->info.bai.nrun;
158       strcpy(dest->info.dum.mc_vers, src->info.bai.mc_vers);
159       break;
160 #endif
161 #ifdef UWI_ASCII_F 
162     case UWI_ASCII_F :
163       dest->info.dum.mc_id = src->info.bai.mc_id;
164       strcpy(dest->info.dum.mc_vers, src->info.bai.mc_vers);
165       break;
166 #endif
167     default: 
168       return RDMC_UNKNOWN_FORMAT;
169     }
170     break;
171 #endif
172   default: 
173     return RDMC_UNKNOWN_FORMAT;
174   }
175
176   return 0; 
177 } /* mccpfp() */
178
179
180
181
182 void rdmc_init_mcfile(mcfile *fp, int format, int mode, FILE *tf)
183 {
184   fp->fp = tf;
185   fp->mode = mode;
186   fp->format = format;
187   fp->fmajor = fp->fminor = fp->zipped  = 0;
188   fp->creator = fp->comment = NULL;            /* default: no file creator */
189   fp->errline = 0;
190   fp->fpos = 0;
191 #if 0
192   fp->time = 0;
193   fp->nrun = 0;
194 #endif
195   fp->sloppy = 0;
196
197   switch (format) {
198 #ifdef DUMAND_ASCII_F
199   case DUMAND_ASCII_F:       /* if it is a dumand-like format */
200     rdmc_init_mcfile_dumand(&(fp->info.dum));
201     fp->fmajor = DUMAND_ASCII_VERSION; 
202     break;
203 #endif
204 #ifdef UWI_ASCII_F
205   case UWI_ASCII_F:       /* if it is the UWI format: read default geometry */
206     rdmc_init_mcfile_uwi(&(fp->info.uwi));
207     fp->fmajor = UWI_ASCII_VERSION;
208     break;
209 #endif
210 #ifdef AMANDA_ASCII_F
211   case AMANDA_ASCII_F:       /* if it is a amanda-like format */
212     rdmc_init_mcfile_f2000(&(fp->info.f2000));
213     fp->fmajor = AMANDA_ASCII_VERSION; 
214     fp->fminor = AMANDA_ASCII_MINOR; 
215     break;
216 #endif
217 #ifdef BAIKAL_BIN_F
218   case BAIKAL_BIN_F:                       /* if it is a baikal-like format */
219     rdmc_init_mcfile_baikal(&(fp->info.bai));
220     fp->fmajor = BAIKAL_NEW;                         /* default: new format */
221     break;
222 #endif
223   default: 
224     break;
225   }
226 }
227
228 void rdmc_init_mcfile_f2000(f2000_fp_t *t){
229   t->unread=0;
230   t->parse_line[0] = '\0' ;
231   t->errline=0;
232   t->nolex=0;
233   t->f2k_buffer = malloc(sizeof(rdmc_f2k_buffer_t));
234   rdmc_init_f2k_buffer(t->f2k_buffer);
235 }
236
237 void rdmc_free_mcfile_f2000(f2000_fp_t *t){
238   rdmc_unlink_f2k_buffer(t->f2k_buffer);
239   free(t->f2k_buffer);
240   t->f2k_buffer=NULL;
241 }
242
243 void rdmc_init_mcfile_dumand(dumand_fp_t  *t){
244   t->mc_id = 'U';
245   t->igtrack = -1;
246   t->daswrun = 0;
247   t->igeo = 0;
248   t->igen = 0;
249   t->time = 0;
250   t->nrun = 0;
251 }
252
253 void rdmc_init_mcfile_uwi(uwi_fp_t   *t){
254   t->mc_id = 'U';
255   strcpy(t->mc_vers,"0.");
256 }
257
258 void rdmc_init_mcfile_baikal(baikal_fp_t   *t){
259   t->mc = 1;                                /* default: mc file */
260   t->swap = 0;                                /* default: no bytes swapped */
261   t->fortran_recs = 1;                         /* default: fortran file */
262   t->nw_rec_arr = 3;
263   t->nw_rec_evt = 9;
264   t->rec_vers = 0;
265   t->min_vers = 0;
266   t->enr = 0;                                        /* first event number */
267   t->mc_id = 'U';
268   strcpy(t->mc_vers,"0.");
269   t->igtrack = -1;
270   t->igen = 0;
271   t->time = 0;
272   t->nrun = 0;
273 }
274
275 void rdmc_free_mcfile(mcfile *fp)
276 {
277   if (fp->format == AMANDA_ASCII_F)
278     rdmc_free_mcfile_f2000(&(fp->info.f2000));
279
280   if(fp->creator){
281     free(fp->creator);
282     fp->creator=NULL;
283   }
284   if(fp->comment){
285     free(fp->comment);
286     fp->comment=NULL;
287   }
288   free(fp);
289 }
290
291