Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fakeFrame.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file fakeFrame.C
1 /*
2 ** fakeFrame.C
3 **
4 ** Author: $Author: dave $
5 ** Date: $Date: 2003/03/01 20:14:42 $
6 **
7 ** $Log: fakeFrame.C,v $
8 ** Revision 1.2 2003/03/01 20:14:42 dave
9 ** Put ifdef DEBUG around Debug_Output call instead of trying to define the call itself as a macro
10 **
11 ** Revision 1.1.1.1 2000/07/21 01:51:12 purschke
12 ** mlp -- adding the new automakified "basic" module to CVS.
13 **
14 **
15 ** Revision 1.6 1999/09/29 22:16:07 steinber
16 ** mods to bring afs to nevis1 version
17 **
18 ** Revision 1.4 1998/12/11 22:02:01 markacs
19 ** (stephen markacs) adding log into cvs tags
20 **
21 */
22 
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <malloc.h>
26 #include "phenixOnline.h"
27 #include "fakeFrame.h"
28 #include "Cframe.h"
29 #include "CframeV1.h"
30 #include "packetRoutines.h"
31 #include "frameRoutines.h"
32 #include "framePublic.h"
33 #include "formatIO.h"
34 
35 #define BUFFER_SIZE 65536
36 
38  PHDWORD* frame_ptr,
39  int bufferSize,
40  UINT sourceId,
41  ALIGNBLK alignBlk,
42  int number_of_packets,
43  int packet_ids[],
44  int packet_lengths[],
45  int historySize,
46  int errorSize
47  )
48 {
49  int remainingSpace;
50 
51  int total_frame_size;
52  int maxFrameLen;
53  PHDWORD* write_ptr;
54 
55  // int total_data_words;
56  PHDWORD data_arr[BUFFER_SIZE];
57  UINT addr_arr[BUFFER_SIZE];
58  int packetLength;
59  int numBytes;
60 
61  int err;
62  int i,j;
63  int historyBlockSize;
64 
65  // Set registers and clear data buffer
66 
67  maxFrameLen = BUFFER_SIZE;
68  dwordClear(&data_arr,BUFFER_SIZE);
69 
70  if ( (err = makeFrameHdr(frame_ptr,maxFrameLen,0x1,0x1, sourceId)) != 0 ){
71  printf("FakeFrame: makeFrameHdr failed\n");
72  return(-1);
73  }
74 
75  setAlignBlock(frame_ptr,(PHDWORD*) &alignBlk,2);
76 
77  write_ptr = findFrameEnd(frame_ptr)+1;
78 
79  for (i = 0; i<number_of_packets;i++)
80  {
81 
82  remainingSpace = bufferSize - (int) (write_ptr - frame_ptr);
83  //printf("Remaining space = %d\n",remainingSpace);
84  makeUnstructPacket(write_ptr,
85  remainingSpace,
86  packet_ids[i], //packetId
87  sizeof(PHDWORD), //wordSize
88  0 //hitformat
89  );
90 
91 // numBytes = packet_lengths[i] * sizeof(PHDWORD);
92 
93  numBytes = packet_lengths[i] ; // number of "words", actually
94 
95  for (j=0; j<packet_lengths[i];j++){
96 // data_arr[j]=packet_ids[i];
97  data_arr[j]=j;
98  }
99 
100  packetLength = storePacketHits(
101  write_ptr,
102  remainingSpace,
103  addr_arr,
104  (BYTE*) &data_arr,
105  numBytes,
106  0
107  );
108  extendFrameDataNopad(frame_ptr,bufferSize,packetLength);
109 #ifdef DEBUG
110  Debug_Output("Packet %2d : Length = %d Total=%d\n",
111  i,packetLength,getFrameDataLength(frame_ptr));
112 #endif
113  write_ptr += packetLength;
114  }
115 
116  // printf("1: Frame data length: %d\n",getFrameDataLength(frame_ptr));
117  remainingSpace = bufferSize - (int) (write_ptr - frame_ptr);
118  historyBlockSize = storeFrameHistory(frame_ptr,
119  remainingSpace,
120  (PHDWORD*) &data_arr,
121  historySize);
122  // printf("2: Frame data length: %d\n",getFrameDataLength(frame_ptr));
123  write_ptr += historyBlockSize;
124 
125  /*
126  printf("Frame lengths: Header,Data,History = %d, %d, %d\n",
127  getFrameHdrLength(frame_ptr),
128  getFrameDataLength(frame_ptr),
129  getFrameHistoryLength(frame_ptr)
130  );
131  */
132 
133  total_frame_size = getFrameLength(frame_ptr);
134 
135  return total_frame_size;
136 
137 }
138 
140  PHDWORD* frame_ptr,
141  int total_frame_size,
142  int length_of_buffer,
143  PHDWORD* start_of_buffer[]
144  )
145 {
146  int i,j;
147  int number_of_buffers;
148  PHDWORD* write_ptr;
149  PHDWORD* write_ptr_buf;
150  write_ptr = frame_ptr;
151 
152  number_of_buffers = total_frame_size / length_of_buffer + 1;
153 
154  for (i=0;i<number_of_buffers;i++){
155  start_of_buffer[i] = (PHDWORD*) malloc(4*length_of_buffer);
156  write_ptr_buf = start_of_buffer[i];
157 
158  for (j=0 ; j<length_of_buffer ; j++){
159  *write_ptr_buf = *write_ptr;
160  write_ptr++;
161  write_ptr_buf++;
162  }
163  }
164 
165  /*
166  printf("\nFrame header from start_buffer[0]\n");
167  dumpFrameHdr(start_of_buffer[0]);
168  printf("\n");
169  */
170 
171  return number_of_buffers;
172 
173 }
174 
175 
176