GSI Object Oriented Online Offline (Go4)  GO4-6.1.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
f_evt.c
Go to the documentation of this file.
1 // $Id: f_evt.c 3081 2021-03-17 15:18:55Z linev $
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 #if MBS_ENDIAN == 1
138 #include "s_filhe_swap.h"
139 #else
140 #include "s_filhe.h"
141 #endif
142 
143 
144 #ifdef RFIO
145 #define RFIO_open rfio_open
146 #define RFIO_close rfio_close
147 #define RFIO_read rfio_read
148 #define RFIO_lseek rfio_lseek
149 #include "rawapin.h" /* RFIO stuff */
150 #else
151 #define RFIO_open open
152 #define RFIO_close close
153 #define RFIO_read read
154 #define RFIO_lseek lseek
155 #endif
156 
157 #ifdef GSI__WINNT
158 #define own_getpid _getpid
159 #else
160 #define own_getpid getpid
161 #endif
162 
163 
164 // DABC
165 #include "fLmd.h"
166 // -- DABC
167 
168 #include "gps_sc_def.h"
169 #include "f_evt.h"
170 #include "f_evcli.h"
171 #include "portnum_def.h"
172 
178 
181 static int l_gl_source_port = 0;
182 
183 /*1+ C Procedure *************+****************************************/
184 /* */
185 /*+ Module : f_evt__example */
186 /* */
187 /*--------------------------------------------------------------------*/
188 /*+ CALLING : Examples for calling event API */
189 /*--------------------------------------------------------------------*/
190 /* */
191 /*+ PURPOSE : See f_evt_examples.c */
192 /* */
193 /* */
194 /*2+Implementation************+****************************************/
195 /*+ User Example : In m_lea_user.c */
196 /*+ Channel structure : defined in f_evt.h */
197 /*+ File name : f_evt.c */
198 /*+ Version : 1.01 */
199 /*+ Author : H.Essel */
200 /*+ Created : 16-Feb-2000 */
201 /*+ Updates : Date Purpose */
202 /*1- C Procedure *************+****************************************/
203 
204 
205 /*****************+***********+****************************************/
206 /* */
207 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
208 /* Postfach 11 05 52 */
209 /* D-64220 Darmstadt */
210 /* */
211 /*1+ C Procedure *************+****************************************/
212 /* */
213 /*+ Module : f_evt_get_subevent */
214 /* */
215 /*--------------------------------------------------------------------*/
216 /*+ CALLING : l_sts = f_evt_get_subevent(ve10_1 *,subevent,**head,**data,*lwords) */
217 /*--------------------------------------------------------------------*/
218 /* */
219 /*+ PURPOSE : get subevent pointer */
220 /* */
221 /*+ ARGUMENTS : */
222 /* */
223 /*+ ve10_1 : (s_ve10_1 *) event header pointer */
224 /*+ subevent : subevent number (1,2,3...) */
225 /* If = 0, f_evt_get_subevent returns the number of */
226 /* subevents. In this case the following arguments */
227 /* might be NULL. */
228 /*+ head : Address of s_ves10_1 subevent header pointer */
229 /*+ data : Address of INTS4 event data pointer */
230 /*+ lwords : Address of INTS4 to get number of data longwords */
231 /* */
232 /*+ Return type : int */
233 /*- GETEVT__SUCCESS : Found subevent. */
234 /*- GETEVT__NOMORE : No more subevents. */
235 /*+ Declaration : */
236 /* INTS4 f_evt_get_subevent( */
237 /* s_ve10_1 *, INTS4, INTS4 **, INTS4 **, INTS4 *); */
238 /*1- C Procedure *************+****************************************/
239 INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d,INTS4 *pl_lwords)
240 {
241  s_ves10_1 *ps_ves10_1;
242  INTS4 l_total,l_sub,l_sum;
243  INTS4 ll,*pl_next;
244 
245  if(ps_ve10_1 == NULL) return(GETEVT__FAILURE);
246  pl_next = (INTS4 *) (ps_ve10_1 + 1);
247  l_total = ps_ve10_1->l_dlen-4; /* total words in subevents */
248  l_sum = 0;
249  ll=0;
250  while(l_sum < l_total)
251  {
252  ps_ves10_1 = (s_ves10_1 *) pl_next;
253  ll++;
254  if(ll == l_subevent)
255  {
256  if(pl_lwords != NULL) *pl_lwords = ps_ves10_1->l_dlen/2-1;
257  if(pl_se != NULL) *pl_se = (INTS4 *) ps_ves10_1;
258  if(pl_d != NULL) *pl_d = (INTS4 *) (ps_ves10_1+1);
259  return(GETEVT__SUCCESS);
260  }
261  l_sub = ps_ves10_1->l_dlen+4; /* total words of subevent */
262  l_sum += l_sub;
263  pl_next = (INTS4 *)(ps_ves10_1);
264  pl_next += l_sub/2;
265  }
266  if(pl_lwords != NULL) *pl_lwords = ll;
267  if(pl_se != NULL) *pl_se = NULL;
268  if(pl_d != NULL) *pl_d = NULL;
269  if(l_subevent == 0) return(ll);
270  else return(GETEVT__NOMORE);
271 }
272 /*****************+***********+****************************************/
273 /* */
274 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
275 /* Postfach 11 05 52 */
276 /* D-64220 Darmstadt */
277 /* */
278 /*1+ C Procedure *************+****************************************/
279 /* */
280 /*+ Module : f_evt_type */
281 /* */
282 /*--------------------------------------------------------------------*/
283 /*+ CALLING : l_status = f_evt_type(bufhe,evhe,sid,long,hex,data) */
284 /*--------------------------------------------------------------------*/
285 /* */
286 /*+ PURPOSE : print event */
287 /* */
288 /*+ ARGUMENTS : */
289 /* */
290 /*+ bufhe : (s_bufhe *) buffer header pointer (=NULL no output) */
291 /*+ evhe : (s_evhe *) event header pointer (=NULL no output) */
292 /*+ sid : subevent ID (-1 is all) */
293 /*+ long : output longwords */
294 /*+ hex : output hex longwords */
295 /*+ data : output data */
296 /* */
297 /*+ Return type : int */
298 /*+ Declaration : */
299 /* INTS4 f_evt_type( */
300 /* s_bufhe *,s_evhe *, INTS4, INTS4, INTS4, INTS4); */
301 /*1- C Procedure *************+****************************************/
302 INTS4 f_evt_type(s_bufhe *ps_bufhe,s_evhe *ps_evhe, INTS4 l_subid,INTS4 l_long,INTS4 l_hex,INTS4 l_data)
303 {
304  s_ves10_1 *ps_ves10_1;
305  s_ve10_1 *ps_ve10_1;
306  s_filhe *ps_filhe;
307  INTS4 *pl_data;
308  INTS4 l_s;
309  INTS4 l, ll, l_status, l_ldata, l_used;
310  CHARS c_line[132];
311  CHARS c_full[132];
312  CHARS c_time[32];
313 
314  strcpy(c_full," ");
315  l_ldata=l_data;
316  if((l_hex+l_long) > 0) l_ldata=1;
317 
318  /* Print buffer header (file header) */
319  if(ps_bufhe != NULL)
320  {
321  sprintf(c_line,"--------------------------------------------------------");
322  printf("%s\n",c_line);
323  /* calculate real buffer size */
324  ll=ps_bufhe->l_dlen*2;
325  if(ll%512 > 0)ll += 512-ll%512;
326  /* file header */
327  l_status = f_ut_utime(ps_bufhe->l_time[0],ps_bufhe->l_time[1],c_time);
328  if(ps_bufhe->i_type == 2000)
329  {
330  ps_filhe=(s_filhe *)ps_bufhe;
331  sprintf(c_line,"File header info:");
332  printf("%s\n",c_line);
333  sprintf(c_line,"Size: %d [%d b], used %d [b]",ps_filhe->filhe_dlen,ll,ps_filhe->filhe_used*2);
334  printf("%s\n",c_line);
335  sprintf(c_line,"Label: %s",ps_filhe->filhe_label);
336  printf("%s\n",c_line);
337  sprintf(c_line,"File: %s",ps_filhe->filhe_file);
338  printf("%s\n",c_line);
339  sprintf(c_line,"User: %s",ps_filhe->filhe_user);
340  printf("%s\n",c_line);
341  sprintf(c_line,"Time: %s",ps_filhe->filhe_time);
342  printf("%s\n",c_line);
343  sprintf(c_line,"Run: %s",ps_filhe->filhe_run);
344  printf("%s\n",c_line);
345  sprintf(c_line,"Exp: %s",ps_filhe->filhe_exp);
346  printf("%s\n",c_line);
347  for(ll=0;ll<ps_filhe->filhe_lines;ll++)
348  {
349  sprintf(c_line,"comment: %s",ps_filhe->s_strings[ll].string);
350  printf("%s\n",c_line);
351  }
352  }
353  else
354  {
355  l_used=ps_bufhe->i_used;
356  if(ps_bufhe->l_dlen > MAX__DLEN)l_used=ps_bufhe->l_free[2];
357  sprintf(c_line,"Buffer %9d, Length %5d[w] Size %5d[b] used %5d[w] %s",
358  ps_bufhe->l_buf,
359  ps_bufhe->l_dlen,
360  ll,l_used,
361  c_time);
362  printf("%s\n",c_line);
363  sprintf(c_line," Events %3d Type/Subtype %5d %5d FragEnd=%d FragBegin=%d Total %5d[w]",
364  ps_bufhe->l_evt,
365  ps_bufhe->i_type,
366  ps_bufhe->i_subtype,
367  ps_bufhe->h_end,
368  ps_bufhe->h_begin,
369  ps_bufhe->l_free[1]);
370  printf("%s\n",c_line);
371  }
372  sprintf(c_line,"--------------------------------------------------------");
373  printf("%s\n",c_line);
374  }
375 
376  if(ps_evhe == NULL) return(0);
377 
378  /* print event 4,x or 6,x */
379  if(ps_evhe->i_type != 10)
380  {
381  sprintf(c_line,"Event type %d, subtype %d, data longwords %d",
382  ps_evhe->i_type,ps_evhe->i_subtype,ps_evhe->l_dlen/2);
383  printf("%s\n",c_line);
384  if((l_ldata != 0) & ((ps_evhe->i_type == 4)|(ps_evhe->i_type == 6)))
385  { /* output data, assume data as longword */
386  pl_data = (INTS4 *)ps_evhe;
387  pl_data += 2;
388  for(l=0;l<ps_evhe->l_dlen/2;l++)
389  {
390  sprintf(c_line,"%08x ",*pl_data);
391  strncat(c_full, c_line, sizeof(c_full)-1);
392  pl_data++;
393  if(l%8 == 7) {
394  printf("%s\n",c_full);
395  strcpy(c_full," ");
396  }
397  }
398  if(strlen(c_full) > 2) printf("%s\n",c_full);
399  }
400  return(0);
401  }
402 
403  /* Print event 10,1 */
404  ps_ve10_1 = (s_ve10_1 *)ps_evhe;
405  /* Print event header */
406  sprintf(c_line,"Event %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d",
407  ps_ve10_1->l_count,
408  ps_ve10_1->i_type,
409  ps_ve10_1->i_subtype,
410  ps_ve10_1->l_dlen,
411  ps_ve10_1->i_trigger);
412  printf("%s\n",c_line);
413 
414  /********************/
415  l_s=0;
416  l_status=0;
417  while(l_status == 0)
418  {
419  l_s++;
420  l_status=f_evt_get_subevent(ps_ve10_1,l_s,(INTS4 **)&ps_ves10_1,(INTS4 **)&pl_data,(INTS4 *)&ll);
421  if(l_status == 0)
422  {
423  if((l_subid < 0)|(l_subid == ps_ves10_1->i_procid))
424  {
425  sprintf(c_line," SubEv ID %6d Type/Subtype %5d %5d Length %5d[w] Control %2d Subcrate %2d",
426  ps_ves10_1->i_procid,
427  ps_ves10_1->i_type,
428  ps_ves10_1->i_subtype,
429  ps_ves10_1->l_dlen,
430  ps_ves10_1->h_control,
431  ps_ves10_1->h_subcrate);
432  printf("%s\n",c_line);
433  if(l_ldata != 0)
434  { /* output data */
435  if((l_long != 0) | (l_hex != 0))
436  { /* In this case we assume data as one longword per channel */
437  for(l=0;l<ll;l++)
438  {
439  if(l_hex != 0) sprintf(c_line,"%04x.%04x ",(*pl_data>>16)&0xffff,*pl_data&0xffff);
440  else sprintf(c_line,"%8d ",*pl_data);
441  strncat(c_full, c_line, sizeof(c_full)-1);
442  pl_data++;
443  if(l%8 == 7)
444  {
445  printf("%s\n",c_full);
446  strcpy(c_full," ");
447  }
448  }
449  if(strlen(c_full) > 2)printf("%s\n",c_full);
450  strcpy(c_full," ");
451  }
452  else
453  { /* In this case we assume data as two words per channel */
454  for(l=0;l<ll;l++)
455  {
456  sprintf(c_line,"%8d%8d",*pl_data&0xffff,(*pl_data>>16)&0xffff);
457  strncat(c_full, c_line, sizeof(c_full)-1);
458  pl_data++;
459  if(l%4 == 3)
460  {
461  printf("%s\n",c_full);
462  strcpy(c_full," ");
463  }
464  }
465  if(strlen(c_full) > 2)printf("%s\n",c_full);
466  strcpy(c_full," ");
467  }
468  }
469  }
470  }
471  }
472  return(0);
473 }
474 
475 /*1+ C Main ****************+******************************************/
476 /*+ Module : f_evt_source_port */
477 /*--------------------------------------------------------------------*/
478 /*+ CALLING : f_evt_source_port(long l_port) */
479 /*--------------------------------------------------------------------*/
480 /* */
481 /*+ PURPOSE : f_evt_source_port sets port number for event source */
482 /*+ ARGUMENTS : */
483 /*+ l_port : Port number: */
484 /*+ Return type : int. */
485 /*+ Status codes: */
486 /*- GETEVT__SUCCESS : success. */
487 /*+ Declaration : */
488 /* INTS4 f_evt_source_port(INTS4); */
489 /*1- C Main ****************+******************************************/
491 {
492  l_gl_source_port=l_port;
493  if (l_port>0) printf("Use MBS source port %d\n",l_port);
494  return 0;
495 }
496 
497 
498 /*1+ C Main ****************+******************************************/
499 /*+ Module : f_evt_rev_port */
500 /*--------------------------------------------------------------------*/
501 /*+ CALLING : f_evt_rev_port(long l_port) */
502 /*--------------------------------------------------------------------*/
503 /* */
504 /*+ PURPOSE : f_evt_rev_port sets port number for event server */
505 /*+ ARGUMENTS : */
506 /*+ l_port : Port number: */
507 /*+ Return type : int. */
508 /*+ Status codes: */
509 /*- GETEVT__SUCCESS : success. */
510 /*+ Declaration : */
511 /* INTS4 f_evt_rev_port(INTS4); */
512 /*1- C Main ****************+******************************************/
514 {
515  l_gl_source_port=l_port;
516  if (l_port>0) printf("Use MBS source port %d\n",l_port);
517  return 0;
518 }
519 
520 /*1+ C Main ****************+******************************************/
521 /*+ Module : f_evt_get_open */
522 /*--------------------------------------------------------------------*/
523 /*+ CALLING : f_evt_get_open(long l_mode, char &c_server[], s_evt_channel &s_chan, */
524 /* char **ps_info, long l_sample,l_para)*/
525 /*--------------------------------------------------------------------*/
526 /* */
527 /*+ PURPOSE : f_evt_get_open opens an event stream from specified*/
528 /* channel. */
529 /*+ ARGUMENTS : */
530 /*+ l_mode : Type of server: */
531 /*- GETEVT__FILE : Input from file */
532 /*- GETEVT__STREAM : Input from MBS stream server */
533 /*- GETEVT__TRANS : Input from MBS transport */
534 /*- GETEVT__EVENT : Input from MBS event server */
535 /*- GETEVT__REVSERV: Input from remote event server */
536 /*+ c_server : Node of server or file name. */
537 /*+ s_chan : structure s_evt_channel, must be allocated. */
538 /*+ ps_info : address of pointer. If it is not NULL, then */
539 /* try to return file header or other information */
540 /* about server. If it is NULL, then returns nothing. */
541 /*+ l_sample : used by event server to send only every */
542 /* 'l_sample' event. */
543 /*+ l_para : currently not used */
544 /*+ Return type : int. */
545 /*+ Status codes: */
546 /*- GETEVT__SUCCESS : success. */
547 /*- GETEVT__NOFILE : file does not exist. */
548 /*- GETEVT__RDERR : read server error. */
549 /*- GETEVT__NOSERVER : can not connect server. */
550 /*+ Declaration : */
551 /* INTS4 f_evt_get_open( */
552 /* INTS4, CHARS *, s_evt_channel *, CHARS **, INTS4, INTS4); */
553 /*+ FUNCTION : Opens the input channel and save context in s_chan. */
554 /*+ NOTE : Up to four input channels can be opened. */
555 /*1- C Main ****************+******************************************/
556 INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan,
557  CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
558 {
559 
560  INTS4 l_swap, l_swap_head, l_is_goosybuf, l_filehead=0, l_size, l_size_head, l_dummy, l_header_size, l_port;
561  CHARS c_file[256], *pc_temp;
562  s_filhe *ps_filhe;
563  INTS4 l_status;
564 
565  ps_chan->cb_polling = NULL;
566 
567  l_port = l_gl_source_port;
568 
569 #ifndef GSI__WINNT
570 // disable automatic detection of RFIO on Windows while file name can contain ":"
571  if((pc_temp=strchr(pc_server,':')) != NULL) {
572  l_mode=GETEVT__RFIO;
573  /* printf("rfio file %s\n",pc_server);*/
574  }
575 #endif
576 
577 #ifndef RFIO
578  if(l_mode == GETEVT__RFIO)
579  {
580  printf("rfio not supported!\n");
581  return(GETEVT__NOFILE);
582  }
583 #endif
584 
585  if(ps_info != NULL) *ps_info=NULL;
586  // when timeout is already set by f_evt_timeout(), do not overwrite
587  if(ps_chan->l_timeout==0)ps_chan->l_timeout=-1; /* no timeout */
588  strcpy(ps_chan->c_channel,pc_server);
589  switch(l_mode) {
590  case GETEVT__FILE :
591  strcpy(c_file,pc_server);
592  if(strlen(c_file) < 5) strncat(c_file, ".lmd", sizeof(c_file)-1);
593  else {
594  pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
595  if((strcmp(pc_temp,".LMD") != 0) &&
596  (strcmp(pc_temp,".lmd") != 0)) strncat(c_file, ".lmd", sizeof(c_file)-1);
597  }
598 
599  if((ps_chan->l_channel_no=open(c_file,GET__OPEN_FLAG))== -1)
600  {
601  return(GETEVT__NOFILE);
602  }
603  /* read first 512 bytes */
604  if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
605  printf("LMD format error: no LMD file: %s\n",c_file);
606  close(ps_chan->l_channel_no);
607  ps_chan->l_channel_no=-1;
608  return(GETEVT__NOLMDFILE);
609  }
610 // DABC
611  ps_chan->pLmd=NULL;
612  if((*((INTS4 *)(c_temp+4)) == LMD__TYPE_FILE_HEADER_101_1)||
613  (*((INTS4 *)(c_temp+4)) == 0x65000100)){
614  close(ps_chan->l_channel_no);
615  ps_chan->pLmd=fLmdAllocateControl();
616  fLmdGetOpen(ps_chan->pLmd,c_file,NULL,LMD__BUFFER,LMD__NO_INDEX);
617  ps_chan->l_server_type=l_mode;
618  return GETEVT__SUCCESS;
619  }
620 // -- DABC
621  /* check for file header, return size and swap */
622  f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
623  if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0)) {
624  printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
625  close(ps_chan->l_channel_no);
626  ps_chan->l_channel_no=-1;
627  return(GETEVT__NOLMDFILE);
628  }
629 
630  /* read file header and first buffer and check for goosy header */
631  if(l_filehead == 1) {
632  lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
633  l_header_size=l_size_head;
634  if(((s_filhe *)c_temp)->filhe_dlen > MAX__DLEN){
635  l_header_size=((s_filhe *)c_temp)->filhe_used*2+48;
636  // printf("Large buffer, read short header %d bytes\n",l_header_size);
637  }
638  if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size){
639  printf("LMD format error: no LMD file: %s\n",c_file);
640  close(ps_chan->l_channel_no);
641  ps_chan->l_channel_no=-1;
642  return(GETEVT__NOLMDFILE);
643  }
644  if(read(ps_chan->l_channel_no,c_temp,MIN_BUF_LGTH)!=MIN_BUF_LGTH) {
645  close(ps_chan->l_channel_no);
646  ps_chan->l_channel_no=-1;
647  return(GETEVT__RDERR);
648  }
649  f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
650  if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head)) {
651  printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
652  close(ps_chan->l_channel_no);
653  ps_chan->l_channel_no=-1;
654  return(GETEVT__NOLMDFILE);
655  }
656  }/* check buffer behind header */
657  ps_chan->l_buf_size=l_size_head;
658  lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
659  if(ps_info != NULL) *ps_info=NULL;
660  /* found file header */
661  if(l_filehead == 1) {
662  if(read(ps_chan->l_channel_no,c_temp,l_header_size)!=l_header_size) {
663  printf("LMD format error: no LMD file: %s\n",c_file);
664  close(ps_chan->l_channel_no);
665  ps_chan->l_channel_no=-1;
666  return(GETEVT__NOLMDFILE);
667  }
668  ps_filhe = (s_filhe *) c_temp;
669  if(ps_info != NULL) {/* if user want file header be returned */
670  if( l_swap_head ==1) f_evt_swap_filhe((s_bufhe *)ps_filhe);
671  *ps_info=c_temp; /* now , get file header and return */
672  }
673  /*
674  printf("type %d, subtype %d\n",ps_filhe->filhe_type,ps_filhe->filhe_subtype);
675  printf("strings %d %d %d %d %d %x\n",
676  ps_filhe->filhe_label_l,
677  ps_filhe->filhe_file_l,
678  ps_filhe->filhe_user_l,
679  ps_filhe->filhe_run_l,
680  ps_filhe->filhe_exp_l,
681  ps_filhe->filhe_lines);
682  pi=(INTS2 *)&ps_filhe->s_strings;
683  for(l_dummy=0;l_dummy<ps_filhe->filhe_lines;l_dummy++)
684  {
685  printf("comment %d, %s\n",*pi,(c_temp+366+l_dummy*80));
686  pi += 40;
687  }
688  */
689  } /* file header */
690 
691  /* points to a real buffer start */
692  /* and read header buffer, if there */
693  ps_chan->l_io_buf_size=ps_chan->l_buf_size;
694  /* may larger, but must multiplexed */
695  break;
696  case GETEVT__STREAM :
697 
698  if (l_port<=0) l_port = PORT__STREAM_SERV;
699 
700  /* initialize connection with stream server */
701  if(f_stc_connectserver(pc_server,l_port,&ps_chan->l_channel_no,
703  {
704  return(GETEVT__NOSERVER);
705  }
706 
707  l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
708  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
709  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
710 
711  if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
712  ps_chan->l_buf_size=*((INTS4 *)(c_temp+4)); /* buffer size */
713  ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
714  /* # buffers per stream */
715  ps_chan->l_stream_bufs = 0; /* counter */
716 
717  ps_chan->l_io_buf_size=(ps_chan->l_buf_size)*(ps_chan->l_bufs_in_stream);
718 // DABC
719  ps_chan->pLmd=NULL;
720  if(*((INTS4 *)(c_temp+12)) == 0) {
721  ps_chan->pLmd=fLmdAllocateControl();
722  ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
723  // SL: we should deliver default portnumber while it is used only to identify transport
724  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);
725  printf("f_evt_get_open for STREAM: port=%d timeout=%d \n",l_port, ps_chan->l_timeout);
726 
727  ps_chan->l_server_type=l_mode;
728  return GETEVT__SUCCESS;
729  }
730 // -- DABC
731  break;
732  case GETEVT__TRANS :
733 
734  if (l_port<=0) l_port = PORT__TRANSPORT;
735 
736  /* initialize connection with stream server */
737  if(f_stc_connectserver(pc_server,l_port,&ps_chan->l_channel_no,
739  {
740  return(GETEVT__NOSERVER);
741  }
742 
743  l_status=f_stc_read(c_temp,16,ps_chan->l_channel_no,ps_chan->l_timeout);
744  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
745  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
746 
747  if( *((INTS4 *)(c_temp))!=1)f_evt_swap(c_temp, 16);
748  ps_chan->l_buf_size=*((INTS4 *)(c_temp+4)); /* buffer size */
749  ps_chan->l_bufs_in_stream=*((INTS4 *)(c_temp+8));
750  /* # buffers per stream */
751  ps_chan->l_io_buf_size=ps_chan->l_buf_size;
752 // DABC
753  ps_chan->pLmd=NULL;
754  if(*((INTS4 *)(c_temp+12)) == 0) {
755  ps_chan->pLmd=fLmdAllocateControl();
756  ps_chan->pLmd->pTCP=&s_tcpcomm_st_evt;
757  fLmdInitMbs(ps_chan->pLmd,pc_server,ps_chan->l_buf_size,ps_chan->l_bufs_in_stream,0,PORT__TRANSPORT,ps_chan->l_timeout);
758  printf("f_evt_get_open for TRANSPORT: port=%d timeout=%d \n",l_port, ps_chan->l_timeout);
759  ps_chan->l_server_type=l_mode;
760  return GETEVT__SUCCESS;
761  }
762 // -- DABC
763  break;
764  case GETEVT__REVSERV :
765  if (l_port<=0) l_port = PORT__EVENT_SERV;
766  if(f_evcli_con(ps_chan, pc_server, l_port, -1, l_sample)!=STC__SUCCESS)
767  {
768  return(GETEVT__NOSERVER);
769  }
770  break;
771  case GETEVT__EVENT :
772  if (l_port<=0) l_port = PORT__EVENT_SERV;
773  if(f_evcli_con(ps_chan, pc_server, l_port, -1, l_sample)!=STC__SUCCESS)
774  {
775  return(GETEVT__NOSERVER);
776  }
777  break;
778  case GETEVT__RFIO :
779  ps_chan->l_channel_no=-1;
780  ps_chan->l_channel_no=RFIO_open(pc_server,GET__OPEN_FLAG,0);
781  if(ps_chan->l_channel_no < 0) return(GETEVT__NOSERVER);
782  /* read first 512 bytes */
784  {
785  printf("LMD format error: no LMD file: %s\n",pc_server);
786  RFIO_close(ps_chan->l_channel_no);
787  ps_chan->l_channel_no=-1;
788  return(GETEVT__NOLMDFILE);
789  }
790  /* check for file header, return size and swap */
791  f_evt_check_buf(c_temp, &l_size_head, &l_is_goosybuf, &l_swap_head, &l_filehead);
792  if(((l_is_goosybuf==0)&(l_filehead==0))|(l_size_head==0))
793  {
794  printf("LMD format error: swap=%d, header=%d, isLMD=%d, size=%d\n",l_swap_head,l_filehead,l_is_goosybuf,l_size_head);
795  RFIO_close(ps_chan->l_channel_no);
796  ps_chan->l_channel_no=-1;
797  return(GETEVT__NOLMDFILE);
798  }
799  /* read file header and first buffer and check for goosy header */
800  if(l_filehead == 1)
801  {
802  RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
803  if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
804  {
805  printf("LMD format error: no LMD file: %s\n",pc_server);
806  RFIO_close(ps_chan->l_channel_no);
807  ps_chan->l_channel_no=-1;
808  return(GETEVT__NOLMDFILE);
809  }
811  {
812  RFIO_close(ps_chan->l_channel_no);
813  ps_chan->l_channel_no=-1;
814  return(GETEVT__RDERR);
815  }
816  f_evt_check_buf(c_temp, &l_size, &l_is_goosybuf, &l_swap, &l_dummy);
817  if((l_is_goosybuf==0)|(l_size!=l_size_head)|(l_swap!=l_swap_head))
818  {
819  printf("LMD format error: swap=%d, isLMD=%d, size=%d\n",l_swap,l_is_goosybuf,l_size);
820  RFIO_close(ps_chan->l_channel_no);
821  ps_chan->l_channel_no=-1;
822  return(GETEVT__NOLMDFILE);
823  }
824  }/* check buffer behind header */
825  ps_chan->l_buf_size=l_size_head;
826  RFIO_lseek(ps_chan->l_channel_no, 0, SEEK_SET); /* rewind file */
827  if(ps_info != NULL)*ps_info=NULL;
828  /* found file header */
829  if(l_filehead == 1)
830  {
831  if(RFIO_read(ps_chan->l_channel_no,c_temp,l_size_head)!=l_size_head)
832  {
833  printf("LMD format error: no LMD file: %s\n",pc_server);
834  RFIO_close(ps_chan->l_channel_no);
835  ps_chan->l_channel_no=-1;
836  return(GETEVT__NOLMDFILE);
837  }
838  ps_filhe=(s_filhe *)c_temp;
839  if(ps_info != NULL) /* if user want file header be returned */
840  {
841  if( l_swap_head ==1)f_evt_swap_filhe((s_bufhe *)ps_filhe);
842  *ps_info=c_temp; /* now , get file header and return */
843  }
844  /*
845  printf("type %d, subtype %d\n",ps_filhe->filhe_type,ps_filhe->filhe_subtype);
846  printf("strings %d %d %d %d %d %x\n",
847  ps_filhe->filhe_label_l,
848  ps_filhe->filhe_file_l,
849  ps_filhe->filhe_user_l,
850  ps_filhe->filhe_run_l,
851  ps_filhe->filhe_exp_l,
852  ps_filhe->filhe_lines);
853  pi=(INTS2 *)&ps_filhe->s_strings;
854  for(l_dummy=0;l_dummy<ps_filhe->filhe_lines;l_dummy++)
855  {
856  printf("comment %d, %s\n",*pi,(c_temp+366+l_dummy*80));
857  pi += 40;
858  }
859  */
860  }/* file header */
861  ps_chan->l_io_buf_size=ps_chan->l_buf_size;
862  break;
863  default :
864  if(ps_info != NULL) *ps_info=NULL;
865  return(GETEVT__NOSERVER);
866  } /* end of switch */
867 
868  if((l_mode != GETEVT__EVENT)&(l_mode != GETEVT__REVSERV))
869  {
870  if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
871  {
872  printf("Memory allocation error\n");
873  exit(2);
874  }
875  ps_chan->l_evt_buf_size=ps_chan->l_io_buf_size;
876  if( (ps_chan->pc_evt_buf=malloc(ps_chan->l_evt_buf_size))==NULL)
877  {
878  printf("Memory allocation error\n");
879  exit(2);
880  }
881  } /* l_mode != GETEVT__EVENT */
882  ps_chan->l_server_type=l_mode;
883  ps_chan->l_first_get=1; /* so we will first call f_getvet_get */
884  return GETEVT__SUCCESS;
885 } /* end of f_evt_get_open */
886 
887 /*1+ C Main ****************+******************************************/
888 /*+ Module : f_evt_get_event */
889 /*--------------------------------------------------------------------*/
890 /*+ CALLING : f_evt_get_event(s_evt_channel &s_chan, long **ppl_buffer, long **ppl_goobuf) */
891 /*--------------------------------------------------------------------*/
892 /* */
893 /*+ PURPOSE : f_evt_get_event returnes address of event */
894 /*+ ARGUMENTS : */
895 /*+ s_chan : Input channel from open. */
896 /*+ ppl_buffer: Address of pointer. Returns address of event. */
897 /*+ ppl_goobuf: Address of pointer. Returns address of buffer. */
898 /*+ Return type : int. */
899 /*+ Status codes: */
900 /*- GETEVT__SUCCESS : success. */
901 /*- GETEVT__FRAGMENT : Event fragment found. */
902 /*- GETEVT__NOMORE : No more events. */
903 /*- GETEVT__RDERR : read server or file error */
904 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
905 /*+ Declaration : */
906 /* INTS4 f_evt_get_event( */
907 /* s_evt_channel *, INTS4 **, INTS4 **); */
908 /*+ FUNCTION : Get next event and returnes pointer. The pointer */
909 /* may point to the event in the buffer or internal */
910 /* event buffer (spanned events). The content of the */
911 /* pointer may be destroyed by next call. */
912 /*1- C Main ****************+******************************************/
913 INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
914 {
915  INTS4 l_temp,l_prev_ok=1, l_stat, l_used;
916  s_bufhe *ps_bufhe_cur;
917  sMbsHeader *pevt = NULL;
918 
919 // DABC
920  if(ps_chan->pLmd != NULL) {
921  if(ps_chan->l_server_type == GETEVT__TRANS) {
922  l_stat = fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
923  } else if(ps_chan->l_server_type == GETEVT__STREAM) {
924  l_stat = fLmdGetMbsEvent(ps_chan->pLmd, &pevt);
925  } else if(ps_chan->l_server_type == GETEVT__FILE) {
926  l_stat = fLmdGetElement(ps_chan->pLmd,LMD__NO_INDEX, &pevt);
927  }
928 
929  // any error, then pointer is null
930  if(pevt==NULL) {
931  if (ps_chan->l_server_type == GETEVT__FILE){
932  if(l_stat == GETLMD__NOMORE) return GETEVT__NOMORE;
933  if(l_stat == GETLMD__EOFILE) return GETEVT__NOMORE;
934  if(l_stat == GETLMD__NOBUFFER) return GETEVT__FAILURE;
935  return GETEVT__RDERR;
936  } else {
937  if(l_stat == LMD__TIMEOUT) return GETEVT__TIMEOUT;
938  return GETEVT__RDERR;
939  }
940  }
941  // OK
942  if(ppl_goobuf)*ppl_goobuf = NULL;
943  *ppl_buffer = (INTS4 *)pevt;
944  return(GETEVT__SUCCESS);
945  }
946 // -- DABC
947 
948  if((ps_chan->l_server_type == GETEVT__EVENT)|(ps_chan->l_server_type == GETEVT__REVSERV))
949  {
950  *ppl_goobuf = NULL;
951  if(f_evcli_evt(ps_chan) != STC__SUCCESS) /* no more event, get new buffer */
952  {
953  l_stat=f_evcli_buf(ps_chan);
954  if(l_stat == STC__TIMEOUT) return(GETEVT__TIMEOUT);
955  if(l_stat != STC__SUCCESS) return(GETEVT__FAILURE);
956  }
957  *ppl_buffer = (INTS4 *) ps_chan->pc_evt_buf;
958  return(GETEVT__SUCCESS);
959  }
960 
961  /* e.g. read_buffer is 16384, GOOSY buffer may be only 2048, *
962  * this ps_chan->l_io_buf_posi indicats when the read_buffer is finished */
963 
964  if(ps_chan->l_first_get==1)
965  {
966  ps_chan->l_buf_posi=0; /* goosy buffer position */
967  ps_chan->l_buf_lmt=0; /* end of this goosy buffer */
968  ps_chan->l_io_buf_posi=MAX_LONG; /* Iuput buffer(for read file) position */
969  ps_chan->l_first_buf=1; /* boolean */
970  ps_chan->l_first_get=0; /* boolean */
971  }
972  /* why we need this part codes? beacause we may (open, get, close) *
973  * and (open, get, close) again!!! Especially when we use m-histo *
974  * so the second or later (open,get,close) should reset these *
975  * static value */
976 
977  ps_chan->l_evt_buf_posi=0;
978 /* above, internal event buffer position, internal buffer will be returned */
979 
980  while(1)
981  {
982  /* if previous goosy buffer has finished, read a new buffer from i/o buffer,
983  or from file if i/o buffer is all readout */
984  while (ps_chan->l_buf_posi >= ps_chan->l_buf_lmt)
985  {
986  /* if this i/o buffer is read to end */
987  /* end of this read_buffer which may contain several GOOSY buffers*/
988  if(ps_chan->l_io_buf_posi>=ps_chan->l_io_buf_size)
989  {
990  if((l_temp=f_evt_get_newbuf(ps_chan))!=GETEVT__SUCCESS) return(l_temp);
991  ps_chan->l_io_buf_posi=0;
992  } /* end of real read server */
993  ps_chan->ps_bufhe = (s_bufhe*) (ps_chan->pc_io_buf+ps_chan->l_io_buf_posi);
994  l_prev_ok = (ps_chan->l_buf_no == (ps_chan->ps_bufhe->l_buf-1)) ? 1 : 0;
995  ps_chan->l_buf_no = ps_chan->ps_bufhe->l_buf;
996  if(ps_chan->ps_bufhe->i_type == 2000) { /* file header */
997  printf("Unsolicited file header found!\n");
998  ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
999  ps_chan->l_buf_posi = ps_chan->l_io_buf_posi;
1000  ps_chan->l_buf_lmt = ps_chan->l_io_buf_posi;
1001  } else {
1002  l_used=ps_chan->ps_bufhe->l_free[2]; // large buffers HE, Oct 2007
1003  if(ps_chan->ps_bufhe->l_dlen <= MAX__DLEN)l_used=ps_chan->ps_bufhe->i_used;
1004  ps_chan->l_buf_posi = ps_chan->l_io_buf_posi + sizeof(s_bufhe);
1005  ps_chan->l_buf_lmt = ps_chan->l_buf_posi + l_used*2;
1006  ps_chan->l_io_buf_posi += ps_chan->l_buf_size;
1007  }
1008  } /* end of read file while loop */
1009 
1010  /* now, ps_chan->l_buf_posi points to start of an event or spanned event */
1011  ps_chan->ps_ve10_1 = (s_ve10_1 *) (ps_chan->pc_io_buf + ps_chan->l_buf_posi);
1012  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 */
1013  ps_chan->l_buf_posi += sizeof(s_evhe);
1014  ps_chan->l_frag_len = ps_chan->ps_ve10_1->l_dlen*2;
1015  } else /* if this is a real start of an event */
1016  ps_chan->l_frag_len = (ps_chan->ps_ve10_1->l_dlen-4)*2 + sizeof(s_ve10_1);
1017 
1018  if(ps_chan->l_frag_len + ps_chan->l_buf_posi > ps_chan->l_buf_lmt)
1019  {
1020  return(GETEVT__FRAGMENT);
1021  }
1022 
1023  /* if ps_chan->l_buf_posi is not start of an event and ps_chan->l_first_buf =1 *
1024  * then skip to next event */
1025  if((ps_chan->ps_bufhe->h_end==1)&&((ps_chan->l_first_buf==1) || (l_prev_ok == 0))) {
1026  /* if the first buffer is spanned at begin, then skip */
1027  ps_chan->l_first_buf=0; /* 24-Apr-1996 */
1028  l_prev_ok=1; /* 2001 HE */
1029  ps_chan->l_evt_buf_posi=0; /* 2001 HE stuff in event buffer obsolete */
1030  ps_chan->l_buf_posi += ps_chan->l_frag_len;
1031  /* now,ps_chan->l_buf_posi points to start of an event or spanned event */
1032  continue; /* continue "while" loop */
1033  }
1034 
1035  ps_chan->l_first_buf=0;
1036 
1037  /* if ps_chan->l_buf_posi is start of an event and the event is not *
1038  * spanned, then return pointer */
1039  if( (ps_chan->l_evt_buf_posi==0) &&
1040  ( (ps_chan->ps_bufhe->h_begin==0) || ((ps_chan->l_buf_posi+ps_chan->l_frag_len) < ps_chan->l_buf_lmt) ) )
1041  {
1042  *ppl_buffer = (INTS4 *)(ps_chan->pc_io_buf+ps_chan->l_buf_posi);
1043  ps_chan->l_buf_posi += ps_chan->l_frag_len;
1044  ps_chan->l_evt_buf_posi = 0;
1045  if(ppl_goobuf) *ppl_goobuf = (INTS4 *) (ps_chan->ps_bufhe);
1046  return(GETEVT__SUCCESS);
1047  }
1048 
1049  /* 2001 HE if we start a spanned event, save buffer header of first buffer */
1050  if(ps_chan->l_evt_buf_posi==0)
1051  {
1052  memcpy((CHARS *)&ps_chan->s_bufhe_1,(CHARS *)ps_chan->ps_bufhe,sizeof(s_bufhe));
1053  ps_bufhe_cur=(s_bufhe *)&ps_chan->s_bufhe_1;
1054  }
1055  /* copy the part of this event which in this buffer into *
1056  * internal buffer, data will be moved by realloc function */
1057  if(ps_chan->l_evt_buf_size<ps_chan->l_evt_buf_posi+ps_chan->l_frag_len)
1058  {
1059  ps_chan->l_evt_buf_size=ps_chan->l_evt_buf_posi+ps_chan->l_frag_len;
1060  if( (ps_chan->pc_evt_buf=realloc
1061  (ps_chan->pc_evt_buf, ps_chan->l_evt_buf_size))==NULL)
1062  {
1063  printf("Memory allocation error\n");
1064  exit(2);
1065  }
1066  }
1067  memcpy(ps_chan->pc_evt_buf+ps_chan->l_evt_buf_posi,ps_chan->pc_io_buf+ps_chan->l_buf_posi,
1068  ps_chan->l_frag_len);
1069  ps_chan->l_buf_posi += ps_chan->l_frag_len;
1070  if(ps_chan->l_evt_buf_posi == 0)
1071  {
1072  }
1073  ps_chan->l_evt_buf_posi += ps_chan->l_frag_len;
1074 
1075  if((ps_chan->ps_bufhe->h_begin!=1)||(ps_chan->l_buf_posi<ps_chan->l_buf_lmt))
1076  {
1077  /* change event header's l_dlen */
1078  ((s_ve10_1 *)(ps_chan->pc_evt_buf))->l_dlen=ps_chan->l_evt_buf_posi/2-4;
1079  *ppl_buffer=(INTS4 *)(ps_chan->pc_evt_buf);
1080  if(ppl_goobuf)*ppl_goobuf=(INTS4 *)(ps_bufhe_cur);
1081  return(GETEVT__SUCCESS);
1082  }
1083  }/* if this event spanned to next buffer, then loop */
1084 } /* end of f_evt_get_event */
1085 
1086 /*1+ C Main ******************+****************************************/
1087 /*+ Module : f_evt_get_close */
1088 /*--------------------------------------------------------------------*/
1089 /*+ CALLING : f_evt_get_close( s_evt_channel &s_chan) */
1090 /*--------------------------------------------------------------------*/
1091 /* */
1092 /*+ PURPOSE : f_evt_get_close closes event stream of specified */
1093 /* channel. */
1094 /*+ ARGUMENTS : */
1095 /*+ s_chan : Input channel from open. */
1096 /*+ Return type : int. */
1097 /*+ Status codes: */
1098 /*- GETEVT__SUCCESS : success. */
1099 /*- GETEVT__CLOSE_ERR : close server or file error */
1100 /*+ Declaration : */
1101 /* INTS4 f_evt_get_close(s_evt_channel *); */
1102 /*+ FUNCTION : Closes the specified input channel. */
1103 /*1- C Main ******************+****************************************/
1105 {
1106  INTS4 l_close_failure;
1107 
1108 // DABC
1109  if(ps_chan->pLmd != NULL){
1110  if(ps_chan->l_server_type == GETEVT__TRANS)fLmdCloseMbs(ps_chan->pLmd);
1111  else if(ps_chan->l_server_type == GETEVT__STREAM)fLmdCloseMbs(ps_chan->pLmd);
1112  else if(ps_chan->l_server_type == GETEVT__FILE) fLmdGetClose(ps_chan->pLmd);
1113  free(ps_chan->pLmd);
1114  ps_chan->pLmd=NULL;
1115  return GETEVT__SUCCESS;
1116  }
1117 // -- DABC
1118  l_close_failure=0;
1119  if(ps_chan->l_channel_no >= 0)
1120  {
1121  switch(ps_chan->l_server_type)
1122  {
1123  case GETEVT__FILE :
1124  if(close(ps_chan->l_channel_no)==-1) l_close_failure=1;
1125  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1126  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1127  break;
1128  case GETEVT__STREAM :
1129  /* disconnect with stream server */
1130  f_stc_write("CLOSE", 12, ps_chan->l_channel_no);
1131  if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
1132  if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
1133  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1134  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1135  break;
1136  case GETEVT__TRANS :
1137  /* disconnect with stream server */
1138  if(f_stc_discclient(ps_chan->l_channel_no)!=STC__SUCCESS)l_close_failure=1;
1139  if(f_stc_close(&s_tcpcomm_st_evt)!=STC__SUCCESS) l_close_failure=1;
1140  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1141  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1142  break;
1143  case GETEVT__REVSERV :
1144  case GETEVT__EVENT :
1145  if(f_evcli_close(ps_chan)!=STC__SUCCESS) l_close_failure=1;
1146  break;
1147  case GETEVT__RFIO :
1148  RFIO_close(ps_chan->l_channel_no);
1149  ps_chan->l_channel_no=-1;
1150  if(ps_chan->pc_io_buf != NULL)free(ps_chan->pc_io_buf);
1151  if(ps_chan->pc_evt_buf != NULL)free(ps_chan->pc_evt_buf);
1152  break;
1153  default :
1154  l_close_failure=1;
1155  } /* end of switch */
1156  ps_chan->pc_io_buf=NULL;
1157  ps_chan->l_channel_no=-1;
1158  if(l_close_failure==1) return(GETEVT__CLOSE_ERR);
1159  return GETEVT__SUCCESS;
1160  }
1161 return GETEVT__SUCCESS;
1162 
1163 } /* end of f_evt_get_close */
1164 
1165 
1166 /*1+ C Main ****************+******************************************/
1167 /*+ Module : f_evt_put_open */
1168 /*--------------------------------------------------------------------*/
1169 /*+ CALLING : f_evt_put_open(char *c_file[], long l_size, long l_stream, long l_type, */
1170 /* long l_subtype, s_evt_channel *ps_chan, char *ps_filhe) */
1171 /*--------------------------------------------------------------------*/
1172 /* */
1173 /*+ PURPOSE : f_evt_put_open opens an event output stream. */
1174 /*+ ARGUMENTS : */
1175 /*+ c_file : Name of file. */
1176 /*+ l_size : Size of output buffers in bytes. */
1177 /*+ l_stream : Number of buffers with spanning events. */
1178 /*+ l_type : Buffer type number */
1179 /*+ l_subtype : Buffer subtype number */
1180 /*+ ps_chan : Address of channel structure which will be returned.*/
1181 /*+ ps_filhe : Address of user specified file header */
1182 /*+ Return type : int. */
1183 /*+ Status codes: */
1184 /*- PUTEVT__SUCCESS : success. */
1185 /*- PUTEVT__FILE_EXIST: file already exists. */
1186 /*- PUTEVT__FAILURE : failure. */
1187 /*+ Declaration : */
1188 /* INTS4 f_evt_put_open( */
1189 /* CHARS *,INTS4,INTS4,INTS4,INTS4,s_evt_channel *,CHARS *); */
1190 /*+ FUNCTION : Opens the output channel and save context in */
1191 /* s_evt_channel structure. */
1192 /*+ NOTE : Up to four output channels can be opened. */
1193 /* User Example : In m_lea_user.c */
1194 /*1- C Main ****************+******************************************/
1195 INTS4 f_evt_put_open(CHARS *pc_file, INTS4 l_size, INTS4 l_stream,
1196  INTS4 l_type, INTS4 l_subtype, s_evt_channel *ps_chan, CHARS *ps_filhe)
1197 {
1198  s_filhe *ps_file_head;
1199  INTS4 l_write_size;
1200  INTS4 l_status;
1201  time_t s_timet;
1202  struct timespec s_timespec;
1203  CHARS c_mode[80];
1204  CHARS c_file[256], *pc_temp;
1205 
1206 // DABC
1207  ps_chan->pLmd=NULL;
1208  if(l_stream==0) {
1209  ps_chan->pLmd=fLmdAllocateControl();
1210  l_status=fLmdPutOpen(ps_chan->pLmd,pc_file,NULL,l_size,
1212  return(l_status);
1213  }
1214 // -- DABC
1215 
1216  ps_chan->l_first_put=1;
1217 
1218  ps_chan->l_buf_size=l_size;
1219  ps_chan->l_bufs_in_stream=l_stream;
1220  ps_chan->l_buf_type=l_type;
1221  ps_chan->l_buf_subtype=l_subtype;
1222  ps_chan->l_io_buf_size=ps_chan->l_buf_size * ps_chan->l_bufs_in_stream;
1223  if( (ps_chan->pc_io_buf=malloc(ps_chan->l_io_buf_size))==NULL)
1224  {
1225  printf("Memory allocation error\n");
1226  exit(2);
1227  }
1228 
1229  strcpy(c_file,pc_file);
1230  if(strlen(c_file) < 5) strncat(c_file,".lmd", sizeof(c_file)-1);
1231  else
1232  {
1233  pc_temp = (CHARS *) &c_file[strlen(c_file)-4];
1234  if((strcmp(pc_temp,".LMD") != 0) &&
1235  (strcmp(pc_temp,".lmd") != 0)) strncat(c_file, ".lmd", sizeof(c_file)-1);
1236  }
1237  if((ps_chan->l_channel_no=open(c_file,PUT__OPEN_APD_FLAG) )!= -1) {
1238  return(PUTEVT__FILE_EXIST);
1239  } else
1240  {
1241  if((ps_chan->l_channel_no=open(c_file,PUT__CRT_FLAG,
1242  DEF_FILE_ACCE) )== -1)
1243  return(PUTEVT__FAILURE);
1244  /* open OK */
1245  else
1246  {
1247  /* output file header */
1248  ps_file_head=(s_filhe *)ps_chan->pc_io_buf;
1249  /* if user specify file header */
1250  if(ps_filhe != NULL) {
1251  memcpy(ps_file_head, ps_filhe,ps_chan->l_buf_size );
1252  } else {
1253  memset( ps_file_head, '\0', ps_chan->l_buf_size);
1254  snprintf(ps_file_head->filhe_run, sizeof(ps_file_head->filhe_run), "Pid %d%c", own_getpid(),'\0');
1255  ps_file_head->filhe_run_l = (INTS2) strlen(ps_file_head->filhe_run);
1256  }
1257  ps_file_head->filhe_dlen=ps_chan->l_buf_size/2;
1258  ps_file_head->filhe_subtype=1;
1259  ps_file_head->filhe_type=2000;
1260  clock_gettime(CLOCK_REALTIME, &s_timespec);
1261  ps_file_head->filhe_stime[0] = (INTS4) s_timespec.tv_sec;
1262  ps_file_head->filhe_stime[1] = (INTS4) s_timespec.tv_nsec/1000000;
1263  ps_file_head->filhe_free[0] = 1;
1264  ps_file_head->filhe_file_l = (INTS2) strlen(c_file);/* not include \0 */
1265  strncpy(ps_file_head->filhe_file, c_file, sizeof(ps_file_head->filhe_file));
1266  strncpy(ps_file_head->filhe_user, getenv("USER"), sizeof(ps_file_head->filhe_user)); /* user name */
1267  ps_file_head->filhe_user_l = (INTS2) strlen(ps_file_head->filhe_user);
1268  time(&s_timet);/* get calendar time */
1269  strncpy(c_mode, ctime(&s_timet), sizeof(c_mode));
1270  strncpy(ps_file_head->filhe_time, &c_mode[4], sizeof(ps_file_head->filhe_time));
1271  ps_file_head->filhe_time[20]=' ';
1272  l_write_size=write(ps_chan->l_channel_no,(CHARS *)ps_file_head,
1273  ps_chan->l_buf_size);
1274  if(l_write_size==-1)
1275  {
1276  return(PUTEVT__WRERR);
1277  }
1278  if(l_write_size!=ps_chan->l_buf_size)
1279  {
1280  return(PUTEVT__TOOBIG);
1281  }
1282  return(PUTEVT__SUCCESS);
1283  }
1284  }
1285 } /* end of f_evt_put_open */
1286 
1287 /*1+ C Main ****************+******************************************/
1288 /*+ Module : f_evt_put_event */
1289 /*--------------------------------------------------------------------*/
1290 /*+ CALLING : f_evt_put_event(s_evt_channel *ps_chan, long &la_evt_buf[]) */
1291 /*--------------------------------------------------------------------*/
1292 /* */
1293 /*+ PURPOSE : f_evt_put_event outputs event */
1294 /*+ ARGUMENTS : */
1295 /*+ ps_chan : Address of channel structure as returned from */
1296 /* f_evt_put_open. */
1297 /*+ la_evt_buf : event data array. Standard GSI event structure. */
1298 /*+ Return type : int. */
1299 /*+ Status codes: */
1300 /*- PUTEVT__SUCCESS : success. */
1301 /*- PUTEVT__WRERR : read server or file error */
1302 /*+ Declaration : */
1303 /* INTS4 f_evt_put_event(s_evt_channel *, INTS4 *); */
1304 /*+ FUNCTION : Copies current event into output buffer. Writes */
1305 /* buffer to file, when full. */
1306 /*1- C Main ****************+******************************************/
1307 
1309 {
1310  INTS4 l_evt_buf_posi;
1311  INTS4 l_buf_remain_size; /* net free space of I/O buffer */
1312  INTS4 l_write_size, l_temp, l_free;
1313  INTS4 l_status;
1314  CHARS *pc_addr;
1315  s_bufhe *ps_bufhe;
1316 
1317 // DABC
1318  if(ps_chan->pLmd != NULL){
1319  l_status=fLmdPutElement(ps_chan->pLmd,(sMbsHeader *)pl_evt_buf);
1320  return(l_status);
1321  }
1322 // -- DABC
1323  if(ps_chan->l_first_put==1)
1324  {
1325  ps_chan->l_first_put=0;
1326  ps_chan->l_io_buf_posi=0;
1327  ps_chan->l_buf_no=1;
1328  }
1329  l_evt_buf_posi=0;
1330  ps_chan->l_evt_size=( ((s_ve10_1 *)(pl_evt_buf))->l_dlen)*2 + sizeof(s_evhe);
1331 
1332  /* get l_buf_remain_size is available size in stream */
1333  l_buf_remain_size = ps_chan->l_io_buf_size - ps_chan->l_io_buf_posi;
1334  l_temp = (l_buf_remain_size / ps_chan->l_buf_size)*(sizeof(s_bufhe)+sizeof(s_evhe) );
1335  l_buf_remain_size -= l_temp;/* minus space occupied by buffer header and spanned event header */
1336 
1337  if(ps_chan->l_evt_size>l_buf_remain_size)/* output this i/o buffer */
1338  {
1339  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);
1340  /* clear rest of this GOOSY buffer */
1341  l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1342  if(ps_chan->l_io_buf_posi%ps_chan->l_buf_size == 0) l_temp -= ps_chan->l_buf_size;
1343  /* l_temp points to start of last GOOSY buf in i/o buf area */
1344  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
1345  if(l_temp==0)ps_chan->ps_bufhe->h_end = 0; /* first buf in stream, no end */
1346  else ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
1347  ps_chan->ps_bufhe->h_begin = 0; /* evt has end, so not spanned to next buf */
1348  for(l_temp=0;l_temp<ps_chan->l_io_buf_size;l_temp+=ps_chan->l_buf_size)
1349  {
1350  pc_addr = ps_chan->pc_io_buf+l_temp;
1351  ps_bufhe=(s_bufhe *)pc_addr;
1352  if(ps_bufhe->l_evt>0)/* do not write empty buffers */
1353  {
1354  l_write_size=write(ps_chan->l_channel_no, pc_addr,ps_chan->l_buf_size);
1355  if(l_write_size==-1) return(PUTEVT__WRERR);
1356  if(l_write_size!=ps_chan->l_buf_size) return(PUTEVT__TOOBIG);
1357  }
1358  else ps_chan->l_buf_no--; /* decrement buffer number for not written buffer */
1359  } /* buffer output loop */
1360  ps_chan->l_io_buf_posi=0;
1361  ps_chan->ps_bufhe=(s_bufhe *)ps_chan->pc_io_buf;
1362  /* get l_buf_remain_size of new stream */
1363  l_buf_remain_size = ps_chan->l_io_buf_size;
1364  l_temp = (l_buf_remain_size / ps_chan->l_buf_size) * (sizeof(s_bufhe)+sizeof(s_evhe) );
1365  l_buf_remain_size -= l_temp; /* minus space occupied by buf header and spanned event header */
1366  l_buf_remain_size += sizeof(s_evhe);/* 1st buf always no span */
1367  /* if event can not fit in a new stream, then error */
1368  if(ps_chan->l_evt_size>l_buf_remain_size) return(PUTEVT__TOO_SMALLS);
1369  }
1370 
1371  if(ps_chan->l_io_buf_posi==0)f_evt_ini_bufhe(ps_chan);/* init all buffer headers */
1372 
1373  /* write event into i/o buf till end of event, change ps_chan->l_io_buf_posi */
1374  while(l_evt_buf_posi<ps_chan->l_evt_size)
1375  {
1376  ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);
1377  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)==0)
1378  {
1379  ps_chan->l_io_buf_posi += sizeof(s_bufhe);
1380  ps_chan->ps_ve10_1 = (s_ve10_1 *)(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi);/* behind header */
1381  if(l_evt_buf_posi != 0)
1382  {
1383  ps_chan->l_io_buf_posi += sizeof(s_evhe); /* behind element header */
1384  l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1385  /* l_write_size points to start of this GOOSY buf in i/o buf area */
1386  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
1387  ps_chan->ps_bufhe->i_used += sizeof(s_evhe)/2;
1388  }
1389  }
1390  l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1391  /* l_write_size points to start of this GOOSY buf in i/o buf area */
1392  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_write_size);
1393  l_write_size = l_write_size + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
1394  /* l_write_size is remain free space in this GOOSY buf */
1395  if(l_write_size>(ps_chan->l_evt_size-l_evt_buf_posi))
1396  l_write_size=(ps_chan->l_evt_size-l_evt_buf_posi);
1397  memcpy(ps_chan->pc_io_buf + ps_chan->l_io_buf_posi, (CHARS *)pl_evt_buf + l_evt_buf_posi, l_write_size);
1398  ps_chan->ps_bufhe->l_evt ++; /* number of fragments */
1399  ps_chan->l_io_buf_posi += l_write_size;
1400  l_evt_buf_posi += l_write_size;
1401  ps_chan->ps_bufhe->i_used += l_write_size/2;
1402  /* if the remain free space of GOOSY buffer does not large enough *
1403  * to hold even a event header, then turn to next GOOSY buffer and *
1404  * fill buffer header. or 8 long words aligned ???????? */
1405  l_free=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1406  /* l_free points to start of this GOOSY buf in i/o buf area */
1407  l_free = l_free + ps_chan->l_buf_size - ps_chan->l_io_buf_posi;
1408  if(l_free==ps_chan->l_buf_size)l_free=0;
1409  /* l_free is remain free space in this GOOSY buf */
1410  if(l_free<sizeof(s_ve10_1))ps_chan->l_io_buf_posi += l_free;
1411  /* change spanned evt header l_dlen */
1412  if(l_evt_buf_posi!=l_write_size)
1413  {
1414  ps_chan->ps_ve10_1->l_dlen= l_write_size/2;
1415  ps_chan->ps_ve10_1->i_subtype = ps_chan->l_buf_subtype;
1416  ps_chan->ps_ve10_1->i_type = ps_chan->l_buf_type;
1417  }
1418  else ps_chan->ps_ve10_1->l_dlen= (l_write_size-sizeof(s_evhe))/2; /* header of first frag */
1419  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)==0)
1420  {
1421  if(l_evt_buf_posi<ps_chan->l_evt_size) ps_chan->ps_bufhe->h_begin = 1;
1422  if(ps_chan->l_io_buf_posi > ps_chan->l_buf_size) /* so first buf in stream */
1423  ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))->h_begin;
1424  ps_chan->ps_bufhe->l_free[1] = ((s_ve10_1 *)(pl_evt_buf))->l_dlen; /* lgth of last event in buf */
1425  } /* end of processs prev buffer head and ... */
1426 
1427  } /* end of write event into i/o buf till end of event */
1428  return(PUTEVT__SUCCESS);
1429 } /* end of f_evt_put_event */
1430 
1431 /*1+ C Main ****************+******************************************/
1432 /*+ Module : f_evt_put_buffer */
1433 /*--------------------------------------------------------------------*/
1434 /*+ CALLING : f_evt_put_buffer(s_evt_channel *ps_chan, s_bufhe *ps_bufhe) */
1435 /*--------------------------------------------------------------------*/
1436 /* */
1437 /*+ PURPOSE : f_evt_put_buffer outputs buffer */
1438 /*+ ARGUMENTS : */
1439 /*+ ps_chan : Address of channel structure as returned from */
1440 /* f_evt_put_open. */
1441 /*+ ps_bufhe : Buffer. */
1442 /*+ Return type : int. */
1443 /*+ Status codes: */
1444 /*- PUTEVT__SUCCESS : success. */
1445 /*- PUTEVT__WRERR : read server or file error */
1446 /*+ Declaration : */
1447 /* INTS4 f_evt_put_buffer(s_evt_channel *, s_bufhe *); */
1448 /*+ FUNCTION : Writes buffer to file. */
1449 /*1- C Main ****************+******************************************/
1450 
1452 {
1453  INTS4 l_write_size;
1454  INTS4 l_status;
1455 
1456 // DABC
1457  if(ps_chan->pLmd != NULL){
1458  l_status=fLmdPutBuffer(ps_chan->pLmd,(sMbsHeader *)(ps_bufhe+1),ps_bufhe->l_evt);
1459  return(l_status);
1460  }
1461 // -- DABC
1462  ps_chan->l_io_buf_posi = ps_chan->l_buf_size;
1463  ps_chan->l_io_buf_size = ps_chan->l_buf_size;
1464  l_write_size=write(ps_chan->l_channel_no, (CHARS *) ps_bufhe, ps_chan->l_buf_size);
1465  if(l_write_size==-1)
1466  {
1467  return(PUTEVT__WRERR);
1468  }
1469  if(l_write_size!=ps_chan->l_buf_size)
1470  {
1471  return(PUTEVT__TOOBIG);
1472  }
1473  return PUTEVT__SUCCESS;
1474 } /* end of f_evt_put_buffer */
1475 
1476 /*1+ C Main ****************+******************************************/
1477 /*+ Module : f_evt_put_close */
1478 /*--------------------------------------------------------------------*/
1479 /*+ CALLING : f_evt_put_close(s_evt_channel *ps_chan) */
1480 /*--------------------------------------------------------------------*/
1481 /* */
1482 /*+ PURPOSE : f_evt_put_close closes specified channel. */
1483 /*+ ARGUMENTS : */
1484 /*+ channel : Channel number. */
1485 /*+ Return type : int. */
1486 /*+ Status codes: */
1487 /*- PUTEVT__SUCCESS : success. */
1488 /*- PUTEVT__FAILURE : failure. */
1489 /*- PUTEVT__CLOSE_ERR : close server or file error */
1490 /*+ Declaration : */
1491 /* INTS4 f_evt_put_close(s_evt_channel *); */
1492 /*+ FUNCTION : Closes the specified output channel after writing */
1493 /* last buffer. */
1494 /*1- C Main ****************+******************************************/
1495 
1497 {
1498  INTS4 l_write_size, l_temp, l_temp2;
1499  INTS4 l_status;
1500 
1501 // DABC
1502  if(ps_chan->pLmd != NULL){
1503  l_status=fLmdPutClose(ps_chan->pLmd);
1504  return(l_status);
1505  }
1506 // -- DABC
1507  if(ps_chan->l_first_put==1) goto g_close;
1508 
1509  /* if not the end of GOOSY buf, fill buffer header */
1510  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)!=0)
1511  {
1512  l_temp=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size)*ps_chan->l_buf_size;
1513  /* l_temp points to start of this GOOSY buf in i/o buf area */
1514  memset(ps_chan->pc_io_buf+ps_chan->l_io_buf_posi, '\0',
1515  l_temp+ps_chan->l_buf_size-ps_chan->l_io_buf_posi);
1516  /* clear rest of this GOOSY buffer */
1517  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
1518 
1519  ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
1520  ps_chan->ps_bufhe->h_begin = 0; /* evt has end, so not spanned to next buf */
1521  if(l_temp==0) /* so fisrt buf in stream */
1522  ps_chan->ps_bufhe->h_end = 0;
1523  else
1524  ps_chan->ps_bufhe->h_end = ((s_bufhe *)((CHARS *)ps_chan->ps_bufhe - ps_chan->l_buf_size))
1525  ->h_begin;
1526  ps_chan->ps_bufhe->i_used = (ps_chan->l_io_buf_posi%ps_chan->l_buf_size -
1527  sizeof(s_bufhe))/2;
1528  } /* end of process of infilished buffer header */
1529 
1530  /* if at the end of io buf, need not flush */
1531  if(ps_chan->l_io_buf_posi!=ps_chan->l_io_buf_size)
1532  {
1533  if((ps_chan->l_io_buf_posi%ps_chan->l_buf_size)!=0)
1534  l_write_size=(ps_chan->l_io_buf_posi/ps_chan->l_buf_size+1) *
1535  ps_chan->l_buf_size;
1536  else
1537  l_write_size=ps_chan->l_io_buf_posi;
1538 
1539  for(l_temp=0;l_temp<l_write_size;l_temp+=ps_chan->l_buf_size){
1540 /* why use this loop instead of write the whole io_buf out? because in
1541  VMS side, the record can only be l_buf_size big, not l_write_size big */
1542  l_temp2=write(ps_chan->l_channel_no, ps_chan->pc_io_buf+l_temp,
1543  ps_chan->l_buf_size);
1544  if(l_temp2==-1)
1545  {
1546  return(PUTEVT__WRERR);
1547  }
1548  if(l_temp2!=ps_chan->l_buf_size)
1549  {
1550  return(PUTEVT__TOOBIG);
1551  }
1552  }
1553  } /* end of flush */
1554 
1555 g_close:
1556  free(ps_chan->pc_io_buf);
1557  /* free io buffer Memory */
1558 
1559  l_status=close(ps_chan->l_channel_no);
1560  ps_chan->l_channel_no=-1;
1561  if(l_status == -1) return(PUTEVT__CLOSE_ERR);
1562  else return PUTEVT__SUCCESS;
1563 } /* end of f_evt_put_close */
1564 
1565 /*1+ C Main ****************+******************************************/
1566 /*+ Module : f_evt_error */
1567 /*--------------------------------------------------------------------*/
1568 /*+ CALLING : f_evt_error( long l_error , char &c_string[], long l_out ) */
1569 /*--------------------------------------------------------------------*/
1570 /* */
1571 /*+ PURPOSE : f_evt_error displays error messages. */
1572 /*+ ARGUMENTS : */
1573 /*+ l_error : The error id as returned from other calls */
1574 /*+ c_string : The string into f_evt_error() copies the message....*/
1575 /*+ l_out : specifies the output device for the error message. */
1576 /*- out = 1 : error message is copied to string. */
1577 /*- out = 0 : error message is printed on terminal. */
1578 /*+ Return type : int (longword). */
1579 /*+ Status codes: */
1580 /*- GETEVT__SUCCESS : success. */
1581 /*- GETEVT__FAILURE : failure */
1582 /*+ Declaration : */
1583 /* INTS4 f_evt_error( INTS4 , CHARS * , INTS4 ); */
1584 /*+ FUNCTION : f_evt_error displays the error message for the */
1585 /* error id ( l_error ). If out = 1 the error */
1586 /* message is copied into string, else */
1587 /* f_evt_error prints the message on terminal. */
1588 /*1- C Main ******************+****************************************/
1589 INTS4 f_evt_error( INTS4 l_error , CHARS *pc_dest , INTS4 l_out )
1590 {
1591  CHARS c_line[80];
1592 
1593  switch( l_error )
1594  {
1595  case GETEVT__NOFILE :
1596  sprintf(c_line,"-I-f_evt: no such input file");
1597  break;
1598  case GETEVT__NOTAGFILE :
1599  sprintf(c_line,"-I-f_evt: no such tag file");
1600  break;
1601  case GETEVT__NOTAG :
1602  sprintf(c_line,"-I-f_evt: no such event tag");
1603  break;
1604  case GETEVT__TIMEOUT :
1605  sprintf(c_line,"-I-f_evt: time out");
1606  break;
1607  case GETEVT__NOSERVER :
1608  sprintf(c_line,"-I-f_evt: no such server");
1609  break;
1610  case GETEVT__RDERR :
1611  sprintf(c_line,"-I-f_evt: read server error");
1612  break;
1613  case GETEVT__TAGRDERR :
1614  sprintf(c_line,"-I-f_evt: read tag file error");
1615  break;
1616  case GETEVT__TAGWRERR :
1617  sprintf(c_line,"-I-f_evt: write tag file error");
1618  break;
1619  case GETEVT__FRAGMENT :
1620  sprintf(c_line,"-I-f_evt: data format error");
1621  break;
1622  case GETEVT__NOMORE :
1623  sprintf(c_line,"-I-f_evt: no more event");
1624  break;
1625  case GETEVT__CLOSE_ERR:
1626  sprintf(c_line,"-I-f_evt: close server error");
1627  break;
1628  case GETEVT__FAILURE :
1629  sprintf(c_line,"-I-f_evt: failure");
1630  break;
1631  case GETEVT__NOCHANNEL :
1632  sprintf(c_line,"-I-f_evt: too many channels");
1633  break;
1634  case GETEVT__NOLMDFILE :
1635  sprintf(c_line,"-I-f_evt: input file is no LMD file");
1636  break;
1637  case GETEVT__SUCCESS :
1638  sprintf(c_line,"-I-f_evt: success");
1639  break;
1640  case PUTEVT__FILE_EXIST :
1641  sprintf(c_line,"-I-f_evt: output file already exist");
1642  break;
1643  case PUTEVT__WRERR :
1644  sprintf(c_line,"-I-f_evt: write file error");
1645  break;
1646  case PUTEVT__TOOBIG :
1647  sprintf(c_line,"-I-f_evt: output file too large");
1648  break;
1649  case PUTEVT__TOO_SMALLS:
1650  sprintf(c_line,"-I-f_evt: event can not fit in a stream");
1651  break;
1652  case PUTEVT__CLOSE_ERR :
1653  sprintf(c_line,"-I-f_evt: close output error");
1654  break;
1655  case PUTEVT__FAILURE :
1656  sprintf(c_line,"-I-f_evt: output failure");
1657  break;
1658  case PUTEVT__NOCHANNEL :
1659  sprintf(c_line,"-I-f_evt: too many channels");
1660  break;
1661  default :
1662  sprintf(c_line,"-I-f_evt: unknown message id %d",l_error);
1663  if(l_out==0)printf("%s\n",c_line);
1664  if(l_out==1)strcpy(pc_dest,c_line);
1665  return GETEVT__FAILURE;
1666  } /* end switch( l_error ) */
1667 
1668  if(l_out==0)printf("%s\n",c_line);
1669  if(l_out==1)strcpy(pc_dest,c_line);
1670 
1671  return GETEVT__SUCCESS;
1672 } /* end of f_evt_error */
1673 
1674 
1675 /*1+ C Main ****************+******************************************/
1676 /*+ Module : f_evt_get_buffer */
1677 /*--------------------------------------------------------------------*/
1678 /*+ CALLING : f_evt_get_buffer(s_evt_channel &s_chan, INTS4 *pl_buffer) */
1679 /*--------------------------------------------------------------------*/
1680 /* */
1681 /*+ PURPOSE : f_evt_get_buffer read one buffer from server into */
1682 /* user buffer. */
1683 /*+ ARGUMENTS : */
1684 /*+ s_chan : structure s_evt_channel. */
1685 /*+ pl_buffer : Address of user buffer */
1686 /*+ Return type : int. */
1687 /*+ Status codes: */
1688 /*- GETEVT__SUCCESS : success. */
1689 /*- GETEVT__FAILURE : failure */
1690 /*- GETEVT__RDERR : read server or file error */
1691 /*- GETEVT__NOMORE : No more events. */
1692 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
1693 /*+ Declaration : */
1694 /* INTS4 f_evt_get_buffer(s_evt_channel *, INTS4 *); */
1695 /*1- C Main ****************+******************************************/
1697 {
1698  INTS4 l_temp;
1699  CHARS * pc_temp;
1700  INTS4 l_status;
1701 
1702  pc_temp=(CHARS *)ps_chan->pc_io_buf;
1703  switch(ps_chan->l_server_type)
1704  {
1705  case GETEVT__FILE :
1706  l_temp=read(ps_chan->l_channel_no,ps_buffer, ps_chan->l_buf_size);
1707  if(l_temp == 0)
1708  /* if end of file, then exit */
1709  {
1710  ps_chan->l_io_buf_size = 0;
1711  return(GETEVT__NOMORE);
1712  }
1713  else if(l_temp == -1)
1714  {
1715  ps_chan->l_io_buf_size = 0;
1716  return(GETEVT__RDERR);
1717  }
1718  break;
1719  case GETEVT__RFIO :
1720  l_temp=RFIO_read(ps_chan->l_channel_no,(CHARS *)ps_buffer, ps_chan->l_buf_size);
1721  if(l_temp == 0)
1722  {
1723  ps_chan->l_io_buf_size = 0;
1724  return(GETEVT__NOMORE);
1725  }
1726  else if(l_temp == -1)
1727  {
1728  ps_chan->l_io_buf_size = 0;
1729  return(GETEVT__RDERR);
1730  }
1731  break;
1732  case GETEVT__STREAM :
1733  if(ps_chan->l_stream_bufs == 0)
1734  if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
1735  {
1736  return(GETEVT__FAILURE);
1737  }
1738 
1739  l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1740  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
1741  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
1742  ps_chan->l_stream_bufs++;
1743  if(ps_chan->l_stream_bufs == ps_chan->l_bufs_in_stream)ps_chan->l_stream_bufs = 0;
1744  break;
1745  case GETEVT__TRANS :
1746  l_status=f_stc_read(ps_buffer, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1747  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
1748  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
1749  break;
1750  case GETEVT__REVSERV :
1751  case GETEVT__EVENT :
1752  default :
1753  return(GETEVT__FAILURE);
1754  } /* end of switch */
1755 
1756  /* swap */
1757  if( ((s_bufhe *)(ps_buffer))->l_free[0] !=1)
1758  f_evt_swap((CHARS *)ps_buffer, ps_chan->l_buf_size);
1759 
1760  return(GETEVT__SUCCESS);
1761 } /* end of f_evt_get_buffer */
1762 /*1+ C Main ****************+******************************************/
1763 /*+ Module : f_evt_skip_buffer */
1764 /*--------------------------------------------------------------------*/
1765 /*+ CALLING : f_evt_skip_buffer(s_evt_channel &s_chan, INTS4 l_buffer) */
1766 /*--------------------------------------------------------------------*/
1767 /* */
1768 /*+ PURPOSE : Skip buffers in file. */
1769 /*+ ARGUMENTS : */
1770 /*+ s_chan : structure s_evt_channel. */
1771 /*+ l_buffer : buffers to skip */
1772 /*+ Return type : int. */
1773 /*+ Status codes: */
1774 /*- GETEVT__SUCCESS : success. */
1775 /*- GETEVT__FAILURE : failure */
1776 /*- GETEVT__RDERR : read server or file error */
1777 /*- GETEVT__NOMORE : No more events. */
1778 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
1779 /*+ Declaration : */
1780 /* INTS4 f_evt_skip_buffer(s_evt_channel *, INTS4); */
1781 /*1- C Main ****************+******************************************/
1783 {
1784  INTS4 l_temp;
1785  CHARS * pc_temp;
1786 
1787  pc_temp=(CHARS *)ps_chan->pc_io_buf;
1788  switch(ps_chan->l_server_type)
1789  {
1790  case GETEVT__FILE :
1791  l_temp=lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
1792  if(l_temp == -1)
1793  /* if end of file, then exit */
1794  {
1795  return(GETEVT__NOMORE);
1796  }
1797  break;
1798  case GETEVT__RFIO :
1799  l_temp=RFIO_lseek(ps_chan->l_channel_no,l_buffer*ps_chan->l_buf_size,SEEK_CUR);
1800  if(l_temp == -1)
1801  {
1802  return(GETEVT__NOMORE);
1803  }
1804  break;
1805  case GETEVT__STREAM :
1806  case GETEVT__TRANS :
1807  case GETEVT__REVSERV :
1808  case GETEVT__EVENT :
1809  default : return(GETEVT__FAILURE);
1810  } /* end of switch */
1811 
1812  ps_chan->l_first_get=1; /* so we will first call f_getevt_get */
1813  return(GETEVT__SUCCESS);
1814 } /* end of f_evt_skip_buffer */
1815 
1816 /*1+ C Main ****************+******************************************/
1817 /*+ Module : f_evt_timeout */
1818 /*--------------------------------------------------------------------*/
1819 /*+ CALLING : f_evt_timeout(s_evt_channel *ps_chan, seconds) */
1820 /*--------------------------------------------------------------------*/
1821 /* */
1822 /*+ PURPOSE : Set a timeout for TCP read operations */
1823 /*+ ARGUMENTS : */
1824 /*+ ps_chan : Address of channel structure. */
1825 /*+ seconds : -1: wait (default) */
1826 /* >0: if after n seconds no data arrived, */
1827 /* read functions return GETEVT__TIMEOUT. */
1828 /*+ Return type : INTS4 */
1829 /*+ Declaration : */
1830 /* INTS4 f_evt_timeout(s_evt_channel *, INTS4 ); */
1831 /*+ FUNCTION : Set a timeout for TCP read operations. */
1832 /* The calls of f_evt_get_event, f_evt_get_buffer */
1833 /* will return GETEVT__TIMEOUT when seconds have been */
1834 /* set to positive value. */
1835 /*1- C Main ****************+******************************************/
1837 {
1838  ps_chan->l_timeout = l_sec;
1839  return(GETEVT__SUCCESS);
1840 } /* end of f_evt_timeout */
1841 
1842 /*1- C Main ****************+******************************************/
1843 /*+ Module : f_evt_swap */
1844 /*--------------------------------------------------------------------*/
1845 /*+ CALLING : sts = f_evt_swap(char &c_source[], long l_length) */
1846 /*--------------------------------------------------------------------*/
1847 /* */
1848 /*+ PURPOSE : Long word byte swap. */
1849 /*+ ARGUMENTS : */
1850 /*+ c_source : source data array. */
1851 /*+ l_length : length (in bytes) */
1852 /*+ FUNCTION : Long word byte swap. Works on the source field. */
1853 /*+ Return type : int */
1854 /*+ Status codes: bit 0: success */
1855 /*1- C Procedure ***********+******************************************/
1856 INTS4 f_evt_swap(CHARS * pc_source, INTS4 l_length)
1857 {
1858  CHARS * p_s, * p_d;
1859  INTS4 l_save;
1860  CHARS ch_temp;
1861 
1862  if(l_length%4 == 2){
1863  ch_temp=*(pc_source+l_length-2);
1864  *(pc_source+l_length-2)=*(pc_source+l_length-1);
1865  *(pc_source+l_length-1)=ch_temp;
1866  }
1867  l_length=(l_length/4)*4; /* aligned */
1868  for(p_d=pc_source,p_s=(CHARS *)&l_save; p_d<pc_source+l_length;)
1869  {
1870  l_save = *((INTS4 *)p_d);
1871  p_s += 4; /* increment source */
1872  *(p_d++) = *(--p_s);
1873  *(p_d++) = *(--p_s);
1874  *(p_d++) = *(--p_s);
1875  *(p_d++) = *(--p_s);
1876  }
1877  return(0);
1878 } /* end of f_evt_swap */
1879 /*1- C Main ****************+******************************************/
1880 /*+ Module : f_evt_swap */
1881 /*--------------------------------------------------------------------*/
1882 /*+ CALLING : sts = f_evt_swap_filhe(s_filhe *) */
1883 /*--------------------------------------------------------------------*/
1884 /* */
1885 /*+ PURPOSE : Swap file header. */
1886 /*+ ARGUMENTS : */
1887 /*+ c_source : source data array. */
1888 /*+ l_length : length (in bytes) */
1889 /*+ FUNCTION : Long word byte swap. Works on the source field. */
1890 /*+ Return type : int */
1891 /*+ Status codes: bit 0: success */
1892 /*1- C Procedure ***********+******************************************/
1894 {
1895  INTS4 ii;
1896  INTS2 *pi;
1897  s_filhe *ps_filhe;
1898 
1899  f_evt_swap((CHARS *)ps_bufhe,48);
1900  if(ps_bufhe->i_type == 2000)
1901  {
1902  ps_filhe=(s_filhe *)ps_bufhe;
1903  f_evt_swap((CHARS *)&ps_filhe->filhe_lines,4);/* number of comment lines ps_filhe->filhe_lines*/
1904  ps_filhe->filhe_label_l=ps_filhe->filhe_label_l>>8;
1905  ps_filhe->filhe_file_l =ps_filhe->filhe_file_l >>8;
1906  ps_filhe->filhe_user_l =ps_filhe->filhe_user_l >>8;
1907  ps_filhe->filhe_run_l =ps_filhe->filhe_run_l >>8;
1908  ps_filhe->filhe_exp_l =ps_filhe->filhe_exp_l >>8;
1909  pi=(INTS2 *)&ps_filhe->s_strings;
1910  for(ii=0;ii<ps_filhe->filhe_lines;ii++) {
1911  *pi=*pi>>8;
1912  pi += 40;
1913  }
1914  }
1915 
1916  return(0);
1917 } /* end of f_evt_swap */
1918 
1919 /*1- C Main ****************+******************************************/
1920 /*+ Module : f_evt_get_buffer_ptr */
1921 /*--------------------------------------------------------------------*/
1922 /*+ CALLING : f_evt_get_buffer_ptr(s_evt_channel &s_chan) */
1923 /*--------------------------------------------------------------------*/
1924 /* */
1925 /*+ PURPOSE : f_evt_get_buffer_ptr returns buffer pointer */
1926 /*+ ARGUMENTS : */
1927 /*+ s_chan : structure s_evt_channel. */
1928 /*+ Return type : int. */
1929 /*+ Status codes: */
1930 /*1- C Main ****************+******************************************/
1932 {
1933  return(ps_chan->pc_io_buf);
1934 }
1935 /*1- C Main ****************+******************************************/
1936 /*+ Module : f_evt_get_newbuf */
1937 /*--------------------------------------------------------------------*/
1938 /*+ CALLING : f_evt_get_newbuf(s_evt_channel &s_chan) */
1939 /*--------------------------------------------------------------------*/
1940 /* */
1941 /*+ PURPOSE : f_evt_get_newbuf read a buffer from server */
1942 /*+ ARGUMENTS : */
1943 /*+ s_chan : structure s_evt_channel. */
1944 /*+ Return type : int. */
1945 /*+ Status codes: */
1946 /*- GETEVT__SUCCESS : success. */
1947 /*- GETEVT__FAILURE : failure */
1948 /*- GETEVT__RDERR : read server or file error */
1949 /*- GETEVT__NOMORE : No more events. */
1950 /*- GETEVT__TIMEOUT : when enabled by f_evt_timeout */
1951 /*1- C Main ****************+******************************************/
1953 {
1954  INTS4 l_temp;
1955  CHARS * pc_temp;
1956  INTS4 l_status;
1957 
1958  pc_temp=(CHARS *)ps_chan->pc_io_buf;
1959  switch(ps_chan->l_server_type)
1960  {
1961  case GETEVT__FILE :
1962  while(1){
1963  l_temp=read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
1964  if(l_temp == 0) return(GETEVT__NOMORE);
1965  if(l_temp == -1) return(GETEVT__RDERR);
1966  if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
1967  break; /* skip out while(1) */
1968  } /* end of while(1) */
1969  break;
1970  case GETEVT__STREAM :
1971  if(f_stc_write("GETEVT", 12, ps_chan->l_channel_no)!=STC__SUCCESS)
1972  {
1973  return(GETEVT__FAILURE);
1974  }
1975 
1976  for(l_temp=0; l_temp<ps_chan->l_bufs_in_stream; l_temp++)
1977  {
1978  l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1979  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
1980  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
1981  pc_temp+=ps_chan->l_buf_size;
1982  }
1983  l_temp=((s_bufhe *)(ps_chan->pc_io_buf))->l_evt;
1984  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1) // swap
1985  f_evt_swap((CHARS *)&l_temp,4);
1986  if(l_temp < 0) {// server will shutdown
1987  printf("**** I-f_evt: Stream server request for disconnect!\n");
1988  f_evt_get_close(ps_chan);
1989  return(GETEVT__RDERR);
1990  }
1991  /* if first buffer is empty, all are empty */
1992  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_evt == 0) return(GETEVT__TIMEOUT);
1993  break;
1994  case GETEVT__TRANS :
1995  l_status=f_stc_read(pc_temp, ps_chan->l_buf_size, ps_chan->l_channel_no,ps_chan->l_timeout);
1996  l_temp=((s_bufhe *)(ps_chan->pc_io_buf))->l_evt;
1997  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1) // swap
1998  f_evt_swap((CHARS *)&l_temp,4);
1999  if(l_temp < 0) {// server will shutdown
2000  printf("**** I-f_evt: Transport server request for disconnect!\n");
2001  f_evt_get_close(ps_chan);
2002  return(GETEVT__RDERR);
2003  }
2004  if(l_status == STC__TIMEOUT) return(GETEVT__TIMEOUT);
2005  if(l_status != STC__SUCCESS) return(GETEVT__RDERR);
2006  break;
2007  case GETEVT__RFIO :
2008  l_temp=RFIO_read(ps_chan->l_channel_no,pc_temp, ps_chan->l_io_buf_size);
2009  if(l_temp == 0) return(GETEVT__NOMORE);
2010  if(l_temp == -1) return(GETEVT__RDERR);
2011  if(l_temp < ps_chan->l_io_buf_size)return(GETEVT__RDERR);
2012  break;
2013  case GETEVT__REVSERV :
2014  case GETEVT__EVENT :
2015  default :
2016  return(GETEVT__FAILURE);
2017  } /* end of switch */
2018 
2019  if( ((s_bufhe *)(ps_chan->pc_io_buf))->l_free[0] !=1) // swap
2020  f_evt_swap(ps_chan->pc_io_buf, ps_chan->l_io_buf_size);
2021 
2022  return(GETEVT__SUCCESS);
2023 } /* end of f_evt_get_newbuf */
2024 
2025 /*1- C Main ****************+******************************************/
2026 /*+ Module : f_evt_check_buf */
2027 /*--------------------------------------------------------------------*/
2028 /*+ CALLING : f_evt_check_buf(CHARS *pc_head, INTS4 *pl_goosybuf, */
2029 /* INTS4 *pl_swap, INTS4 *pl_filehead) */
2030 /*--------------------------------------------------------------------*/
2031 /* */
2032 /*+ PURPOSE : check a buffer is a file header or GOOSY buffer, */
2033 /* and whether it's swaped. */
2034 /*+ ARGUMENTS : */
2035 /*+ pc_head : pointer to the buffer to be checked. */
2036 /*+ pl_goosybuf : 1 is goosy buffer, 0 is header */
2037 /*+ pl_swap : 1 means different endian, 0 means same endian. */
2038 /*+ pl_filehead : 1 means first buffer is header */
2039 /*+ Return type : void */
2040 /*+ Status codes: */
2041 /*+ FUNCTION : check a buffer is a file header or GOOSY buffer, */
2042 /* and whether it's swaped. */
2043 /*1- C Main ****************+******************************************/
2044 INTS4 f_evt_check_buf(CHARS *pc_head, INTS4 *pl_size, INTS4 *pl_is_goosybuf, INTS4 *pl_swap, INTS4 *pl_filehead)
2045 {
2046  INTU4 l_size;
2047 
2048  *pl_is_goosybuf=0;
2049  *pl_filehead=0;
2050  *pl_size=0;
2051  *pl_swap=0;
2052  /* first check if it's file header */
2053  if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
2054  (((s_filhe *)(pc_head))->filhe_type==2000) )
2055  {
2056  *pl_swap=0;
2057  *pl_is_goosybuf=0;
2058  *pl_filehead=1;
2059  l_size=((s_bufhe *)(pc_head))->l_dlen*2;
2060  if(l_size%512 > 0) l_size += sizeof(s_bufhe);
2061  if((l_size>>24) > 0) *pl_size=0;
2062  else *pl_size=l_size;
2063  return(PUTEVT__SUCCESS);
2064  }
2065  f_evt_swap(pc_head, sizeof(s_filhe));
2066  if( (((s_filhe *)(pc_head))->filhe_subtype==1)&&
2067  (((s_filhe *)(pc_head))->filhe_type==2000) )
2068  {
2069  *pl_swap=1;
2070  *pl_is_goosybuf=0;
2071  *pl_filehead=1;
2072  l_size=((s_bufhe *)(pc_head))->l_dlen*2;
2073  if(l_size%512 > 0) l_size += sizeof(s_bufhe);
2074  if((l_size>>24) > 0) *pl_size=0;
2075  else *pl_size=l_size;
2076  return(PUTEVT__SUCCESS);
2077  }
2078 
2079  /* if not file header, check if it's goosy buffer header */
2080  l_size=((s_bufhe *)(pc_head))->l_dlen*2;
2081  if(l_size%512 > 0) l_size += sizeof(s_bufhe);
2082  if( (((l_size>>24)== 0)&&(l_size > 0))&&
2083  (((s_bufhe *)(pc_head))->h_begin<2)&&
2084  (((s_bufhe *)(pc_head))->h_begin>=0)&&
2085  (((s_bufhe *)(pc_head))->h_end<2)&&
2086  (((s_bufhe *)(pc_head))->h_end>=0)&&
2087  //(((s_bufhe *)(pc_head))->i_used<=(MAX_BUF_LGTH-sizeof(s_bufhe))/2)&&
2088  ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2]>0))&&
2089  //(((s_bufhe *)(pc_head))->i_used>0)&&
2090  ( (((s_bufhe *)(pc_head))->l_free[0]==1)||
2091  (((s_bufhe *)(pc_head))->l_free[0]==0)||
2092 /* above, because some old lsm file forgot to set this bit, so it's zero */
2093  (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
2094  {
2095  *pl_swap=1; /* !!!, because already swaped once */
2096  *pl_is_goosybuf=1;
2097  *pl_size=l_size;
2098  return(PUTEVT__SUCCESS);
2099  }
2100  f_evt_swap(pc_head, sizeof(s_filhe));
2101  l_size=((s_bufhe *)(pc_head))->l_dlen*2+sizeof(s_bufhe);
2102  if( (((l_size>>24)== 0)&&(l_size > 0))&&
2103  (((s_bufhe *)(pc_head))->l_dlen>0)&&
2104  (((s_bufhe *)(pc_head))->h_begin<2)&&
2105  (((s_bufhe *)(pc_head))->h_begin>=0)&&
2106  (((s_bufhe *)(pc_head))->h_end<2)&&
2107  (((s_bufhe *)(pc_head))->h_end>=0)&&
2108  //(((s_bufhe *)(pc_head))->i_used<=(MAX_BUF_LGTH-sizeof(s_bufhe))/2)&&
2109  ((((s_bufhe *)(pc_head))->i_used>0)||(((s_bufhe *)(pc_head))->l_free[2]>0))&&
2110  //(((s_bufhe *)(pc_head))->i_used>0)&&
2111  ( (((s_bufhe *)(pc_head))->l_free[0]==1)||
2112  (((s_bufhe *)(pc_head))->l_free[0]==0)||
2113 /* above, because some old lsm file forgot to set this bit, so it's zero */
2114  (((s_bufhe *)(pc_head))->l_free[0]==256*256*256) ) )
2115  {
2116  *pl_swap=0; /* !!!, because already swaped 2 times */
2117  *pl_is_goosybuf=1;
2118  *pl_size=l_size;
2119  return(PUTEVT__SUCCESS);
2120  }
2121  return(PUTEVT__SUCCESS);
2122 } /* end of f_evt_check_buf */
2123 
2124 /*1- C Main ****************+******************************************/
2125 /*+ Module : f_evt_ini_bufhe */
2126 /*--------------------------------------------------------------------*/
2127 /*+ CALLING : f_evt_ini_bufhe(s_evt_channel *ps_chan) */
2128 /*--------------------------------------------------------------------*/
2129 /* */
2130 /*+ PURPOSE : pre-fill each GOOSY buffer header in a stream */
2131 /*+ ARGUMENTS : */
2132 /*+ ps_chan : Address of channel structure. */
2133 /*+ Return type : void . */
2134 /*1- C Main ****************+******************************************/
2136 {
2137  INTS4 l_temp;
2138  struct timespec s_timespec;
2139 
2140  /* because "timeb" is not "typedef", so we must use "struct" */
2141 
2142  for(l_temp=0; l_temp<ps_chan->l_io_buf_size; l_temp += ps_chan->l_buf_size)
2143  {
2144  ps_chan->ps_bufhe=(s_bufhe *)(ps_chan->pc_io_buf + l_temp);
2145  ps_chan->ps_bufhe->l_dlen = (ps_chan->l_buf_size - sizeof(s_bufhe))/2;
2146  ps_chan->ps_bufhe->i_subtype = ps_chan->l_buf_subtype;
2147  ps_chan->ps_bufhe->i_type = ps_chan->l_buf_type;
2148  ps_chan->ps_bufhe->h_begin = 0;
2149  ps_chan->ps_bufhe->h_end = 0;
2150  ps_chan->ps_bufhe->i_used = 0;
2151  ps_chan->ps_bufhe->l_buf = ps_chan->l_buf_no; ps_chan->l_buf_no++;
2152  ps_chan->ps_bufhe->l_evt = 0;
2153  ps_chan->ps_bufhe->l_current_i = 0;
2154  clock_gettime(CLOCK_REALTIME, &s_timespec);
2155  ps_chan->ps_bufhe->l_time[0] = (INTS4) s_timespec.tv_sec;
2156  ps_chan->ps_bufhe->l_time[1] = (INTS4) s_timespec.tv_nsec/1000000;
2157  ps_chan->ps_bufhe->l_free[0] = 1; /* for swap flag */
2158  ps_chan->ps_bufhe->l_free[1] = 0;
2159  ps_chan->ps_bufhe->l_free[2] = 0;
2160  ps_chan->ps_bufhe->l_free[3] = 0;
2161  }
2162  return(PUTEVT__SUCCESS);
2163 } /* end of f_evt_ini_bufhe */
2164 
2165 /*1+ C Main ****************+******************************************/
2166 /*+ Module : f_evt_cre_tagfile */
2167 /*--------------------------------------------------------------------*/
2168 /*+ CALLING : f_evt_cre_tagfile(lmdfile,tagfile,filter) */
2169 /*--------------------------------------------------------------------*/
2170 /* */
2171 /*+ PURPOSE : Create a tag file from lmd file */
2172 /*+ ARGUMENTS : */
2173 /*+ lmdfile : LMD file name */
2174 /*+ tagfile : tag file name */
2175 /*+ filter : optional function for filter */
2176 /*+ Return type : INTS4 . */
2177 /*+ Status codes: */
2178 /*- GETEVT__SUCCESS : success. */
2179 /*- GETEVT__NOFILE : file does not exist. */
2180 /*- GETEVT__TAGWRERR : tag file write error. */
2181 /*- GETEVT__RDERR : lmd read error. */
2182 /*+ Declaration : */
2183 /* INTS4 f_evt_cre_tagfile(CHARS *,CHARS *, INTS4 (*)()); */
2184 /*+ FUNCTION : Create a tag file from lmd file */
2185 /*+ filter : The filter function is called at the beginning */
2186 /* with a NULL as argument, then for each event */
2187 /* with the event pointer. Returning 0 skips the event, */
2188 /* 1 takes the event into the tag file. */
2189 /* Different tag files can be created from one lmd file. */
2190 /*1- C Main ****************+******************************************/
2192 {
2193  /* take it */
2194 return(1);
2195 //if(ps_ve10_1 != NULL)
2196 //{
2197 // printf("Filter %9d Type/Subtype %5d %5d Length %5d[w] Trigger %2d\n",
2198 // ps_ve10_1->l_count,
2199 // ps_ve10_1->i_type,
2200 // ps_ve10_1->i_subtype,
2201 // ps_ve10_1->l_dlen,
2202 // ps_ve10_1->i_trigger);
2203 // if(ps_ve10_1->l_count%2) return(1); /* take it */
2204 // else return(0); /* skip it */
2205 //}
2206 //else printf("Initialized filter function\n");
2207 // return(0);
2208 }
2209 INTS4 f_evt_cre_tagfile(CHARS *pc_lmd, CHARS *pc_tag,INTS4 (*e_filter)())
2210 {
2211  INTS4 ii,l_take_it,l_temp,l_chan,l_out,l_file_pos=0,l_bufnr=0,l_events=0;
2212  INTS4 l_firste,*pl,l_len,l_last=-1,l_lin=0,l_fragsize;
2213  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;
2214  INTU4 *ps,*pd;
2215  CHARS *pc_evt_buf=NULL;
2216  s_ve10_1 *ps_ve10_1;
2217  s_bufhe *ps_bufhe;
2218  s_taghe s_taghe;
2219  s_tag s_tag;
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==0) || (*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,*pl,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;
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:64
#define GETEVT__NOSERVER
Definition: f_evt.h:144
INTS2 filhe_file_l
Definition: s_filhe.h:69
INTS4 l_last
Definition: f_evt.h:48
INTS4 f_evt_rev_port(INTS4 l_port)
Definition: f_evt.c:513
int f_evcli_evt(s_evt_channel *ps_chan)
Definition: f_evcli.c:480
CHARS h_end
Definition: s_bufhe.h:48
#define PUTEVT__SUCCESS
Definition: f_evt.h:155
#define GETEVT__SUCCESS
Definition: f_evt.h:139
CHARS filhe_file[86]
Definition: s_filhe.h:70
INTS4 l_channel_no
Definition: f_evt.h:66
#define PUTEVT__CLOSE_ERR
Definition: f_evt.h:160
s_tag * ps_tag
Definition: f_evt.h:96
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:239
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
Definition: f_stccomm.c:1093
CHARS * pc_evt_buf
Definition: f_evt.h:87
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:302
INTS4 f_evt_tag_filter(s_ve10_1 *ps_ve10_1)
Definition: f_evt.c:2191
INTS4 l_first_buf
Definition: f_evt.h:84
#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:44
#define LMD__LARGE_FILE
Definition: sMbs.h:28
INTS4 f_evt_get_close(s_evt_channel *ps_chan)
Definition: f_evt.c:1104
#define GETEVT__TIMEOUT
Definition: f_evt.h:148
INTS4 l_lmdswap
Definition: f_evt.h:94
CHARS h_subcrate
Definition: s_ves10_1.h:41
sLmdControl * pLmd
Definition: f_evt.h:97
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:556
s_bufhe s_bufhe_1
Definition: f_evt.h:89
INTS4 f_evt_get_buffer(s_evt_channel *ps_chan, INTS4 *ps_buffer)
Definition: f_evt.c:1696
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:82
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:1836
#define MAX_BUF_LGTH
Definition: f_evt.h:34
#define GETEVT__NOCHANNEL
Definition: f_evt.h:147
s_bufhe * ps_bufhe
Definition: f_evt.h:88
#define GETEVT__NOFILE
Definition: f_evt.h:143
#define PORT__TRANSPORT
Definition: portnum_def.h:19
INTS4 l_buf_size
Definition: f_evt.h:67
INTS4 f_evt_put_event(s_evt_channel *ps_chan, INTS4 *pl_evt_buf)
Definition: f_evt.c:1308
Definition: s_evhe.h:32
#define PUTEVT__TOOBIG
Definition: f_evt.h:158
s_evt_channel * f_evt_control()
Definition: f_evt.c:2819
#define GETEVT__FAILURE
Definition: f_evt.h:140
INTS2 filhe_subtype
Definition: s_filhe.h:59
#define GETEVT__TAGWRERR
Definition: f_evt.h:152
INTS2 i_subtype
Definition: s_bufhe.h:46
INTS4 l_bufs_in_stream
Definition: f_evt.h:71
INTS2 i_type
Definition: s_ve10_1.h:38
#define GETEVT__NOLMDFILE
Definition: f_evt.h:153
uint32_t fLmdGetMbsEvent(sLmdControl *pLmdControl, sMbsHeader **event)
Definition: fLmd.c:322
INTS4 filhe_lines
Definition: s_filhe.h:78
INTS2 i_procid
Definition: s_ves10_1.h:40
int f_evcli_close(s_evt_channel *ps_chan)
Definition: f_evcli.c:499
#define RFIO_lseek
Definition: f_evt.c:154
INTS2 i_type
Definition: s_evhe.h:35
INTS4 f_evt_source_port(INTS4 l_port)
Definition: f_evt.c:490
INTS4 l_first_put
Definition: f_evt.h:83
#define RFIO_open
Definition: f_evt.c:151
INTS4 f_evt_error(INTS4 l_error, CHARS *pc_dest, INTS4 l_out)
Definition: f_evt.c:1589
#define GETEVT__EVENT
Definition: f_evt.h:131
uint32_t fLmdGetElement(sLmdControl *pLmdControl, uint32_t iEvent, sMbsHeader **event)
Definition: fLmd.c:606
int l
Definition: f_mbs_status.c:34
#define GETEVT__NOMORE
Definition: f_evt.h:142
#define MIN_BUF_LGTH
Definition: f_evt.h:35
INTS4 l_filesize
Definition: f_evt.h:46
#define PUTEVT__FAILURE
Definition: f_evt.h:157
INTS4 l_buf_no
Definition: f_evt.h:68
s_taghe * ps_taghe
Definition: f_evt.h:95
INTS2 filhe_type
Definition: s_filhe.h:58
CHARS * pc_io_buf
Definition: f_evt.h:86
#define STC__TIMEOUT
Definition: f_stccomm.h:374
INTS4 f_stc_discclient(INTS4 i_channel)
Definition: f_stccomm.c:1174
CHARS * f_evt_get_buffer_ptr(s_evt_channel *ps_chan)
Definition: f_evt.c:1931
#define GETEVT__NOTAGFILE
Definition: f_evt.h:149
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:284
uint32_t fLmdPutClose(sLmdControl *pLmdControl)
Definition: fLmd.c:253
static int l_gl_source_port
Definition: f_evt.c:181
uint32_t fLmdGetClose(sLmdControl *pLmdControl)
Definition: fLmd.c:686
INTS4 l_evt_buf_posi
Definition: f_evt.h:76
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:55
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:386
#define GETEVT__NOTAG
Definition: f_evt.h:150
#define STC__SUCCESS
Definition: f_stccomm.h:369
#define MAX_LONG
Definition: f_evt.h:37
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:145
INTS2 filhe_user_l
Definition: s_filhe.h:71
#define GETEVT__TRANS
Definition: f_evt.h:130
INTS4 l_stream_bufs
Definition: f_evt.h:72
INTS4 l_first
Definition: f_evt.h:47
INTS4 f_evt_get_newbuf(s_evt_channel *)
Definition: f_evt.c:1952
int l_status
Definition: f_evcli.c:185
INTS4 l_tagswap
Definition: f_evt.h:93
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:2044
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:92
INTS4 f_evt_ini_bufhe(s_evt_channel *ps_chan)
Definition: f_evt.c:2135
#define GETEVT__FRAGMENT
Definition: f_evt.h:141
INTS4 l_version
Definition: f_evt.h:42
#define PUTEVT__TOO_SMALLS
Definition: f_evt.h:159
INTS2 i_subtype
Definition: s_evhe.h:36
#define PUTEVT__WRERR
Definition: f_evt.h:161
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:39
#define RFIO_close
Definition: f_evt.c:152
static CHARS c_temp[MAX_BUF_LGTH]
Definition: f_evt.c:180
INTS4 l_endian
Definition: f_evt.h:41
#define GETEVT__REVSERV
Definition: f_evt.h:132
INTS4 l_evt_size
Definition: f_evt.h:77
uint32_t fLmdGetOpen(sLmdControl *pLmdControl, char *Filename, sMbsFileHeader *pBuffHead, uint32_t iBytes, uint32_t iUseOffset)
Definition: fLmd.c:404
INTS4 f_evt_cre_tagfile(CHARS *pc_lmd, CHARS *pc_tag, INTS4(*e_filter)())
Definition: f_evt.c:2209
INTS2 i_trigger
Definition: s_ve10_1.h:41
#define PUTEVT__FILE_EXIST
Definition: f_evt.h:156
INTS2 filhe_label_l
Definition: s_filhe.h:67
CHARS c_channel[128]
Definition: f_evt.h:91
INTS4 f_evt_put_buffer(s_evt_channel *ps_chan, s_bufhe *ps_bufhe)
Definition: f_evt.c:1451
#define PORT__EVENT_SERV
Definition: portnum_def.h:22
INTS4 l_events
Definition: f_evt.h:45
INTS4 l_frag_len
Definition: f_evt.h:85
INTS4 l_bufsize
Definition: f_evt.h:43
uint32_t fLmdCloseMbs(sLmdControl *pLmdControl)
Definition: fLmd.c:305
INTS4 f_evt_skip_buffer(s_evt_channel *ps_chan, INTS4 l_buffer)
Definition: f_evt.c:1782
#define PUTEVT__NOCHANNEL
Definition: f_evt.h:162
INTS4 l_timeout
Definition: f_evt.h:78
static struct s_tcpcomm s_tcpcomm_st_evt
Definition: f_evt.c:179
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
sLmdControl * fLmdAllocateControl()
Definition: fLmd.c:769
INTS4 l_io_buf_size
Definition: f_evt.h:73
INTS2 filhe_run_l
Definition: s_filhe.h:74
INTS4 f_evt_put_close(s_evt_channel *ps_chan)
Definition: f_evt.c:1496
INTS4 l_current_i
Definition: s_bufhe.h:52
INTS4 f_evt_swap(CHARS *pc_source, INTS4 l_length)
Definition: f_evt.c:1856
INTS4 l_buf_posi
Definition: f_evt.h:69
#define PORT__STREAM_SERV
Definition: portnum_def.h:21
uint32_t fLmdPutElement(sLmdControl *pLmdControl, sMbsHeader *pHeader)
Definition: fLmd.c:145
Definition: f_evt.h:52
#define LMD__TYPE_FILE_HEADER_101_1
Definition: sMbs.h:17
#define RFIO_read
Definition: f_evt.c:153
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
INTS2 i_type
Definition: s_ves10_1.h:38
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:160
#define GETLMD__NOBUFFER
Definition: fLmd.h:32
INTS4 l_linear
Definition: f_evt.h:49
#define GETEVT__TAGRDERR
Definition: f_evt.h:151
INTS4 l_event
Definition: f_evt.h:54
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:1195
char CHARS
Definition: typedefs.h:21
void(* cb_polling)()
Definition: f_evt.h:98
INTS4 filhe_free[4]
Definition: s_filhe.h:66
INTS4 l_buf_subtype
Definition: f_evt.h:65
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:913
INTS2 i_used
Definition: s_bufhe.h:47
uint32_t fLmdPutBuffer(sLmdControl *pLmdControl, sMbsHeader *pHeader, uint32_t Items)
Definition: fLmd.c:204
#define GETEVT__FILE
Definition: f_evt.h:128
s_ve10_1 * ps_ve10_1
Definition: f_evt.h:90
#define GETEVT__RFIO
Definition: f_evt.h:133
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:201
INTS2 i_subtype
Definition: s_ves10_1.h:39
#define GETEVT__STREAM
Definition: f_evt.h:129
INTS4 f_evt_swap_filhe(s_bufhe *)
Definition: f_evt.c:1893
#define GETEVT__CLOSE_ERR
Definition: f_evt.h:146
INTS4 l_count
Definition: s_ve10_1.h:42
INTS4 l_io_buf_posi
Definition: f_evt.h:74
INTS4 l_evt_buf_size
Definition: f_evt.h:75
CHARS h_control
Definition: s_ves10_1.h:42
INTS4 l_server_type
Definition: f_evt.h:63
INTS4 l_buf_lmt
Definition: f_evt.h:70