GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
f_evt.c
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "typedefs.h"
15 #include "f_stccomm.h"
16 #include "f_ut_time.h"
17 
18 #ifdef GSI__LYNX
19 #undef unix
20 #endif
21 
22 #ifdef GSI__LINUX /* Linux */
23 #undef unix
24 #endif
25 
26 #ifdef GSI__SOLARIS /* Solaris */
27 #undef unix
28 #endif
29 
30 #ifdef GSI__WINNT /* Windows NT */
31 #endif
32 
33 #ifdef GSI__AIX
34 #define AIX_DEC
35 #endif
36 
37 #ifdef unix /* DEC OSF/1 */
38 #define AIX_DEC
39 #endif
40 
41 #ifdef GSI__WINNT
42 #include <memory.h>
43 #include <sys/timeb.h>
44 #include <sys/types.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <fcntl.h>
48 #include <string.h>
49 #include <sys/stat.h>
50 #include <fcntl.h>
51 #include <process.h>
52 #define DEF_FILE_ACCE S_IREAD|S_IWRITE /* rw */
53 #define GET__OPEN_FLAG O_RDONLY|O_BINARY
54 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
55 #define PUT__CRT_FLAG O_CREAT|O_RDWR
56 #define PUT__CRT_OPT ""
57 
58 
59 #include <winsock.h>
60 #define WS_VERSION_REQD 0x0101
61 #define WS_VERSION_MAJOR HIBYTE(WS_VERSION_REQD)
62 #define WS_VERSION_MINOR LOBYTE(WS_VERSION_REQD)
63 #define MIN_SOCKETS_REQD 6
64 // WSADATA wsaData;
65 #endif
66 
67 #ifdef Linux /* Linux */
68 #include <stdio.h>
69 #include <stdlib.h>
70 #include <fcntl.h>
71 #include <string.h>
72 #include <unistd.h>
73 #include <memory.h>
74 #include <pwd.h>
75 #include <sys/types.h>
76 #include <sys/stat.h>
77 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH /* rw-r--r-- */
78 #define GET__OPEN_FLAG O_RDONLY
79 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
80 #define PUT__CRT_FLAG O_CREAT|O_RDWR
81 #define PUT__CRT_OPT ""
82 #endif
83 
84 #ifdef Solaris /* Linux */
85 #include <stdio.h>
86 #include <stdlib.h>
87 #include <fcntl.h>
88 #include <string.h>
89 #include <unistd.h>
90 #include <memory.h>
91 #include <pwd.h>
92 #include <sys/types.h>
93 #include <sys/stat.h>
94 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH /* rw-r--r-- */
95 #define GET__OPEN_FLAG O_RDONLY
96 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
97 #define PUT__CRT_FLAG O_CREAT|O_RDWR
98 #define PUT__CRT_OPT ""
99 #endif
100 
101 #ifdef Darwin /* MaxOS X */
102 #include <stdio.h>
103 #include <stdlib.h>
104 #include <fcntl.h>
105 #include <string.h>
106 #include <unistd.h>
107 #include <memory.h>
108 #include <pwd.h>
109 #include <sys/types.h>
110 #include <sys/stat.h>
111 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH /* rw-r--r-- */
112 #define GET__OPEN_FLAG O_RDONLY
113 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
114 #define PUT__CRT_FLAG O_CREAT|O_RDWR
115 #define PUT__CRT_OPT ""
116 #endif
117 
118 
119 
120 #ifdef _AIX
121 #include <stdio.h>
122 #include <stdlib.h>
123 #include <fcntl.h>
124 #include <string.h>
125 #include <unistd.h>
126 #include <memory.h>
127 #include <pwd.h>
128 #include <sys/types.h>
129 #include <sys/mode.h>
130 #define DEF_FILE_ACCE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH /* rw-r--r-- */
131 #define GET__OPEN_FLAG O_RDONLY
132 #define PUT__OPEN_APD_FLAG O_RDWR|O_APPEND
133 #define PUT__CRT_FLAG O_CREAT|O_RDWR
134 #define PUT__CRT_OPT ""
135 #endif
136 
137 #include "s_filhe.h"
138 
139 
140 #ifdef RFIO
141 #define RFIO_open rfio_open
142 #define RFIO_close rfio_close
143 #define RFIO_read rfio_read
144 #define RFIO_lseek rfio_lseek
145 #include "rawapin.h" /* RFIO stuff */
146 #else
147 #define RFIO_open open
148 #define RFIO_close close
149 #define RFIO_read read
150 #define RFIO_lseek lseek
151 #endif
152 
153 #ifdef GSI__WINNT
154 #define own_getpid _getpid
155 #else
156 #define own_getpid getpid
157 #endif
158 
159 
160 // DABC
161 #include "fLmd.h"
162 // -- DABC
163 
164 #include "gps_sc_def.h"
165 #include "f_evt.h"
166 #include "f_evcli.h"
167 #include "portnum_def.h"
168 
174 
177 static int l_gl_source_port = 0;
178 
179 /*1+ C Procedure *************+****************************************/
180 /* */
181 /*+ Module : f_evt__example */
182 /* */
183 /*--------------------------------------------------------------------*/
184 /*+ CALLING : Examples for calling event API */
185 /*--------------------------------------------------------------------*/
186 /* */
187 /*+ PURPOSE : See f_evt_examples.c */
188 /* */
189 /* */
190 /*2+Implementation************+****************************************/
191 /*+ User Example : In m_lea_user.c */
192 /*+ Channel structure : defined in f_evt.h */
193 /*+ File name : f_evt.c */
194 /*+ Version : 1.01 */
195 /*+ Author : H.Essel */
196 /*+ Created : 16-Feb-2000 */
197 /*+ Updates : Date Purpose */
198 /*1- C Procedure *************+****************************************/
199 
200 
201 /*****************+***********+****************************************/
202 /* */
203 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
204 /* Postfach 11 05 52 */
205 /* D-64220 Darmstadt */
206 /* */
207 /*1+ C Procedure *************+****************************************/
208 /* */
209 /*+ Module : f_evt_get_subevent */
210 /* */
211 /*--------------------------------------------------------------------*/
212 /*+ CALLING : l_sts = f_evt_get_subevent(ve10_1 *,subevent,**head,**data,*lwords) */
213 /*--------------------------------------------------------------------*/
214 /* */
215 /*+ PURPOSE : get subevent pointer */
216 /* */
217 /*+ ARGUMENTS : */
218 /* */
219 /*+ ve10_1 : (s_ve10_1 *) event header pointer */
220 /*+ subevent : subevent number (1,2,3...) */
221 /* If = 0, f_evt_get_subevent returns the number of */
222 /* subevents. In this case the following arguments */
223 /* might be NULL. */
224 /*+ head : Address of s_ves10_1 subevent header pointer */
225 /*+ data : Address of INTS4 event data pointer */
226 /*+ lwords : Address of INTS4 to get number of data longwords */
227 /* */
228 /*+ Return type : int */
229 /*- GETEVT__SUCCESS : Found subevent. */
230 /*- GETEVT__NOMORE : No more subevents. */
231 /*+ Declaration : */
232 /* INTS4 f_evt_get_subevent( */
233 /* s_ve10_1 *, INTS4, INTS4 **, INTS4 **, INTS4 *); */
234 /*1- C Procedure *************+****************************************/
235 INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d,INTS4 *pl_lwords)
236 {
237  s_ves10_1 *ps_ves10_1;
238  INTS4 l_total,l_sub,l_sum;
239  INTS4 ll,*pl_next;
240 
241  if(ps_ve10_1 == NULL) return(GETEVT__FAILURE);
242  pl_next = (INTS4 *) (ps_ve10_1 + 1);
243  l_total = ps_ve10_1->l_dlen-4; /* total words in subevents */
244  l_sum = 0;
245  ll=0;
246  while(l_sum < l_total)
247  {
248  ps_ves10_1 = (s_ves10_1 *) pl_next;
249  ll++;
250  if(ll == l_subevent)
251  {
252  if(pl_lwords != NULL) *pl_lwords = ps_ves10_1->l_dlen/2-1;
253  if(pl_se != NULL) *pl_se = (INTS4 *) ps_ves10_1;
254  if(pl_d != NULL) *pl_d = (INTS4 *) (ps_ves10_1+1);
255  return(GETEVT__SUCCESS);
256  }
257  l_sub = ps_ves10_1->l_dlen+4; /* total words of subevent */
258  l_sum += l_sub;
259  pl_next = (INTS4 *)(ps_ves10_1);
260  pl_next += l_sub/2;
261  }
262  if(pl_lwords != NULL) *pl_lwords = ll;
263  if(pl_se != NULL) *pl_se = NULL;
264  if(pl_d != NULL) *pl_d = NULL;
265  if(l_subevent == 0) return(ll);
266  else return(GETEVT__NOMORE);
267 }
268 /*****************+***********+****************************************/
269 /* */
270 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
271 /* Postfach 11 05 52 */
272 /* D-64220 Darmstadt */
273 /* */
274 /*1+ C Procedure *************+****************************************/
275 /* */
276 /*+ Module : f_evt_type */
277 /* */
278 /*--------------------------------------------------------------------*/
279 /*+ CALLING : l_status = f_evt_type(bufhe,evhe,sid,long,hex,data) */
280 /*--------------------------------------------------------------------*/
281 /* */
282 /*+ PURPOSE : print event */
283 /* */
284 /*+ ARGUMENTS : */
285 /* */
286 /*+ bufhe : (s_bufhe *) buffer header pointer (=NULL no output) */
287 /*+ evhe : (s_evhe *) event header pointer (=NULL no output) */
288 /*+ sid : subevent ID (-1 is all) */
289 /*+ long : output longwords */
290 /*+ hex : output hex longwords */
291 /*+ data : output data */
292 /* */
293 /*+ Return type : int */
294 /*+ Declaration : */
295 /* INTS4 f_evt_type( */
296 /* s_bufhe *,s_evhe *, INTS4, INTS4, INTS4, INTS4); */
297 /*1- C Procedure *************+****************************************/
298 INTS4 f_evt_type(s_bufhe *ps_bufhe,s_evhe *ps_evhe, INTS4 l_subid,INTS4 l_long,INTS4 l_hex,INTS4 l_data)
299 {
300  s_ves10_1 *ps_ves10_1;
301  s_ve10_1 *ps_ve10_1;
302  s_filhe *ps_filhe;
303  INTS4 *pl_data;
304  INTS4 l_s;
305  INTS4 l, ll, l_status, l_ldata, l_used;
306  CHARS c_line[132];
307  CHARS c_full[132];
308  CHARS c_time[32];
309 
310  strcpy(c_full," ");
311  l_ldata=l_data;
312  if((l_hex+l_long) > 0) l_ldata=1;
313 
314  /* Print buffer header (file header) */
315  if(ps_bufhe != NULL)
316  {
317  sprintf(c_line,"--------------------------------------------------------");
318  printf("%s\n",c_line);
319  /* calculate real buffer size */
320  ll=ps_bufhe->l_dlen*2;
321  if(ll%512 > 0)ll += 512-ll%512;
322  /* file header */
323  l_status = f_ut_utime(ps_bufhe->l_time[0],ps_bufhe->l_time[1],c_time);
324  if(ps_bufhe->i_type == 2000)
325  {
326  ps_filhe=(s_filhe *)ps_bufhe;
327  sprintf(c_line,"File header info:");
328  printf("%s\n",c_line);
329  sprintf(c_line,"Size: %d [%d b], used %d [b]",ps_filhe->filhe_dlen,ll,ps_filhe->filhe_used*2);
330  printf("%s\n",c_line);
331  sprintf(c_line,"Label: %s",ps_filhe->filhe_label);
332  printf("%s\n",c_line);
333  sprintf(c_line,"File: %s",ps_filhe->filhe_file);
334  printf("%s\n",c_line);
335  sprintf(c_line,"User: %s",ps_filhe->filhe_user);
336  printf("%s\n",c_line);
337  sprintf(c_line,"Time: %s",ps_filhe->filhe_time);
338  printf("%s\n",c_line);
339  sprintf(c_line,"Run: %s",ps_filhe->filhe_run);
340  printf("%s\n",c_line);
341  sprintf(c_line,"Exp: %s",ps_filhe->filhe_exp);
342  printf("%s\n",c_line);
343  for(ll=0;ll<ps_filhe->filhe_lines;ll++)
344  {
345  sprintf(c_line,"comment: %s",ps_filhe->s_strings[ll].string);
346  printf("%s\n",c_line);
347  }
348  }
349  else
350  {
351  l_used=ps_bufhe->i_used;
352  if(ps_bufhe->l_dlen > MAX__DLEN)l_used=ps_bufhe->l_free[2];
353  sprintf(c_line,"Buffer %9d, Length %5d[w] Size %5d[b] used %5d[w] %s",
354  ps_bufhe->l_buf,
355  ps_bufhe->l_dlen,
356  ll,l_used,
357  c_time);
358  printf("%s\n",c_line);
359  sprintf(c_line," Events %3d Type/Subtype %5d %5d FragEnd=%d FragBegin=%d Total %5d[w]",
360  ps_bufhe->l_evt,
361  ps_bufhe->i_type,
362  ps_bufhe->i_subtype,
363  ps_bufhe->h_end,
364  ps_bufhe->h_begin,
365  ps_bufhe->l_free[1]);
366  printf("%s\n",c_line);
367  }
368  sprintf(c_line,"--------------------------------------------------------");
369  printf("%s\n",c_line);
370  }
371 
372  if(ps_evhe == NULL) return(0);
373 
374  /* print event 4,x or 6,x */
375  if(ps_evhe->i_type != 10)
376  {
377  sprintf(c_line,"Event type %d, subtype %d, data longwords %d",
378  ps_evhe->i_type,ps_evhe->i_subtype,ps_evhe->l_dlen/2);
379  printf("%s\n",c_line);
380  if((l_ldata != 0) & ((ps_evhe->i_type == 4)|(ps_evhe->i_type == 6)))
381  { /* output data, assume data as longword */
382  pl_data = (INTS4 *)ps_evhe;
383  pl_data += 2;
384  for(l=0;l<ps_evhe->l_dlen/2;l++)
385  {
386  sprintf(c_line,"%08x ",*pl_data);
387  strncat(c_full, c_line, sizeof(c_full)-1);
388  pl_data++;
389  if(l%8 == 7) {
390  printf("%s\n",c_full);
391  strcpy(c_full," ");
392  }
393  }
394  if(strlen(c_full) > 2) printf("%s\n",c_full);
395  }
396  return(0);
397  }
398 
399  /* Print event 10,1 */
400  ps_ve10_1 = (s_ve10_1 *)ps_evhe;
401  /* Print event header */
402  sprintf(c_line,"Event %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d",
403  ps_ve10_1->l_count,
404  ps_ve10_1->i_type,
405  ps_ve10_1->i_subtype,
406  ps_ve10_1->l_dlen,
407  ps_ve10_1->i_trigger);
408  printf("%s\n",c_line);
409 
410  /********************/
411  l_s=0;
412  l_status=0;
413  while(l_status == 0)
414  {
415  l_s++;
416  l_status=f_evt_get_subevent(ps_ve10_1,l_s,(INTS4 **)&ps_ves10_1,(INTS4 **)&pl_data,(INTS4 *)&ll);
417  if(l_status == 0)
418  {
419  if((l_subid < 0)|(l_subid == ps_ves10_1->i_procid))
420  {
421  sprintf(c_line," SubEv ID %6d Type/Subtype %5d %5d Length %5d[w] Control %2d Subcrate %2d",
422  ps_ves10_1->i_procid,
423  ps_ves10_1->i_type,
424  ps_ves10_1->i_subtype,
425  ps_ves10_1->l_dlen,
426  ps_ves10_1->h_control,
427  ps_ves10_1->h_subcrate);
428  printf("%s\n",c_line);
429  if(l_ldata != 0)
430  { /* output data */
431  if((l_long != 0) | (l_hex != 0))
432  { /* In this case we assume data as one longword per channel */
433  for(l=0;l<ll;l++)
434  {
435  if(l_hex != 0) sprintf(c_line,"%04x.%04x ",(*pl_data>>16)&0xffff,*pl_data&0xffff);
436  else sprintf(c_line,"%8d ",*pl_data);
437  strncat(c_full, c_line, sizeof(c_full)-1);
438  pl_data++;
439  if(l%8 == 7)
440  {
441  printf("%s\n",c_full);
442  strcpy(c_full," ");
443  }
444  }
445  if(strlen(c_full) > 2)printf("%s\n",c_full);
446  strcpy(c_full," ");
447  }
448  else
449  { /* In this case we assume data as two words per channel */
450  for(l=0;l<ll;l++)
451  {
452  sprintf(c_line,"%8d%8d",*pl_data&0xffff,(*pl_data>>16)&0xffff);
453  strncat(c_full, c_line, sizeof(c_full)-1);
454  pl_data++;
455  if(l%4 == 3)
456  {
457  printf("%s\n",c_full);
458  strcpy(c_full," ");
459  }
460  }
461  if(strlen(c_full) > 2)printf("%s\n",c_full);
462  strcpy(c_full," ");
463  }
464  }
465  }
466  }
467  }
468  return(0);
469 }
470 
471 /*1+ C Main ****************+******************************************/
472 /*+ Module : f_evt_source_port */
473 /*--------------------------------------------------------------------*/
474 /*+ CALLING : f_evt_source_port(long l_port) */
475 /*--------------------------------------------------------------------*/
476 /* */
477 /*+ PURPOSE : f_evt_source_port sets port number for event source */
478 /*+ ARGUMENTS : */
479 /*+ l_port : Port number: */
480 /*+ Return type : int. */
481 /*+ Status codes: */
482 /*- GETEVT__SUCCESS : success. */
483 /*+ Declaration : */
484 /* INTS4 f_evt_source_port(INTS4); */
485 /*1- C Main ****************+******************************************/
487 {
488  l_gl_source_port=l_port;
489  if (l_port>0) printf("Use MBS source port %d\n",l_port);
490  return 0;
491 }
492 
493 
494 /*1+ C Main ****************+******************************************/
495 /*+ Module : f_evt_rev_port */
496 /*--------------------------------------------------------------------*/
497 /*+ CALLING : f_evt_rev_port(long l_port) */
498 /*--------------------------------------------------------------------*/
499 /* */
500 /*+ PURPOSE : f_evt_rev_port sets port number for event server */
501 /*+ ARGUMENTS : */
502 /*+ l_port : Port number: */
503 /*+ Return type : int. */
504 /*+ Status codes: */
505 /*- GETEVT__SUCCESS : success. */
506 /*+ Declaration : */
507 /* INTS4 f_evt_rev_port(INTS4); */
508 /*1- C Main ****************+******************************************/
510 {
511  l_gl_source_port=l_port;
512  if (l_port>0) printf("Use MBS source port %d\n",l_port);
513  return 0;
514 }
515 
516 /*1+ C Main ****************+******************************************/
517 /*+ Module : f_evt_get_open */
518 /*--------------------------------------------------------------------*/
519 /*+ CALLING : f_evt_get_open(long l_mode, char &c_server[], s_evt_channel &s_chan, */
520 /* char **ps_info, long l_sample,l_para)*/
521 /*--------------------------------------------------------------------*/
522 /* */
523 /*+ PURPOSE : f_evt_get_open opens an event stream from specified*/
524 /* channel. */
525 /*+ ARGUMENTS : */
526 /*+ l_mode : Type of server: */
527 /*- GETEVT__FILE : Input from file */
528 /*- GETEVT__STREAM : Input from MBS stream server */
529 /*- GETEVT__TRANS : Input from MBS transport */
530 /*- GETEVT__EVENT : Input from MBS event server */
531 /*- GETEVT__REVSERV: Input from remote event server */
532 /*+ c_server : Node of server or file name. */
533 /*+ s_chan : structure s_evt_channel, must be allocated. */
534 /*+ ps_info : address of pointer. If it is not NULL, then */
535 /* try to return file header or other information */
536 /* about server. If it is NULL, then returns nothing. */
537 /*+ l_sample : used by event server to send only every */
538 /* 'l_sample' event. */
539 /*+ l_para : currently not used */
540 /*+ Return type : int. */
541 /*+ Status codes: */
542 /*- GETEVT__SUCCESS : success. */
543 /*- GETEVT__NOFILE : file does not exist. */
544 /*- GETEVT__RDERR : read server error. */
545 /*- GETEVT__NOSERVER : can not connect server. */
546 /*+ Declaration : */
547 /* INTS4 f_evt_get_open( */
548 /* INTS4, CHARS *, s_evt_channel *, CHARS **, INTS4, INTS4); */
549 /*+ FUNCTION : Opens the input channel and save context in s_chan. */
550 /*+ NOTE : Up to four input channels can be opened. */
551 /*1- C Main ****************+******************************************/
552 INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan,
553  CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
554 {
555 
556  INTS4 l_swap, l_swap_head, l_is_goosybuf, l_filehead=0, l_size, l_size_head, l_dummy, l_header_size = 0, l_port;
557  CHARS c_file[256], *pc_temp;
558  s_filhe *ps_filhe;
559  INTS4 l_status;
560 
561  ps_chan->cb_polling = NULL;
562 
563  l_port = l_gl_source_port;
564 
565 #ifndef GSI__WINNT
566 // disable automatic detection of RFIO on Windows while file name can contain ":"
567  if((pc_temp=strchr(pc_server,':')) != NULL) {
568  l_mode=GETEVT__RFIO;
569  /* printf("rfio file %s\n",pc_server);*/
570  }
571 #endif
572 
573 #ifndef RFIO
574  if(l_mode == GETEVT__RFIO)
575  {
576  printf("rfio not supported!\n");
577  return(GETEVT__NOFILE);
578  }
579 #endif
580 
581  if(ps_info != NULL) *ps_info=NULL;
582  // when timeout is already set by f_evt_timeout(), do not overwrite
583  if(ps_chan->l_timeout == 0) ps_chan->l_timeout=-1; /* no timeout */
584  strcpy(ps_chan->c_channel,pc_server);
585  switch(l_mode) {
586  case GETEVT__FILE :
587  strcpy(c_file,pc_server);
588  if(strlen(c_file) < 5) strncat(c_file, ".lmd", sizeof(c_file)-1);
589  else {
590  pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
591  if((strcmp(pc_temp,".LMD") != 0) &&
592  (strcmp(pc_temp,".lmd") != 0)) strncat(c_file, ".lmd", sizeof(c_file)-1);
593  }
594 
595  if((ps_chan->l_channel_no=open(c_file,GET__OPEN_FLAG))== -1)
596  {
597  return(GETEVT__NOFILE);
598  }
599  /* read first 512 bytes */
600  if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
601  printf("LMD format error: no LMD file: %s\n",c_file);
602  close(ps_chan->l_channel_no);
603  ps_chan->l_channel_no=-1;
604  return(GETEVT__NOLMDFILE);
605  }
606 // DABC
607  ps_chan->pLmd=NULL;
608  if((*((INTS4 *)(c_temp+4)) == LMD__TYPE_FILE_HEADER_101_1)||
609  (*((INTS4 *)(c_temp+4)) == 0x65000100)){
610  close(ps_chan->l_channel_no);
611  ps_chan->pLmd=fLmdAllocateControl();
612  fLmdGetOpen(ps_chan->pLmd,c_file,NULL,LMD__BUFFER,LMD__NO_INDEX);
613  ps_chan->l_server_type=l_mode;
614  return GETEVT__SUCCESS;
615  }
616 // -- DABC
617  /* check for file header, return size and swap */
618  f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
619  if(((l_is_goosybuf == 0) & (l_filehead == 0)) | (l_size_head == 0)) {
620  printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
621  close(ps_chan->l_channel_no);
622  ps_chan->l_channel_no=-1;
623  return(GETEVT__NOLMDFILE);
624  }
625 
626  /* read file header and first buffer and check for goosy header */
627  if(l_filehead == 1) {
628  lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
629  l_header_size=l_size_head;
630  if(((s_filhe *)c_temp)->filhe_dlen > MAX__DLEN){
631  l_header_size=((s_filhe *)c_temp)->filhe_used*2+48;
632  // printf("Large buffer, read short header %d bytes\n",l_header_size);
633  }
634  if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size){
635  printf("LMD format error: no LMD file: %s\n",c_file);
636  close(ps_chan->l_channel_no);
637  ps_chan->l_channel_no=-1;
638  return(GETEVT__NOLMDFILE);
639  }
640  if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
641  close(ps_chan->l_channel_no);
642  ps_chan->l_channel_no=-1;
643  return(GETEVT__RDERR);
644  }
645  f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
646  if((l_is_goosybuf == 0) | (l_size != l_size_head) | (l_swap != l_swap_head)) {
647  printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
648  close(ps_chan->l_channel_no);
649  ps_chan->l_channel_no=-1;
650  return(GETEVT__NOLMDFILE);
651  }
652  }/* check buffer behind header */
653  ps_chan->l_buf_size=l_size_head;
654  lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
655  if(ps_info != NULL) *ps_info=NULL;
656  /* found file header */
657  if(l_filehead == 1) {
658  if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size) {
659  printf("LMD format error: no LMD file: %s\n",c_file);
660  close(ps_chan->l_channel_no);
661  ps_chan->l_channel_no=-1;
662  return(GETEVT__NOLMDFILE);
663  }
664  ps_filhe = (s_filhe *) c_temp;
665  if(ps_info != NULL) {/* if user want file header be returned */
666  if( l_swap_head == 1) f_evt_swap_filhe((s_bufhe *)ps_filhe);
667  *ps_info=c_temp; /* now , get file header and return */
668  }
669  /*
670  printf("type %d, subtype %d\n",ps_filhe->filhe_type,ps_filhe->filhe_subtype);
671  printf("strings %d %d %d %d %d %x\n",
672  ps_filhe->filhe_label_l,
673  ps_filhe->filhe_file_l,
674  ps_filhe->filhe_user_l,
675  ps_filhe->filhe_run_l,
676  ps_filhe->filhe_exp_l,
677  ps_filhe->filhe_lines);
678  pi=(INTS2 *)&ps_filhe->s_strings;
679  for(l_dummy=0;l_dummy<ps_filhe->filhe_lines;l_dummy++)
680  {
681  printf("comment %d, %s\n",*pi,(c_temp+366+l_dummy*80));
682  pi += 40;
683  }
684  */
685  } /* file header */
686 
687  /* points to a real buffer start */
688  /* and read header buffer, if there */
689  ps_chan->l_io_buf_size=ps_chan->l_buf_size;
690  /* may larger, but must multiplexed */
691  break;
692  case GETEVT__STREAM :
693 
694  if (l_port<=0) l_port = PORT__STREAM_SERV;
695 
696  /* initialize connection with stream server */
697  if(f_stc_connectserver(pc_server,l_port,&ps_chan->l_channel_no,
699  {
700  return(GETEVT__NOSERVER);
701  }
702 
703  l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
704  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
705  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
706 
707  if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
708  ps_chan->l_buf_size=*((INTS4 *)(c_temp+4)); /* buffer size */
709  ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
710  /* # buffers per stream */
711  ps_chan->l_stream_bufs = 0; /* counter */
712 
713  ps_chan->l_io_buf_size=(ps_chan->l_buf_size)*(ps_chan->l_bufs_in_stream);
714 // DABC
715  ps_chan->pLmd=NULL;
716  if(*((INTS4 *)(c_temp+12)) == 0) {
717  ps_chan->pLmd=fLmdAllocateControl();
718  ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
719  // SL: we should deliver default portnumber while it is used only to identify transport
720  fLmdInitMbs(ps_chan->pLmd,pc_server,ps_chan->l_buf_size,ps_chan->l_bufs_in_stream,0,PORT__STREAM_SERV,ps_chan->l_timeout);
721  printf("f_evt_get_open for STREAM: port=%d timeout=%d \n",l_port, ps_chan->l_timeout);
722 
723  ps_chan->l_server_type=l_mode;
724  return GETEVT__SUCCESS;
725  }
726 // -- DABC
727  break;
728  case GETEVT__TRANS :
729 
730  if (l_port<=0) l_port = PORT__TRANSPORT;
731 
732  /* initialize connection with stream server */
733  if(f_stc_connectserver(pc_server,l_port,&ps_chan->l_channel_no,
735  {
736  return(GETEVT__NOSERVER);
737  }
738 
739  l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
740  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
741  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
742 
743  if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
744  ps_chan->l_buf_size=*((INTS4 *)(c_temp+4)); /* buffer size */
745  ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
746  /* # buffers per stream */
747  ps_chan->l_io_buf_size=ps_chan->l_buf_size;
748 // DABC
749  ps_chan->pLmd=NULL;
750  if(*((INTS4 *)(c_temp+12)) == 0) {
751  ps_chan->pLmd=fLmdAllocateControl();
752  ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
753  fLmdInitMbs(ps_chan->pLmd,pc_server,ps_chan->l_buf_size,ps_chan->l_bufs_in_stream,0,PORT__TRANSPORT,ps_chan->l_timeout);
754  printf("f_evt_get_open for TRANSPORT: port=%d timeout=%d \n",l_port, ps_chan->l_timeout);
755  ps_chan->l_server_type=l_mode;
756  return GETEVT__SUCCESS;
757  }
758 // -- DABC
759  break;
760  case GETEVT__REVSERV :
761  if (l_port<=0) l_port = PORT__EVENT_SERV;
762  if(f_evcli_con(ps_chan, pc_server, l_port, -1, l_sample)!=STC__SUCCESS)
763  {
764  return(GETEVT__NOSERVER);
765  }
766  break;
767  case GETEVT__EVENT :
768  if (l_port<=0) l_port = PORT__EVENT_SERV;
769  if(f_evcli_con(ps_chan, pc_server, l_port, -1, l_sample)!=STC__SUCCESS)
770  {
771  return(GETEVT__NOSERVER);
772  }
773  break;
774  case GETEVT__RFIO :
775  ps_chan->l_channel_no=-1;
776  ps_chan->l_channel_no=RFIO_open(pc_server,GET__OPEN_FLAG,0);
777  if(ps_chan->l_channel_no < 0) return(GETEVT__NOSERVER);
778  /* read first 512 bytes */
780  {
781  printf("LMD format error: no LMD file: %s\n",pc_server);
782  RFIO_close(ps_chan->l_channel_no);
783  ps_chan->l_channel_no=-1;
784  return(GETEVT__NOLMDFILE);
785  }
786  /* check for file header, return size and swap */
787  f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
788  if(((l_is_goosybuf == 0) & (l_filehead == 0)) | (l_size_head == 0))
789  {
790  printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
791  RFIO_close(ps_chan->l_channel_no);
792  ps_chan->l_channel_no=-1;
793  return(GETEVT__NOLMDFILE);
794  }
795  /* read file header and first buffer and check for goosy header */
796  if(l_filehead == 1)
797  {
798  RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
799  if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
800  {
801  printf("LMD format error: no LMD file: %s\n",pc_server);
802  RFIO_close(ps_chan->l_channel_no);
803  ps_chan->l_channel_no=-1;
804  return(GETEVT__NOLMDFILE);
805  }
807  {
808  RFIO_close(ps_chan->l_channel_no);
809  ps_chan->l_channel_no=-1;
810  return(GETEVT__RDERR);
811  }
812  f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
813  if((l_is_goosybuf == 0) | (l_size != l_size_head) | (l_swap != l_swap_head))
814  {
815  printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
816  RFIO_close(ps_chan->l_channel_no);
817  ps_chan->l_channel_no=-1;
818  return(GETEVT__NOLMDFILE);
819  }
820  }/* check buffer behind header */
821  ps_chan->l_buf_size=l_size_head;
822  RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
823  if(ps_info != NULL)*ps_info=NULL;
824  /* found file header */
825  if(l_filehead == 1)
826  {
827  if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
828  {
829  printf("LMD format error: no LMD file: %s\n",pc_server);
830  RFIO_close(ps_chan->l_channel_no);
831  ps_chan->l_channel_no=-1;
832  return(GETEVT__NOLMDFILE);
833  }
834  ps_filhe=(s_filhe *)c_temp;
835  if(ps_info != NULL) /* if user want file header be returned */
836  {
837  if( l_swap_head == 1) f_evt_swap_filhe((s_bufhe *)ps_filhe);
838  *ps_info=c_temp; /* now , get file header and return */
839  }
840  /*
841  printf("type %d, subtype %d\n",ps_filhe->filhe_type,ps_filhe->filhe_subtype);
842  printf("strings %d %d %d %d %d %x\n",
843  ps_filhe->filhe_label_l,
844  ps_filhe->filhe_file_l,
845  ps_filhe->filhe_user_l,
846  ps_filhe->filhe_run_l,
847  ps_filhe->filhe_exp_l,
848  ps_filhe->filhe_lines);
849  pi=(INTS2 *)&ps_filhe->s_strings;
850  for(l_dummy=0;l_dummy<ps_filhe->filhe_lines;l_dummy++)
851  {
852  printf("comment %d, %s\n",*pi,(c_temp+366+l_dummy*80));
853  pi += 40;
854  }
855  */
856  }/* file header */
857  ps_chan->l_io_buf_size=ps_chan->l_buf_size;
858  break;
859  default :
860  if(ps_info != NULL) *ps_info=NULL;
861  return(GETEVT__NOSERVER);
862  } /* end of switch */
863 
864  if((l_mode != GETEVT__EVENT)&(l_mode != GETEVT__REVSERV))
865  {
866  if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
867  {
868  printf("Memory allocation error\n");
869  exit(2);
870  }
871  ps_chan->l_evt_buf_size=ps_chan->l_io_buf_size;
872  if( (ps_chan->pc_evt_buf=malloc(ps_chan->l_evt_buf_size))==NULL)
873  {
874  printf("Memory allocation error\n");
875  exit(2);
876  }
877  } /* l_mode != GETEVT__EVENT */
878  ps_chan->l_server_type=l_mode;
879  ps_chan->l_first_get=1; /* so we will first call f_getvet_get */
880  return GETEVT__SUCCESS;
881 } /* end of f_evt_get_open */
882 
883 /*1+ C Main ****************+******************************************/
884 /*+ Module : f_evt_get_event */
885 /*--------------------------------------------------------------------*/
886 /*+ CALLING : f_evt_get_event(s_evt_channel &s_chan, long **ppl_buffer, long **ppl_goobuf) */
887 /*--------------------------------------------------------------------*/
888 /* */
889 /*+ PURPOSE : f_evt_get_event returnes address of event */
890 /*+ ARGUMENTS : */
891 /*+ s_chan : Input channel from open. */
892 /*+ ppl_buffer: Address of pointer. Returns address of event. */
893 /*+ ppl_goobuf: Address of pointer. Returns address of buffer. */
894 /*+ Return type : int. */
895 /*+ Status codes: */
896 /*- GETEVT__SUCCESS : success. */
897 /*- GETEVT__FRAGMENT : Event fragment found. */
898 /*- GETEVT__NOMORE : No more events. */
899 /*- GETEVT__RDERR : read server or file error */
900 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
901 /*+ Declaration : */
902 /* INTS4 f_evt_get_event( */
903 /* s_evt_channel *, INTS4 **, INTS4 **); */
904 /*+ FUNCTION : Get next event and returnes pointer. The pointer */
905 /* may point to the event in the buffer or internal */
906 /* event buffer (spanned events). The content of the */
907 /* pointer may be destroyed by next call. */
908 /*1- C Main ****************+******************************************/
909 INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
910 {
911  INTS4 l_temp,l_prev_ok = 1, l_stat = 0, l_used;
912  s_bufhe *ps_bufhe_cur = NULL;
913  sMbsHeader *pevt = NULL;
914 
915 // DABC
916 
917  if(ps_chan->pLmd != NULL) {
918  if(ps_chan->l_server_type == GETEVT__TRANS) {
919  l_stat = fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
920  } else if(ps_chan->l_server_type == GETEVT__STREAM) {
921  l_stat = fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
922  } else if(ps_chan->l_server_type == GETEVT__FILE) {
923  l_stat = fLmdGetElement(ps_chan->pLmd,LMD__NO_INDEX, &pevt);
924  }
925 
926  // any error, then pointer is null
927  if(pevt==NULL) {
928  if (ps_chan->l_server_type == GETEVT__FILE){
929  if(l_stat == GETLMD__NOMORE) return GETEVT__NOMORE;
930  if(l_stat == GETLMD__EOFILE) return GETEVT__NOMORE;
931  if(l_stat == GETLMD__NOBUFFER) return GETEVT__FAILURE;
932  return GETEVT__RDERR;
933  } else {
934  if(l_stat == LMD__TIMEOUT) return GETEVT__TIMEOUT;
935  return GETEVT__RDERR;
936  }
937  }
938  // OK
939  if(ppl_goobuf)*ppl_goobuf = NULL;
940  *ppl_buffer = (INTS4 *)pevt;
941  return(GETEVT__SUCCESS);
942  }
943 // -- DABC
944 
945  if((ps_chan->l_server_type == GETEVT__EVENT)|(ps_chan->l_server_type == GETEVT__REVSERV))
946  {
947  *ppl_goobuf = NULL;
948  if(f_evcli_evt(ps_chan) != STC__SUCCESS) /* no more event, get new buffer */
949  {
950  l_stat = f_evcli_buf(ps_chan);
951  if(l_stat == STC__TIMEOUT) return(GETEVT__TIMEOUT);
952  if(l_stat != STC__SUCCESS) return(GETEVT__FAILURE);
953  }
954  *ppl_buffer = (INTS4 *) ps_chan->pc_evt_buf;
955  return(GETEVT__SUCCESS);
956  }
957 
958  /* e.g. read_buffer is 16384, GOOSY buffer may be only 2048, *
959  * this ps_chan->l_io_buf_posi indicats when the read_buffer is finished */
960 
961  if(ps_chan->l_first_get==1)
962  {
963  ps_chan->l_buf_posi=0; /* goosy buffer position */
964  ps_chan->l_buf_lmt=0; /* end of this goosy buffer */
965  ps_chan->l_io_buf_posi=MAX_LONG; /* Iuput buffer(for read file) position */
966  ps_chan->l_first_buf=1; /* boolean */
967  ps_chan->l_first_get=0; /* boolean */
968  }
969  /* why we need this part codes? beacause we may (open, get, close) *
970  * and (open, get, close) again!!! Especially when we use m-histo *
971  * so the second or later (open,get,close) should reset these *
972  * static value */
973 
974  ps_chan->l_evt_buf_posi=0;
975 /* above, internal event buffer position, internal buffer will be returned */
976 
977  while(1)
978  {
979  /* if previous goosy buffer has finished, read a new buffer from i/o buffer,
980  or from file if i/o buffer is all readout */
981  while (ps_chan->l_buf_posi >= ps_chan->l_buf_lmt)
982  {
983  /* if this i/o buffer is read to end */
984  /* end of this read_buffer which may contain several GOOSY buffers*/
985  if(ps_chan->l_io_buf_posi>=ps_chan->l_io_buf_size)
986  {
987  if((l_temp=f_evt_get_newbuf(ps_chan))!=GETEVT__SUCCESS) return(l_temp);
988  ps_chan->l_io_buf_posi=0;
989  } /* end of real read server */
990  ps_chan->ps_bufhe = (s_bufhe*) (ps_chan->pc_io_buf+ps_chan->l_io_buf_posi);
991  l_prev_ok = (ps_chan->l_buf_no == (ps_chan->ps_bufhe->l_buf-1)) ? 1 : 0;
992  ps_chan->l_buf_no = ps_chan->ps_bufhe->l_buf;
993  if(ps_chan->ps_bufhe->i_type == 2000) { /* file header */
994  printf("Unsolicited file header found!\n");
995  ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
996  ps_chan->l_buf_posi = ps_chan->l_io_buf_posi;
997  ps_chan->l_buf_lmt = ps_chan->l_io_buf_posi;
998  } else {
999  l_used=ps_chan->ps_bufhe->l_free[2]; // large buffers HE, Oct 2007
1000  if(ps_chan->ps_bufhe->l_dlen <= MAX__DLEN)l_used=ps_chan->ps_bufhe->i_used;
1001  ps_chan->l_buf_posi = ps_chan->l_io_buf_posi + sizeof(s_bufhe);
1002  ps_chan->l_buf_lmt = ps_chan->l_buf_posi + l_used*2;
1003  ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
1004  }
1005  } /* end of read file while loop */
1006 
1007  /* now, ps_chan->l_buf_posi points to start of an event or spanned event */
1008  ps_chan->ps_ve10_1 = (s_ve10_1 *) (ps_chan->pc_io_buf + ps_chan->l_buf_posi);
1009  if( (ps_chan->l_evt_buf_posi != 0) || ((ps_chan->ps_bufhe->h_end==1) && (ps_chan->l_first_buf==1)) ) { /* if this is a spanned part of an event */
1010  ps_chan->l_buf_posi += sizeof(s_evhe);
1011  ps_chan->l_frag_len = ps_chan->ps_ve10_1->l_dlen*2;
1012  } else /* if this is a real start of an event */
1013  ps_chan->l_frag_len = (ps_chan->ps_ve10_1->l_dlen-4)*2 + sizeof(s_ve10_1);
1014 
1015  if(ps_chan->l_frag_len + ps_chan->l_buf_posi > ps_chan->l_buf_lmt)
1016  {
1017  return(GETEVT__FRAGMENT);
1018  }
1019 
1020  /* if ps_chan->l_buf_posi is not start of an event and ps_chan->l_first_buf =1 *
1021  * then skip to next event */
1022  if((ps_chan->ps_bufhe->h_end==1)&&((ps_chan->l_first_buf==1) || (l_prev_ok == 0))) {
1023  /* if the first buffer is spanned at begin, then skip */
1024  ps_chan->l_first_buf=0; /* 24-Apr-1996 */
1025  l_prev_ok=1; /* 2001 HE */
1026  ps_chan->l_evt_buf_posi=0; /* 2001 HE stuff in event buffer obsolete */
1027  ps_chan->l_buf_posi += ps_chan->l_frag_len;
1028  /* now,ps_chan->l_buf_posi points to start of an event or spanned event */
1029  continue; /* continue "while" loop */
1030  }
1031 
1032  ps_chan->l_first_buf=0;
1033 
1034  /* if ps_chan->l_buf_posi is start of an event and the event is not *
1035  * spanned, then return pointer */
1036  if( (ps_chan->l_evt_buf_posi == 0) &&
1037  ( (ps_chan->ps_bufhe->h_begin == 0) || ((ps_chan->l_buf_posi+ps_chan->l_frag_len) < ps_chan->l_buf_lmt) ) )
1038  {
1039  *ppl_buffer = (INTS4 *)(ps_chan->pc_io_buf+ps_chan->l_buf_posi);
1040  ps_chan->l_buf_posi += ps_chan->l_frag_len;
1041  ps_chan->l_evt_buf_posi = 0;
1042  if(ppl_goobuf) *ppl_goobuf = (INTS4 *) (ps_chan->ps_bufhe);
1043  return(GETEVT__SUCCESS);
1044  }
1045 
1046  /* 2001 HE if we start a spanned event, save buffer header of first buffer */
1047  if(ps_chan->l_evt_buf_posi == 0)
1048  {
1049  memcpy((CHARS *)&ps_chan->s_bufhe_1,(CHARS *)ps_chan->ps_bufhe,sizeof(s_bufhe));
1050  ps_bufhe_cur=(s_bufhe *)&ps_chan->s_bufhe_1;
1051  }
1052  /* copy the part of this event which in this buffer into *
1053  * internal buffer, data will be moved by realloc function */
1054  if(ps_chan->l_evt_buf_size<ps_chan->l_evt_buf_posi+ps_chan->l_frag_len)
1055  {
1056  ps_chan->l_evt_buf_size=ps_chan->l_evt_buf_posi+ps_chan->l_frag_len;
1057  if( (ps_chan->pc_evt_buf=realloc
1058  (ps_chan->pc_evt_buf, ps_chan->l_evt_buf_size))==NULL)
1059  {
1060  printf("Memory allocation error\n");
1061  exit(2);
1062  }
1063  }
1064  memcpy(ps_chan->pc_evt_buf+ps_chan->l_evt_buf_posi,ps_chan->pc_io_buf+ps_chan->l_buf_posi,
1065  ps_chan->l_frag_len);
1066  ps_chan->l_buf_posi += ps_chan->l_frag_len;
1067  if(ps_chan->l_evt_buf_posi == 0)
1068  {
1069  }
1070  ps_chan->l_evt_buf_posi += ps_chan->l_frag_len;
1071 
1072  if((ps_chan->ps_bufhe->h_begin!=1)||(ps_chan->l_buf_posi<ps_chan->l_buf_lmt))
1073  {
1074  /* change event header's l_dlen */
1075  ((s_ve10_1 *)(ps_chan->pc_evt_buf))->l_dlen=ps_chan->l_evt_buf_posi/2-4;
1076  *ppl_buffer=(INTS4 *)(ps_chan->pc_evt_buf);
1077  if(ppl_goobuf)*ppl_goobuf=(INTS4 *)(ps_bufhe_cur);
1078  return(GETEVT__SUCCESS);
1079  }
1080  }/* if this event spanned to next buffer, then loop */
1081 } /* end of f_evt_get_event */
1082 
1083 /*1+ C Main ******************+****************************************/
1084 /*+ Module : f_evt_get_close */
1085 /*--------------------------------------------------------------------*/
1086 /*+ CALLING : f_evt_get_close( s_evt_channel &s_chan) */
1087 /*--------------------------------------------------------------------*/
1088 /* */
1089 /*+ PURPOSE : f_evt_get_close closes event stream of specified */
1090 /* channel. */
1091 /*+ ARGUMENTS : */
1092 /*+ s_chan : Input channel from open. */
1093 /*+ Return type : int. */
1094 /*+ Status codes: */
1095 /*- GETEVT__SUCCESS : success. */
1096 /*- GETEVT__CLOSE_ERR : close server or file error */
1097 /*+ Declaration : */
1098 /* INTS4 f_evt_get_close(s_evt_channel *); */
1099 /*+ FUNCTION : Closes the specified input channel. */
1100 /*1- C Main ******************+****************************************/
1102 {
1103  INTS4 l_close_failure;
1104 
1105 // DABC
1106  if(ps_chan->pLmd != NULL){
1107  if(ps_chan->l_server_type == GETEVT__TRANS)fLmdCloseMbs(ps_chan->pLmd);
1108  else if(ps_chan->l_server_type == GETEVT__STREAM)fLmdCloseMbs(ps_chan->pLmd);
1109  else if(ps_chan->l_server_type == GETEVT__FILE) fLmdGetClose(ps_chan->pLmd);
1110  free(ps_chan->pLmd);
1111  ps_chan->pLmd=NULL;
1112  return GETEVT__SUCCESS;
1113  }
1114 // -- DABC
1115  l_close_failure=0;
1116  if(ps_chan->l_channel_no >= 0)
1117  {
1118  switch(ps_chan->l_server_type)
1119  {
1120  case GETEVT__FILE :
1121  if(close(ps_chan->l_channel_no)==-1) l_close_failure=1;
1122  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1123  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1124  break;
1125  case GETEVT__STREAM :
1126  /* disconnect with stream server */
1127  f_stc_write("CLOSE", 12, ps_chan->l_channel_no);
1128  if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
1129  if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
1130  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1131  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1132  break;
1133  case GETEVT__TRANS :
1134  /* disconnect with stream server */
1135  if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
1136  if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
1137  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1138  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1139  break;
1140  case GETEVT__REVSERV :
1141  case GETEVT__EVENT :
1142  if(f_evcli_close(ps_chan)!=STC__SUCCESS) l_close_failure=1;
1143  break;
1144  case GETEVT__RFIO :
1145  RFIO_close(ps_chan->l_channel_no);
1146  ps_chan->l_channel_no=-1;
1147  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1148  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1149  break;
1150  default :
1151  l_close_failure=1;
1152  } /* end of switch */
1153  ps_chan->pc_io_buf=NULL;
1154  ps_chan->l_channel_no=-1;
1155  if(l_close_failure==1) return(GETEVT__CLOSE_ERR);
1156  return GETEVT__SUCCESS;
1157  }
1158 return GETEVT__SUCCESS;
1159 
1160 } /* end of f_evt_get_close */
1161 
1162 
1163 /*1+ C Main ****************+******************************************/
1164 /*+ Module : f_evt_put_open */
1165 /*--------------------------------------------------------------------*/
1166 /*+ CALLING : f_evt_put_open(char *c_file[], long l_size, long l_stream, long l_type, */
1167 /* long l_subtype, s_evt_channel *ps_chan, char *ps_filhe) */
1168 /*--------------------------------------------------------------------*/
1169 /* */
1170 /*+ PURPOSE : f_evt_put_open opens an event output stream. */
1171 /*+ ARGUMENTS : */
1172 /*+ c_file : Name of file. */
1173 /*+ l_size : Size of output buffers in bytes. */
1174 /*+ l_stream : Number of buffers with spanning events. */
1175 /*+ l_type : Buffer type number */
1176 /*+ l_subtype : Buffer subtype number */
1177 /*+ ps_chan : Address of channel structure which will be returned.*/
1178 /*+ ps_filhe : Address of user specified file header */
1179 /*+ Return type : int. */
1180 /*+ Status codes: */
1181 /*- PUTEVT__SUCCESS : success. */
1182 /*- PUTEVT__FILE_EXIST: file already exists. */
1183 /*- PUTEVT__FAILURE : failure. */
1184 /*+ Declaration : */
1185 /* INTS4 f_evt_put_open( */
1186 /* CHARS *,INTS4,INTS4,INTS4,INTS4,s_evt_channel *,CHARS *); */
1187 /*+ FUNCTION : Opens the output channel and save context in */
1188 /* s_evt_channel structure. */
1189 /*+ NOTE : Up to four output channels can be opened. */
1190 /* User Example : In m_lea_user.c */
1191 /*1- C Main ****************+******************************************/
1192 INTS4 f_evt_put_open(CHARS *pc_file, INTS4 l_size, INTS4 l_stream,
1193  INTS4 l_type, INTS4 l_subtype, s_evt_channel *ps_chan, CHARS *ps_filhe)
1194 {
1195  s_filhe *ps_file_head;
1196  INTS4 l_write_size;
1197  INTS4 l_status;
1198  time_t s_timet;
1199  struct timespec s_timespec;
1200  CHARS c_mode[80];
1201  CHARS c_file[256], *pc_temp;
1202 
1203 // DABC
1204  ps_chan->pLmd=NULL;
1205  if(l_stream == 0) {
1206  ps_chan->pLmd=fLmdAllocateControl();
1207  l_status=fLmdPutOpen(ps_chan->pLmd,pc_file,NULL,l_size,
1209  return(l_status);
1210  }
1211 // -- DABC
1212 
1213  ps_chan->l_first_put=1;
1214 
1215  ps_chan->l_buf_size=l_size;
1216  ps_chan->l_bufs_in_stream=l_stream;
1217  ps_chan->l_buf_type=l_type;
1218  ps_chan->l_buf_subtype=l_subtype;
1219  ps_chan->l_io_buf_size=ps_chan->l_buf_size * ps_chan->l_bufs_in_stream;
1220  if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
1221  {
1222  printf("Memory allocation error\n");
1223  exit(2);
1224  }
1225 
1226  strcpy(c_file,pc_file);
1227  if(strlen(c_file) < 5) strncat(c_file,".lmd", sizeof(c_file)-1);
1228  else
1229  {
1230  pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
1231  if((strcmp(pc_temp,".LMD") != 0) &&
1232  (strcmp(pc_temp,".lmd") != 0)) strncat(c_file, ".lmd", sizeof(c_file)-1);
1233  }
1234  if((ps_chan->l_channel_no=open(c_file,PUT__OPEN_APD_FLAG) )!= -1) {
1235  return(PUTEVT__FILE_EXIST);
1236  } else
1237  {
1238  if((ps_chan->l_channel_no=open(c_file,PUT__CRT_FLAG,
1239  DEF_FILE_ACCE) )== -1)
1240  return(PUTEVT__FAILURE);
1241  /* open OK */
1242  else
1243  {
1244  /* output file header */
1245  ps_file_head=(s_filhe *)ps_chan->pc_io_buf;
1246  /* if user specify file header */
1247  if(ps_filhe != NULL) {
1248  memcpy(ps_file_head, ps_filhe,ps_chan->l_buf_size );
1249  } else {
1250  memset( ps_file_head, 0, ps_chan->l_buf_size);
1251  snprintf(ps_file_head->filhe_run, sizeof(ps_file_head->filhe_run), "Pid %d%c", own_getpid(),'\0');
1252  ps_file_head->filhe_run_l = (INTS2) strlen(ps_file_head->filhe_run);
1253  }
1254  ps_file_head->filhe_dlen=ps_chan->l_buf_size/2;
1255  ps_file_head->filhe_subtype=1;
1256  ps_file_head->filhe_type=2000;
1257  clock_gettime(CLOCK_REALTIME, &s_timespec);
1258  ps_file_head->filhe_stime[0] = (INTS4) s_timespec.tv_sec;
1259  ps_file_head->filhe_stime[1] = (INTS4) s_timespec.tv_nsec/1000000;
1260  ps_file_head->filhe_free[0] = 1;
1261  ps_file_head->filhe_file_l = (INTS2) strlen(c_file);/* not include \0 */
1262  strncpy(ps_file_head->filhe_file, c_file, sizeof(ps_file_head->filhe_file));
1263  strncpy(ps_file_head->filhe_user, getenv("USER"), sizeof(ps_file_head->filhe_user)); /* user name */
1264  ps_file_head->filhe_user_l = (INTS2) strlen(ps_file_head->filhe_user);
1265  time(&s_timet);/* get calendar time */
1266  strncpy(c_mode, ctime(&s_timet), sizeof(c_mode));
1267  strncpy(ps_file_head->filhe_time, &c_mode[4], sizeof(ps_file_head->filhe_time));
1268  ps_file_head->filhe_time[20]=' ';
1269  l_write_size=write(ps_chan->l_channel_no,(CHARS *)ps_file_head,
1270  ps_chan->l_buf_size);
1271  if(l_write_size==-1)
1272  {
1273  return(PUTEVT__WRERR);
1274  }
1275  if(l_write_size!=ps_chan->l_buf_size)
1276  {
1277  return(PUTEVT__TOOBIG);
1278  }
1279  return(PUTEVT__SUCCESS);
1280  }
1281  }
1282 } /* end of f_evt_put_open */
1283 
1284 /*1+ C Main ****************+******************************************/
1285 /*+ Module : f_evt_put_event */
1286 /*--------------------------------------------------------------------*/
1287 /*+ CALLING : f_evt_put_event(s_evt_channel *ps_chan, long &la_evt_buf[]) */
1288 /*--------------------------------------------------------------------*/
1289 /* */
1290 /*+ PURPOSE : f_evt_put_event outputs event */
1291 /*+ ARGUMENTS : */
1292 /*+ ps_chan : Address of channel structure as returned from */
1293 /* f_evt_put_open. */
1294 /*+ la_evt_buf : event data array. Standard GSI event structure. */
1295 /*+ Return type : int. */
1296 /*+ Status codes: */
1297 /*- PUTEVT__SUCCESS : success. */
1298 /*- PUTEVT__WRERR : read server or file error */
1299 /*+ Declaration : */
1300 /* INTS4 f_evt_put_event(s_evt_channel *, INTS4 *); */
1301 /*+ FUNCTION : Copies current event into output buffer. Writes */
1302 /* buffer to file, when full. */
1303 /*1- C Main ****************+******************************************/
1304 
1306 {
1307  INTS4 l_evt_buf_posi;
1308  INTS4 l_buf_remain_size; /* net free space of I/O buffer */
1309  INTS4 l_write_size, l_temp, l_free;
1310  INTS4 l_status;
1311  CHARS *pc_addr;
1312  s_bufhe *ps_bufhe;
1313 
1314 // DABC
1315  if(ps_chan->pLmd != NULL){
1316  l_status=fLmdPutElement(ps_chan->pLmd,(sMbsHeader *)pl_evt_buf);
1317  return(l_status);
1318  }
1319 // -- DABC
1320  if(ps_chan->l_first_put==1)
1321  {
1322  ps_chan->l_first_put=0;
1323  ps_chan->l_io_buf_posi=0;
1324  ps_chan->l_buf_no=1;
1325  }
1326  l_evt_buf_posi=0;
1327  ps_chan->l_evt_size=( ((s_ve10_1 *)(pl_evt_buf))->l_dlen)*2 + sizeof(s_evhe);
1328 
1329  /* get l_buf_remain_size is available size in stream */
1330  l_buf_remain_size = ps_chan->l_io_buf_size - ps_chan->l_io_buf_posi;
1331  l_temp = (l_buf_remain_size / ps_chan->l_buf_size)*(sizeof(s_bufhe)+sizeof(s_evhe) );
1332  l_buf_remain_size -= l_temp;/* minus space occupied by buffer header and spanned event header */
1333 
1334  if(ps_chan->l_evt_size>l_buf_remain_size)/* output this i/o buffer */
1335  {
1336  memset(ps_chan->pc_io_buf+ps_chan->l_io_buf_posi, 0, ps_chan->l_io_buf_size-ps_chan->l_io_buf_posi);
1337  /* clear rest of this GOOSY buffer */
1338  l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1339  if(ps_chan->l_io_buf_posi%ps_chan->l_buf_size == 0) l_temp -= ps_chan->l_buf_size;
1340  /* l_temp points to start of last GOOSY buf in i/o buf area */
1341  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
1342  if(l_temp == 0)ps_chan->ps_bufhe->h_end = 0; /* first buf in stream, no end */
1343  else ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
1344  ps_chan->ps_bufhe->h_begin = 0; /* evt has end, so not spanned to next buf */
1345  for(l_temp=0;l_temp<ps_chan->l_io_buf_size;l_temp+=ps_chan->l_buf_size)
1346  {
1347  pc_addr = ps_chan->pc_io_buf+l_temp;
1348  ps_bufhe=(s_bufhe *)pc_addr;
1349  if(ps_bufhe->l_evt>0)/* do not write empty buffers */
1350  {
1351  l_write_size=write(ps_chan->l_channel_no, pc_addr,ps_chan->l_buf_size);
1352  if(l_write_size==-1) return(PUTEVT__WRERR);
1353  if(l_write_size!=ps_chan->l_buf_size) return(PUTEVT__TOOBIG);
1354  }
1355  else ps_chan->l_buf_no--; /* decrement buffer number for not written buffer */
1356  } /* buffer output loop */
1357  ps_chan->l_io_buf_posi=0;
1358  ps_chan->ps_bufhe=(s_bufhe *)ps_chan->pc_io_buf;
1359  /* get l_buf_remain_size of new stream */
1360  l_buf_remain_size = ps_chan->l_io_buf_size;
1361  l_temp = (l_buf_remain_size / ps_chan->l_buf_size) * (sizeof(s_bufhe)+sizeof(s_evhe) );
1362  l_buf_remain_size -= l_temp; /* minus space occupied by buf header and spanned event header */
1363  l_buf_remain_size += sizeof(s_evhe);/* 1st buf always no span */
1364  /* if event can not fit in a new stream, then error */
1365  if(ps_chan->l_evt_size>l_buf_remain_size) return(PUTEVT__TOO_SMALLS);
1366  }
1367 
1368  if(ps_chan->l_io_buf_posi == 0)f_evt_ini_bufhe(ps_chan);/* init all buffer headers */
1369 
1370  /* write event into i/o buf till end of event, change ps_chan->l_io_buf_posi */
1371  while(l_evt_buf_posi<ps_chan->l_evt_size)
1372  {
1373  ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);
1374  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size) == 0)
1375  {
1376  ps_chan->l_io_buf_posi += sizeof(s_bufhe);
1377  ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);/* behind header */
1378  if(l_evt_buf_posi != 0)
1379  {
1380  ps_chan->l_io_buf_posi += sizeof(s_evhe); /* behind element header */
1381  l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1382  /* l_write_size points to start of this GOOSY buf in i/o buf area */
1383  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
1384  ps_chan->ps_bufhe->i_used += sizeof(s_evhe)/2;
1385  }
1386  }
1387  l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1388  /* l_write_size points to start of this GOOSY buf in i/o buf area */
1389  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
1390  l_write_size = l_write_size + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
1391  /* l_write_size is remain free space in this GOOSY buf */
1392  if(l_write_size>(ps_chan->l_evt_size-l_evt_buf_posi))
1393  l_write_size=(ps_chan->l_evt_size-l_evt_buf_posi);
1394  memcpy(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi, (CHARS *)pl_evt_buf + l_evt_buf_posi, l_write_size);
1395  ps_chan->ps_bufhe->l_evt ++; /* number of fragments */
1396  ps_chan->l_io_buf_posi += l_write_size;
1397  l_evt_buf_posi += l_write_size;
1398  ps_chan->ps_bufhe->i_used += l_write_size/2;
1399  /* if the remain free space of GOOSY buffer does not large enough *
1400  * to hold even a event header, then turn to next GOOSY buffer and *
1401  * fill buffer header. or 8 long words aligned ???????? */
1402  l_free=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1403  /* l_free points to start of this GOOSY buf in i/o buf area */
1404  l_free = l_free + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
1405  if(l_free==ps_chan->l_buf_size)l_free=0;
1406  /* l_free is remain free space in this GOOSY buf */
1407  if(l_free<sizeof(s_ve10_1))ps_chan->l_io_buf_posi += l_free;
1408  /* change spanned evt header l_dlen */
1409  if(l_evt_buf_posi!=l_write_size)
1410  {
1411  ps_chan->ps_ve10_1->l_dlen= l_write_size/2;
1412  ps_chan->ps_ve10_1->i_subtype = ps_chan->l_buf_subtype;
1413  ps_chan->ps_ve10_1->i_type = ps_chan->l_buf_type;
1414  }
1415  else ps_chan->ps_ve10_1->l_dlen= (l_write_size-sizeof(s_evhe))/2; /* header of first frag */
1416  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size) == 0)
1417  {
1418  if(l_evt_buf_posi<ps_chan->l_evt_size) ps_chan->ps_bufhe->h_begin = 1;
1419  if(ps_chan->l_io_buf_posi > ps_chan->l_buf_size) /* so first buf in stream */
1420  ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
1421  ps_chan->ps_bufhe->l_free[1] = ((s_ve10_1 *)(pl_evt_buf))->l_dlen; /* lgth of last event in buf */
1422  } /* end of processs prev buffer head and ... */
1423 
1424  } /* end of write event into i/o buf till end of event */
1425  return(PUTEVT__SUCCESS);
1426 } /* end of f_evt_put_event */
1427 
1428 /*1+ C Main ****************+******************************************/
1429 /*+ Module : f_evt_put_buffer */
1430 /*--------------------------------------------------------------------*/
1431 /*+ CALLING : f_evt_put_buffer(s_evt_channel *ps_chan, s_bufhe *ps_bufhe) */
1432 /*--------------------------------------------------------------------*/
1433 /* */
1434 /*+ PURPOSE : f_evt_put_buffer outputs buffer */
1435 /*+ ARGUMENTS : */
1436 /*+ ps_chan : Address of channel structure as returned from */
1437 /* f_evt_put_open. */
1438 /*+ ps_bufhe : Buffer. */
1439 /*+ Return type : int. */
1440 /*+ Status codes: */
1441 /*- PUTEVT__SUCCESS : success. */
1442 /*- PUTEVT__WRERR : read server or file error */
1443 /*+ Declaration : */
1444 /* INTS4 f_evt_put_buffer(s_evt_channel *, s_bufhe *); */
1445 /*+ FUNCTION : Writes buffer to file. */
1446 /*1- C Main ****************+******************************************/
1447 
1449 {
1450  INTS4 l_write_size;
1451  INTS4 l_status;
1452 
1453 // DABC
1454  if(ps_chan->pLmd != NULL){
1455  l_status=fLmdPutBuffer(ps_chan->pLmd,(sMbsHeader *)(ps_bufhe+1),ps_bufhe->l_evt);
1456  return(l_status);
1457  }
1458 // -- DABC
1459  ps_chan->l_io_buf_posi = ps_chan->l_buf_size;
1460  ps_chan->l_io_buf_size = ps_chan->l_buf_size;
1461  l_write_size=write(ps_chan->l_channel_no, (CHARS *) ps_bufhe, ps_chan->l_buf_size);
1462  if(l_write_size==-1)
1463  {
1464  return(PUTEVT__WRERR);
1465  }
1466  if(l_write_size!=ps_chan->l_buf_size)
1467  {
1468  return(PUTEVT__TOOBIG);
1469  }
1470  return PUTEVT__SUCCESS;
1471 } /* end of f_evt_put_buffer */
1472 
1473 /*1+ C Main ****************+******************************************/
1474 /*+ Module : f_evt_put_close */
1475 /*--------------------------------------------------------------------*/
1476 /*+ CALLING : f_evt_put_close(s_evt_channel *ps_chan) */
1477 /*--------------------------------------------------------------------*/
1478 /* */
1479 /*+ PURPOSE : f_evt_put_close closes specified channel. */
1480 /*+ ARGUMENTS : */
1481 /*+ channel : Channel number. */
1482 /*+ Return type : int. */
1483 /*+ Status codes: */
1484 /*- PUTEVT__SUCCESS : success. */
1485 /*- PUTEVT__FAILURE : failure. */
1486 /*- PUTEVT__CLOSE_ERR : close server or file error */
1487 /*+ Declaration : */
1488 /* INTS4 f_evt_put_close(s_evt_channel *); */
1489 /*+ FUNCTION : Closes the specified output channel after writing */
1490 /* last buffer. */
1491 /*1- C Main ****************+******************************************/
1492 
1494 {
1495  INTS4 l_write_size, l_temp, l_temp2;
1496  INTS4 l_status;
1497 
1498 // DABC
1499  if(ps_chan->pLmd != NULL){
1500  l_status=fLmdPutClose(ps_chan->pLmd);
1501  return(l_status);
1502  }
1503 // -- DABC
1504  if(ps_chan->l_first_put==1) goto g_close;
1505 
1506  /* if not the end of GOOSY buf, fill buffer header */
1507  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size) != 0)
1508  {
1509  l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1510  /* l_temp points to start of this GOOSY buf in i/o buf area */
1511  memset(ps_chan->pc_io_buf+ps_chan->l_io_buf_posi, 0,
1512  l_temp+ps_chan->l_buf_size-ps_chan->l_io_buf_posi);
1513  /* clear rest of this GOOSY buffer */
1514  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
1515 
1516  ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
1517  ps_chan->ps_bufhe->h_begin = 0; /* evt has end, so not spanned to next buf */
1518  if(l_temp == 0) /* so fisrt buf in stream */
1519  ps_chan->ps_bufhe->h_end = 0;
1520  else
1521  ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))
1522  ->h_begin;
1523  ps_chan->ps_bufhe->i_used = (ps_chan->l_io_buf_posi%ps_chan->l_buf_size -
1524  sizeof(s_bufhe))/2;
1525  } /* end of process of infilished buffer header */
1526 
1527  /* if at the end of io buf, need not flush */
1528  if(ps_chan->l_io_buf_posi!=ps_chan->l_io_buf_size)
1529  {
1530  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size) != 0)
1531  l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size+1) *
1532  ps_chan->l_buf_size;
1533  else
1534  l_write_size=ps_chan->l_io_buf_posi;
1535 
1536  for(l_temp=0;l_temp<l_write_size;l_temp+=ps_chan->l_buf_size){
1537 /* why use this loop instead of write the whole io_buf out? because in
1538  VMS side, the record can only be l_buf_size big, not l_write_size big */
1539  l_temp2=write(ps_chan->l_channel_no, ps_chan->pc_io_buf+l_temp,
1540  ps_chan->l_buf_size);
1541  if(l_temp2==-1)
1542  {
1543  return(PUTEVT__WRERR);
1544  }
1545  if(l_temp2!=ps_chan->l_buf_size)
1546  {
1547  return(PUTEVT__TOOBIG);
1548  }
1549  }
1550  } /* end of flush */
1551 
1552 g_close:
1553  free(ps_chan->pc_io_buf);
1554  /* free io buffer Memory */
1555 
1556  l_status=close(ps_chan->l_channel_no);
1557  ps_chan->l_channel_no=-1;
1558  if(l_status == -1) return(PUTEVT__CLOSE_ERR);
1559  else return PUTEVT__SUCCESS;
1560 } /* end of f_evt_put_close */
1561 
1562 /*1+ C Main ****************+******************************************/
1563 /*+ Module : f_evt_error */
1564 /*--------------------------------------------------------------------*/
1565 /*+ CALLING : f_evt_error( long l_error , char &c_string[], long l_out ) */
1566 /*--------------------------------------------------------------------*/
1567 /* */
1568 /*+ PURPOSE : f_evt_error displays error messages. */
1569 /*+ ARGUMENTS : */
1570 /*+ l_error : The error id as returned from other calls */
1571 /*+ c_string : The string into f_evt_error() copies the message....*/
1572 /*+ l_out : specifies the output device for the error message. */
1573 /*- out = 1 : error message is copied to string. */
1574 /*- out = 0 : error message is printed on terminal. */
1575 /*+ Return type : int (longword). */
1576 /*+ Status codes: */
1577 /*- GETEVT__SUCCESS : success. */
1578 /*- GETEVT__FAILURE : failure */
1579 /*+ Declaration : */
1580 /* INTS4 f_evt_error( INTS4 , CHARS * , INTS4 ); */
1581 /*+ FUNCTION : f_evt_error displays the error message for the */
1582 /* error id ( l_error ). If out = 1 the error */
1583 /* message is copied into string, else */
1584 /* f_evt_error prints the message on terminal. */
1585 /*1- C Main ******************+****************************************/
1586 INTS4 f_evt_error( INTS4 l_error , CHARS *pc_dest , INTS4 l_out )
1587 {
1588  CHARS c_line[80];
1589 
1590  switch( l_error )
1591  {
1592  case GETEVT__NOFILE :
1593  sprintf(c_line,"-I-f_evt: no such input file");
1594  break;
1595  case GETEVT__NOTAGFILE :
1596  sprintf(c_line,"-I-f_evt: no such tag file");
1597  break;
1598  case GETEVT__NOTAG :
1599  sprintf(c_line,"-I-f_evt: no such event tag");
1600  break;
1601  case GETEVT__TIMEOUT :
1602  sprintf(c_line,"-I-f_evt: time out");
1603  break;
1604  case GETEVT__NOSERVER :
1605  sprintf(c_line,"-I-f_evt: no such server");
1606  break;
1607  case GETEVT__RDERR :
1608  sprintf(c_line,"-I-f_evt: read server error");
1609  break;
1610  case GETEVT__TAGRDERR :
1611  sprintf(c_line,"-I-f_evt: read tag file error");
1612  break;
1613  case GETEVT__TAGWRERR :
1614  sprintf(c_line,"-I-f_evt: write tag file error");
1615  break;
1616  case GETEVT__FRAGMENT :
1617  sprintf(c_line,"-I-f_evt: data format error");
1618  break;
1619  case GETEVT__NOMORE :
1620  sprintf(c_line,"-I-f_evt: no more event");
1621  break;
1622  case GETEVT__CLOSE_ERR:
1623  sprintf(c_line,"-I-f_evt: close server error");
1624  break;
1625  case GETEVT__FAILURE :
1626  sprintf(c_line,"-I-f_evt: failure");
1627  break;
1628  case GETEVT__NOCHANNEL :
1629  sprintf(c_line,"-I-f_evt: too many channels");
1630  break;
1631  case GETEVT__NOLMDFILE :
1632  sprintf(c_line,"-I-f_evt: input file is no LMD file");
1633  break;
1634  case GETEVT__SUCCESS :
1635  sprintf(c_line,"-I-f_evt: success");
1636  break;
1637  case PUTEVT__FILE_EXIST :
1638  sprintf(c_line,"-I-f_evt: output file already exist");
1639  break;
1640  case PUTEVT__WRERR :
1641  sprintf(c_line,"-I-f_evt: write file error");
1642  break;
1643  case PUTEVT__TOOBIG :
1644  sprintf(c_line,"-I-f_evt: output file too large");
1645  break;
1646  case PUTEVT__TOO_SMALLS:
1647  sprintf(c_line,"-I-f_evt: event can not fit in a stream");
1648  break;
1649  case PUTEVT__CLOSE_ERR :
1650  sprintf(c_line,"-I-f_evt: close output error");
1651  break;
1652  case PUTEVT__FAILURE :
1653  sprintf(c_line,"-I-f_evt: output failure");
1654  break;
1655  case PUTEVT__NOCHANNEL :
1656  sprintf(c_line,"-I-f_evt: too many channels");
1657  break;
1658  default :
1659  sprintf(c_line,"-I-f_evt: unknown message id %d",l_error);
1660  if(l_out == 0)printf("%s\n",c_line);
1661  if(l_out==1)strcpy(pc_dest,c_line);
1662  return GETEVT__FAILURE;
1663  } /* end switch( l_error ) */
1664 
1665  if(l_out == 0)printf("%s\n",c_line);
1666  if(l_out == 1)strcpy(pc_dest,c_line);
1667 
1668  return GETEVT__SUCCESS;
1669 } /* end of f_evt_error */
1670 
1671 
1672 /*1+ C Main ****************+******************************************/
1673 /*+ Module : f_evt_get_buffer */
1674 /*--------------------------------------------------------------------*/
1675 /*+ CALLING : f_evt_get_buffer(s_evt_channel &s_chan, INTS4 *pl_buffer) */
1676 /*--------------------------------------------------------------------*/
1677 /* */
1678 /*+ PURPOSE : f_evt_get_buffer read one buffer from server into */
1679 /* user buffer. */
1680 /*+ ARGUMENTS : */
1681 /*+ s_chan : structure s_evt_channel. */
1682 /*+ pl_buffer : Address of user buffer */
1683 /*+ Return type : int. */
1684 /*+ Status codes: */
1685 /*- GETEVT__SUCCESS : success. */
1686 /*- GETEVT__FAILURE : failure */
1687 /*- GETEVT__RDERR : read server or file error */
1688 /*- GETEVT__NOMORE : No more events. */
1689 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
1690 /*+ Declaration : */
1691 /* INTS4 f_evt_get_buffer(s_evt_channel *, INTS4 *); */
1692 /*1- C Main ****************+******************************************/
1694 {
1695  INTS4 l_temp;
1696  // CHARS * pc_temp;
1697  INTS4 l_status;
1698 
1699  // pc_temp=(CHARS *)ps_chan->pc_io_buf;
1700  switch(ps_chan->l_server_type)
1701  {
1702  case GETEVT__FILE :
1703  l_temp=read(ps_chan->l_channel_no,ps_buffer, ps_chan->l_buf_size);
1704  if(l_temp == 0)
1705  /* if end of file, then exit */
1706  {
1707  ps_chan->l_io_buf_size = 0;
1708  return(GETEVT__NOMORE);
1709  }
1710  else if(l_temp == -1)
1711  {
1712  ps_chan->l_io_buf_size = 0;
1713  return(GETEVT__RDERR);
1714  }
1715  break;
1716  case GETEVT__RFIO :
1717  l_temp=RFIO_read(ps_chan->l_channel_no,(CHARS *)ps_buffer, ps_chan->l_buf_size);
1718  if(l_temp == 0)
1719  {
1720  ps_chan->l_io_buf_size = 0;
1721  return(GETEVT__NOMORE);
1722  }
1723  else if(l_temp == -1)
1724  {
1725  ps_chan->l_io_buf_size = 0;
1726  return(GETEVT__RDERR);
1727  }
1728  break;
1729  case GETEVT__STREAM :
1730  if(ps_chan->l_stream_bufs == 0)
1731  if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
1732  {
1733  return(GETEVT__FAILURE);
1734  }
1735 
1736  l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1737  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
1738  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
1739  ps_chan->l_stream_bufs++;
1740  if(ps_chan->l_stream_bufs == ps_chan->l_bufs_in_stream)ps_chan->l_stream_bufs = 0;
1741  break;
1742  case GETEVT__TRANS :
1743  l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1744  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
1745  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
1746  break;
1747  case GETEVT__REVSERV :
1748  case GETEVT__EVENT :
1749  default :
1750  return(GETEVT__FAILURE);
1751  } /* end of switch */
1752 
1753  /* swap */
1754  if( ((s_bufhe *)(ps_buffer))->l_free[0] != 1)
1755  f_evt_swap((CHARS *)ps_buffer, ps_chan->l_buf_size);
1756 
1757  return(GETEVT__SUCCESS);
1758 } /* end of f_evt_get_buffer */
1759 /*1+ C Main ****************+******************************************/
1760 /*+ Module : f_evt_skip_buffer */
1761 /*--------------------------------------------------------------------*/
1762 /*+ CALLING : f_evt_skip_buffer(s_evt_channel &s_chan, INTS4 l_buffer) */
1763 /*--------------------------------------------------------------------*/
1764 /* */
1765 /*+ PURPOSE : Skip buffers in file. */
1766 /*+ ARGUMENTS : */
1767 /*+ s_chan : structure s_evt_channel. */
1768 /*+ l_buffer : buffers to skip */
1769 /*+ Return type : int. */
1770 /*+ Status codes: */
1771 /*- GETEVT__SUCCESS : success. */
1772 /*- GETEVT__FAILURE : failure */
1773 /*- GETEVT__RDERR : read server or file error */
1774 /*- GETEVT__NOMORE : No more events. */
1775 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
1776 /*+ Declaration : */
1777 /* INTS4 f_evt_skip_buffer(s_evt_channel *, INTS4); */
1778 /*1- C Main ****************+******************************************/
1780 {
1781  INTS4 l_temp;
1782  // CHARS * pc_temp;
1783 
1784  // pc_temp=(CHARS *)ps_chan->pc_io_buf;
1785  switch(ps_chan->l_server_type)
1786  {
1787  case GETEVT__FILE :
1788  l_temp=lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
1789  if(l_temp == -1)
1790  /* if end of file, then exit */
1791  {
1792  return(GETEVT__NOMORE);
1793  }
1794  break;
1795  case GETEVT__RFIO :
1796  l_temp=RFIO_lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
1797  if(l_temp == -1)
1798  {
1799  return(GETEVT__NOMORE);
1800  }
1801  break;
1802  case GETEVT__STREAM :
1803  case GETEVT__TRANS :
1804  case GETEVT__REVSERV :
1805  case GETEVT__EVENT :
1806  default : return(GETEVT__FAILURE);
1807  } /* end of switch */
1808 
1809  ps_chan->l_first_get=1; /* so we will first call f_getevt_get */
1810  return(GETEVT__SUCCESS);
1811 } /* end of f_evt_skip_buffer */
1812 
1813 /*1+ C Main ****************+******************************************/
1814 /*+ Module : f_evt_timeout */
1815 /*--------------------------------------------------------------------*/
1816 /*+ CALLING : f_evt_timeout(s_evt_channel *ps_chan, seconds) */
1817 /*--------------------------------------------------------------------*/
1818 /* */
1819 /*+ PURPOSE : Set a timeout for TCP read operations */
1820 /*+ ARGUMENTS : */
1821 /*+ ps_chan : Address of channel structure. */
1822 /*+ seconds : -1: wait (default) */
1823 /* >0: if after n seconds no data arrived, */
1824 /* read functions return GETEVT__TIMEOUT. */
1825 /*+ Return type : INTS4 */
1826 /*+ Declaration : */
1827 /* INTS4 f_evt_timeout(s_evt_channel *, INTS4 ); */
1828 /*+ FUNCTION : Set a timeout for TCP read operations. */
1829 /* The calls of f_evt_get_event, f_evt_get_buffer */
1830 /* will return GETEVT__TIMEOUT when seconds have been */
1831 /* set to positive value. */
1832 /*1- C Main ****************+******************************************/
1834 {
1835  ps_chan->l_timeout = l_sec;
1836  return(GETEVT__SUCCESS);
1837 } /* end of f_evt_timeout */
1838 
1839 /*1- C Main ****************+******************************************/
1840 /*+ Module : f_evt_swap */
1841 /*--------------------------------------------------------------------*/
1842 /*+ CALLING : sts = f_evt_swap(char &c_source[], long l_length) */
1843 /*--------------------------------------------------------------------*/
1844 /* */
1845 /*+ PURPOSE : Long word byte swap. */
1846 /*+ ARGUMENTS : */
1847 /*+ c_source : source data array. */
1848 /*+ l_length : length (in bytes) */
1849 /*+ FUNCTION : Long word byte swap. Works on the source field. */
1850 /*+ Return type : int */
1851 /*+ Status codes: bit 0: success */
1852 /*1- C Procedure ***********+******************************************/
1853 INTS4 f_evt_swap(CHARS * pc_source, INTS4 l_length)
1854 {
1855  CHARS * p_s, * p_d;
1856  INTS4 l_save;
1857  CHARS ch_temp;
1858 
1859  if(l_length%4 == 2){
1860  ch_temp=*(pc_source+l_length-2);
1861  *(pc_source+l_length-2)=*(pc_source+l_length-1);
1862  *(pc_source+l_length-1)=ch_temp;
1863  }
1864  l_length=(l_length/4)*4; /* aligned */
1865  for(p_d=pc_source,p_s=(CHARS *)&l_save; p_d<pc_source+l_length;)
1866  {
1867  l_save = *((INTS4 *)p_d);
1868  p_s += 4; /* increment source */
1869  *(p_d++) = *(--p_s);
1870  *(p_d++) = *(--p_s);
1871  *(p_d++) = *(--p_s);
1872  *(p_d++) = *(--p_s);
1873  }
1874  return(0);
1875 } /* end of f_evt_swap */
1876 /*1- C Main ****************+******************************************/
1877 /*+ Module : f_evt_swap */
1878 /*--------------------------------------------------------------------*/
1879 /*+ CALLING : sts = f_evt_swap_filhe(s_filhe *) */
1880 /*--------------------------------------------------------------------*/
1881 /* */
1882 /*+ PURPOSE : Swap file header. */
1883 /*+ ARGUMENTS : */
1884 /*+ c_source : source data array. */
1885 /*+ l_length : length (in bytes) */
1886 /*+ FUNCTION : Long word byte swap. Works on the source field. */
1887 /*+ Return type : int */
1888 /*+ Status codes: bit 0: success */
1889 /*1- C Procedure ***********+******************************************/
1891 {
1892  INTS4 ii;
1893  INTS2 *pi;
1894  s_filhe *ps_filhe;
1895 
1896  f_evt_swap((CHARS *)ps_bufhe,48);
1897  if(ps_bufhe->i_type == 2000)
1898  {
1899  ps_filhe=(s_filhe *)ps_bufhe;
1900  f_evt_swap((CHARS *)&ps_filhe->filhe_lines,4);/* number of comment lines ps_filhe->filhe_lines*/
1901  ps_filhe->filhe_label_l=ps_filhe->filhe_label_l>>8;
1902  ps_filhe->filhe_file_l =ps_filhe->filhe_file_l >>8;
1903  ps_filhe->filhe_user_l =ps_filhe->filhe_user_l >>8;
1904  ps_filhe->filhe_run_l =ps_filhe->filhe_run_l >>8;
1905  ps_filhe->filhe_exp_l =ps_filhe->filhe_exp_l >>8;
1906  pi=(INTS2 *)&ps_filhe->s_strings;
1907  for(ii=0;ii<ps_filhe->filhe_lines;ii++) {
1908  *pi=*pi>>8;
1909  pi += 40;
1910  }
1911  }
1912 
1913  return(0);
1914 } /* end of f_evt_swap */
1915 
1916 /*1- C Main ****************+******************************************/
1917 /*+ Module : f_evt_get_buffer_ptr */
1918 /*--------------------------------------------------------------------*/
1919 /*+ CALLING : f_evt_get_buffer_ptr(s_evt_channel &s_chan) */
1920 /*--------------------------------------------------------------------*/
1921 /* */
1922 /*+ PURPOSE : f_evt_get_buffer_ptr returns buffer pointer */
1923 /*+ ARGUMENTS : */
1924 /*+ s_chan : structure s_evt_channel. */
1925 /*+ Return type : int. */
1926 /*+ Status codes: */
1927 /*1- C Main ****************+******************************************/
1929 {
1930  return(ps_chan->pc_io_buf);
1931 }
1932 /*1- C Main ****************+******************************************/
1933 /*+ Module : f_evt_get_newbuf */
1934 /*--------------------------------------------------------------------*/
1935 /*+ CALLING : f_evt_get_newbuf(s_evt_channel &s_chan) */
1936 /*--------------------------------------------------------------------*/
1937 /* */
1938 /*+ PURPOSE : f_evt_get_newbuf read a buffer from server */
1939 /*+ ARGUMENTS : */
1940 /*+ s_chan : structure s_evt_channel. */
1941 /*+ Return type : int. */
1942 /*+ Status codes: */
1943 /*- GETEVT__SUCCESS : success. */
1944 /*- GETEVT__FAILURE : failure */
1945 /*- GETEVT__RDERR : read server or file error */
1946 /*- GETEVT__NOMORE : No more events. */
1947 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
1948 /*1- C Main ****************+******************************************/
1950 {
1951  INTS4 l_temp;
1952  CHARS * pc_temp;
1953  INTS4 l_status;
1954 
1955  pc_temp=(CHARS *)ps_chan->pc_io_buf;
1956  switch(ps_chan->l_server_type)
1957  {
1958  case GETEVT__FILE :
1959  while(1){
1960  l_temp=read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
1961  if(l_temp == 0) return(GETEVT__NOMORE);
1962  if(l_temp == -1) return(GETEVT__RDERR);
1963  if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
1964  break; /* skip out while(1) */
1965  } /* end of while(1) */
1966  break;
1967  case GETEVT__STREAM :
1968  if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
1969  {
1970  return(GETEVT__FAILURE);
1971  }
1972 
1973  for(l_temp=0; l_temp<ps_chan->l_bufs_in_stream; l_temp++)
1974  {
1975  l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1976  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
1977  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
1978  pc_temp+=ps_chan->l_buf_size;
1979  }
1980  l_temp=((s_bufhe *)(ps_chan->pc_io_buf))->l_evt;
1981  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1) // swap
1982  f_evt_swap((CHARS *)&l_temp,4);
1983  if(l_temp < 0) {// server will shutdown
1984  printf("**** I-f_evt: Stream server request for disconnect!\n");
1985  f_evt_get_close(ps_chan);
1986  return(GETEVT__RDERR);
1987  }
1988  /* if first buffer is empty, all are empty */
1989  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_evt == 0) return(GETEVT__TIMEOUT);
1990  break;
1991  case GETEVT__TRANS :
1992  l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1993  l_temp=((s_bufhe *)(ps_chan->pc_io_buf))->l_evt;
1994  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1) // swap
1995  f_evt_swap((CHARS *)&l_temp,4);
1996  if(l_temp < 0) {// server will shutdown
1997  printf("**** I-f_evt: Transport server request for disconnect!\n");
1998  f_evt_get_close(ps_chan);
1999  return(GETEVT__RDERR);
2000  }
2001  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
2002  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
2003  break;
2004  case GETEVT__RFIO :
2005  l_temp=RFIO_read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
2006  if(l_temp == 0) return(GETEVT__NOMORE);
2007  if(l_temp == -1) return(GETEVT__RDERR);
2008  if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
2009  break;
2010  case GETEVT__REVSERV :
2011  case GETEVT__EVENT :
2012  default :
2013  return(GETEVT__FAILURE);
2014  } /* end of switch */
2015 
2016  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1) // swap
2017  f_evt_swap(ps_chan->pc_io_buf, ps_chan->l_io_buf_size);
2018 
2019  return(GETEVT__SUCCESS);
2020 } /* end of f_evt_get_newbuf */
2021 
2022 /*1- C Main ****************+******************************************/
2023 /*+ Module : f_evt_check_buf */
2024 /*--------------------------------------------------------------------*/
2025 /*+ CALLING : f_evt_check_buf(CHARS *pc_head, INTS4 *pl_goosybuf, */
2026 /* INTS4 *pl_swap, INTS4 *pl_filehead) */
2027 /*--------------------------------------------------------------------*/
2028 /* */
2029 /*+ PURPOSE : check a buffer is a file header or GOOSY buffer, */
2030 /* and whether it's swaped. */
2031 /*+ ARGUMENTS : */
2032 /*+ pc_head : pointer to the buffer to be checked. */
2033 /*+ pl_goosybuf : 1 is goosy buffer, 0 is header */
2034 /*+ pl_swap : 1 means different endian, 0 means same endian. */
2035 /*+ pl_filehead : 1 means first buffer is header */
2036 /*+ Return type : void */
2037 /*+ Status codes: */
2038 /*+ FUNCTION : check a buffer is a file header or GOOSY buffer, */
2039 /* and whether it's swaped. */
2040 /*1- C Main ****************+******************************************/
2041 INTS4 f_evt_check_buf(CHARS *pc_head, INTS4 *pl_size, INTS4 *pl_is_goosybuf, INTS4 *pl_swap, INTS4 *pl_filehead)
2042 {
2043  INTU4 l_size;
2044 
2045  *pl_is_goosybuf=0;
2046  *pl_filehead=0;
2047  *pl_size=0;
2048  *pl_swap=0;
2049  /* first check if it's file header */
2050  if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
2051  (((s_filhe *)(pc_head))->filhe_type==2000) )
2052  {
2053  *pl_swap=0;
2054  *pl_is_goosybuf=0;
2055  *pl_filehead=1;
2056  l_size=((s_bufhe *)(pc_head))->l_dlen*2;
2057  if(l_size%512 > 0) l_size += sizeof(s_bufhe);
2058  if((l_size>>24) > 0) *pl_size=0;
2059  else *pl_size=l_size;
2060  return(PUTEVT__SUCCESS);
2061  }
2062  f_evt_swap(pc_head, sizeof(s_filhe));
2063  if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
2064  (((s_filhe *)(pc_head))->filhe_type==2000) )
2065  {
2066  *pl_swap=1;
2067  *pl_is_goosybuf=0;
2068  *pl_filehead=1;
2069  l_size=((s_bufhe *)(pc_head))->l_dlen*2;
2070  if(l_size%512 > 0) l_size += sizeof(s_bufhe);
2071  if((l_size>>24) > 0) *pl_size=0;
2072  else *pl_size=l_size;
2073  return(PUTEVT__SUCCESS);
2074  }
2075 
2076  /* if not file header, check if it's goosy buffer header */
2077  l_size=((s_bufhe *)(pc_head))->l_dlen*2;
2078  if(l_size%512 > 0) l_size += sizeof(s_bufhe);
2079  if( (((l_size>>24) == 0) && (l_size > 0)) &&
2080  (((s_bufhe *)(pc_head))->h_begin < 2) &&
2081  (((s_bufhe *)(pc_head))->h_begin >= 0) &&
2082  (((s_bufhe *)(pc_head))->h_end < 2) &&
2083  (((s_bufhe *)(pc_head))->h_end >= 0) &&
2084  //(((s_bufhe *)(pc_head))->i_used<=(MAX_BUF_LGTH-sizeof(s_bufhe))/2)&&
2085  ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2] > 0))&&
2086  //(((s_bufhe *)(pc_head))->i_used>0)&&
2087  ( (((s_bufhe *)(pc_head))->l_free[0] == 1)||
2088  (((s_bufhe *)(pc_head))->l_free[0] == 0)||
2089 /* above, because some old lsm file forgot to set this bit, so it's zero */
2090  (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
2091  {
2092  *pl_swap=1; /* !!!, because already swaped once */
2093  *pl_is_goosybuf=1;
2094  *pl_size=l_size;
2095  return(PUTEVT__SUCCESS);
2096  }
2097  f_evt_swap(pc_head, sizeof(s_filhe));
2098  l_size=((s_bufhe *)(pc_head))->l_dlen*2+sizeof(s_bufhe);
2099  if( (((l_size>>24)== 0)&&(l_size > 0))&&
2100  (((s_bufhe *)(pc_head))->l_dlen > 0)&&
2101  (((s_bufhe *)(pc_head))->h_begin < 2)&&
2102  (((s_bufhe *)(pc_head))->h_begin >= 0)&&
2103  (((s_bufhe *)(pc_head))->h_end < 2)&&
2104  (((s_bufhe *)(pc_head))->h_end >= 0)&&
2105  //(((s_bufhe *)(pc_head))->i_used<=(MAX_BUF_LGTH-sizeof(s_bufhe))/2)&&
2106  ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2] > 0))&&
2107  //(((s_bufhe *)(pc_head))->i_used>0)&&
2108  ( (((s_bufhe *)(pc_head))->l_free[0] == 1)||
2109  (((s_bufhe *)(pc_head))->l_free[0] == 0)||
2110 /* above, because some old lsm file forgot to set this bit, so it's zero */
2111  (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
2112  {
2113  *pl_swap=0; /* !!!, because already swaped 2 times */
2114  *pl_is_goosybuf=1;
2115  *pl_size=l_size;
2116  return(PUTEVT__SUCCESS);
2117  }
2118  return(PUTEVT__SUCCESS);
2119 } /* end of f_evt_check_buf */
2120 
2121 /*1- C Main ****************+******************************************/
2122 /*+ Module : f_evt_ini_bufhe */
2123 /*--------------------------------------------------------------------*/
2124 /*+ CALLING : f_evt_ini_bufhe(s_evt_channel *ps_chan) */
2125 /*--------------------------------------------------------------------*/
2126 /* */
2127 /*+ PURPOSE : pre-fill each GOOSY buffer header in a stream */
2128 /*+ ARGUMENTS : */
2129 /*+ ps_chan : Address of channel structure. */
2130 /*+ Return type : void . */
2131 /*1- C Main ****************+******************************************/
2133 {
2134  INTS4 l_temp;
2135  struct timespec s_timespec;
2136 
2137  /* because "timeb" is not "typedef", so we must use "struct" */
2138 
2139  for(l_temp=0; l_temp<ps_chan->l_io_buf_size; l_temp += ps_chan->l_buf_size)
2140  {
2141  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
2142  ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
2143  ps_chan->ps_bufhe->i_subtype = ps_chan->l_buf_subtype;
2144  ps_chan->ps_bufhe->i_type = ps_chan->l_buf_type;
2145  ps_chan->ps_bufhe->h_begin = 0;
2146  ps_chan->ps_bufhe->h_end = 0;
2147  ps_chan->ps_bufhe->i_used = 0;
2148  ps_chan->ps_bufhe->l_buf = ps_chan->l_buf_no; ps_chan->l_buf_no++;
2149  ps_chan->ps_bufhe->l_evt = 0;
2150  ps_chan->ps_bufhe->l_current_i = 0;
2151  clock_gettime(CLOCK_REALTIME, &s_timespec);
2152  ps_chan->ps_bufhe->l_time[0] = (INTS4) s_timespec.tv_sec;
2153  ps_chan->ps_bufhe->l_time[1] = (INTS4) s_timespec.tv_nsec/1000000;
2154  ps_chan->ps_bufhe->l_free[0] = 1; /* for swap flag */
2155  ps_chan->ps_bufhe->l_free[1] = 0;
2156  ps_chan->ps_bufhe->l_free[2] = 0;
2157  ps_chan->ps_bufhe->l_free[3] = 0;
2158  }
2159  return(PUTEVT__SUCCESS);
2160 } /* end of f_evt_ini_bufhe */
2161 
2162 /*1+ C Main ****************+******************************************/
2163 /*+ Module : f_evt_cre_tagfile */
2164 /*--------------------------------------------------------------------*/
2165 /*+ CALLING : f_evt_cre_tagfile(lmdfile,tagfile,filter) */
2166 /*--------------------------------------------------------------------*/
2167 /* */
2168 /*+ PURPOSE : Create a tag file from lmd file */
2169 /*+ ARGUMENTS : */
2170 /*+ lmdfile : LMD file name */
2171 /*+ tagfile : tag file name */
2172 /*+ filter : optional function for filter */
2173 /*+ Return type : INTS4 . */
2174 /*+ Status codes: */
2175 /*- GETEVT__SUCCESS : success. */
2176 /*- GETEVT__NOFILE : file does not exist. */
2177 /*- GETEVT__TAGWRERR : tag file write error. */
2178 /*- GETEVT__RDERR : lmd read error. */
2179 /*+ Declaration : */
2180 /* INTS4 f_evt_cre_tagfile(CHARS *,CHARS *, INTS4 (*)()); */
2181 /*+ FUNCTION : Create a tag file from lmd file */
2182 /*+ filter : The filter function is called at the beginning */
2183 /* with a NULL as argument, then for each event */
2184 /* with the event pointer. Returning 0 skips the event, */
2185 /* 1 takes the event into the tag file. */
2186 /* Different tag files can be created from one lmd file. */
2187 /*1- C Main ****************+******************************************/
2189 {
2190  /* take it */
2191 return(1);
2192 //if(ps_ve10_1 != NULL)
2193 //{
2194 // printf("Filter %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d\n",
2195 // ps_ve10_1->l_count,
2196 // ps_ve10_1->i_type,
2197 // ps_ve10_1->i_subtype,
2198 // ps_ve10_1->l_dlen,
2199 // ps_ve10_1->i_trigger);
2200 // if(ps_ve10_1->l_count%2) return(1); /* take it */
2201 // else return(0); /* skip it */
2202 //}
2203 //else printf("Initialized filter function\n");
2204 // return(0);
2205 }
2206 INTS4 f_evt_cre_tagfile(CHARS *pc_lmd, CHARS *pc_tag,INTS4 (*e_filter)(s_ve10_1 *))
2207 {
2208  INTS4 ii,l_take_it,l_temp,l_chan,l_out,l_file_pos=0,l_bufnr=0,l_events=0;
2209  INTS4 l_firste = 0, *pl, l_len, l_last=-1, l_lin=0, l_fragsize;
2210  INTS4 l_swap=0, l_swap_head, l_is_goosybuf, l_filehead=0, l_size=0, l_size_head, l_dummy, l_evsize,l_evt_buf_size=0;
2211  INTU4 *ps,*pd;
2212  CHARS *pc_evt_buf=NULL;
2213  s_ve10_1 *ps_ve10_1;
2214  s_bufhe *ps_bufhe;
2215  s_taghe s_taghe;
2216  s_tag s_tag;
2217 
2218  s_tag.l_event = 0;
2219  s_tag.l_offset = 0;
2220 
2221  ps_bufhe = (s_bufhe *)c_temp;
2222  printf("LMD file %s, TAG file %s\n",pc_lmd,pc_tag);
2223  /* get file attributes */
2224  if((l_chan=open(pc_lmd,GET__OPEN_FLAG))== -1) return(GETEVT__NOFILE);
2225  /* read first 512 bytes */
2226  if(read(l_chan,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
2227  {
2228  close(l_chan);
2229  return(GETEVT__RDERR);
2230  }
2231  /* check for file header, return size and swap */
2232  f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
2233  if(((l_is_goosybuf == 0) & (l_filehead == 0)) | (l_size_head == 0))
2234  {
2235  printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
2236  close(l_chan);
2237  return(GETEVT__NOLMDFILE);
2238  }
2239  /* read file header and first buffer and check for goosy header */
2240  if(l_filehead == 1)
2241  {
2242  lseek(l_chan, 0, SEEK_SET); /* rewind file */
2243  if(read(l_chan,c_temp,l_size_head)!=l_size_head)
2244  {
2245  close(l_chan);
2246  return(GETEVT__RDERR);
2247  }
2248  if(read(l_chan,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH)
2249  {
2250  close(l_chan);
2251  return(GETEVT__RDERR);
2252  }
2253  f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
2254  if((l_is_goosybuf == 0) | (l_size != l_size_head) | (l_swap != l_swap_head))
2255  {
2256  printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
2257  close(l_chan);
2258  return(GETEVT__NOLMDFILE);
2259  }
2260  }/* check buffer behind header */
2261 
2262  lseek(l_chan, 0, SEEK_SET); /* rewind file */
2263 
2264  printf("Buffer swap %d, File header %d, LMD buffer %d, size %d[b]\n",l_swap,l_filehead,l_is_goosybuf,l_size);
2265 
2266  /* found file header, skip */
2267  if(l_filehead == 1)
2268  {
2269  if(read(l_chan,c_temp,l_size)!=l_size)
2270  {
2271  close(l_chan);
2272  return(GETEVT__RDERR);
2273  }
2274  l_file_pos += l_size;
2275  l_bufnr++;
2276  }
2277 
2278  /* Open and create tag file */
2279  if((l_out=open(pc_tag,PUT__CRT_FLAG,DEF_FILE_ACCE))== -1) return(GETEVT__NOFILE);
2280  write(l_out,(CHARS *)&s_taghe,sizeof(s_taghe));
2281 
2282  /* Initialize filter function */
2283  if(e_filter != NULL) ii=(*e_filter)(NULL);
2284 
2285  while(read(l_chan,c_temp,l_size)==l_size)
2286  {
2287  l_file_pos=l_bufnr*l_size;
2288  if(l_swap) f_evt_swap(c_temp,l_size);
2289  if((ps_bufhe->h_end)&(ps_bufhe->h_begin)&(ps_bufhe->l_evt==1))
2290  {
2291  /* only fragment, next buffer */
2292  /* printf("Event fragment skipped Buffer %6d\n",l_bufnr);*/
2293  l_bufnr++;
2294  continue;
2295  }
2296  ps_ve10_1=(s_ve10_1 *)(ps_bufhe + 1);
2297  pl = (INTS4 *)ps_ve10_1;
2298  l_file_pos += sizeof(s_bufhe);
2299  /* skip fragment at begin */
2300  if(ps_bufhe->h_end)
2301  {
2302  l_len = (*pl>>1)+2;
2303  l_file_pos += (l_len<<2); /* bytes */
2304  ps_ve10_1=(s_ve10_1 *)(pl+l_len);
2305  pl = (INTS4 *)ps_ve10_1;
2306  ps_bufhe->l_evt--;
2307  /* printf("Event fragment end skipped Buffer %6d\n",l_bufnr);*/
2308  }
2309  for(ii=1;ii<ps_bufhe->l_evt;ii++) /* except last element */
2310  {
2311  /*printf("Event %10d pos %10d Buffer %6d\n",ps_ve10_1->l_count, l_file_pos,l_bufnr);*/
2312  if(e_filter != NULL) l_take_it=(*e_filter)(ps_ve10_1);
2313  else l_take_it=1;
2314  l_len = (*pl>>1)+2;
2315  s_tag.l_event=ps_ve10_1->l_count;
2316  s_tag.l_offset=l_file_pos;
2317  if(l_take_it)
2318  {
2319  l_events++;
2320  if(ps_ve10_1->l_count != (l_last+1))
2321  {
2322  l_lin++;
2323  if(l_lin == 1)l_firste=ps_ve10_1->l_count;
2324  /* printf("New event number offset %d, index %d\n",ps_ve10_1->l_count,l_events);*/
2325  }
2326  l_last=ps_ve10_1->l_count;
2327  if(write(l_out,(CHARS *)&s_tag,sizeof(s_tag)) != sizeof(s_tag))
2328  {
2329  close(l_chan);
2330  close(l_out);
2331  return(GETEVT__TAGWRERR);
2332  }
2333  }
2334  l_file_pos += (l_len<<2); /* bytes */
2335  ps_ve10_1=(s_ve10_1 *)(pl+l_len);
2336  pl = (INTS4 *)ps_ve10_1;
2337  }
2338 
2339  if(ps_bufhe->l_evt > 0)
2340  {
2341  if(ps_ve10_1->l_dlen < 4) printf("Buffer %d Event fragment %10d dlen %d ts %d %d trigger %d\n"
2342  ,l_bufnr,ps_ve10_1->l_count,ps_ve10_1->l_dlen,ps_ve10_1->i_type,
2343  ps_ve10_1->i_subtype,ps_ve10_1->i_trigger);
2344  s_tag.l_event=ps_ve10_1->l_count;
2345  if(ps_bufhe->h_begin)
2346  {
2347  /* copy event to event buffer for filter function */
2348  if(e_filter != NULL)
2349  {
2350  /* is event buffer big enough? */
2351  l_evsize=ps_bufhe->l_free[1]+4; /* total words */
2352  if(l_evt_buf_size < l_evsize*2)
2353  {
2354  if(pc_evt_buf != NULL)free(pc_evt_buf);
2355  l_evt_buf_size=l_evsize*2;
2356  pc_evt_buf=(CHARS *)malloc(l_evt_buf_size);
2357  }
2358  /* copy event fragment to buffer */
2359  ps=(INTU4 *)ps_ve10_1;
2360  pd=(INTU4 *)pc_evt_buf;
2361  l_fragsize = ps_ve10_1->l_dlen+4; /* fragment size + header [w] */
2362  for(ii=0;ii<l_fragsize/2;ii++) *pd++ = *ps++;
2363  /* loop over fragments */
2364  while(l_fragsize < l_evsize)
2365  {
2366  if(read(l_chan,c_temp,l_size) != l_size)break;
2367  l_bufnr++;
2368  if(l_swap) f_evt_swap(c_temp,l_size);
2369  ps = (INTU4 *) (ps_bufhe+1); /* behind buffer header, fragment header */
2370  l_temp=(INTS4)*ps; /* fragment size [w] */
2371  ps += 2; /* to data behind fragment header */
2372  for(ii=0;ii<l_temp/2;ii++) *pd++ = *ps++;
2373  l_fragsize += l_temp;
2374  }
2375  if(l_fragsize < l_evsize)break;
2376  ps_ve10_1 = (s_ve10_1 *)pc_evt_buf;
2377  ps_ve10_1->l_dlen=l_evsize-4;
2378  /* rewind last buffer, will be read again by while loop */
2379  l_bufnr--;
2380  lseek(l_chan, -l_size, SEEK_CUR);
2381  }
2382  s_tag.l_offset=-l_file_pos;
2383  /* printf("Event %10d pos %10d Buffer -%6d\n",ps_ve10_1->l_count, l_file_pos,l_bufnr);*/
2384  }
2385  else
2386  {
2387  s_tag.l_offset=l_file_pos;
2388  /* printf("Event %10d pos %10d Buffer %6d\n",ps_ve10_1->l_count, l_file_pos,l_bufnr);*/
2389  }
2390  if(e_filter != NULL)l_take_it=(*e_filter)(ps_ve10_1);
2391  else l_take_it=1;
2392  if(l_take_it)
2393  {
2394  l_events++;
2395  if(ps_ve10_1->l_count != (l_last+1))
2396  {
2397  l_lin++;
2398  if(l_lin == 1)l_firste=ps_ve10_1->l_count;
2399  /* printf("New event number offset %d, index %d\n",ps_ve10_1->l_count,l_events);*/
2400  }
2401  l_last=ps_ve10_1->l_count;
2402  if(write(l_out,(CHARS *)&s_tag,sizeof(s_tag)) != sizeof(s_tag))
2403  {
2404  close(l_chan);
2405  close(l_out);
2406  return(GETEVT__TAGWRERR);
2407  }
2408  }
2409  }
2410  l_bufnr++;
2411  /* if(l_bufnr > 3) break; */
2412  }
2413  lseek(l_out, 0, SEEK_SET); /* rewind file */
2414  s_taghe.l_endian = 1;
2415  s_taghe.l_version = 1;
2416  s_taghe.l_bufsize = l_size;
2417  s_taghe.l_buffers = l_bufnr;
2418  s_taghe.l_events = l_events;
2419  s_taghe.l_filesize = sizeof(s_tag)*l_events;
2420  s_taghe.l_linear = (l_lin == 1);
2421  s_taghe.l_first = l_firste;
2422  s_taghe.l_last = s_tag.l_event;
2423  if(write(l_out,(CHARS *)&s_taghe,sizeof(s_taghe)) != sizeof(s_taghe))
2424  {
2425  close(l_chan);
2426  close(l_out);
2427  return(GETEVT__TAGWRERR);
2428  }
2429  close(l_chan);
2430  close(l_out);
2431  printf("Buffers %6d, of size %d, Events %10d, first %d, last %d "
2432  ,s_taghe.l_buffers
2433  ,s_taghe.l_bufsize
2434  ,s_taghe.l_events
2435  ,s_taghe.l_first
2436  ,s_taghe.l_last);
2437  if(s_taghe.l_linear)printf("linear\n");
2438  else printf("not linear\n");
2439 
2440  return(GETEVT__SUCCESS);
2441 } /* end of f_evt_cre_tagfile */
2442 /*1+ C Main ****************+******************************************/
2443 /*+ Module : f_evt_get_tagopen */
2444 /*--------------------------------------------------------------------*/
2445 /*+ CALLING : f_evt_get_tagopen(channel,tagfile,lmdfile,header,print) */
2446 /*--------------------------------------------------------------------*/
2447 /* */
2448 /*+ PURPOSE : Open tag and lmd file */
2449 /*+ ARGUMENTS : */
2450 /*+ channel : s_evt_channel* , must be allocated. */
2451 /*+ tagfile : Name of tag file */
2452 /*+ filename : LMD file name */
2453 /*+ header : address of CHARS pointer. If it is not NULL, then */
2454 /* try to return file header or other information */
2455 /* about server. If it is NULL, then returns nothing. */
2456 /*+ print : Print flag: 1=verbose */
2457 /*+ Return type : INTS4 . */
2458 /*+ Status codes: */
2459 /*- GETEVT__SUCCESS : success. */
2460 /*- GETEVT__NOFILE : file does not exist. */
2461 /*- GETEVT__TAGRDERR : tag file read error. */
2462 /*- GETEVT__RDERR : read server error. */
2463 /*+ Declaration : */
2464 /* INTS4 f_evt_get_tagopen( */
2465 /* s_evt_channel *,CHARS *,CHARS *,CHARS **,INTS4); */
2466 /*+ FUNCTION : Open tag file and lmd file. If no tag file is found, */
2467 /* a standard f_evt_get_open is called. In this case */
2468 /* following tag functions call standard f_evt_get functions. */
2469 /*1- C Main ****************+******************************************/
2470 INTS4 f_evt_get_tagopen(s_evt_channel *ps_chan,CHARS *pc_tag,CHARS *pc_lmd, CHARS **ps_head, INTS4 l_prihe)
2471 {
2472  INTS4 ii;
2473  s_bufhe *ps_bufhe;
2474 
2475  ps_chan->ps_tag = NULL; /* tagfile buffer */
2476  ps_chan->ps_taghe = NULL;
2477  if(l_prihe)printf("LMD file %s, TAG file %s\n",pc_lmd,pc_tag);
2478 
2479  /* if tag file name not specified, do not try to open it SL:11.11.09*/
2480  if ((pc_tag == NULL) || (*pc_tag == 0))
2481  ps_chan->l_tagfile_no = -1;
2482  else
2483  ps_chan->l_tagfile_no = open(pc_tag, GET__OPEN_FLAG);
2484 
2485  /* open tag file and read header */
2486  if(ps_chan->l_tagfile_no == -1)
2487  {
2488  /* no tag file, use normal open */
2489  /*=============================================*/
2490  ii=f_evt_get_open(GETEVT__FILE, pc_lmd, ps_chan, (CHARS **) &ps_bufhe,0,0);
2491  *ps_head = (CHARS *) ps_bufhe;
2492  if(ii!=GETEVT__SUCCESS)
2493  {
2494  printf("Error opening input file %s\n",pc_lmd);
2495  return (ii);
2496  }
2497  /* printf("No tag file for %s\n",pc_lmd); */
2498  if(l_prihe) ii = f_evt_type(ps_bufhe,NULL,0,0,0,0);
2499  return(GETEVT__SUCCESS);
2500  }
2501  /*=============================================*/
2502  /* tag file found */
2503  ps_chan->ps_taghe = (s_taghe *)malloc(sizeof(s_taghe));
2504  if(read(ps_chan->l_tagfile_no,(CHARS *)ps_chan->ps_taghe,sizeof(s_taghe))!=sizeof(s_taghe))
2505  {
2506  free(ps_chan->ps_taghe);
2507  ps_chan->ps_taghe = NULL;
2508  close(ps_chan->l_tagfile_no);
2509  return(GETEVT__TAGRDERR);
2510  }
2511  if(ps_chan->ps_taghe->l_endian != 1)ps_chan->l_tagswap=1;
2512  if(ps_chan->l_tagswap)f_evt_swap((CHARS *)ps_chan->ps_taghe,sizeof(s_taghe));
2513  if(l_prihe)
2514  {
2515  printf("Buffers %6d, of size %d, Events %10d, first %d, last %d"
2516  ,ps_chan->ps_taghe->l_buffers
2517  ,ps_chan->ps_taghe->l_bufsize
2518  ,ps_chan->ps_taghe->l_events
2519  ,ps_chan->ps_taghe->l_first
2520  ,ps_chan->ps_taghe->l_last);
2521  if(ps_chan->ps_taghe->l_linear)printf(" linear\n");
2522  else printf(" not linear\n");
2523  }
2524  if((ps_chan->l_channel_no=open(pc_lmd,GET__OPEN_FLAG))== -1)
2525  {
2526  if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
2527  ps_chan->ps_taghe = NULL;
2528  close(ps_chan->l_tagfile_no);
2529  return(GETEVT__NOFILE);
2530  }
2531  /* read buffer header to check if we have to swap */
2532  ps_bufhe = (s_bufhe *)c_temp;
2533  if(read(ps_chan->l_channel_no,c_temp,ps_chan->ps_taghe->l_bufsize)!=ps_chan->ps_taghe->l_bufsize)
2534  {
2535  if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
2536  ps_chan->ps_taghe = NULL;
2537  if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
2538  ps_chan->ps_tag = NULL;
2539  close(ps_chan->l_tagfile_no);
2540  close(ps_chan->l_channel_no);
2541  return(GETEVT__RDERR);
2542  }
2543  if(ps_chan->ps_taghe->l_linear == 0)
2544  {
2545  ps_chan->ps_tag = (s_tag *)malloc(ps_chan->ps_taghe->l_filesize);
2546  if(read(ps_chan->l_tagfile_no,(CHARS *)ps_chan->ps_tag,ps_chan->ps_taghe->l_filesize)!=ps_chan->ps_taghe->l_filesize)
2547  {
2548  if(ps_chan->ps_taghe != NULL) free(ps_chan->ps_taghe);
2549  ps_chan->ps_taghe = NULL;
2550  if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
2551  ps_chan->ps_tag = NULL;
2552  close(ps_chan->l_tagfile_no);
2553  close(ps_chan->l_channel_no);
2554  return(GETEVT__TAGRDERR);
2555  }
2556  }
2557  if(ps_bufhe->l_free[0] != 1)ps_chan->l_lmdswap=1;
2558  if(ps_chan->l_lmdswap)f_evt_swap_filhe(ps_bufhe);
2559  if(l_prihe) ii = f_evt_type(ps_bufhe,NULL,0,0,0,0);
2560  if(ps_head != NULL)
2561  {
2562  if(ps_bufhe->i_type == 2000) *ps_head = (CHARS *)ps_bufhe;
2563  }
2564  ps_chan->l_evt_buf_size=0;
2565  ps_chan->pc_evt_buf=NULL;
2566  ps_chan->l_io_buf_posi=0; /* keeps index of last event */
2567  return(GETEVT__SUCCESS);
2568 }
2569 
2570 /*1+ C Main ****************+******************************************/
2571 /*+ Module : f_evt_get_tagnext */
2572 /*--------------------------------------------------------------------*/
2573 /*+ CALLING : f_evt_get_tagnext(channel,skip,**event) */
2574 /*--------------------------------------------------------------------*/
2575 /* */
2576 /*+ PURPOSE : Get tagged event from lmd file */
2577 /*+ ARGUMENTS : */
2578 /*+ channel : s_evt_channel* , must be allocated. */
2579 /*+ event : address of pointer. If it is not NULL, then */
2580 /* return event pointer. */
2581 /*+ Return type : INTS4 . */
2582 /*+ Status codes: */
2583 /*- GETEVT__SUCCESS : success. */
2584 /*- GETEVT__NOFILE : file does not exist. */
2585 /*- GETEVT__TAGRDERR : tag file read error. */
2586 /*- GETEVT__RDERR : lmd read error. */
2587 /*- GETEVT__FRAGMENT : Event fragment found. */
2588 /*- GETEVT__NOMORE : No more events. */
2589 /*+ Declaration : */
2590 /* INTS4 f_evt_get_tagnext(s_evt_channel *,INTS4,INTS4 **); */
2591 /*+ FUNCTION : Get next event at current position, either in tag */
2592 /* file, or in lmd file. Optional <skip> events are skipped. */
2593 /*1- C Main ****************+******************************************/
2594 INTS4 f_evt_get_tagnext(s_evt_channel *ps_chan,INTS4 l_skip, INTS4 **pl_event)
2595 {
2596  INTS4 ii = 0,*pl = NULL,kk;
2597  /* no tagfile */
2598  /*=============================================*/
2599  if(ps_chan->ps_taghe == NULL)
2600  {
2601  for(kk=0;kk<=l_skip;kk++)
2602  {
2603  ii=f_evt_get_event(ps_chan, (INTS4 **) &pl, NULL);
2604  if(ii != GETEVT__SUCCESS) break;
2605  }
2606  }
2607  /*=============================================*/
2608  else
2609  {
2610  /* l_io_buf_posi is the index of last event */
2611  ii=f_evt_get_tagevent(ps_chan,ps_chan->l_io_buf_posi+l_skip+1,1,(INTS4 **)&pl);
2612  }
2613  if(pl_event != NULL) *pl_event=pl;
2614  return(ii);
2615 }
2616 /*1+ C Main ****************+******************************************/
2617 /*+ Module : f_evt_get_tagevent */
2618 /*--------------------------------------------------------------------*/
2619 /*+ CALLING : f_evt_get_tagevent(*channel, value, mode, **event) */
2620 /*--------------------------------------------------------------------*/
2621 /* */
2622 /*+ PURPOSE : Get tagged event from lmd file */
2623 /*+ ARGUMENTS : */
2624 /*+ channel : s_evt_channel* , must be allocated. */
2625 /*+ value : event number or index */
2626 /*+ mode : 0: value is number, 1: value is index */
2627 /*+ event : address of pointer. If it is not NULL, then */
2628 /* return event pointer. */
2629 /*+ Return type : INTS4 . */
2630 /*+ Status codes: */
2631 /*- GETEVT__SUCCESS : success. */
2632 /*- GETEVT__TAGRDERR : tag file read error. */
2633 /*- GETEVT__RDERR : lmd read error. */
2634 /*- GETEVT__FRAGMENT : Event fragment found. */
2635 /*- GETEVT__NOMORE : No more events. */
2636 /*- GETEVT__NOTAG : Specified event not in tag file. */
2637 /*+ Declaration : */
2638 /* INTS4 f_evt_get_tagevent( */
2639 /* s_evt_channel *,INTS4,INTS4,INTS4 **); */
2640 /*+ FUNCTION : Get tag event. If no tag file is there, skip <value> */
2641 /* events, or look for event number <value> */
2642 /*1- C Main ****************+******************************************/
2643 INTS4 f_evt_get_tagevent(s_evt_channel *ps_chan,INTS4 l_value, INTS4 l_type, INTS4 **pl_event)
2644 {
2645  INTS4 ii,kk, /*l_evt,*/ l_off,l_typ,l_val,l_evsize,l_fragsize;
2646  INTS4 la_head[2], *pl = NULL;
2647  CHARS *pc;
2648  s_ve10_1 *ps_ve10_1;
2649  s_bufhe *ps_bufhe;
2650  s_tag *ps_tag;
2651  s_tag s_tag_l;
2652 
2653  l_typ=l_type;
2654  l_val=l_value;
2655  /* no tagfile */
2656  /*=============================================*/
2657  if(ps_chan->ps_taghe == NULL)
2658  {
2659  /* search by index */
2660  if(l_type == 1)
2661  {
2662  if(l_val == 0) l_val=1;
2663  for(kk=0;kk<l_val;kk++)
2664  {
2665  ii=f_evt_get_event(ps_chan, (INTS4 **) &pl, NULL);
2666  if(ii != GETEVT__SUCCESS)return(ii);
2667  }
2668  *pl_event=pl;
2669  }
2670  else /* search by event number */
2671  {
2672  ii=f_evt_get_event(ps_chan, (INTS4 **) &ps_ve10_1, NULL);
2673  if(ii != GETEVT__SUCCESS)return(ii);
2674  while(ps_ve10_1->l_count != l_val)
2675  {
2676  ii=f_evt_get_event(ps_chan, (INTS4 **) &ps_ve10_1, NULL);
2677  if(ii != GETEVT__SUCCESS)return(ii);
2678  }
2679  *pl_event = (INTS4 *)ps_ve10_1;
2680  }
2681  return(GETEVT__SUCCESS);
2682  }
2683  /*=============================================*/
2684  ps_ve10_1 = (s_ve10_1 *)c_temp;
2685  ps_bufhe = (s_bufhe *)c_temp;
2686 
2687  /* linear==1 means that event numbers are subsequent. */
2688  /* in that case we can calculate index from number */
2689  if(ps_chan->ps_taghe->l_linear)
2690  {
2691  if(l_typ == 0)l_val=l_value-ps_chan->ps_taghe->l_first+1;
2692  l_typ=1;
2693  }
2694  /* search by index or by value */
2695  if(l_typ == 1)
2696  {
2697  if(l_val > ps_chan->ps_taghe->l_events)
2698  {
2699  printf("Event index %d not found\n",l_val);
2700  return(GETEVT__NOTAG);
2701  }
2702  if(l_val == 0) l_val=1;
2703  ps_tag=(s_tag *)&s_tag_l;
2704  lseek(ps_chan->l_tagfile_no, (l_val-1)*sizeof(s_tag)+sizeof(s_taghe), SEEK_SET); /* set file offset*/
2705  if(read(ps_chan->l_tagfile_no,(CHARS *)ps_tag,sizeof(s_tag))!=sizeof(s_tag))
2706  {
2707  return(GETEVT__TAGRDERR);
2708  }
2709  if(ps_chan->l_tagswap)f_evt_swap((CHARS *)ps_tag,sizeof(s_tag));
2710  ps_chan->l_io_buf_posi=l_val; /* keeps index */
2711  }
2712  else
2713  {
2714  ps_tag=ps_chan->ps_tag;
2715  for(ii=1;ii<=ps_chan->ps_taghe->l_events;ii++)
2716  {
2717  if(ps_tag->l_event == l_val) break;
2718  ps_tag++;
2719  }
2720  if(ps_tag->l_event != l_val)
2721  {
2722  printf("Event number %d not found\n",l_val);
2723  return(GETEVT__NOTAG);
2724  }
2725  ps_chan->l_io_buf_posi=ii; /* keeps index of last event */
2726  }
2727  /* now we have the requested event in ps_tag */
2728  l_off=ps_tag->l_offset;
2729  if(l_off < 0) l_off=((-l_off)/ps_chan->ps_taghe->l_bufsize)*ps_chan->ps_taghe->l_bufsize;
2730  // l_evt = ps_tag->l_event;
2731  /* full event in buffer, read */
2732  if(ps_tag->l_offset > 0)
2733  {
2734  ps_ve10_1 = (s_ve10_1 *)c_temp;
2735  lseek(ps_chan->l_channel_no, l_off, SEEK_SET); /* set file offset*/
2736  if(read(ps_chan->l_channel_no,c_temp,8)!=8) return(GETEVT__RDERR);
2737  if(ps_chan->l_lmdswap)f_evt_swap(c_temp,8);
2738  if(read(ps_chan->l_channel_no,(CHARS *)&c_temp[8],ps_ve10_1->l_dlen*2)!=ps_ve10_1->l_dlen*2)return(GETEVT__RDERR);
2739  if(ps_chan->l_lmdswap)f_evt_swap((CHARS *)&c_temp[8],ps_ve10_1->l_dlen*2);
2740  /*ii=f_evt_type(NULL,(s_evhe *)ps_ve10_1,-1,0,1,1);*/
2741  }
2742  else
2743  /* spanning event begin, read to event buffer */
2744  {
2745  lseek(ps_chan->l_channel_no, l_off, SEEK_SET); /* set file offset to buffer begin */
2746  if(read(ps_chan->l_channel_no,c_temp,sizeof(s_bufhe))!=sizeof(s_bufhe)) return(GETEVT__RDERR);
2747  if(ps_chan->l_lmdswap)f_evt_swap(c_temp,sizeof(s_bufhe));
2748  /* is event buffer big enough? */
2749  l_evsize=ps_bufhe->l_free[1]+4; /* total words */
2750  if(ps_chan->l_evt_buf_size < l_evsize*2)
2751  {
2752  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
2753  ps_chan->l_evt_buf_size=l_evsize*2;
2754  ps_chan->pc_evt_buf=(CHARS *)malloc(ps_chan->l_evt_buf_size);
2755  }
2756  l_fragsize=0;
2757  ps_ve10_1 = (s_ve10_1 *)ps_chan->pc_evt_buf;
2758  lseek(ps_chan->l_channel_no, -ps_tag->l_offset, SEEK_SET); /* set file offset*/
2759  if(read(ps_chan->l_channel_no,ps_chan->pc_evt_buf,8)!=8) return(GETEVT__RDERR);
2760  if(ps_chan->l_lmdswap)f_evt_swap(ps_chan->pc_evt_buf,8);
2761  pc=ps_chan->pc_evt_buf+8;
2762  /* read fragment */
2763  if(read(ps_chan->l_channel_no,pc,ps_ve10_1->l_dlen*2)!=ps_ve10_1->l_dlen*2)return(GETEVT__RDERR);
2764  l_fragsize += ps_ve10_1->l_dlen+4; /* fragment size + header [w] */
2765  pc += ps_ve10_1->l_dlen*2; /* next in event buffer */
2766  ps_ve10_1->l_dlen=l_evsize-4; /* set correct event size */
2767  /* loop over fragments */
2768  while(l_fragsize < l_evsize)
2769  {
2770  l_off += ps_chan->ps_taghe->l_bufsize; /* next buffer absolut address */
2771  lseek(ps_chan->l_channel_no,l_off+sizeof(s_bufhe), SEEK_SET); /* set file offset*/
2772  if(read(ps_chan->l_channel_no,(CHARS *)&la_head,8)!=8) return(GETEVT__RDERR);
2773  if(ps_chan->l_lmdswap)f_evt_swap((CHARS *)&la_head,8);
2774  if(read(ps_chan->l_channel_no,pc,la_head[0]*2)!=la_head[0]*2) return(GETEVT__RDERR);
2775  pc += la_head[0]*2;
2776  l_fragsize += la_head[0];
2777  }
2778  /* now swap whole event in buffer */
2779  pc=ps_chan->pc_evt_buf+8; /* header already swapped */
2780  ps_ve10_1 = (s_ve10_1 *)ps_chan->pc_evt_buf;
2781  if(ps_chan->l_lmdswap)f_evt_swap(pc,ps_ve10_1->l_dlen*2);
2782  }
2783  *pl_event = (INTS4 *)ps_ve10_1;
2784  return(GETEVT__SUCCESS);
2785 } /* end of f_evt_ini_bufhe */
2786 
2787 /*1+ C Main ****************+******************************************/
2788 /*+ Module : f_evt_get_tagclose */
2789 /*--------------------------------------------------------------------*/
2790 /*+ CALLING : f_evt_get_tagclose(s_evt_channel) */
2791 /*--------------------------------------------------------------------*/
2792 /* */
2793 /*+ PURPOSE : Close tag and lmd file, cleanup s_evt_channel */
2794 /*+ ARGUMENTS : */
2795 /*+ channel : s_evt_channel* , must be allocated. */
2796 /*+ Return type : INTS4 */
2797 /*+ Declaration : */
2798 /* INTS4 f_evt_get_tagclose(s_evt_channel *); */
2799 /*+ FUNCTION : Create a tag file from lmd file */
2800 /*1- C Main ****************+******************************************/
2802 {
2803  /*=============================================*/
2804  if(ps_chan->ps_taghe == NULL)
2805  {
2806  f_evt_get_close(ps_chan);
2807  return(GETEVT__SUCCESS);
2808  }
2809  /*=============================================*/
2810  free(ps_chan->ps_taghe);
2811  if(ps_chan->ps_tag != NULL) free(ps_chan->ps_tag);
2812  if(ps_chan->pc_evt_buf != NULL) free(ps_chan->pc_evt_buf);
2813  close(ps_chan->l_tagfile_no);
2814  close(ps_chan->l_channel_no);
2815  memset((void *)ps_chan, 0, sizeof(s_evt_channel)); /* clear memory */
2816  return(GETEVT__SUCCESS);
2817 }
2818 
2820 {
2821  s_evt_channel *x;
2822  x = (s_evt_channel *)malloc(sizeof(s_evt_channel));
2823  if (x != NULL)
2824  memset(x, 0, sizeof(s_evt_channel));
2825  return(x);
2826  }
INTS4 l_buf_type
Definition: f_evt.h:56
#define GETEVT__NOSERVER
Definition: f_evt.h:136
INTS2 filhe_file_l
Definition: s_filhe.h:69
INTS4 l_last
Definition: f_evt.h:40
INTS4 f_evt_rev_port(INTS4 l_port)
Definition: f_evt.c:509
int f_evcli_evt(s_evt_channel *ps_chan)
Definition: f_evcli.c:478
CHARS h_end
Definition: s_bufhe.h:48
#define PUTEVT__SUCCESS
Definition: f_evt.h:147
#define GETEVT__SUCCESS
Definition: f_evt.h:131
CHARS filhe_file[86]
Definition: s_filhe.h:70
INTS4 l_channel_no
Definition: f_evt.h:58
#define PUTEVT__CLOSE_ERR
Definition: f_evt.h:152
s_tag * ps_tag
Definition: f_evt.h:88
INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d, INTS4 *pl_lwords)
Definition: f_evt.c:235
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
Definition: f_stccomm.c:1089
CHARS * pc_evt_buf
Definition: f_evt.h:79
INTS4 f_evt_type(s_bufhe *ps_bufhe, s_evhe *ps_evhe, INTS4 l_subid, INTS4 l_long, INTS4 l_hex, INTS4 l_data)
Definition: f_evt.c:298
INTS4 f_evt_tag_filter(s_ve10_1 *ps_ve10_1)
Definition: f_evt.c:2188
INTS4 l_first_buf
Definition: f_evt.h:76
#define GETLMD__EOFILE
Definition: fLmd.h:30
short INTS2
Definition: typedefs.h:26
#define LMD__INDEX
Definition: sMbs.h:26
INTS4 f_stc_read(void *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)
Definition: f_stccomm.c:134
INTS4 l_buffers
Definition: f_evt.h:36
#define LMD__LARGE_FILE
Definition: sMbs.h:28
INTS4 f_evt_get_close(s_evt_channel *ps_chan)
Definition: f_evt.c:1101
#define GETEVT__TIMEOUT
Definition: f_evt.h:140
INTS4 l_lmdswap
Definition: f_evt.h:86
sLmdControl * pLmd
Definition: f_evt.h:89
CHARS filhe_run[66]
Definition: s_filhe.h:75
INTS4 l_evt
Definition: s_bufhe.h:51
#define GETLMD__NOMORE
Definition: fLmd.h:31
INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan, CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
Definition: f_evt.c:552
s_bufhe s_bufhe_1
Definition: f_evt.h:81
INTS4 f_evt_get_buffer(s_evt_channel *ps_chan, INTS4 *ps_buffer)
Definition: f_evt.c:1693
INTS2 filhe_used
Definition: s_filhe.h:60
#define LMD__NO_OVERWRITE
Definition: sMbs.h:35
CHARS string[78]
Definition: s_filhe.h:22
INTS4 l_free[4]
Definition: s_bufhe.h:54
INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel)
Definition: f_stccomm.c:339
#define LMD__NO_INDEX
Definition: sMbs.h:34
INTS4 l_first_get
Definition: f_evt.h:74
CHARS filhe_exp[66]
Definition: s_filhe.h:77
INTS4 f_evt_timeout(s_evt_channel *ps_chan, INTS4 l_sec)
Definition: f_evt.c:1833
#define MAX_BUF_LGTH
Definition: f_evt.h:26
#define GETEVT__NOCHANNEL
Definition: f_evt.h:139
s_bufhe * ps_bufhe
Definition: f_evt.h:80
#define GETEVT__NOFILE
Definition: f_evt.h:135
#define PORT__TRANSPORT
Definition: portnum_def.h:21
INTS4 l_buf_size
Definition: f_evt.h:59
INTS4 f_evt_put_event(s_evt_channel *ps_chan, INTS4 *pl_evt_buf)
Definition: f_evt.c:1305
Definition: s_evhe.h:32
#define PUTEVT__TOOBIG
Definition: f_evt.h:150
#define GETEVT__FAILURE
Definition: f_evt.h:132
INTS2 filhe_subtype
Definition: s_filhe.h:59
#define GETEVT__TAGWRERR
Definition: f_evt.h:144
INTS2 i_subtype
Definition: s_bufhe.h:46
INTS4 l_bufs_in_stream
Definition: f_evt.h:63
INTS2 i_type
Definition: s_ve10_1.h:38
#define GETEVT__NOLMDFILE
Definition: f_evt.h:145
uint32_t fLmdGetMbsEvent(sLmdControl *pLmdControl, sMbsHeader **event)
Definition: fLmd.c:321
INTS4 filhe_lines
Definition: s_filhe.h:78
int f_evcli_close(s_evt_channel *ps_chan)
Definition: f_evcli.c:498
#define RFIO_lseek
Definition: f_evt.c:150
INTS2 i_type
Definition: s_evhe.h:35
INTS4 f_evt_source_port(INTS4 l_port)
Definition: f_evt.c:486
INTS4 l_first_put
Definition: f_evt.h:75
#define RFIO_open
Definition: f_evt.c:147
INTS4 f_evt_error(INTS4 l_error, CHARS *pc_dest, INTS4 l_out)
Definition: f_evt.c:1586
#define GETEVT__EVENT
Definition: f_evt.h:123
uint32_t fLmdGetElement(sLmdControl *pLmdControl, uint32_t iEvent, sMbsHeader **event)
Definition: fLmd.c:601
int l
Definition: f_mbs_status.c:31
#define GETEVT__NOMORE
Definition: f_evt.h:134
#define MIN_BUF_LGTH
Definition: f_evt.h:27
INTS4 l_filesize
Definition: f_evt.h:38
#define PUTEVT__FAILURE
Definition: f_evt.h:149
INTS4 l_buf_no
Definition: f_evt.h:60
s_taghe * ps_taghe
Definition: f_evt.h:87
INTS2 filhe_type
Definition: s_filhe.h:58
CHARS * pc_io_buf
Definition: f_evt.h:78
#define STC__TIMEOUT
Definition: f_stccomm.h:374
INTS4 f_stc_discclient(INTS4 i_channel)
Definition: f_stccomm.c:1170
CHARS * f_evt_get_buffer_ptr(s_evt_channel *ps_chan)
Definition: f_evt.c:1928
#define GETEVT__NOTAGFILE
Definition: f_evt.h:141
uint32_t fLmdInitMbs(sLmdControl *pLmdControl, char *Nodename, uint32_t iMaxBytes, uint32_t iBuffers, uint32_t iStreams, uint32_t iPort, uint32_t iTimeout)
Definition: fLmd.c:282
uint32_t fLmdPutClose(sLmdControl *pLmdControl)
Definition: fLmd.c:251
static int l_gl_source_port
Definition: f_evt.c:177
uint32_t fLmdGetClose(sLmdControl *pLmdControl)
Definition: fLmd.c:684
INTS4 l_evt_buf_posi
Definition: f_evt.h:68
INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
Definition: f_stccomm.c:494
INTS4 l_offset
Definition: f_evt.h:47
INTS2 i_type
Definition: s_bufhe.h:45
unsigned int INTU4
Definition: typedefs.h:29
int f_evcli_buf(s_evt_channel *ps_chan)
Definition: f_evcli.c:375
#define GETEVT__NOTAG
Definition: f_evt.h:142
#define STC__SUCCESS
Definition: f_stccomm.h:369
#define MAX_LONG
Definition: f_evt.h:29
struct cv_string s_strings[30]
Definition: s_filhe.h:79
INTS4 l_dlen
Definition: s_bufhe.h:44
INTS4 l_dlen
Definition: s_ve10_1.h:37
#define GETEVT__RDERR
Definition: f_evt.h:137
INTS2 filhe_user_l
Definition: s_filhe.h:71
#define GETEVT__TRANS
Definition: f_evt.h:122
INTS4 l_stream_bufs
Definition: f_evt.h:64
s_evt_channel * f_evt_control(void)
Definition: f_evt.c:2819
INTS4 l_first
Definition: f_evt.h:39
INTS4 f_evt_get_newbuf(s_evt_channel *)
Definition: f_evt.c:1949
INTS4 f_evt_cre_tagfile(CHARS *pc_lmd, CHARS *pc_tag, INTS4(*e_filter)(s_ve10_1 *))
Definition: f_evt.c:2206
int l_status
Definition: f_evcli.c:169
INTS4 l_tagswap
Definition: f_evt.h:85
INTS4 l_dlen
Definition: s_ves10_1.h:37
#define LMD__BUFFER
Definition: sMbs.h:30
#define LMD__TIMEOUT
Definition: fLmd.h:36
int INTS4
Definition: typedefs.h:28
CHARS h_begin
Definition: s_bufhe.h:49
INTS4 f_evt_check_buf(CHARS *, INTS4 *, INTS4 *, INTS4 *, INTS4 *)
Definition: f_evt.c:2041
INTS4 filhe_dlen
Definition: s_filhe.h:57
INTS4 f_evt_get_tagnext(s_evt_channel *ps_chan, INTS4 l_skip, INTS4 **pl_event)
Definition: f_evt.c:2594
INTS4 l_tagfile_no
Definition: f_evt.h:84
INTS4 f_evt_ini_bufhe(s_evt_channel *ps_chan)
Definition: f_evt.c:2132
#define GETEVT__FRAGMENT
Definition: f_evt.h:133
#define PUTEVT__TOO_SMALLS
Definition: f_evt.h:151
INTS2 i_subtype
Definition: s_evhe.h:36
#define PUTEVT__WRERR
Definition: f_evt.h:153
CHARS filhe_label[30]
Definition: s_filhe.h:68
CHARS filhe_time[24]
Definition: s_filhe.h:73
CHARS filhe_user[30]
Definition: s_filhe.h:72
Definition: f_evt.h:31
#define RFIO_close
Definition: f_evt.c:148
static CHARS c_temp[MAX_BUF_LGTH]
Definition: f_evt.c:176
INTS4 l_endian
Definition: f_evt.h:33
#define GETEVT__REVSERV
Definition: f_evt.h:124
INTS4 l_evt_size
Definition: f_evt.h:69
uint32_t fLmdGetOpen(sLmdControl *pLmdControl, char *Filename, sMbsFileHeader *pBuffHead, uint32_t iBytes, uint32_t iUseOffset)
Definition: fLmd.c:398
INTS2 i_trigger
Definition: s_ve10_1.h:41
#define PUTEVT__FILE_EXIST
Definition: f_evt.h:148
INTS2 filhe_label_l
Definition: s_filhe.h:67
CHARS c_channel[128]
Definition: f_evt.h:83
INTS4 f_evt_put_buffer(s_evt_channel *ps_chan, s_bufhe *ps_bufhe)
Definition: f_evt.c:1448
#define PORT__EVENT_SERV
Definition: portnum_def.h:24
INTS4 l_events
Definition: f_evt.h:37
INTS4 l_frag_len
Definition: f_evt.h:77
INTS4 l_bufsize
Definition: f_evt.h:35
uint32_t fLmdCloseMbs(sLmdControl *pLmdControl)
Definition: fLmd.c:303
INTS4 f_evt_skip_buffer(s_evt_channel *ps_chan, INTS4 l_buffer)
Definition: f_evt.c:1779
#define PUTEVT__NOCHANNEL
Definition: f_evt.h:154
INTS4 l_timeout
Definition: f_evt.h:70
static struct s_tcpcomm s_tcpcomm_st_evt
Definition: f_evt.c:175
INTS4 f_evt_get_tagopen(s_evt_channel *ps_chan, CHARS *pc_tag, CHARS *pc_lmd, CHARS **ps_head, INTS4 l_prihe)
Definition: f_evt.c:2470
#define MAX__DLEN
Definition: s_bufhe.h:21
INTS4 f_ut_utime(INTS4, INTS4, CHARS *)
Definition: f_ut_utime.c:57
INTS4 f_evt_get_tagevent(s_evt_channel *ps_chan, INTS4 l_value, INTS4 l_type, INTS4 **pl_event)
Definition: f_evt.c:2643
INTS4 l_io_buf_size
Definition: f_evt.h:65
INTS2 filhe_run_l
Definition: s_filhe.h:74
INTS4 f_evt_put_close(s_evt_channel *ps_chan)
Definition: f_evt.c:1493
INTS4 l_current_i
Definition: s_bufhe.h:52
INTS4 f_evt_swap(CHARS *pc_source, INTS4 l_length)
Definition: f_evt.c:1853
INTS4 l_buf_posi
Definition: f_evt.h:61
#define PORT__STREAM_SERV
Definition: portnum_def.h:23
uint32_t fLmdPutElement(sLmdControl *pLmdControl, sMbsHeader *pHeader)
Definition: fLmd.c:145
Definition: f_evt.h:44
#define LMD__TYPE_FILE_HEADER_101_1
Definition: sMbs.h:17
#define RFIO_read
Definition: f_evt.c:149
INTS2 filhe_exp_l
Definition: s_filhe.h:76
INTS4 filhe_stime[2]
Definition: s_filhe.h:65
INTS4 l_dlen
Definition: s_evhe.h:34
uint32_t fLmdPutOpen(sLmdControl *pLmdControl, char *Filename, sMbsFileHeader *pBuffHead, uint32_t iBytes, uint32_t iOver, uint32_t iUseOffset, uint32_t iLargeFile)
Definition: fLmd.c:71
INTS4 l_buf
Definition: s_bufhe.h:50
struct s_tcpcomm * pTCP
Definition: fLmd.h:65
INTS4 l_time[2]
Definition: s_bufhe.h:53
#define own_getpid
Definition: f_evt.c:156
#define GETLMD__NOBUFFER
Definition: fLmd.h:32
INTS4 l_linear
Definition: f_evt.h:41
#define GETEVT__TAGRDERR
Definition: f_evt.h:143
sLmdControl * fLmdAllocateControl(void)
Definition: fLmd.c:773
INTS4 l_event
Definition: f_evt.h:46
INTS2 i_subtype
Definition: s_ve10_1.h:39
INTS4 f_evt_put_open(CHARS *pc_file, INTS4 l_size, INTS4 l_stream, INTS4 l_type, INTS4 l_subtype, s_evt_channel *ps_chan, CHARS *ps_filhe)
Definition: f_evt.c:1192
char CHARS
Definition: typedefs.h:21
INTS4 filhe_free[4]
Definition: s_filhe.h:66
INTS4 l_buf_subtype
Definition: f_evt.h:57
INTS4 f_evt_get_tagclose(s_evt_channel *ps_chan)
Definition: f_evt.c:2801
INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
Definition: f_evt.c:909
INTS2 i_used
Definition: s_bufhe.h:47
uint32_t fLmdPutBuffer(sLmdControl *pLmdControl, sMbsHeader *pHeader, uint32_t Items)
Definition: fLmd.c:205
#define GETEVT__FILE
Definition: f_evt.h:120
s_ve10_1 * ps_ve10_1
Definition: f_evt.h:82
#define GETEVT__RFIO
Definition: f_evt.h:125
int f_evcli_con(s_evt_channel *ps_chan, char *pc_node, int l_aport, int l_aevents, int l_asample)
Definition: f_evcli.c:185
#define GETEVT__STREAM
Definition: f_evt.h:121
INTS4 f_evt_swap_filhe(s_bufhe *)
Definition: f_evt.c:1890
void(* cb_polling)(void)
Definition: f_evt.h:90
#define GETEVT__CLOSE_ERR
Definition: f_evt.h:138
INTS4 l_count
Definition: s_ve10_1.h:42
INTS4 l_io_buf_posi
Definition: f_evt.h:66
INTS4 l_evt_buf_size
Definition: f_evt.h:67
INTS4 l_server_type
Definition: f_evt.h:55
INTS4 l_buf_lmt
Definition: f_evt.h:62