StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
L2BinEvent.cxx
1 #include <stdio.h>
2 #include <string.h>
3 #include <assert.h>
4 /*********************************************************************
5  * $Id: L2BinEvent.cxx,v 1.2 2010/04/18 06:05:32 pibero Exp $
6  * \author Jan Balewski, IUCF, 2006
7  *********************************************************************
8  * Descripion:
9  * binary dump of TRIG, BTOW & ETOW data
10  *********************************************************************
11  */
12 
13 #include "L2BinEvent.h"
14 
15 //===============================
16 //===============================
17 L2BinEvent::L2BinEvent() {
18  // nop
19 }
20 
21 //===============================
22 //===============================
23 int
24 L2BinEvent::read(struct BinEveContainer* eve,FILE *fd, int dbg){
25  assert(eve);
26  assert(fd);
27 
28  //................ clear old event
29  memset(eve->lenA,0,sizeof(eve->lenA));
30  memset(eve->mHEAD,':',sizeof(eve->mHEAD));
31  memset(eve->mBTOW_BANK,0,sizeof(eve->mBTOW_BANK));
32  memset(eve->mETOW_BANK,0,sizeof(eve->mETOW_BANK));
33  memset(eve->mTrigData ,0,sizeof(eve->mTrigData));
34  eve->mBTOW_in=eve->mETOW_in=0;
35  //.............. read new event
36 
37  unsigned int i;
38  char *c;
39  c=(char *)eve->lenA;
40  for(i=0;i<sizeof(eve->lenA);i++) c[i]=fgetc(fd);
41  if(dbg) for(i=0;i<4;i++) printf("lenA[%d]=%d\n",i,eve->lenA[i]);
42 
43 
44  if(eve->lenA[0]> sizeof(eve->mHEAD)) return -10;
45  if(eve->lenA[1]> sizeof(eve-> mTrigData))return -11;
46  if(eve->lenA[2]> sizeof(eve->mBTOW_BANK))return -12;
47  if(eve->lenA[3]> sizeof(eve->mETOW_BANK))return -13;
48 
49 
50  c=(char *)eve->mHEAD;
51  for(i=0;i<eve->lenA[0];i++) c[i]=fgetc(fd);
52 
53  c=(char *)eve->mTrigData;
54  for(i=0;i<eve->lenA[1];i++) c[i]=fgetc(fd);
55 
56  c=(char *)eve->mBTOW_BANK;
57  for(i=0;i<eve->lenA[2];i++) c[i]=fgetc(fd);
58 
59  c=(char *)eve->mETOW_BANK;
60  for(i=0;i<eve->lenA[3];i++) c[i]=fgetc(fd);
61 
62 
63  char EOE[5];
64  for(i=0;i<4;i++) EOE[i]=fgetc(fd);
65  EOE[4]=0; // terminate this string
66  if(!strstr(EOE,"EofE")) return -1;
67  assert(strstr(EOE,"EofE")); // end of events marker
68 
69  eve->mBTOW_in=eve->lenA[2]>0;
70  eve->mETOW_in=eve->lenA[3]>0;
71 
72  if(dbg) printf("head='%s'\nBTOW_in=%d, ETOW_in=%d \n",eve->mHEAD,eve->mBTOW_in,eve->mETOW_in);
73  return 0;
74 }
75 
76 
77 //===============================
78 //===============================
79 void
80 L2BinEvent::write(char* headText, int trgLen, void * trgData,
81  int bemcLen, unsigned short *bemcData,
82  int eemcLen, unsigned short *eemcData,
83  FILE *binFd){
84  assert(binFd);
85 
86  BinEveContainer eve; // only partially used
87 
88  // collect record length
89 
90  eve.lenA[0]=sizeof(eve.mHEAD);
91  eve.lenA[1]=trgLen; //sizeof(TrgDataType);
92  eve.lenA[2]=bemcLen;
93  eve.lenA[3]=eemcLen;
94 
95  // ready to write
96  unsigned int i;
97 
98  const char *c=(char*)eve.lenA;
99  for(i=0;i< sizeof(eve.lenA);i++) fputc(c[i],binFd);
100 
101  c=(char*)headText;
102  for(i=0;i<eve.lenA[0];i++) fputc(c[i],binFd);
103 
104  c=(char*) trgData;
105  for(i=0;i<eve.lenA[1];i++) fputc(c[i],binFd);
106 
107  c=(char*)bemcData;
108  for(i=0;i< eve.lenA[2];i++) fputc(c[i],binFd);
109 
110  c=(char*)eemcData;
111  for(i=0;i<eve.lenA[3];i++) fputc(c[i],binFd);
112 
113  c="EofE";
114  for(i=0;i<4;i++) fputc(c[i],binFd); // end of events marker
115 
116 }
117 
118 /*
119 *********************************************************************
120  $Log: L2BinEvent.cxx,v $
121  Revision 1.2 2010/04/18 06:05:32 pibero
122  Address compiler warnings.
123 
124  Revision 1.1 2007/10/11 00:33:12 balewski
125  L2algo added
126 
127  Revision 1.2 2006/03/11 17:08:32 balewski
128  now CVS comments should work
129 
130 */
131